From da3b25f2951e306316b2001abea97f1f4deeec33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sun, 5 Nov 2023 17:08:00 +0100 Subject: [PATCH] add some debug checks --- src/edmonds.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/edmonds.cpp b/src/edmonds.cpp index b88ad04..f7dbaf8 100644 --- a/src/edmonds.cpp +++ b/src/edmonds.cpp @@ -5,6 +5,23 @@ using namespace ED; 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 * 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()) { + check_integrity(graph); + std::cout << "Check passed" << std::endl; if (graph.is_out_of_forest(neighbor_id)) { + std::cout << "Grow forest" << std::endl; // Grow Forest 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()) { + std::cout << "Augment" << std::endl; // Paths are disjoint -> augment graph.node(x_path.front()).matched_neighbor = y_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 // new stack frames in OPT mode - maximum_matching_from_initial_matching(graph); - return; + graph.reset_forest(); + break; } else { + std::cout << "Contract blossom" << std::endl; // Paths are not disjoint -> shrink blossom size_t distance_from_x = x_path.size() - 1; size_t distance_from_y = y_path.size() - 1;