Skip to content

induced_subgraph does not preserve weights for edge lists. #32

@simonschoelly

Description

@simonschoelly

Description of bug
When creating an edge induced subgraph of a SimpleWeightedGraph with weights different from one, these weights are not preserved. This is in contrast to a vertex induced subgraph, where this works correctly.

How to reproduce
Detail steps to reproduce the behavior.

Expected behavior

julia> g = SimpleWeightedGraph([0 2; 2 0])
{2, 1} undirected simple Int64 graph with Int64 weights

julia> weights(g)
2×2 SparseArrays.SparseMatrixCSC{Int64, Int64} with 2 stored entries:
   2
 2  

# vertex induced subgraph
julia> weights(first(induced_subgraph(g, [1,2])))
2×2 SparseArrays.SparseMatrixCSC{Int64, Int64} with 2 stored entries:
   2
 2  

# edge induced subgraph
julia> weights(first(induced_subgraph(g, [Edge(1,2)])))
2×2 SparseArrays.SparseMatrixCSC{Int64, Int64} with 2 stored entries:
   1
 1  

The entries in the last spare matrix should also be two, but have been set to the default value of 1.

Version information
Julia: v1.8
Graphs.jl: v1.7.4
SimpleWeightedGraphs: v1.2.1

Additional context
src/overrides.jl contains a specialized version of induced_subgraph for vertex lists, but not for edge list - so we probably have to implement that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions