Skip to content

Commit 780a555

Browse files
committed
Fix the matching invariance
1 parent 064d588 commit 780a555

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/bipartite_graph.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ end
6363
function Base.setindex!(m::Matching{U}, v::Union{Integer, U}, i::Integer) where {U}
6464
if m.inv_match !== nothing
6565
oldv = m.match[i]
66+
# TODO: maybe default Matching to always have an `inv_match`?
67+
68+
# To maintain the invariant that `m.inv_match[m.match[i]] == i`, we need
69+
# to unassign the matching at `m.inv_match[v]` if it exists.
70+
if v isa Int && (iv = m.inv_match[v]) isa Int
71+
m.match[iv] = unassigned
72+
end
6673
if isa(oldv, Int)
6774
@assert m.inv_match[oldv] == i
6875
m.inv_match[oldv] = unassigned

0 commit comments

Comments
 (0)