rename functions

This commit is contained in:
Maximilian Keßler 2023-11-05 17:09:06 +01:00
parent da3b25f295
commit c972fc309c
Signed by: max
GPG key ID: BCC5A619923C0BA5
3 changed files with 31 additions and 32 deletions

View file

@ -17,7 +17,7 @@ void check_integrity(Graph const & graph)
if (not graph.is_outer(id))
{
assert(graph.root_of_ear_component(id) == id);
assert(graph.rho(id) == id);
}
}
}
@ -42,7 +42,7 @@ std::vector<NodeId> path_to_forest_root(Graph const & graph, NodeId id)
// We are traversing the path to a root of the forest,
// but we know that each root is exposed by M, so after traversing
// the matching edge, we cannot have reached a root.
id = graph.ear_or_root_neighbor(id);
id = graph.phi(id);
retval.push_back(id);
}
return retval;
@ -74,10 +74,9 @@ void maximum_matching_from_initial_matching(Graph & graph)
{
std::cout << "Grow forest" << std::endl;
// Grow Forest
graph.node(neighbor_id).ear_or_root_neighbor = id;
graph.node(neighbor_id).phi = id;
}
else if (graph.is_outer(neighbor_id) and \
graph.root_of_ear_component(id) != graph.root_of_ear_component(neighbor_id))
else if (graph.is_outer(neighbor_id) and graph.rho(id) != graph.rho(neighbor_id))
{
std::vector<NodeId> x_path = path_to_forest_root(graph, id);
std::vector<NodeId> y_path = path_to_forest_root(graph, neighbor_id);
@ -118,44 +117,44 @@ void maximum_matching_from_initial_matching(Graph & graph)
--distance_from_y;
}
// found first vertex of x_path \cap y_path
while (graph.root_of_ear_component(x_path[distance_from_x]) != x_path[distance_from_x])
while (graph.rho(x_path[distance_from_x]) != x_path[distance_from_x])
{
++distance_from_x;
++distance_from_y;
};
// found first vertex fixed by root_of_ear_component
// found first vertex fixed by rho
NodeId blossom_root_id = x_path[distance_from_x];
for(size_t i = 1; i <= distance_from_x; i += 2)
{
if (graph.root_of_ear_component(graph.ear_or_root_neighbor(x_path[i])) != blossom_root_id)
if (graph.rho(graph.phi(x_path[i])) != blossom_root_id)
{
graph.node(graph.ear_or_root_neighbor(x_path[i])).ear_or_root_neighbor = x_path[i];
graph.node(graph.phi(x_path[i])).phi = x_path[i];
}
}
for(size_t i = 1; i <= distance_from_y; i += 2)
{
if (graph.root_of_ear_component(graph.ear_or_root_neighbor(y_path[i])) != blossom_root_id)
if (graph.rho(graph.phi(y_path[i])) != blossom_root_id)
{
graph.node(graph.ear_or_root_neighbor(y_path[i])).ear_or_root_neighbor = y_path[i];
graph.node(graph.phi(y_path[i])).phi = y_path[i];
}
}
if (graph.root_of_ear_component(x_path.front()) != blossom_root_id)
if (graph.rho(x_path.front()) != blossom_root_id)
{
graph.node(x_path.front()).ear_or_root_neighbor = y_path.front();
graph.node(x_path.front()).phi = y_path.front();
}
if (graph.root_of_ear_component(y_path.front()) != blossom_root_id)
if (graph.rho(y_path.front()) != blossom_root_id)
{
graph.node(x_path.front()).ear_or_root_neighbor = x_path.front();
graph.node(x_path.front()).phi = x_path.front();
}
// Update root indices
for(size_t i = 0; i <= distance_from_x; ++i)
{
graph.node(x_path[i]).root_of_ear_component = blossom_root_id;
graph.node(x_path[i]).rho = blossom_root_id;
}
for(size_t i = 0; i <= distance_from_y; ++i)
{
graph.node(y_path[i]).root_of_ear_component = blossom_root_id;
graph.node(y_path[i]).rho = blossom_root_id;
}
}
}

View file

@ -178,28 +178,28 @@ std::ostream & operator<<(std::ostream & output, Graph const & graph)
bool Graph::is_outer(NodeId const id) const {
return matched_neighbor(id) == id or \
ear_or_root_neighbor(matched_neighbor(id)) != matched_neighbor(id);
phi(matched_neighbor(id)) != matched_neighbor(id);
}
bool Graph::is_inner(NodeId const id) const
{
return ear_or_root_neighbor(id) != id and \
ear_or_root_neighbor(matched_neighbor(id)) == matched_neighbor(id);
return phi(id) != id and \
phi(matched_neighbor(id)) == matched_neighbor(id);
}
bool Graph::is_out_of_forest(const ED::NodeId id) const
{
return matched_neighbor(id) != id and \
ear_or_root_neighbor(id) == id and \
ear_or_root_neighbor(matched_neighbor(id)) == matched_neighbor(id);
phi(id) == id and \
phi(matched_neighbor(id)) == matched_neighbor(id);
}
void Graph::reset_forest()
{
NodeId cur_id = 0;
for(auto & node : _nodes) {
node.ear_or_root_neighbor = cur_id;
node.root_of_ear_component = cur_id;
node.phi = cur_id;
node.rho = cur_id;
node.scanned = false;
// Note that we do not change the matching itself here
++cur_id;

View file

@ -93,8 +93,8 @@ public:
public:
NodeId matched_neighbor {invalid_node_id};
NodeId ear_or_root_neighbor {invalid_node_id};
NodeId root_of_ear_component {invalid_node_id};
NodeId phi {invalid_node_id};
NodeId rho {invalid_node_id};
bool scanned;
private:
@ -172,9 +172,9 @@ public:
NodeId matched_neighbor(NodeId const id) const;
NodeId ear_or_root_neighbor(NodeId const id) const;
NodeId phi(NodeId const id) const;
NodeId root_of_ear_component(NodeId const id) const;
NodeId rho(NodeId const id) const;
bool is_outer(NodeId const id) const;
@ -247,17 +247,17 @@ NodeId Graph::matched_neighbor(NodeId const id) const
}
inline
NodeId Graph::ear_or_root_neighbor(const ED::NodeId id) const
NodeId Graph::phi(const NodeId id) const
{
assert(id <= num_nodes());
return _nodes[id].ear_or_root_neighbor;
return _nodes[id].phi;
}
inline
NodeId Graph::root_of_ear_component(const ED::NodeId id) const
NodeId Graph::rho(const NodeId id) const
{
assert(id <= num_nodes());
return _nodes[id].root_of_ear_component;
return _nodes[id].rho;
}
} // namespace ED