64 for (
int j = 0; j < n; ++j) {
65 for (
int k = j + 1; k < n; ++k) {
73 bool nodes_resize_policy,
75 bool edges_resize_policy) :
93 std::pair< NodeId, NodeId > thePair;
94 NodeId current, from_current;
96 for (
const auto node:
nodes()) {
99 if (!examined_nodes[node]) {
101 examined_nodes[node] =
true;
104 thePair.first = node;
105 thePair.second = node;
106 open_nodes.
insert(thePair);
108 while (!open_nodes.
empty()) {
110 thePair = open_nodes.
front();
113 current = thePair.first;
114 from_current = thePair.second;
117 for (
const auto new_node:
neighbours(current))
120 if (new_node != from_current) {
121 if (examined_nodes[new_node])
return true;
123 examined_nodes[new_node] =
true;
124 thePair.first = new_node;
125 thePair.second = current;
126 open_nodes.
insert(thePair);
144 std::stringstream output;
145 std::stringstream nodeStream;
146 std::stringstream edgeStream;
148 output <<
"digraph \""
149 <<
"no_name\" {" << std::endl
150 <<
"edge [dir=none]" << std::endl;
151 nodeStream <<
"node [shape = ellipse];" << std::endl;
152 std::string tab =
" ";
154 for (
const auto node:
nodes()) {
155 nodeStream << tab << node <<
";";
159 if (!treatedNodes.
exists(nei))
160 edgeStream << tab << node <<
" -> " << nei <<
";" << std::endl;
162 treatedNodes.
insert(node);
165 output << nodeStream.str() << std::endl << edgeStream.str() << std::endl <<
"}" << std::endl;
174 for (
const auto node:
nodes) {
188 for (
const auto node:
nodes()) {
189 if (res.
exists(node))
continue;
191 while (!
nodes.empty()) {
192 auto actual = *(
nodes.begin());
194 res.
insert(actual, numCC);
EdgeGraphPart(Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
virtual std::string toString() const
to friendly display the content of the EdgeGraphPart
const NodeSet & neighbours(NodeId id) const
returns the set of node neighbours to a given node
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
Generic doubly linked lists.
bool exists(const Val &val) const
Checks whether there exists a given element in the list.
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 & insert(const Val &val)
Inserts a new element at the end of the chained list (alias of pushBack).
Size size() const
alias for sizeNodes
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
virtual std::string toString() const
a function to display the set of nodes
NodeProperty< VAL > nodesPropertyFromVal(const VAL &a, Size size=0) const
a method to create a hashMap with key:NodeId and value:VAL
NodeGraphPart(Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true)
default constructor
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
std::vector< NodeId > addNodes(Size n)
insert n nodes
Base class for undirected graphs.
virtual std::string toDot() const
to friendly display graph in DOT format
bool hasUndirectedCycle() const
checks whether the graph contains cycles
static UndiGraph completeGraph(int n)
create a complete UndiGraph with n nodes
void addEdge(NodeId first, NodeId second) override
insert a new edge into the undirected graph
virtual ~UndiGraph()
destructor
NodeProperty< NodeId > nodes2ConnectedComponent() const
returns a property {node:id of connected component}
std::string toString() const override
to friendly display the content of the graph
virtual UndiGraph partialUndiGraph(NodeSet nodes)
returns the partial graph formed by the nodes given in parameter
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
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.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
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
Base classes for undirected graphs.
Inline implementation of Base classes for undirected graphs.