shrink apart from last loop
This commit is contained in:
parent
e568e298f0
commit
0131c31c74
1 changed files with 40 additions and 1 deletions
41
edmonds.cpp
41
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue