File tree 1 file changed +5
-10
lines changed
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(
107
107
) where {U<: Real }
108
108
109
109
h = deepcopy (g)
110
- iter = collect (edges (h))
110
+ # collect needed since we modify the edges later
111
+ edge_iter = collect (edges (h))
111
112
l = nv (h)
112
113
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
115
116
add_edge! (h, src (edge) + l, dst (edge) + l)
116
117
weights[edge] = - w[src (edge), dst (edge)]
117
118
weights[Edge (dst (edge), src (edge))] = - w[src (edge), dst (edge)]
@@ -125,13 +126,7 @@ function maximum_weight_matching_reduction(
125
126
126
127
match = minimum_weight_perfect_matching (h, weights)
127
128
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 ]
135
130
136
131
return result
137
132
end
You can’t perform that action at this time.
0 commit comments