61 for (
int j = 0; j < n; ++j) {
62 for (
int k = j + 1; k < n; ++k) {
70 bool nodes_resize_policy,
72 bool arcs_resize_policy) :
89 std::stringstream strBuff;
90 std::string tab =
" ";
91 strBuff <<
"digraph {" << std::endl;
93 for (
const auto node:
nodes())
94 strBuff << tab << node <<
";" << std::endl;
98 for (
const auto& arc:
arcs())
99 strBuff << tab << arc.tail() <<
" -> " << arc.head() <<
";" << std::endl;
101 strBuff <<
"}" << std::endl << std::endl;
102 return strBuff.str();
113 const auto& dag = *
this;
117 auto border = std::vector< NodeId >();
118 border.reserve(dag.size() / 2);
119 auto count = dag.nodesPropertyFromVal<
Size >(0, dag.size());
120 for (
const auto node: dag.nodes()) {
121 if (dag.parents(node).empty()) { border.push_back(node); }
122 count[node] = dag.parents(node).size();
125 if (border.empty()) {
129 while (!border.empty()) {
130 const auto root = border.back();
138 for (
const auto child: dag.children(root)) {
139 if (count[child] == 1) { border.push_back(child); }
140 if (count[child] == 0) {
152 if (!
exists(from))
return false;
163 while (!nodeFIFO.
empty()) {
164 new_one = nodeFIFO.
front();
167 for (
const auto chi:
children(new_one)) {
168 if (chi == to)
return true;
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
ArcGraphPart(Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true)
default constructor
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
std::string toString() const
to friendly display the content of the ArcGraphPart
Base class for all oriented graphs.
bool hasDirectedPath(NodeId from, NodeId to)
checks whether there exists a directed path from from to to
static DiGraph completeGraph(int n)
Build a complete DiGraph with n nodes.
virtual std::string toDot() const
to friendly display the content of the graph in the DOT syntax
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
virtual void addArc(const NodeId tail, const NodeId head)
insert a new arc into the directed graph
Sequence< NodeId > topologicalOrder() const
Build and return a topological order.
virtual ~DiGraph()
destructor
virtual std::string toString() const
to friendly display the content of the graph
Exception : existence of a directed cycle in a graph.
Generic doubly linked lists.
Val & front() const
Returns a reference to first element of a list, if any.
bool empty() const noexcept
Returns a boolean indicating whether the chained list is empty.
void popFront()
Removes the first element of a List, if any.
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
virtual std::string toString() const
a function to display the set of nodes
bool exists(const NodeId id) const
alias for existsNode
NodeGraphPart(Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true)
default constructor
std::vector< NodeId > addNodes(Size n)
insert n nodes
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
void insert(const Key &k)
Inserts a new element into the set.
Base classes for oriented graphs.
Inline implementation of Base classes for oriented graphs.
#define GUM_ERROR(type, msg)
some utils for topology : NodeId, Edge, Arc and consorts ...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size NodeId
Type for node ids.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
gum is the global namespace for all aGrUM entities
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree