Store μ,φ,ρ in nodes

Also, add simple property checkers whether nodes are
inner/outer/out-of-forest.
This commit is contained in:
Maximilian Keßler 2023-11-04 17:26:17 +01:00
parent 174777396a
commit 4a332be0e7
Signed by: max
GPG key ID: BCC5A619923C0BA5
2 changed files with 53 additions and 0 deletions

View file

@ -178,4 +178,22 @@ std::ostream & operator<<(std::ostream & output, Graph const & graph)
return output; return output;
} }
bool Graph::is_outer(NodeId const id) const {
return matched_neighbor(id) == id or \
ear_or_root_neighbor(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);
}
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);
}
} // namespace ED } // namespace ED

View file

@ -69,6 +69,7 @@ using size_type = uint32_t;
* Note the same Id may be used by different graphs though! * Note the same Id may be used by different graphs though!
*/ */
using NodeId = size_type; using NodeId = size_type;
constexpr NodeId invalid_node_id = std::numeric_limits<NodeId>::max();
/** /**
@class Node @class Node
@ -103,6 +104,9 @@ private:
void add_neighbor(NodeId const id); void add_neighbor(NodeId const id);
std::vector<NodeId> _neighbors; std::vector<NodeId> _neighbors;
NodeId _matched_neighbor {invalid_node_id};
NodeId _ear_or_root_neighbor {invalid_node_id};
NodeId _root_of_ear_component {invalid_node_id};
}; // class Node }; // class Node
/** /**
@ -159,6 +163,18 @@ public:
@brief Prints the graph to the given ostream in DIMACS format. @brief Prints the graph to the given ostream in DIMACS format.
**/ **/
friend std::ostream & operator<<(std::ostream & str, Graph const & graph); friend std::ostream & operator<<(std::ostream & str, Graph const & graph);
NodeId matched_neighbor(NodeId const id) const;
NodeId ear_or_root_neighbor(NodeId const id) const;
NodeId root_of_ear_component(NodeId const id) const;
bool is_outer(NodeId const id) const;
bool is_inner(NodeId const id) const;
bool is_out_of_forest(NodeId const id) const;
private: private:
std::vector<Node> _nodes; std::vector<Node> _nodes;
size_type _num_edges; size_type _num_edges;
@ -206,6 +222,25 @@ Node const & Graph::node(NodeId const id) const
} }
//END: Inline section //END: Inline section
inline
NodeId Graph::matched_neighbor(NodeId const id) const
{
return _nodes[id]._matched_neighbor;
}
inline
NodeId Graph::ear_or_root_neighbor(const ED::NodeId id) const
{
return _nodes[id]._ear_or_root_neighbor;
}
inline
NodeId Graph::root_of_ear_component(const ED::NodeId id) const
{
return _nodes[id]._root_of_ear_component;
}
} // namespace ED } // namespace ED
#endif /* GRAPH_HPP */ #endif /* GRAPH_HPP */