1
0
Fork 0

Fix bug in delta2 tracking

This commit is contained in:
Joris van Rantwijk 2024-06-09 19:49:02 +02:00
parent 73479532ac
commit e9baa88c70
2 changed files with 18 additions and 0 deletions

View File

@ -1051,6 +1051,7 @@ class _MatchingContext:
assert blossom.parent is None assert blossom.parent is None
assert blossom.label == _LABEL_T assert blossom.label == _LABEL_T
assert blossom.delta2_node is None
# Remove expanded blossom from the delta4 queue. # Remove expanded blossom from the delta4 queue.
assert blossom.delta4_node is not None assert blossom.delta4_node is not None
@ -1131,6 +1132,11 @@ class _MatchingContext:
assert blossom.parent is None assert blossom.parent is None
assert blossom.label == _LABEL_NONE assert blossom.label == _LABEL_NONE
# Remove blossom from delta2 heap.
assert blossom.delta2_node is not None
self.delta2_queue.delete(blossom.delta2_node)
blossom.delta2_node = None
# Split union-find structure. # Split union-find structure.
blossom.vertex_set.split() blossom.vertex_set.split()

View File

@ -243,6 +243,18 @@ class TestMaximumWeightMatching(unittest.TestCase):
mwm([(1,2,19), (1,4,17), (1,5,19), (2,3,15), (2,5,21), (4,6,18), (4,7,11), (5,6,19)]), mwm([(1,2,19), (1,4,17), (1,5,19), (2,3,15), (2,5,21), (4,6,18), (4,7,11), (5,6,19)]),
[(1,5), (2,3), (4,6)]) [(1,5), (2,3), (4,6)])
def test61_triangles_n9(self):
"""t.f 9 nodes"""
#
# [1]------[4] [7]
# | \ | \ | \
# | [3] | [6] | [9]
# | / | / | /
# [2] [5]------[8]
#
result = mwm([(1,2,1), (1,3,1), (2,3,1), (4,5,1), (4,6,1), (5,6,1), (7,8,1), (7,9,1), (8,9,1), (1,4,1), (5,8,1)])
self.assertEqual(len(result), 4)
def test_fail_bad_input(self): def test_fail_bad_input(self):
"""bad input values""" """bad input values"""
with self.assertRaises(TypeError): with self.assertRaises(TypeError):