diff --git a/src/edmonds.cpp b/src/edmonds.cpp index fa378ba..e9db6f0 100644 --- a/src/edmonds.cpp +++ b/src/edmonds.cpp @@ -8,10 +8,28 @@ using namespace ED; namespace Edmonds { -void check_integrity(GraphAttributes & attrs) +NodeId get_rho(GraphAttributes const & attrs, NodeId id) +{ + while(attrs.rho_[id] != id) + { + id = attrs.rho_[id]; + } + return id; +} + +void check_integrity(GraphAttributes const & attrs) { for(NodeId id = 0; id < attrs.num_nodes(); ++id) { + // Check that rho does not have any cycles + NodeId cur_rho_id = id; + size_t count = attrs.num_nodes(); + while(attrs.rho_[cur_rho_id] != cur_rho_id and count--) + { + cur_rho_id = attrs.rho_[cur_rho_id]; + } + assert(count != 0); + // Check that μ encodes a valid matching NodeId matched = attrs.mu[id]; if(matched != id) @@ -22,13 +40,13 @@ void check_integrity(GraphAttributes & attrs) if (attrs.is_out_of_forest(id)) { assert(attrs.phi[id] == id); - assert(attrs.rho(id) == id); + assert(get_rho(attrs, id) == id); } else { // check for a path to the root, i.e. ρ(node) NodeId cur_node = id; - while(cur_node != attrs.rho(cur_node)) + while(cur_node != get_rho(attrs, cur_node)) { // If the condition was true, then cur_node is outer, part of a blossom // and we want to follow its path @@ -36,8 +54,8 @@ void check_integrity(GraphAttributes & attrs) // and point to vertices that have the same rho assert(attrs.mu[cur_node] != cur_node); assert(attrs.phi[cur_node] != cur_node); - assert(attrs.rho(attrs.mu[cur_node]) == attrs.rho(cur_node)); - assert(attrs.rho(attrs.phi[cur_node]) == attrs.rho(cur_node)); + assert(get_rho(attrs,attrs.mu[cur_node]) == get_rho(attrs,cur_node)); + assert(get_rho(attrs,attrs.phi[cur_node]) == get_rho(attrs,cur_node)); // now, walk along the matched edge cur_node = attrs.mu[cur_node]; @@ -46,7 +64,7 @@ void check_integrity(GraphAttributes & attrs) // - not be the identity // - result in a node that has the same rho assert(attrs.phi[cur_node] != cur_node); - assert(attrs.rho(attrs.phi[cur_node]) == attrs.rho(cur_node)); + assert(get_rho(attrs, attrs.phi[cur_node]) == get_rho(attrs,cur_node)); cur_node = attrs.mu[attrs.phi[cur_node]]; } @@ -54,7 +72,7 @@ void check_integrity(GraphAttributes & attrs) if (not attrs.is_outer(id)) { - assert(attrs.rho(id) == id); + assert(get_rho(attrs,id) == id); } } }