33 #endif // GUM_NOINLINE 41 bool nodes_resize_policy,
43 bool edges_resize_policy) :
58 std::pair< NodeId, NodeId > thePair;
59 NodeId current, from_current;
61 for (
const auto node :
nodes()) {
64 if (!examined_nodes[node]) {
66 examined_nodes[node] =
true;
70 thePair.second = node;
71 open_nodes.
insert(thePair);
73 while (!open_nodes.
empty()) {
75 thePair = open_nodes.
front();
78 current = thePair.first;
79 from_current = thePair.second;
82 for (
const auto new_node :
neighbours(current))
85 if (new_node != from_current) {
86 if (examined_nodes[new_node])
89 examined_nodes[new_node] =
true;
90 thePair.first = new_node;
91 thePair.second = current;
92 open_nodes.
insert(thePair);
110 std::stringstream output;
111 std::stringstream nodeStream;
112 std::stringstream edgeStream;
114 output <<
"digraph \"" 115 <<
"no_name\" {" << std::endl
116 <<
"edge [dir=none]" << std::endl;
117 nodeStream <<
"node [shape = ellipse];" << std::endl;
118 std::string tab =
" ";
120 for (
const auto node :
nodes()) {
121 nodeStream << tab << node <<
";";
125 if (!treatedNodes.
exists(nei))
126 edgeStream << tab << node <<
" -> " << nei <<
";" << std::endl;
128 treatedNodes.
insert(node);
131 output << nodeStream.str() << std::endl
132 << edgeStream.str() << std::endl
142 for (
const auto node : nodesSet) {
146 if (nodesSet.contains(nei) && partialGraph.
existsNode(nei))
147 partialGraph.
addEdge(node, nei);
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
bool empty() const noexcept
Returns a boolean indicating whether the chained list is empty.
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
Size size() const
alias for sizeNodes
virtual void addEdge(const NodeId first, const NodeId second)
insert a new edge into the undirected graph
NodeProperty< VAL > nodesProperty(VAL(*f)(const NodeId &), Size size=0) const
a method to create a HashTable with key:NodeId and value:VAL
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Classes for undirected edge sets.
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.
The class for generic Hash Tables.
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
virtual ~UndiGraph()
destructor
std::ostream & operator<<(std::ostream &output, const BayesNet< GUM_SCALAR > &bn)
Prints map's DAG in output using the Graphviz-dot format.
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
std::string toString() const
a function to display the set of nodes
Class for node sets in graph.
bool exists(const Val &val) const
Checks whether there exists a given element in the list.
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
UndiGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
const std::string toString() const
to friendly display the content of the EdgeGraphPart
Val & insert(const Val &val)
Inserts a new element at the end of the chained list (alias of pushBack).
Val & front() const
Returns a reference to first element of a list, if any.
Base class for undirected graphs.
bool hasUndirectedCycle() const
checks whether the graph contains cycles
virtual const std::string toString() const
to friendly display the content of the graph
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size NodeId
Type for node ids.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual const std::string toDot() const
to friendly display graph in DOT format
virtual UndiGraph partialUndiGraph(NodeSet nodesSet)
returns the partial graph formed by the nodes given in parameter