JuliaGraphs / LightGraphsExtras.jl

Additional functionality for LightGraphs.jl
Other
21 stars 13 forks source link

Matching: iteration over edges as tuples fails #28

Closed matbesancon closed 6 years ago

matbesancon commented 6 years ago

While running the tests for matching:

g = CompleteGraph(3)
w =Dict{Edge,Float64}()
w[Edge(1,2)] = 1
@test_throws ErrorException maximum_weight_matching(g,w)

This throws a MethodError before it reaches the ErrorException:

ERROR: MethodError: no method matching start(::LightGraphs.SimpleGraphs.SimpleEdge{Int64})

This is due to the iteration over a collection of edges as a collection of tuples which is not supported.

maximum_weight_matching.jl (line 31-36)

    # put the edge weights in w in the right order to be compatible with edge_list
    for (i,j) in keys(w)
      if i >= j && !haskey(w, j=>i) # replace i=>j by j=>i if necessary.
        w[Edge(j,i)] = w[Edge(i,j)]
      end
    end

How to reproduce the error:

edges = [LightGraphs.Edge(3,4), LightGraphs.Edge(4,3)]
for (i, j) in edges
       println(i)
end
ERROR: MethodError: no method matching start(::LightGraphs.SimpleGraphs.SimpleEdge{Int64})