From c972fc309cd5a5426360db8eb9d3b0179651f902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sun, 5 Nov 2023 17:09:06 +0100 Subject: [PATCH] rename functions --- src/edmonds.cpp | 33 ++++++++++++++++----------------- src/graph.cpp | 14 +++++++------- src/graph.hpp | 16 ++++++++-------- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/edmonds.cpp b/src/edmonds.cpp index f7dbaf8..50b1529 100644 --- a/src/edmonds.cpp +++ b/src/edmonds.cpp @@ -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 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 x_path = path_to_forest_root(graph, id); std::vector 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; } } } diff --git a/src/graph.cpp b/src/graph.cpp index 59dbee9..2f94593 100644 --- a/src/graph.cpp +++ b/src/graph.cpp @@ -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; diff --git a/src/graph.hpp b/src/graph.hpp index 2d8d1b1..2a7387f 100644 --- a/src/graph.hpp +++ b/src/graph.hpp @@ -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