add some debug checks

This commit is contained in:
Maximilian Keßler 2023-11-05 17:08:00 +01:00
parent 57ed5cf593
commit da3b25f295
Signed by: max
GPG key ID: BCC5A619923C0BA5

View file

@ -5,6 +5,23 @@ using namespace ED;
namespace Edmonds { namespace Edmonds {
void check_integrity(Graph const & graph)
{
for(NodeId id = 0; id < graph.num_nodes(); ++id)
{
NodeId matched = graph.matched_neighbor(id);
if(matched != id)
{
assert(graph.matched_neighbor(matched) == id);
}
if (not graph.is_outer(id))
{
assert(graph.root_of_ear_component(id) == id);
}
}
}
/** /**
* @return List of vertices of the x-r path, where r is the root of the * @return List of vertices of the x-r path, where r is the root of the
* special blossom forest component x belongs to. * special blossom forest component x belongs to.
@ -51,8 +68,11 @@ void maximum_matching_from_initial_matching(Graph & graph)
{ {
for(NodeId neighbor_id : graph.node(id).neighbors()) for(NodeId neighbor_id : graph.node(id).neighbors())
{ {
check_integrity(graph);
std::cout << "Check passed" << std::endl;
if (graph.is_out_of_forest(neighbor_id)) if (graph.is_out_of_forest(neighbor_id))
{ {
std::cout << "Grow forest" << std::endl;
// Grow Forest // Grow Forest
graph.node(neighbor_id).ear_or_root_neighbor = id; graph.node(neighbor_id).ear_or_root_neighbor = id;
} }
@ -64,6 +84,7 @@ void maximum_matching_from_initial_matching(Graph & graph)
if (x_path.back() != y_path.back()) if (x_path.back() != y_path.back())
{ {
std::cout << "Augment" << std::endl;
// Paths are disjoint -> augment // Paths are disjoint -> augment
graph.node(x_path.front()).matched_neighbor = y_path.front(); graph.node(x_path.front()).matched_neighbor = y_path.front();
graph.node(y_path.front()).matched_neighbor = x_path.front(); graph.node(y_path.front()).matched_neighbor = x_path.front();
@ -81,11 +102,12 @@ void maximum_matching_from_initial_matching(Graph & graph)
} }
// Note that since this is tail-recursion, this will not generate // Note that since this is tail-recursion, this will not generate
// new stack frames in OPT mode // new stack frames in OPT mode
maximum_matching_from_initial_matching(graph); graph.reset_forest();
return; break;
} }
else else
{ {
std::cout << "Contract blossom" << std::endl;
// 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_x = x_path.size() - 1;
size_t distance_from_y = y_path.size() - 1; size_t distance_from_y = y_path.size() - 1;