Store μ,φ,ρ in nodes
Also, add simple property checkers whether nodes are inner/outer/out-of-forest.
This commit is contained in:
parent
174777396a
commit
4a332be0e7
2 changed files with 53 additions and 0 deletions
18
graph.cpp
18
graph.cpp
|
@ -178,4 +178,22 @@ std::ostream & operator<<(std::ostream & output, Graph const & graph)
|
|||
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
|
||||
|
|
35
graph.hpp
35
graph.hpp
|
@ -69,6 +69,7 @@ using size_type = uint32_t;
|
|||
* Note the same Id may be used by different graphs though!
|
||||
*/
|
||||
using NodeId = size_type;
|
||||
constexpr NodeId invalid_node_id = std::numeric_limits<NodeId>::max();
|
||||
|
||||
/**
|
||||
@class Node
|
||||
|
@ -103,6 +104,9 @@ private:
|
|||
void add_neighbor(NodeId const id);
|
||||
|
||||
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
|
||||
|
||||
/**
|
||||
|
@ -159,6 +163,18 @@ public:
|
|||
@brief Prints the graph to the given ostream in DIMACS format.
|
||||
**/
|
||||
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:
|
||||
std::vector<Node> _nodes;
|
||||
size_type _num_edges;
|
||||
|
@ -206,6 +222,25 @@ Node const & Graph::node(NodeId const id) const
|
|||
}
|
||||
//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
|
||||
|
||||
#endif /* GRAPH_HPP */
|
||||
|
|
Loading…
Reference in a new issue