more checks

This commit is contained in:
Maximilian Keßler 2023-11-05 17:38:43 +01:00
parent c972fc309c
commit 7c36caa505
Signed by: max
GPG Key ID: BCC5A619923C0BA5

View File

@ -9,12 +9,46 @@ void check_integrity(Graph const & graph)
{
for(NodeId id = 0; id < graph.num_nodes(); ++id)
{
// Check that μ encodes a valid matching
NodeId matched = graph.matched_neighbor(id);
if(matched != id)
{
assert(graph.matched_neighbor(matched) == id);
}
if (graph.is_out_of_forest(id))
{
assert(graph.phi(id) == id);
assert(graph.rho(id) == id);
}
else
{
// check for a path to the root, i.e. ρ(node)
NodeId cur_node = id;
while(cur_node != graph.rho(cur_node))
{
// If the condition was true, then cur_node is outer, part of a blossom
// and we want to follow its path
// therefore, we check that both φ and μ are not the identity on this node
// and point to vertices that have the same rho
assert(graph.matched_neighbor(cur_node) != cur_node);
assert(graph.phi(cur_node) != cur_node);
assert(graph.rho(graph.matched_neighbor(cur_node)) == graph.rho(cur_node));
assert(graph.rho(graph.phi(cur_node)) == graph.rho(cur_node));
// now, walk along the matched edge
cur_node = graph.matched_neighbor(cur_node);
// now we want to walk along φ, this will again
// - not be the identity
// - result in a node that has the same rho
assert(graph.phi(cur_node) != cur_node);
assert(graph.rho(graph.phi(cur_node)) == graph.rho(cur_node));
cur_node = graph.matched_neighbor(graph.phi(cur_node));
}
}
if (not graph.is_outer(id))
{
assert(graph.rho(id) == id);