From 0131c31c74c0a71dca4b02b4eccf09134fb6ee92 Mon Sep 17 00:00:00 2001 From: heikodanielbraun Date: Sat, 4 Nov 2023 19:46:31 +0100 Subject: [PATCH] shrink apart from last loop --- edmonds.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/edmonds.cpp b/edmonds.cpp index 3449fa2..0574a31 100644 --- a/edmonds.cpp +++ b/edmonds.cpp @@ -67,10 +67,49 @@ Graph maximum_matching(Graph & graph) else { // Paths are not disjoint -> shrink blossom + size_t distance_from_x = x_path.size() - 1; + size_t distance_from_y = y_path.size() - 1; + while (x_path[distance_from_x] == y_path[distance_from_y]) + { + --distance_from_x; + --distance_from_y; + } + // found first vertex of x_path \cap y_path + do + { + ++distance_from_x; + ++distance_from_y; + } while (graph.root_of_ear_component(x_path[distance_from_x] != x_path[distance_from_x])); + // found first vertex fixed by root_of_ear_component + size_t x_position_of_blossom_root = distance_from_x + 1; + size_t y_position_of_blossom_root = distance_from_y + 1; + NodeId blossom_root = x_path[x_position_of_blossom_root]; + for(size_t i = 1; i <= x_position_of_blossom_root; i += 2) + { + if (graph.root_of_ear_component(graph.ear_or_root_neighbor(x_path[i])) != x_path[i]) + { + graph.node(graph.ear_or_root_neighbor(x_path[i])).ear_or_root_neighbor = x_path[i]; + } + } + for(size_t i = 1; i <= y_position_of_blossom_root; i += 2) + { + if (graph.root_of_ear_component(graph.ear_or_root_neighbor(y_path[i])) != y_path[i]) + { + graph.node(graph.ear_or_root_neighbor(y_path[i])).ear_or_root_neighbor = y_path[i]; + } + } + if (graph.root_of_ear_component(x_path.front()) != blossom_root) + { + graph.node(x_path.front()).ear_or_root_neighbor = y_path.front(); + } + if (graph.root_of_ear_component(y_path.front()) != blossom_root) + { + graph.node(x_path.front()).ear_or_root_neighbor = x_path.front(); + } } } } } } }; -} \ No newline at end of file +}