better integrity check

This commit is contained in:
Maximilian Keßler 2023-11-06 22:03:48 +01:00
parent 497d601ffc
commit 6418c17413
Signed by: max
GPG key ID: BCC5A619923C0BA5

View file

@ -8,10 +8,28 @@ using namespace ED;
namespace Edmonds { 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) 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 // Check that μ encodes a valid matching
NodeId matched = attrs.mu[id]; NodeId matched = attrs.mu[id];
if(matched != id) if(matched != id)
@ -22,13 +40,13 @@ void check_integrity(GraphAttributes & attrs)
if (attrs.is_out_of_forest(id)) if (attrs.is_out_of_forest(id))
{ {
assert(attrs.phi[id] == id); assert(attrs.phi[id] == id);
assert(attrs.rho(id) == id); assert(get_rho(attrs, id) == id);
} }
else else
{ {
// check for a path to the root, i.e. ρ(node) // check for a path to the root, i.e. ρ(node)
NodeId cur_node = id; 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 // If the condition was true, then cur_node is outer, part of a blossom
// and we want to follow its path // 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 // and point to vertices that have the same rho
assert(attrs.mu[cur_node] != cur_node); assert(attrs.mu[cur_node] != cur_node);
assert(attrs.phi[cur_node] != cur_node); assert(attrs.phi[cur_node] != cur_node);
assert(attrs.rho(attrs.mu[cur_node]) == attrs.rho(cur_node)); assert(get_rho(attrs,attrs.mu[cur_node]) == get_rho(attrs,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));
// now, walk along the matched edge // now, walk along the matched edge
cur_node = attrs.mu[cur_node]; cur_node = attrs.mu[cur_node];
@ -46,7 +64,7 @@ void check_integrity(GraphAttributes & attrs)
// - not be the identity // - not be the identity
// - result in a node that has the same rho // - result in a node that has the same rho
assert(attrs.phi[cur_node] != cur_node); 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]]; cur_node = attrs.mu[attrs.phi[cur_node]];
} }
@ -54,7 +72,7 @@ void check_integrity(GraphAttributes & attrs)
if (not attrs.is_outer(id)) if (not attrs.is_outer(id))
{ {
assert(attrs.rho(id) == id); assert(get_rho(attrs,id) == id);
} }
} }
} }