30 #endif // GUM_NOINLINE 35 bool nodes_resize_policy,
37 bool arcs_resize_policy) :
40 __mutableTopologicalOrder(nullptr) {
66 std::stringstream strBuff;
67 std::string tab =
" ";
68 strBuff <<
"digraph {" << std::endl;
70 for (
const auto node :
nodes())
71 strBuff << tab << node <<
";" << std::endl;
75 for (
const auto& arc :
arcs())
76 strBuff << tab << arc.tail() <<
" -> " << arc.head() <<
";" << std::endl;
78 strBuff <<
"}" << std::endl << std::endl;
107 auto roots = std::vector< NodeId >();
109 for (
const auto node : dag.nodes()) {
110 if (dag.parents(node).empty()) { roots.push_back(node); }
113 while (roots.size()) {
116 "cycles prevent the creation of a topological ordering.");
123 auto child = *(dag.children(back).begin());
124 dag.eraseArc(
Arc(back, child));
126 if (dag.parents(child).empty()) { roots.push_back(child); }
130 GUM_ASSERT(dag.sizeArcs() == (
gum::Size)(0));
Base classes for oriented graphs.
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
gum is the global namespace for all aGrUM entities
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...
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...
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Inline implementation of Base classes for oriented graphs.
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.