From e9baa88c70a1721636b8842860fe0b4b1a3eda48 Mon Sep 17 00:00:00 2001 From: Joris van Rantwijk Date: Sun, 9 Jun 2024 19:49:02 +0200 Subject: [PATCH] Fix bug in delta2 tracking --- python/mwmatching.py | 6 ++++++ python/test_mwmatching.py | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/python/mwmatching.py b/python/mwmatching.py index 787df39..4d33824 100644 --- a/python/mwmatching.py +++ b/python/mwmatching.py @@ -1051,6 +1051,7 @@ class _MatchingContext: assert blossom.parent is None assert blossom.label == _LABEL_T + assert blossom.delta2_node is None # Remove expanded blossom from the delta4 queue. assert blossom.delta4_node is not None @@ -1131,6 +1132,11 @@ class _MatchingContext: assert blossom.parent is 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. blossom.vertex_set.split() diff --git a/python/test_mwmatching.py b/python/test_mwmatching.py index c106c10..05a3a68 100644 --- a/python/test_mwmatching.py +++ b/python/test_mwmatching.py @@ -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)]), [(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): """bad input values""" with self.assertRaises(TypeError):