1#include <Core/Containers/AdjacencyList.hpp>
12 m_child( adj.m_child ), m_parent( adj.m_parent ) {}
27 CORE_ASSERT( ( parent <
size() ),
"Index parent out of bounds" );
41 for ( uint i = 0; i < this->
size(); ++i ) {
43 delete_flag[i] =
true;
49 for ( uint j = this->
size(); j > 0; --j ) {
51 if ( prune_flag[i] ) {
52 this->m_parent.
erase( this->m_parent.
begin() + i );
53 this->m_child.
erase( this->m_child.
begin() + i );
59 for ( uint i = 0; i < this->
size(); ++i ) {
61 ( ( this->m_parent[i] == -1 ) || ( delete_flag[i] ) ) ? -1 : pruned[this->m_parent[i]];
62 for (
auto it = this->m_child[i].begin(); it != this->m_child[i].
end(); ++it ) {
63 if ( delete_flag[( *it )] ) {
64 this->m_child[i].
erase( it );
67 else { *it = pruned[*it]; }
79 using Edge = Eigen::Matrix<uint, 2, 1>;
82 for ( uint i = 0; i < m_child.
size(); ++i ) {
83 if ( include_leaf &&
isLeaf( i ) ) {
90 for (
const auto& edge : m_child[i] ) {
103 if ( m_parent.
size() != m_child.
size() ) {
104 return ConsistencyStatus::IncompatibleChildrenAndParentList;
107 for ( uint node = 0; node <
size(); ++node ) {
108 if ( m_parent.
at( node ) >=
int( node ) ) {
return ConsistencyStatus::WrongParentOrdering; }
109 if ( m_parent.
at( node ) < -1 ) {
return ConsistencyStatus::WrongParentIndex; }
111 for (
const auto& child : m_child.
at( node ) ) {
112 if ( m_parent.
at( child ) !=
int( node ) ) {
113 return ConsistencyStatus::InconsistentParentIndex;
117 if (
isLeaf( node ) != ( m_child.
at( node ).size() == 0 ) ) {
118 return ConsistencyStatus::NonLeafNodeWithoutChild;
121 return ConsistencyStatus::Valid;
126 const std::string comment {
"#ID PARENT nCHILDREN CHILDREN\n" };
127 const uint size = adj.
size();
130 for ( uint i = 0; i < size; ++i ) {
134 for ( uint j = 0; j < c; ++j ) {
AdjacencyList()
CONSTRUCTOR.
ConsistencyStatus computeConsistencyStatus() const
Return true if the graph is consistent.
uint size() const
Return the number of nodes in the graph.
void pruneLeaves()
Prune the leaves of the graph.
uint addRoot()
Return the index of the added root.
bool isLeaf(const uint i) const
Return true if the node is a leaf node.
bool isRoot(const uint i) const
Return true if a node is a root node.
VectorArray< Eigen::Matrix< uint, 2, 1 > > extractEdgeList(bool include_leaf=false) const
~AdjacencyList()
DESTRUCTOR.
uint addNode(const uint parent)
Return the index of the added leaf.
This class implements ContainerIntrospectionInterface for AlignedStdVector.
hepler function to manage enum as underlying types in VariableSet