30 #endif // GUM_NOINLINE 38 bool nodes_resize_policy,
40 bool edges_resize_policy) :
55 std::pair< NodeId, NodeId > thePair;
56 NodeId current, from_current;
58 for (
const auto node :
nodes()) {
61 if (!examined_nodes[node]) {
63 examined_nodes[node] =
true;
67 thePair.second = node;
68 open_nodes.
insert(thePair);
70 while (!open_nodes.
empty()) {
72 thePair = open_nodes.
front();
75 current = thePair.first;
76 from_current = thePair.second;
79 for (
const auto new_node :
neighbours(current))
82 if (new_node != from_current) {
83 if (examined_nodes[new_node])
86 examined_nodes[new_node] =
true;
87 thePair.first = new_node;
88 thePair.second = current;
89 open_nodes.
insert(thePair);
107 std::stringstream output;
108 std::stringstream nodeStream;
109 std::stringstream edgeStream;
111 output <<
"digraph \"" 112 <<
"no_name\" {" << std::endl
113 <<
"edge [dir=none]" << std::endl;
114 nodeStream <<
"node [shape = ellipse];" << std::endl;
115 std::string tab =
" ";
117 for (
const auto node :
nodes()) {
118 nodeStream << tab << node <<
";";
122 if (!treatedNodes.
exists(nei))
123 edgeStream << tab << node <<
" -> " << nei <<
";" << std::endl;
125 treatedNodes.
insert(node);
128 output << nodeStream.str() << std::endl
129 << edgeStream.str() << std::endl
139 for (
const auto node : nodesSet) {
143 if (nodesSet.contains(nei) && partialGraph.
existsNode(nei))
144 partialGraph.
addEdge(node, nei);
Inline implementation of Base classes for undirected graphs.
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
Base classes for undirected graphs.
Classes for undirected edge sets.
Generic doubly linked lists.
gum is the global namespace for all aGrUM entities
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.
some utils for topology : NodeId, Edge, Arc and consorts ...
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