From 99bc2912d857255556fc8052a8e31e8afc4d8793 Mon Sep 17 00:00:00 2001 From: Joris van Rantwijk Date: Mon, 6 Feb 2023 09:04:43 +0100 Subject: [PATCH] Fix wrong assumption about subblossom labels When a blossom forms, the labels of sub-blossoms do NOT strictly alternate between S and T when walking around the blossom. --- python/max_weight_matching.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/python/max_weight_matching.py b/python/max_weight_matching.py index 2591169..a6deb08 100644 --- a/python/max_weight_matching.py +++ b/python/max_weight_matching.py @@ -753,11 +753,12 @@ def _make_blossom( # Former T-vertices which are part of this blossom have now become # S-vertices. Add them to the queue. - for sub in subblossoms[1::2]: - if sub < num_vertex: - stage_data.queue.append(sub) - else: - stage_data.queue.extend(matching.blossom_vertices(sub)) + for sub in subblossoms: + if stage_data.blossom_label[sub] == _LABEL_T: + if sub < num_vertex: + stage_data.queue.append(sub) + else: + stage_data.queue.extend(matching.blossom_vertices(sub)) # Calculate the set of least-slack edges to other S-blossoms. # We basically merge the edge lists from all sub-blossoms, but reject @@ -780,7 +781,9 @@ def _make_blossom( 0 for b in range(2 * num_vertex)] # Add the least-slack edges of every S-sub-blossom. - for sub in subblossoms[0::2]: + for sub in subblossoms: + if stage_data.blossom_label[sub] != _LABEL_S: + continue if sub < num_vertex: # Trivial blossoms don't have a list of least-slack edges, # so we just look at all adjacent edges. This happens at most @@ -1072,7 +1075,7 @@ def _find_path_through_blossom( # ^^^ ^^^ # <------------------- # - # We must flip edges from (v,w) to (w,v) to make them fit + # We flip edges from (v,w) to (w,v) to make them fit # in the path from "s" to base. edges.append(blossom.edges[i-1][::-1]) nodes.append(blossom.subblossoms[i-1])