rename functions
This commit is contained in:
parent
da3b25f295
commit
c972fc309c
3 changed files with 31 additions and 32 deletions
|
@ -17,7 +17,7 @@ void check_integrity(Graph const & graph)
|
||||||
|
|
||||||
if (not graph.is_outer(id))
|
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,
|
// We are traversing the path to a root of the forest,
|
||||||
// but we know that each root is exposed by M, so after traversing
|
// but we know that each root is exposed by M, so after traversing
|
||||||
// the matching edge, we cannot have reached a root.
|
// the matching edge, we cannot have reached a root.
|
||||||
id = graph.ear_or_root_neighbor(id);
|
id = graph.phi(id);
|
||||||
retval.push_back(id);
|
retval.push_back(id);
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -74,10 +74,9 @@ void maximum_matching_from_initial_matching(Graph & graph)
|
||||||
{
|
{
|
||||||
std::cout << "Grow forest" << std::endl;
|
std::cout << "Grow forest" << std::endl;
|
||||||
// Grow Forest
|
// 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 \
|
else if (graph.is_outer(neighbor_id) and graph.rho(id) != graph.rho(neighbor_id))
|
||||||
graph.root_of_ear_component(id) != graph.root_of_ear_component(neighbor_id))
|
|
||||||
{
|
{
|
||||||
std::vector<NodeId> x_path = path_to_forest_root(graph, id);
|
std::vector<NodeId> x_path = path_to_forest_root(graph, id);
|
||||||
std::vector<NodeId> y_path = path_to_forest_root(graph, neighbor_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;
|
--distance_from_y;
|
||||||
}
|
}
|
||||||
// found first vertex of x_path \cap y_path
|
// 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_x;
|
||||||
++distance_from_y;
|
++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];
|
NodeId blossom_root_id = x_path[distance_from_x];
|
||||||
for(size_t i = 1; i <= distance_from_x; i += 2)
|
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)
|
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
|
// Update root indices
|
||||||
for(size_t i = 0; i <= distance_from_x; ++i)
|
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)
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,28 +178,28 @@ std::ostream & operator<<(std::ostream & output, Graph const & graph)
|
||||||
|
|
||||||
bool Graph::is_outer(NodeId const id) const {
|
bool Graph::is_outer(NodeId const id) const {
|
||||||
return matched_neighbor(id) == id or \
|
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
|
bool Graph::is_inner(NodeId const id) const
|
||||||
{
|
{
|
||||||
return ear_or_root_neighbor(id) != id and \
|
return phi(id) != id and \
|
||||||
ear_or_root_neighbor(matched_neighbor(id)) == matched_neighbor(id);
|
phi(matched_neighbor(id)) == matched_neighbor(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Graph::is_out_of_forest(const ED::NodeId id) const
|
bool Graph::is_out_of_forest(const ED::NodeId id) const
|
||||||
{
|
{
|
||||||
return matched_neighbor(id) != id and \
|
return matched_neighbor(id) != id and \
|
||||||
ear_or_root_neighbor(id) == id and \
|
phi(id) == id and \
|
||||||
ear_or_root_neighbor(matched_neighbor(id)) == matched_neighbor(id);
|
phi(matched_neighbor(id)) == matched_neighbor(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graph::reset_forest()
|
void Graph::reset_forest()
|
||||||
{
|
{
|
||||||
NodeId cur_id = 0;
|
NodeId cur_id = 0;
|
||||||
for(auto & node : _nodes) {
|
for(auto & node : _nodes) {
|
||||||
node.ear_or_root_neighbor = cur_id;
|
node.phi = cur_id;
|
||||||
node.root_of_ear_component = cur_id;
|
node.rho = cur_id;
|
||||||
node.scanned = false;
|
node.scanned = false;
|
||||||
// Note that we do not change the matching itself here
|
// Note that we do not change the matching itself here
|
||||||
++cur_id;
|
++cur_id;
|
||||||
|
|
|
@ -93,8 +93,8 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NodeId matched_neighbor {invalid_node_id};
|
NodeId matched_neighbor {invalid_node_id};
|
||||||
NodeId ear_or_root_neighbor {invalid_node_id};
|
NodeId phi {invalid_node_id};
|
||||||
NodeId root_of_ear_component {invalid_node_id};
|
NodeId rho {invalid_node_id};
|
||||||
bool scanned;
|
bool scanned;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -172,9 +172,9 @@ public:
|
||||||
|
|
||||||
NodeId matched_neighbor(NodeId const id) const;
|
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;
|
bool is_outer(NodeId const id) const;
|
||||||
|
|
||||||
|
@ -247,17 +247,17 @@ NodeId Graph::matched_neighbor(NodeId const id) const
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
NodeId Graph::ear_or_root_neighbor(const ED::NodeId id) const
|
NodeId Graph::phi(const NodeId id) const
|
||||||
{
|
{
|
||||||
assert(id <= num_nodes());
|
assert(id <= num_nodes());
|
||||||
return _nodes[id].ear_or_root_neighbor;
|
return _nodes[id].phi;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
NodeId Graph::root_of_ear_component(const ED::NodeId id) const
|
NodeId Graph::rho(const NodeId id) const
|
||||||
{
|
{
|
||||||
assert(id <= num_nodes());
|
assert(id <= num_nodes());
|
||||||
return _nodes[id].root_of_ear_component;
|
return _nodes[id].rho;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ED
|
} // namespace ED
|
||||||
|
|
Loading…
Reference in a new issue