shrink apart from last loop

This commit is contained in:
heikodanielbraun 2023-11-04 19:46:31 +01:00
parent e568e298f0
commit 0131c31c74

View file

@ -67,6 +67,45 @@ Graph maximum_matching(Graph & graph)
else else
{ {
// Paths are not disjoint -> shrink blossom // 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();
}
} }
} }
} }