aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
gum::UndiGraph Class Reference

Base class for undirected graphs. More...

#include <undiGraph.h>

+ Inheritance diagram for gum::UndiGraph:
+ Collaboration diagram for gum::UndiGraph:

Public Attributes

Signaler1< NodeIdonNodeAdded
 
Signaler1< NodeIdonNodeDeleted
 
Signaler2< NodeId, NodeIdonEdgeAdded
 
Signaler2< NodeId, NodeIdonEdgeDeleted
 

Public Member Functions

Constructors / Destructors
 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 More...
 
 UndiGraph (const UndiGraph &g)
 copy constructor More...
 
virtual ~UndiGraph ()
 destructor More...
 
Operators
UndiGraphoperator= (const UndiGraph &g)
 copy operator More...
 
bool operator== (const UndiGraph &g) const
 tests whether two UndiGraphs are identical (same nodes, same edges) More...
 
bool operator!= (const UndiGraph &g) const
 tests whether two UndiGraphs are different More...
 
Accessors/Modifiers
void addEdge (NodeId first, NodeId second) override
 insert a new edge into the undirected graph More...
 
void eraseNode (NodeId id) override
 remove a node and its adjacent edges from the graph More...
 
void clear () override
 removes all the nodes and edges from the graph More...
 
std::string toString () const override
 to friendly display the content of the graph More...
 
virtual std::string toDot () const
 to friendly display graph in DOT format More...
 
bool hasUndirectedCycle () const
 checks whether the graph contains cycles More...
 
virtual UndiGraph partialUndiGraph (NodeSet nodes)
 returns the partial graph formed by the nodes given in parameter More...
 
NodeProperty< NodeIdnodes2ConnectedComponent () const
 returns a property {node:id of connected component} More...
 
Operators
bool operator== (const NodeGraphPart &p) const
 check whether two NodeGraphParts contain the same nodes More...
 
bool operator!= (const NodeGraphPart &p) const
 check whether two NodeGraphParts contain different nodes More...
 
Accessors/Modifiers
void populateNodes (const NodeGraphPart &s)
 populateNodes clears *this and fills it with the same nodes as "s" More...
 
template<typename T >
void populateNodesFromProperty (const NodeProperty< T > &h)
 populateNodesFromProperty clears *this and fills it with the keys of "h" More...
 
NodeId nextNodeId () const
 returns a new node id, not yet used by any node More...
 
virtual NodeId addNode ()
 insert a new node and return its id More...
 
std::vector< NodeIdaddNodes (Size n)
 insert n nodes More...
 
virtual void addNodeWithId (const NodeId id)
 try to insert a node with the given id More...
 
bool existsNode (const NodeId id) const
 returns true iff the NodeGraphPart contains the given nodeId More...
 
bool exists (const NodeId id) const
 alias for existsNode More...
 
bool emptyNodes () const
 indicates whether there exists nodes in the NodeGraphPart More...
 
bool empty () const
 alias for emptyNodes More...
 
virtual void clearNodes ()
 remove all the nodes from the NodeGraphPart More...
 
Size sizeNodes () const
 returns the number of nodes in the NodeGraphPart More...
 
Size size () const
 alias for sizeNodes More...
 
NodeId bound () const
 returns a number n such that all node ids are strictly lower than n More...
 
NodeSet asNodeSet () const
 returns a copy of the set of nodes represented by the NodeGraphPart More...
 
const NodeGraphPartnodes () const
 return *this as a NodeGraphPart More...
 
node_iterator_safe beginSafe () const
 a begin iterator to parse the set of nodes contained in the NodeGraphPart More...
 
const node_iterator_safeendSafe () const noexcept
 the end iterator to parse the set of nodes contained in the NodeGraphPart More...
 
node_iterator begin () const noexcept
 a begin iterator to parse the set of nodes contained in the NodeGraphPart More...
 
const node_iteratorend () const noexcept
 the end iterator to parse the set of nodes contained in the NodeGraphPart More...
 
template<typename VAL >
NodeProperty< VAL > nodesProperty (VAL(*f)(const NodeId &), Size size=0) const
 a method to create a HashTable with key:NodeId and value:VAL More...
 
template<typename VAL >
NodeProperty< VAL > nodesProperty (const VAL &a, Size size=0) const
 a method to create a hashMap with key:NodeId and value:VAL More...
 
template<typename VAL >
List< VAL > listMapNodes (VAL(*f)(const NodeId &)) const
 a method to create a list of VAL from a set of nodes (using for every nodee, say x, the VAL f(x)) More...
 
Operators
bool operator== (const EdgeGraphPart &p) const
 tests whether two EdgeGraphParts contain the same edges More...
 
bool operator!= (const EdgeGraphPart &p) const
 tests whether two EdgeGraphParts contain different edges More...
 
Accessors/Modifiers
virtual void eraseEdge (const Edge &edge)
 removes an edge from the EdgeGraphPart More...
 
bool existsEdge (const Edge &edge) const
 indicates whether a given edge exists More...
 
bool existsEdge (const NodeId n1, const NodeId n2) const
 indicates whether a given edge exists More...
 
bool emptyEdges () const
 indicates wether the EdgeGraphPart contains any edge More...
 
virtual void clearEdges ()
 removes all the edges from the EdgeGraphPart More...
 
Size sizeEdges () const
 indicates the number of edges stored within the EdgeGraphPart More...
 
const EdgeSetedges () const
 returns the set of edges stored within the EdgeGraphPart More...
 
const NodeSetneighbours (const NodeId id) const
 returns the set of edges adjacent to a given node More...
 
void eraseNeighbours (const NodeId id)
 erase all the edges adjacent to a given node More...
 
void unvirtualizedEraseNeighbours (const NodeId id)
 same function as eraseNeighbours but without any virtual call to an erase More...
 
template<typename VAL >
EdgeProperty< VAL > edgesProperty (VAL(*f)(const Edge &), Size size=0) const
 a method to create a hashMap of VAL from a set of edges (using for every edge, say x, the VAL f(x)) More...
 
template<typename VAL >
EdgeProperty< VAL > edgesProperty (const VAL &a, Size size=0) const
 a method to create a hashMap of VAL from a set of edges (using for every edge, say x, the VAL a) More...
 
