shrink: bug fixes
This commit is contained in:
parent
c162b92e8c
commit
bfcf885e8f
1 changed files with 23 additions and 12 deletions
35
edmonds.cpp
35
edmonds.cpp
|
@ -77,43 +77,54 @@ Graph maximum_matching_from_initial_matching(Graph & graph)
|
|||
// 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])
|
||||
while (distance_from_x > 0 and distance_from_y > 0 and \
|
||||
x_path[distance_from_x - 1] == y_path[distance_from_y - 1])
|
||||
{
|
||||
--distance_from_x;
|
||||
--distance_from_y;
|
||||
}
|
||||
// found first vertex of x_path \cap y_path
|
||||
do
|
||||
while (graph.root_of_ear_component(x_path[distance_from_x]) != x_path[distance_from_x])
|
||||
{
|
||||
++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)
|
||||
NodeId const blossom = x_path[distance_from_x];
|
||||
|
||||
NodeId blossom_root_id = x_path[distance_from_x];
|
||||
for(size_t i = 1; i <= distance_from_x; i += 2)
|
||||
{
|
||||
if (graph.root_of_ear_component(graph.ear_or_root_neighbor(x_path[i])) != x_path[i])
|
||||
if (graph.root_of_ear_component(graph.ear_or_root_neighbor(x_path[i])) != blossom_root_id)
|
||||
{
|
||||
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)
|
||||
for(size_t i = 1; i <= distance_from_y; i += 2)
|
||||
{
|
||||
if (graph.root_of_ear_component(graph.ear_or_root_neighbor(y_path[i])) != y_path[i])
|
||||
if (graph.root_of_ear_component(graph.ear_or_root_neighbor(y_path[i])) != blossom_root_id)
|
||||
{
|
||||
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)
|
||||
if (graph.root_of_ear_component(x_path.front()) != blossom_root_id)
|
||||
{
|
||||
graph.node(x_path.front()).ear_or_root_neighbor = y_path.front();
|
||||
}
|
||||
if (graph.root_of_ear_component(y_path.front()) != blossom_root)
|
||||
if (graph.root_of_ear_component(y_path.front()) != blossom_root_id)
|
||||
{
|
||||
graph.node(x_path.front()).ear_or_root_neighbor = x_path.front();
|
||||
}
|
||||
|
||||
// Update root indices
|
||||
for(size_t i = 0; i <= distance_from_x; ++i)
|
||||
{
|
||||
graph.node(x_path[i]).root_of_ear_component = blossom_root_id;
|
||||
}
|
||||
for(size_t i = 0; i <= distance_from_y; ++i)
|
||||
{
|
||||
graph.node(y_path[i]).root_of_ear_component = blossom_root_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue