File tree Expand file tree Collapse file tree 1 file changed +5
-10
lines changed Expand file tree Collapse file tree 1 file changed +5
-10
lines changed Original file line number Diff line number Diff line change @@ -107,11 +107,12 @@ function maximum_weight_matching_reduction(
107107) where {U<: Real }
108108
109109 h = deepcopy (g)
110- iter = collect (edges (h))
110+ # collect needed since we modify the edges later
111+ edge_iter = collect (edges (h))
111112 l = nv (h)
112113 add_vertices! (h, l)
113- weights = Dict {typeof(iter[1]),typeof(w[1][1] )} ()
114- for edge in iter
114+ weights = Dict {edgetype(g), eltype(w )} ()
115+ for edge in edge_iter
115116 add_edge! (h, src (edge) + l, dst (edge) + l)
116117 weights[edge] = - w[src (edge), dst (edge)]
117118 weights[Edge (dst (edge), src (edge))] = - w[src (edge), dst (edge)]
@@ -125,13 +126,7 @@ function maximum_weight_matching_reduction(
125126
126127 match = minimum_weight_perfect_matching (h, weights)
127128
128- result = Edge[]
129-
130- for i = 1 : l
131- if (match. mate[i] <= l && match. mate[i] > 0 )
132- push! (result, Edge (i, match. mate[i]))
133- end
134- end
129+ result = [Edge (i, match. mate[i]) for i in 1 : l if match. mate[i] <= l && match. mate[i] > 0 ]
135130
136131 return result
137132end
You can’t perform that action at this time.
0 commit comments