template<typename VAL >
List< VAL > listMapEdges (VAL(*f)(const Edge &)) const
 a method to create a list of VAL from a set of edges (using for every edge, say x, the VAL f(x)) More...
 
const std::vector< NodeIdundirectedPath (const NodeId node1, const NodeId node2) const
 returns a possible path from node1 to node2 in the edge set More...
 
bool hasUndirectedPath (const NodeId n1, const NodeId n2) const
 return true if n1 and n2 are connected (by an undirected path) in the graph. More...
 
bool hasUndirectedPath (const NodeId n1, const NodeId n2, const NodeSet &except) const
 return true if n1 and n2 are connected (by an undirected path not using the nodes of except) in the graph. More...
 
bool hasUndirectedPath (const NodeSet &n1, const NodeSet &n2, const NodeSet &except) const
 return true if n1 and n2 are connected (by an undirected path not using the nodes of except) in the graph. More...
 

Public Types

typedef NodeGraphPartIterator NodeIterator
 
typedef NodeGraphPartIterator NodeConstIterator
 
typedef NodeGraphPartIteratorSafe NodeIteratorSafe
 
typedef NodeGraphPartIteratorSafe NodeConstIteratorSafe
 
typedef EdgeSetIterator EdgeIterator
 
using node_iterator = NodeGraphPartIterator
 types for STL compliance More...
 
using node_const_iterator = NodeGraphPartIterator
 types for STL compliance More...
 
using node_iterator_safe = NodeGraphPartIteratorSafe
 types for STL compliance More...
 
using node_const_iterator_safe = NodeGraphPartIteratorSafe
 types for STL compliance More...
 

Detailed Description

Base class for undirected graphs.

This is the base class for graphs containing undirected edges (so-called edges).

Usage example:
// creating empty graphs
UndiGraph g1,g2;
// adding nodes and edges to g1
NodeId i1=g1.addNode();
NodeId i2=g1.addNode();
NodeId i3=g1.addNode();
g1.addEdge( i1,i2 );
g1.addEdge( i1,i3 );
g1.addEdge( i2,i3 );
//throw an InvalidNode
// g1.addEdge( i1+i2+i3,i1 );
// copying graphs
UndiGraph g3 = g1;
g2 = g1;
UndiGraph g4=g1;
// check if a graph has no node
if ( g1.empty() ) cerr << "graph g1 is empty" << endl;
// remove all the nodes (as well as their adjacent edges)
g1.clear();
// remove some edge
g4.eraseEdge( Edge ( i1,i3 ) );
// remove node
g2.eraseNode( i2 );
// parse a graph
for ( const auto node : g3.nodes() )
cerr << node << endl;
for ( const auto& edge : g3.edges())
cerr << edge << endl;
const EdgeSet& a=g3.neighbours( 3 );
for ( const auto& edge : a)
cerr << " - "<<edge;
cerr<<endl;
// remove all the edges that are adjacent to a given node
g3.eraseNeighbours( 2 );

Definition at line 108 of file undiGraph.h.

Member Typedef Documentation

◆ EdgeIterator

Definition at line 76 of file edgeGraphPart.h.

◆ node_const_iterator

types for STL compliance

Definition at line 258 of file nodeGraphPart.h.

◆ node_const_iterator_safe

types for STL compliance

Definition at line 260 of file nodeGraphPart.h.

◆ node_iterator

types for STL compliance

Definition at line 257 of file nodeGraphPart.h.

◆ node_iterator_safe

types for STL compliance

Definition at line 259 of file nodeGraphPart.h.

◆ NodeConstIterator

Definition at line 267 of file nodeGraphPart.h.

◆ NodeConstIteratorSafe

◆ NodeIterator

Definition at line 266 of file nodeGraphPart.h.

◆ NodeIteratorSafe

Constructor & Destructor Documentation

◆ UndiGraph() [1/2]

gum::UndiGraph::UndiGraph ( Size  nodes_size = HashTableConst::default_size,
bool  nodes_resize_policy = true,
Size  edges_size = HashTableConst::default_size,
bool  edges_resize_policy = true 
)
explicit

default constructor

Parameters
nodes_sizethe size of the hash table used to store all the nodes
nodes_resize_policythe resizing policy of this hash table
edges_sizethe size of the hash table used to store all the edges
edges_resize_policythe resizing policy of this hash table

Definition at line 39 of file undiGraph.cpp.

