33 #endif // GUM_NOINLINE 38 bool nodes_resize_policy,
40 bool arcs_resize_policy) :
43 __mutableTopologicalOrder(nullptr) {
69 std::stringstream strBuff;
70 std::string tab =
" ";
71 strBuff <<
"digraph {" << std::endl;
73 for (
const auto node :
nodes())
74 strBuff << tab << node <<
";" << std::endl;
78 for (
const auto& arc :
arcs())
79 strBuff << tab << arc.tail() <<
" -> " << arc.head() <<
";" << std::endl;
81 strBuff <<
"}" << std::endl << std::endl;
110 auto roots = std::vector< NodeId >();
112 for (
const auto node : dag.nodes()) {
113 if (dag.parents(node).empty()) { roots.push_back(node); }
116 while (roots.size()) {
119 "cycles prevent the creation of a topological ordering.");
126 auto child = *(dag.children(back).begin());
127 dag.eraseArc(
Arc(back, child));
129 if (dag.parents(child).empty()) { roots.push_back(child); }
133 GUM_ASSERT(dag.sizeArcs() == (
gum::Size)(0));
138 if (!
exists(from))
return false;
149 while (!nodeFIFO.
empty()) {
150 new_one = nodeFIFO.
front();
154 for (
const auto chi :
children(new_one)) {
155 if (chi == to)
return true;
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
bool empty() const noexcept
Returns a boolean indicating whether the chained list is empty.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
const std::string toString() const
to friendly display the content of the ArcGraphPart
void clear()
Clear the sequence.
DiGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true)
default constructor
Size size() const noexcept
Returns the size of the sequence.
Classes for directed edge sets.
virtual void clear()
removes all the nodes and arcs from the graph
Size size() const
alias for sizeNodes
virtual const std::string toString() const
to friendly display the content of the graph
virtual ~DiGraph()
destructor
bool exists(const NodeId id) const
alias for existsNode
Generic doubly linked lists.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void popFront()
Removes the first element of a List, if any.
Sequence< NodeId > * __mutableTopologicalOrder
The topology sequence of this Directed Graphical Model.
std::ostream & operator<<(std::ostream &output, const BayesNet< GUM_SCALAR > &bn)
Prints map's DAG in output using the Graphviz-dot format.
The base class for all directed edgesThis class is used as a basis for manipulating all directed edge...
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
Base class for all oriented graphs.
bool exists(const Key &k) const
Check the existence of k in the sequence.
std::string toString() const
a function to display the set of nodes
virtual const std::string toDot() const
to friendly display the content of the graph in the DOT syntax
Class for node sets in graph.
const Sequence< NodeId > & topologicalOrder(bool clear=true) const
The topological order stays the same as long as no variable or arcs are added or erased src the topol...
Val & front() const
Returns a reference to first element of a list, if any.
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
bool hasDirectedPath(const NodeId from, const NodeId to)
checks whether there exists a directed path from from to to
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Size NodeId
Type for node ids.
void insert(const Key &k)
Inserts a new element into the set.
void __topologicalOrder() const
Returns a topological order of this DAGModel.
const Key & back() const
Returns the last element of the sequence.
#define GUM_ERROR(type, msg)
void insert(const Key &k)
Insert an element at the end of the sequence.