Skip to content

Commit b231d30

Browse files
committed
slight changes
1 parent 5166341 commit b231d30

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/maximum_weight_matching.jl

+5-10
Original file line numberDiff line numberDiff 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
137132
end

0 commit comments

Comments
 (0)