42  :
43  NodeGraphPart(nodes_size, nodes_resize_policy),
44  EdgeGraphPart(edges_size, edges_resize_policy) {
45  GUM_CONSTRUCTOR(UndiGraph);
46  }
EdgeGraphPart(Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
NodeGraphPart(Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true)
default constructor
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
Definition: undiGraph.cpp:39

◆ UndiGraph() [2/2]

gum::UndiGraph::UndiGraph ( const UndiGraph g)

copy constructor

Parameters
gthe UndiGraph to copy

Definition at line 48 of file undiGraph.cpp.

48  : NodeGraphPart(g), EdgeGraphPart(g) {
49  GUM_CONS_CPY(UndiGraph);
50  }
EdgeGraphPart(Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
NodeGraphPart(Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true)
default constructor
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
Definition: undiGraph.cpp:39

◆ ~UndiGraph()

gum::UndiGraph::~UndiGraph ( )
virtual

destructor

Definition at line 52 of file undiGraph.cpp.

52 { GUM_DESTRUCTOR(UndiGraph); }
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
Definition: undiGraph.cpp:39

Member Function Documentation

◆ addEdge()

INLINE void gum::UndiGraph::addEdge ( NodeId  first,
NodeId  second 
)
overridevirtual

insert a new edge into the undirected graph

The order in which the extremal nodes are specified is not important.

Parameters
firstthe id of one extremal node of the new inserted edge
secondthe id of the other extremal node of the new inserted edge
Warning
if the edge already exists, nothing is done. In particular, no exception is raised.
Exceptions
InvalidNodeif first and/or second do not belong to the graph nodes

Reimplemented from gum::EdgeGraphPart.

Definition at line 34 of file undiGraph_inl.h.

References gum::Set< Key, Alloc >::emplace().

34  {
35  if (!exists(first)) {
36  GUM_ERROR(InvalidNode, "Node (" << first << ") does not exist.");
37  }
38 
39  if (!exists(second)) {
40  GUM_ERROR(InvalidNode, "Node (" << second << ") does not exist.");
41  }
42 
43  EdgeGraphPart::addEdge(second, first);
44  }
virtual void addEdge(const NodeId n1, const NodeId n2)
insert a new edge into the EdgeGraphPart
bool exists(const NodeId id) const
alias for existsNode
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ addNode()

INLINE NodeId gum::NodeGraphPart::addNode ( )
virtualinherited

insert a new node and return its id

Returns
the id chosen by the internal idFactory

Reimplemented in gum::CliqueGraph.

Definition at line 252 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

252  {
253  NodeId newNode;
254 
255  // fill the first hole if holes exist
256  if (holes__ && (!holes__->empty())) {
257  newNode = *(holes__->begin());
258  eraseHole__(newNode);
259  } else {
260  newNode = boundVal__;
261  ++boundVal__;
263  }
264 
265  GUM_EMIT1(onNodeAdded, newNode);
266 
267  return newNode;
268  }
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:726
#define GUM_EMIT1(signal, arg1)
Definition: signaler1.h:41
iterator begin() const
The usual unsafe begin iterator to parse the set.
Definition: set_tpl.h:516
NodeSet * holes__
the set of nodes not contained in the NodeGraphPart in the interval 1..max__
Signaler1< NodeId > onNodeAdded
NodeId boundVal__
the id below which NodeIds may belong to the NodeGraphPart
void updateEndIteratorSafe__()
updating endIterator (always at max__+1)
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void eraseHole__(NodeId id)
to delete hole.
+ Here is the call graph for this function:

◆ addNodes()

INLINE std::vector< NodeId > gum::NodeGraphPart::addNodes ( Size  n)
inherited

insert n nodes

Parameters
nthe number of nodes to add
Returns
the vector of chosen ids

Definition at line 270 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

270  {
271  std::vector< NodeId > v;
272  v.reserve(N);
273  for (Idx i = 0; i < N; i++)
274  v.push_back(this->addNode());
275  return v;
276  }
+ Here is the call graph for this function:

◆ addNodeWithId()

void gum::NodeGraphPart::addNodeWithId ( const NodeId  id)
virtualinherited

try to insert a node with the given id

Warning
This method should be carefully used. Please prefer populateNodes or populateNodesFromProperty when possible
Exceptions
DuplicateElementexception if the id already exists

Definition at line 131 of file nodeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

131  {
132  if (id >= boundVal__) {
133  if (id > boundVal__) { // we have to add holes
135 
136  for (NodeId i = boundVal__; i < id; ++i)
137  holes__->insert(i);
138  }
139 
140  boundVal__ = id + 1;
141 
143  } else {
144  if (inHoles__(id)) { // we fill a hole
145  eraseHole__(id);
146  } else {
147  GUM_ERROR(DuplicateElement, "Id " << id << " is already used");
148  }
149  }
150 
151  GUM_EMIT1(onNodeAdded, id);
152  }
bool holes_resize_policy__
value for holes__ configuration
#define GUM_EMIT1(signal, arg1)
Definition: signaler1.h:41
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeSet * holes__
the set of nodes not contained in the NodeGraphPart in the interval 1..max__
Signaler1< NodeId > onNodeAdded
NodeId boundVal__
the id below which NodeIds may belong to the NodeGraphPart
void updateEndIteratorSafe__()
updating endIterator (always at max__+1)
bool inHoles__(NodeId id) const
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:632
void eraseHole__(NodeId id)
to delete hole.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
Size holes_size__
value for holes__ configuration
+ Here is the call graph for this function:

◆ asNodeSet()

INLINE NodeSet gum::NodeGraphPart::asNodeSet ( ) const
inherited

returns a copy of the set of nodes represented by the NodeGraphPart

Warning
this function is o(n) where n is the number of nodes. In space and in time. Usually, when you need to parse the nodes of a NodeGraphPart, prefer using
for(const auto n : nodes())
rather than
for(const auto n : asNodeSet())
as this is faster and consumes much less memory.

Definition at line 360 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

360  {
361  NodeSet son(sizeNodes());
362 
363  if (!empty()) {
364  for (NodeId n = 0; n < boundVal__; ++n) {
365  if (!inHoles__(n)) son.insert(n);
366  }
367  }
368 
369  return son;
370  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
bool empty() const
alias for emptyNodes
Size sizeNodes() const
returns the number of nodes in the NodeGraphPart
NodeId boundVal__
the id below which NodeIds may belong to the NodeGraphPart
bool inHoles__(NodeId id) const
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ begin()

INLINE NodeGraphPartIterator gum::NodeGraphPart::begin ( ) const
noexceptinherited

a begin iterator to parse the set of nodes contained in the NodeGraphPart

Definition at line 332 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

332  {
333  NodeGraphPartIterator it(*this);
334  it.validate_(); // stop the iterator at the first not-in-holes
335  return it;
336  }
friend class NodeGraphPartIterator
+ Here is the call graph for this function:

◆ beginSafe()

INLINE NodeGraphPartIteratorSafe gum::NodeGraphPart::beginSafe ( ) const
inherited

a begin iterator to parse the set of nodes contained in the NodeGraphPart

Definition at line 318 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

318  {
319  NodeGraphPartIteratorSafe it(*this);
320  it.validate_(); // stop the iterator at the first not-in-holes
321  return it;
322  }
friend class NodeGraphPartIteratorSafe
+ Here is the call graph for this function:

◆ bound()

INLINE NodeId gum::NodeGraphPart::bound ( ) const
inherited

returns a number n such that all node ids are strictly lower than n

Definition at line 307 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

307 { return boundVal__; }
NodeId boundVal__
the id below which NodeIds may belong to the NodeGraphPart
+ Here is the call graph for this function:

◆ clear()

INLINE void gum::UndiGraph::clear ( )
overridevirtual

removes all the nodes and edges from the graph

Reimplemented from gum::NodeGraphPart.

Definition at line 46 of file undiGraph_inl.h.

References gum::Set< Key, Alloc >::emplace().

46  {
49  }
virtual void clearEdges()
removes all the edges from the EdgeGraphPart
virtual void clearNodes()
remove all the nodes from the NodeGraphPart
+ Here is the call graph for this function:

◆ clearEdges()

void gum::EdgeGraphPart::clearEdges ( )
virtualinherited

removes all the edges from the EdgeGraphPart

Reimplemented in gum::CliqueGraph.

Definition at line 66 of file edgeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

66  {
67  for (const auto& elt: neighbours__)
68  delete elt.second;
69 
70  neighbours__.clear();
71 
72  if (onEdgeDeleted.hasListener()) {
73  EdgeSet tmp = edges__;
74  edges__.clear();
75 
76  for (const auto& edge: tmp)
77  GUM_EMIT2(onEdgeDeleted, edge.first(), edge.second());
78  } else {
79  edges__.clear();
80  }
81  }
EdgeSet edges__
the set of all the edges contained within the EdgeGraphPart
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:41
NodeProperty< NodeSet *> neighbours__
for each node, the set of its adjacent edges
Signaler2< NodeId, NodeId > onEdgeDeleted
Definition: edgeGraphPart.h:79
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:374
+ Here is the call graph for this function:

◆ clearNodes()

INLINE void gum::NodeGraphPart::clearNodes ( )
virtualinherited

remove all the nodes from the NodeGraphPart

Definition at line 309 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

309 { clearNodes__(); }
void clearNodes__()
code for clearing nodes (called twice)
+ Here is the call graph for this function:

◆ edges()

INLINE const EdgeSet & gum::EdgeGraphPart::edges ( ) const
inherited

returns the set of edges stored within the EdgeGraphPart

Definition at line 38 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

38 { return edges__; }
EdgeSet edges__
the set of all the edges contained within the EdgeGraphPart
+ Here is the call graph for this function:

◆ edgesProperty() [1/2]

template<typename VAL >
EdgeProperty< VAL > gum::EdgeGraphPart::edgesProperty ( VAL(*)(const Edge &)  f,
Size  size = 0 
) const
inherited

a method to create a hashMap of VAL from a set of edges (using for every edge, say x, the VAL f(x))

Parameters
fa function assigning a VAL to any edge
sizean optional parameter enabling to fine-tune the returned Property. Roughly speaking, it is a good practice to have a size equal to half the number of edges. If you do not specify this parameter, the method will assign it for you.

◆ edgesProperty() [2/2]

template<typename VAL >
EdgeProperty< VAL > gum::EdgeGraphPart::edgesProperty ( const VAL &  a,
Size  size = 0 
) const
inherited

a method to create a hashMap of VAL from a set of edges (using for every edge, say x, the VAL a)

Parameters
athe default value assigned to each edge in the returned Property
sizean optional parameter enabling to fine-tune the returned Property. Roughly speaking, it is a good practice to have a size equal to half the number of edges. If you do not specify this parameter, the method will assign it for you.

◆ empty()

INLINE bool gum::NodeGraphPart::empty ( ) const
inherited

alias for emptyNodes

Definition at line 305 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

305 { return emptyNodes(); }
bool emptyNodes() const
indicates whether there exists nodes in the NodeGraphPart
+ Here is the call graph for this function:

◆ emptyEdges()

INLINE bool gum::EdgeGraphPart::emptyEdges ( ) const
inherited

indicates wether the EdgeGraphPart contains any edge

Definition at line 34 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

34 { return edges__.empty(); }
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:726
EdgeSet edges__
the set of all the edges contained within the EdgeGraphPart
+ Here is the call graph for this function:

◆ emptyNodes()

INLINE bool gum::NodeGraphPart::emptyNodes ( ) const
inherited

indicates whether there exists nodes in the NodeGraphPart

Definition at line 303 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

303 { return (sizeNodes() == 0); }
Size sizeNodes() const
returns the number of nodes in the NodeGraphPart
+ Here is the call graph for this function:

◆ end()

INLINE const NodeGraphPartIterator & gum::NodeGraphPart::end ( ) const
noexceptinherited

the end iterator to parse the set of nodes contained in the NodeGraphPart

Definition at line 338 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

338  {
339  return endIteratorSafe__;
340  }
NodeGraphPartIteratorSafe endIteratorSafe__
the end iterator (used to speed-up parsings of the NodeGraphPart)
+ Here is the call graph for this function:

◆ endSafe()

INLINE const NodeGraphPartIteratorSafe & gum::NodeGraphPart::endSafe ( ) const
noexceptinherited

the end iterator to parse the set of nodes contained in the NodeGraphPart

Definition at line 328 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

328  {
329  return endIteratorSafe__;
330  }
NodeGraphPartIteratorSafe endIteratorSafe__
the end iterator (used to speed-up parsings of the NodeGraphPart)
+ Here is the call graph for this function:

◆ eraseEdge()

INLINE void gum::EdgeGraphPart::eraseEdge ( const Edge edge)
virtualinherited

removes an edge from the EdgeGraphPart

Parameters
edgethe edge to be removed
Warning
if the edge does not exist, nothing is done. In particular, no exception is thrown. However, the signal onEdgeDeleted is fired only if a node is effectively removed.

Reimplemented in gum::CliqueGraph.

Definition at line 64 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

64  {
65  if (existsEdge(edge)) {
66  // ASSUMING first and second exists in neighbours__ (if not, it is an
67  // error)
68  NodeId id1 = edge.first(), id2 = edge.second();
69 
70  neighbours__[id1]->erase(id2);
71  neighbours__[id2]->erase(id1);
72  edges__.erase(edge);
73  GUM_EMIT2(onEdgeDeleted, id1, id2);
74  }
75  }
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:675
EdgeSet edges__
the set of all the edges contained within the EdgeGraphPart
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:41
bool existsEdge(const Edge &edge) const
indicates whether a given edge exists
NodeProperty< NodeSet *> neighbours__
for each node, the set of its adjacent edges
Signaler2< NodeId, NodeId > onEdgeDeleted
Definition: edgeGraphPart.h:79
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ eraseNeighbours()

INLINE void gum::EdgeGraphPart::eraseNeighbours ( const NodeId  id)
inherited

erase all the edges adjacent to a given node

Parameters
idthe node the adjacent edges of which will be removed
Warning
if no edge is adjacent to id, nothing is done. In particular, no exception is thrown.
although this method is not virtual, it calls method eraseEdge( const Edge& edge ) and, as such, has a "virtual" behaviour

Definition at line 82 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

82  {
83  if (neighbours__.exists(id)) {
84  const NodeSet& set = neighbours(id);
85 
86  for (auto iter = set.beginSafe(); iter != set.endSafe();
87  ++iter) { // safe iterator needed here
88  // warning: use this erase so that you actually use the virtualized
89  // edge removal function
90  eraseEdge(Edge(*iter, id));
91  }
92  }
93  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
NodeProperty< NodeSet *> neighbours__
for each node, the set of its adjacent edges
virtual void eraseEdge(const Edge &edge)
removes an edge from the EdgeGraphPart
+ Here is the call graph for this function:

◆ eraseNode()

INLINE void gum::UndiGraph::eraseNode ( NodeId  id)
overridevirtual

remove a node and its adjacent edges from the graph

Parameters
idthe id of the node to be removed
Warning
if the node does not exist, nothing is done. In particular, no exception is raised.

Reimplemented from gum::NodeGraphPart.

Definition at line 61 of file undiGraph_inl.h.

References gum::Set< Key, Alloc >::emplace().

61  {
62  // warning: to remove the edges adjacent to id, use the unvirtualized
63  // versions
64  // of edge removals
67  }
void unvirtualizedEraseNeighbours(const NodeId id)
same function as eraseNeighbours but without any virtual call to an erase
virtual void eraseNode(const NodeId id)
erase the node with the given id
+ Here is the call graph for this function:

◆ exists()

INLINE bool gum::NodeGraphPart::exists ( const NodeId  id) const
inherited

alias for existsNode

Definition at line 291 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

291  {
292  return existsNode(node);
293  }
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
+ Here is the call graph for this function:

◆ existsEdge() [1/2]

INLINE bool gum::EdgeGraphPart::existsEdge ( const Edge edge) const
inherited

indicates whether a given edge exists

Parameters
edgethe edge we test whether or not it belongs to the EdgeGraphPart

Definition at line 40 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

40  {
41  return edges__.contains(edge);
42  }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:580
EdgeSet edges__
the set of all the edges contained within the EdgeGraphPart
+ Here is the call graph for this function:

◆ existsEdge() [2/2]

INLINE bool gum::EdgeGraphPart::existsEdge ( const NodeId  n1,
const NodeId  n2 
) const
inherited

indicates whether a given edge exists

Parameters
n1the id of one extremity of the edge we test the existence in the EdgeGraphPart
n2the id of the other extremity of the edge we test the existence in the EdgeGraphPart

Definition at line 44 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

45  {
46  return neighbours__.exists(first) && neighbours__[first]->exists(second);
47  }
NodeProperty< NodeSet *> neighbours__
for each node, the set of its adjacent edges
+ Here is the call graph for this function:

◆ existsNode()

INLINE bool gum::NodeGraphPart::existsNode ( const NodeId  id) const
inherited

returns true iff the NodeGraphPart contains the given nodeId

Definition at line 285 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

285  {
286  if (node >= boundVal__) return false;
287 
288  return (!inHoles__(node));
289  }
NodeId boundVal__
the id below which NodeIds may belong to the NodeGraphPart
bool inHoles__(NodeId id) const
+ Here is the call graph for this function:

◆ hasUndirectedCycle()

bool gum::UndiGraph::hasUndirectedCycle ( ) const

checks whether the graph contains cycles

Definition at line 54 of file undiGraph.cpp.

54  {
55  List< std::pair< NodeId, NodeId > > open_nodes;
56  NodeProperty< bool > examined_nodes = nodesProperty(false);
57  std::pair< NodeId, NodeId > thePair;
58  NodeId current, from_current;
59 
60  for (const auto node: nodes()) {
61  // check if the node has already been examined (if this is not the case,
62  // this means that we are on a new connected component)
63  if (!examined_nodes[node]) {
64  // indicates that we are examining a new node
65  examined_nodes[node] = true;
66 
67  // check recursively all the nodes of node's connected component
68  thePair.first = node;
69  thePair.second = node;
70  open_nodes.insert(thePair);
71 
72  while (!open_nodes.empty()) {
73  // get a node to propagate
74  thePair = open_nodes.front();
75  open_nodes.popFront();
76 
77  current = thePair.first;
78  from_current = thePair.second;
79 
80  // check the neighbours
81  for (const auto new_node: neighbours(current))
82 
83  // avoid to check the node we are coming from
84  if (new_node != from_current) {
85  if (examined_nodes[new_node])
86  return true;
87  else {
88  examined_nodes[new_node] = true;
89  thePair.first = new_node;
90  thePair.second = current;
91  open_nodes.insert(thePair);
92  }
93  }
94  }
95  }
96  }
97 
98  return false;
99  }
NodeProperty< VAL > nodesProperty(VAL(*f)(const NodeId &), Size size=0) const
a method to create a HashTable with key:NodeId and value:VAL
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
Size NodeId
Type for node ids.
Definition: graphElements.h:97

◆ hasUndirectedPath() [1/3]

bool gum::EdgeGraphPart::hasUndirectedPath ( const NodeId  n1,
const NodeId  n2 
) const
inherited

return true if n1 and n2 are connected (by an undirected path) in the graph.

Parameters
n1NodeId
n2NodeId
Returns
bool

Definition at line 166 of file edgeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

166  {
167  NodeSet visited;
168  NodeSet temp;
169 
170  temp.insert(n1);
171  while (!temp.empty()) {
172  NodeId current = *(temp.begin());
173  if (current == n2) return true;
174  temp.erase(current);
175  visited.insert(current);
176  for (auto next: neighbours(current)) {
177  if (!temp.contains(next) && !visited.contains(next)) temp.insert(next);
178  }
179  }
180  return false;
181  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:632
+ Here is the call graph for this function:

◆ hasUndirectedPath() [2/3]

bool gum::EdgeGraphPart::hasUndirectedPath ( const NodeId  n1,
const NodeId  n2,
const NodeSet except 
) const
inherited

return true if n1 and n2 are connected (by an undirected path not using the nodes of except) in the graph.

Parameters
n1NodeId
n2NodeId
exceptNodeSet
Warning
n1 in except has no repercussion. However n2 in except naturally leads to 'false'
Returns
bool

Definition at line 183 of file edgeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

185  {
186  NodeSet visited;
187  NodeSet temp;
188 
189  if (except.contains(n2)) return false;
190 
191  temp.insert(n1);
192  while (!temp.empty()) {
193  NodeId current = *(temp.begin());
194  if (current == n2) return true;
195  temp.erase(current);
196  visited.insert(current);
197  for (auto next: neighbours(current)) {
198  if (!temp.contains(next) && !visited.contains(next)
199  && !except.contains(next))
200  temp.insert(next);
201  }
202  }
203  return false;
204  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:632
+ Here is the call graph for this function:

◆ hasUndirectedPath() [3/3]

bool gum::EdgeGraphPart::hasUndirectedPath ( const NodeSet n1,
const NodeSet n2,
const NodeSet except 
) const
inherited

return true if n1 and n2 are connected (by an undirected path not using the nodes of except) in the graph.

Parameters
n1NodeSet
n2NodeSet
exceptNodeSet
Returns
bool

Definition at line 206 of file edgeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

208  {
209  NodeSet visited;
210  NodeSet temp;
211 
212  for (auto n: n1)
213  temp.insert(n);
214 
215  while (!temp.empty()) {
216  NodeId current = *(temp.begin());
217  if (n2.contains(current)) return true;
218  temp.erase(current);
219  visited.insert(current);
220  for (auto next: neighbours(current)) {
221  if (!temp.contains(next) && !visited.contains(next)
222  && !except.contains(next))
223  temp.insert(next);
224  }
225  }
226  return false;
227  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:632
+ Here is the call graph for this function:

◆ listMapEdges()

template<typename VAL >
List< VAL > gum::EdgeGraphPart::listMapEdges ( VAL(*)(const Edge &)  f) const
inherited

a method to create a list of VAL from a set of edges (using for every edge, say x, the VAL f(x))

Parameters
fa function assigning a VAL to any edge

◆ listMapNodes()

template<typename VAL >
List< VAL > gum::NodeGraphPart::listMapNodes ( VAL(*)(const NodeId &)  f) const
inherited

a method to create a list of VAL from a set of nodes (using for every nodee, say x, the VAL f(x))

Parameters
fa function assigning a VAL to any node

◆ neighbours()

INLINE const NodeSet & gum::EdgeGraphPart::neighbours ( const NodeId  id) const
inherited

returns the set of edges adjacent to a given node

Note that the set of edges returned may be empty if no edge within the EdgeGraphPart is adjacent the given node.

Parameters
idthe node to which the edges are adjacent

Definition at line 77 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

77  {
79  return *(neighbours__[id]);
80  }
NodeProperty< NodeSet *> neighbours__
for each node, the set of its adjacent edges
void checkNeighbours__(const NodeId id) const
when the EdgeGraphPart contains no edge adjacent to a given node, this function adds an empty set ent...
+ Here is the call graph for this function:

◆ nextNodeId()

INLINE NodeId gum::NodeGraphPart::nextNodeId ( ) const
inherited

returns a new node id, not yet used by any node

Warning
a code like
id=nextNodeId();addNode(id);
is basically not thread safe !!
Returns
a node id not yet used by any node within the NodeGraphPart

Definition at line 225 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

225  {
226  NodeId next = 0;
227 
228  // return the first hole if holes exist
229  if (holes__ && (!holes__->empty()))
230  next = *(holes__->begin());
231  else // in other case
232  next = boundVal__;
233 
234  return next;
235  }
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:726
iterator begin() const
The usual unsafe begin iterator to parse the set.
Definition: set_tpl.h:516
NodeSet * holes__
the set of nodes not contained in the NodeGraphPart in the interval 1..max__
NodeId boundVal__
the id below which NodeIds may belong to the NodeGraphPart
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ nodes()

INLINE const NodeGraphPart & gum::NodeGraphPart::nodes ( ) const
inherited

return *this as a NodeGraphPart

Definition at line 372 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

372  {
373  return *(static_cast< const NodeGraphPart* >(this));
374  }
NodeGraphPart(Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true)
default constructor
+ Here is the call graph for this function:

◆ nodes2ConnectedComponent()

NodeProperty< NodeId > gum::UndiGraph::nodes2ConnectedComponent ( ) const

returns a property {node:id of connected component}

Definition at line 152 of file undiGraph.cpp.

152  {
153  NodeProperty< NodeId > res;
154 
155  NodeId numCC = 0;
156  for (const auto node: nodes()) {
157  if (res.exists(node)) continue;
158  NodeSet nodes{node};
159  while (!nodes.empty()) {
160  auto actual = *(nodes.begin());
161  nodes.erase(actual);
162  res.insert(actual, numCC);
163  for (const auto nei: neighbours(actual)) {
164  if (!res.exists(nei))
165  if (!nodes.exists(nei)) nodes.insert(nei);
166  }
167  }
168  numCC += 1;
169  }
170 
171  return res;
172  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
bool exists(const NodeId id) const
alias for existsNode
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
bool empty() const
alias for emptyNodes
node_iterator begin() const noexcept
a begin iterator to parse the set of nodes contained in the NodeGraphPart
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
Size NodeId
Type for node ids.
Definition: graphElements.h:97

◆ nodesProperty() [1/2]

template<typename VAL >
NodeProperty< VAL > gum::NodeGraphPart::nodesProperty ( VAL(*)(const NodeId &)  f,
Size  size = 0 
) const
inherited

a method to create a HashTable with key:NodeId and value:VAL

VAL are computed from the nodes using for all node x, VAL f(x). This method is a wrapper of the same method in HashTable.

See also
HashTable::map.
Parameters
fa function assigning a VAL to any node
sizean optional parameter enabling to fine-tune the returned Property. Roughly speaking, it is a good practice to have a size equal to half the number of nodes. If you do not specify this parameter, the method will assign it for you.

◆ nodesProperty() [2/2]

template<typename VAL >
NodeProperty< VAL > gum::NodeGraphPart::nodesProperty ( const VAL &  a,
Size  size = 0 
) const
inherited

a method to create a hashMap with key:NodeId and value:VAL

for all nodes, the value stored is a. This method is a wrapper of the same method in HashTable.

See also
HashTable::map.
Parameters
athe default value assigned to each edge in the returned Property
sizean optional parameter enabling to fine-tune the returned Property. Roughly speaking, it is a good practice to have a size equal to half the number of nodes. If you do not specify this parameter, the method will assign it for you.

◆ operator!=() [1/3]

INLINE bool gum::EdgeGraphPart::operator!= ( const EdgeGraphPart p) const
inherited

tests whether two EdgeGraphParts contain different edges

Parameters
pthe EdgeGraphPart that we compare with this

Definition at line 110 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

110  {
111  return edges__ != p.edges__;
112  }
EdgeSet edges__
the set of all the edges contained within the EdgeGraphPart
+ Here is the call graph for this function:

◆ operator!=() [2/3]

INLINE bool gum::UndiGraph::operator!= ( const UndiGraph g) const

tests whether two UndiGraphs are different

Parameters
gthe UndiGraph with which "this" is compared

Definition at line 73 of file undiGraph_inl.h.

References gum::Set< Key, Alloc >::emplace().

73  {
74  return !operator==(p);
75  }
bool operator==(const UndiGraph &g) const
tests whether two UndiGraphs are identical (same nodes, same edges)
Definition: undiGraph_inl.h:69
+ Here is the call graph for this function:

◆ operator!=() [3/3]

INLINE bool gum::NodeGraphPart::operator!= ( const NodeGraphPart p) const
inherited

check whether two NodeGraphParts contain different nodes

Parameters
pthe NodeGraphPart to be compared with "this"

Definition at line 356 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

356  {
357  return !operator==(p);
358  }
bool operator==(const NodeGraphPart &p) const
check whether two NodeGraphParts contain the same nodes
+ Here is the call graph for this function:

◆ operator=()

INLINE UndiGraph & gum::UndiGraph::operator= ( const UndiGraph g)

copy operator

Parameters
gthe DiGraph to copy

Definition at line 51 of file undiGraph_inl.h.

References gum::Set< Key, Alloc >::emplace().

51  {
52  if (this != &g) {
56  }
57 
58  return *this;
59  }
NodeGraphPart & operator=(const NodeGraphPart &p)
copy operator
void clear() override
removes all the nodes and edges from the graph
Definition: undiGraph_inl.h:46
EdgeGraphPart & operator=(const EdgeGraphPart &s)
copy operator
+ Here is the call graph for this function:

◆ operator==() [1/3]

INLINE bool gum::EdgeGraphPart::operator== ( const EdgeGraphPart p) const
inherited

tests whether two EdgeGraphParts contain the same edges

Parameters
pthe EdgeGraphPart that we compare with this

Definition at line 106 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

106  {
107  return edges__ == p.edges__;
108  }
EdgeSet edges__
the set of all the edges contained within the EdgeGraphPart
+ Here is the call graph for this function:

◆ operator==() [2/3]

INLINE bool gum::UndiGraph::operator== ( const UndiGraph g) const

tests whether two UndiGraphs are identical (same nodes, same edges)

Parameters
gthe UndiGraph with which "this" is compared

Definition at line 69 of file undiGraph_inl.h.

References gum::Set< Key, Alloc >::emplace().

69  {
71  }
bool operator==(const EdgeGraphPart &p) const
tests whether two EdgeGraphParts contain the same edges
bool operator==(const NodeGraphPart &p) const
check whether two NodeGraphParts contain the same nodes
+ Here is the call graph for this function:

◆ operator==() [3/3]

INLINE bool gum::NodeGraphPart::operator== ( const NodeGraphPart p) const
inherited

check whether two NodeGraphParts contain the same nodes

Parameters
pthe NodeGraphPart to be compared with "this"

Definition at line 342 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

342  {
343  if (boundVal__ != p.boundVal__) return false;
344 
345  if (holes__)
346  if (p.holes__)
347  return (*holes__ == *p.holes__);
348  else
349  return false;
350  else if (p.holes__)
351  return false;
352 
353  return true;
354  }
NodeSet * holes__
the set of nodes not contained in the NodeGraphPart in the interval 1..max__
NodeId boundVal__
the id below which NodeIds may belong to the NodeGraphPart
+ Here is the call graph for this function:

◆ partialUndiGraph()

UndiGraph gum::UndiGraph::partialUndiGraph ( NodeSet  nodes)
virtual

returns the partial graph formed by the nodes given in parameter

Definition at line 138 of file undiGraph.cpp.

138  {
139  UndiGraph partialGraph;
140 
141  for (const auto node: nodes) {
142  partialGraph.addNodeWithId(node);
143 
144  for (const auto nei: neighbours(node))
145  if (nodes.contains(nei) && partialGraph.existsNode(nei))
146  partialGraph.addEdge(node, nei);
147  }
148 
149  return partialGraph;
150  }
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
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
Definition: undiGraph.cpp:39

◆ populateNodes()

void gum::NodeGraphPart::populateNodes ( const NodeGraphPart s)
inherited

populateNodes clears *this and fills it with the same nodes as "s"

populateNodes should basically be the preferred way to insert nodes with IDs not selected by the internal idFactory.

Parameters
sthe NodeGraphPart to be copied

Definition at line 63 of file nodeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

63  {
64  clear(); // "virtual" flush of the nodes set
65  holes_size__ = s.holes_size__;
66  holes_resize_policy__ = s.holes_resize_policy__;
67 
68  if (s.holes__) holes__ = new NodeSet(*s.holes__);
69 
70  boundVal__ = s.boundVal__;
71 
73  }
bool holes_resize_policy__
value for holes__ configuration
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeSet * holes__
the set of nodes not contained in the NodeGraphPart in the interval 1..max__
virtual void clear()
alias for clearNodes
NodeId boundVal__
the id below which NodeIds may belong to the NodeGraphPart
void updateEndIteratorSafe__()
updating endIterator (always at max__+1)
Size holes_size__
value for holes__ configuration
+ Here is the call graph for this function:

◆ populateNodesFromProperty()

template<typename T >
void gum::NodeGraphPart::populateNodesFromProperty ( const NodeProperty< T > &  h)
inherited

populateNodesFromProperty clears *this and fills it with the keys of "h"

populateNodes should basically be the preferred way to insert nodes with IDs not selected by the internal idFactory.

◆ size()

INLINE Size gum::NodeGraphPart::size ( ) const
inherited

alias for sizeNodes

Definition at line 283 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

283 { return sizeNodes(); }
Size sizeNodes() const
returns the number of nodes in the NodeGraphPart
+ Here is the call graph for this function:

◆ sizeEdges()

INLINE Size gum::EdgeGraphPart::sizeEdges ( ) const
inherited

indicates the number of edges stored within the EdgeGraphPart

Definition at line 36 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

36 { return edges__.size(); }
EdgeSet edges__
the set of all the edges contained within the EdgeGraphPart
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:720
+ Here is the call graph for this function:

◆ sizeNodes()

INLINE Size gum::NodeGraphPart::sizeNodes ( ) const
inherited

returns the number of nodes in the NodeGraphPart

Definition at line 279 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

279  {
280  return (holes__) ? (boundVal__ - holes__->size()) : boundVal__;
281  }
NodeSet * holes__
the set of nodes not contained in the NodeGraphPart in the interval 1..max__
NodeId boundVal__
the id below which NodeIds may belong to the NodeGraphPart
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:720
+ Here is the call graph for this function:

◆ toDot()

std::string gum::UndiGraph::toDot ( ) const
virtual

to friendly display graph in DOT format

Reimplemented in gum::MixedGraph, and gum::CliqueGraph.

Definition at line 108 of file undiGraph.cpp.

108  {
109  std::stringstream output;
110  std::stringstream nodeStream;
111  std::stringstream edgeStream;
112  List< NodeId > treatedNodes;
113  output << "digraph \""
114  << "no_name\" {" << std::endl
115  << "edge [dir=none]" << std::endl;
116  nodeStream << "node [shape = ellipse];" << std::endl;
117  std::string tab = " ";
118 
119  for (const auto node: nodes()) {
120  nodeStream << tab << node << ";";
121 
122  if (neighbours(node).size() > 0)
123  for (const auto nei: neighbours(node))
124  if (!treatedNodes.exists(nei))
125  edgeStream << tab << node << " -> " << nei << ";" << std::endl;
126 
127  treatedNodes.insert(node);
128  }
129 
130  output << nodeStream.str() << std::endl
131  << edgeStream.str() << std::endl
132  << "}" << std::endl;
133 
134  return output.str();
135  }
Size size() const
alias for sizeNodes
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart

◆ toString()

std::string gum::UndiGraph::toString ( ) const
overridevirtual

to friendly display the content of the graph

Reimplemented from gum::NodeGraphPart.

Definition at line 101 of file undiGraph.cpp.

101  {
102  std::string s = NodeGraphPart::toString();
103  s += " , ";
105  return s;
106  }
std::string toString() const
to friendly display the content of the EdgeGraphPart
virtual std::string toString() const
a function to display the set of nodes

◆ undirectedPath()

const std::vector< NodeId > gum::EdgeGraphPart::undirectedPath ( const NodeId  node1,
const NodeId  node2 
) const
inherited

returns a possible path from node1 to node2 in the edge set

Parameters
node1the id from which the path begins
node2the id to which the path ends
Exceptions
NotFoundexception is raised if no path can be found between the two nodes

Definition at line 126 of file edgeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

126  {
127  // not recursive version => use a FIFO for simulating the recursion
128  List< NodeId > nodeFIFO;
129  nodeFIFO.pushBack(n2);
130 
131  // mark[node] = predecessor if visited, else mark[node] does not exist
132  NodeProperty< NodeId > mark;
133  mark.insert(n2, n2);
134 
135  NodeId current;
136 
137  while (!nodeFIFO.empty()) {
138  current = nodeFIFO.front();
139  nodeFIFO.popFront();
140 
141  // check the neighbour
142  for (const auto new_one: neighbours(current)) {
143  if (mark.exists(new_one)) // if this node is already marked, stop
144  continue;
145 
146  mark.insert(new_one, current);
147 
148  if (new_one == n1) {
149  std::vector< NodeId > v;
150 
151  for (current = n1; current != n2; current = mark[current])
152  v.push_back(current);
153 
154  v.push_back(n2);
155 
156  return v;
157  }
158 
159  nodeFIFO.pushBack(new_one);
160  }
161  }
162 
163  GUM_ERROR(NotFound, "no path found");
164  }
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ unvirtualizedEraseNeighbours()

INLINE void gum::EdgeGraphPart::unvirtualizedEraseNeighbours ( const NodeId  id)
inherited

same function as eraseNeighbours but without any virtual call to an erase

Parameters
idthe node whose ingoing arcs will be removed

Definition at line 95 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

95  {
96  if (neighbours__.exists(id)) {
97  const NodeSet& set = neighbours(id);
98 
99  for (auto iter = set.beginSafe(); iter != set.endSafe();
100  ++iter) { // safe iterator needed here
101  EdgeGraphPart::eraseEdge(Edge(*iter, id));
102  }
103  }
104  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
NodeProperty< NodeSet *> neighbours__
for each node, the set of its adjacent edges
virtual void eraseEdge(const Edge &edge)
removes an edge from the EdgeGraphPart
+ Here is the call graph for this function:

Member Data Documentation

◆ onEdgeAdded

Signaler2< NodeId, NodeId > gum::EdgeGraphPart::onEdgeAdded
inherited

Definition at line 78 of file edgeGraphPart.h.

◆ onEdgeDeleted

Signaler2< NodeId, NodeId > gum::EdgeGraphPart::onEdgeDeleted
inherited

Definition at line 79 of file edgeGraphPart.h.

◆ onNodeAdded

Signaler1< NodeId > gum::NodeGraphPart::onNodeAdded
inherited

Definition at line 271 of file nodeGraphPart.h.

◆ onNodeDeleted

Signaler1< NodeId > gum::NodeGraphPart::onNodeDeleted
inherited

Definition at line 272 of file nodeGraphPart.h.


The documentation for this class was generated from the following files: