aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::MixedGraph Class Reference

Base class for mixed graphs. More...

#include <mixedGraph.h>

+ Inheritance diagram for gum::MixedGraph:
+ Collaboration diagram for gum::MixedGraph:

Public Attributes

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

Public Member Functions

bool hasDirectedPath (const NodeId from, const NodeId to)
 checks whether there exists a directed path from from to to More...
 
Constructors / Destructors
 MixedGraph (Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true, Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
 default constructor More...
 
 MixedGraph (const UndiGraph &g)
 default constructor More...
 
 MixedGraph (const DiGraph &g)
 default constructor More...
 
 MixedGraph (const MixedGraph &g)
 copy constructor More...
 
virtual ~MixedGraph ()
 destructor More...
 
Operators
MixedGraphoperator= (const MixedGraph &g)
 copy operator More...
 
bool operator== (const MixedGraph &g) const
 tests whether two MixedGraphs are identical (same nodes, arcs and edges) More...
 
bool operator!= (const MixedGraph &g) const
 tests whether two MixedGraphs are different More...
 
Accessors/Modifiers
virtual void eraseNode (const NodeId id)
 remove a node as well as its adjacent arcs and edges from the graph More...
 
virtual void clear ()
 removes all the nodes, arcs and edges from the graph More...
 
std::vector< NodeIdmixedOrientedPath (NodeId node1, NodeId node2) const
 returns a mixed edge/directed arc path from node1 to node2 in the arc/edge set More...
 
std::vector< NodeIdmixedUnorientedPath (NodeId node1, NodeId node2) const
 returns a mixed/directed path from node1 to node2 in the arc/edge set More...
 
virtual std::string toDot () const
 to friendly display mixed graph in DOT format More...
 
virtual std::string toString () const
 to friendly display the content of the MixedGraph More...
 
NodeSet adjacents (const NodeId id) const
 returns the set of node adjacent to a given node More...
 
Operators
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...
 
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...
 
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
void addEdge (NodeId first, NodeId second) override
 insert a new edge into the undirected graph 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...
 
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...
 
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 node neighbours 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...
 
Operators
bool operator== (const DiGraph &g) const
 tests whether two DiGraphs are identical (same nodes, same arcs) More...
 
bool operator!= (const DiGraph &g) const
 tests whether two DiGraphs are different More...
 
Operators
bool operator== (const ArcGraphPart &p) const
 tests whether two ArcGraphParts contain the same arcs More...
 
bool operator!= (const ArcGraphPart &p) const
 tests whether two ArcGraphParts contain different arcs More...
 
Accessors/Modifiers
virtual void addArc (const NodeId tail, const NodeId head)
 insert a new arc into the directed graph More...
 
const Sequence< NodeId > & topologicalOrder (bool clear=true) const
 The topological order stays the same as long as no variable or arcs are added or erased src the topology. More...
 
Accessors/Modifiers
virtual void eraseArc (const Arc &arc)
 removes an arc from the ArcGraphPart More...
 
bool existsArc (const Arc &arc) const
 indicates whether a given arc exists More...
 
bool existsArc (NodeId tail, NodeId head) const
 indicates whether a given arc exists More...
 
bool emptyArcs () const
 indicates wether the ArcGraphPart contains any arc More...
 
void clearArcs ()
 removes all the arcs from the ArcGraphPart More...
 
Size sizeArcs () const
 indicates the number of arcs stored within the ArcGraphPart More...
 
const ArcSetarcs () const
 returns the set of arcs stored within the ArcGraphPart More...
 
const NodeSetparents (NodeId id) const
 returns the set of nodes with arc ingoing to a given node More...
 
NodeSet parents (const NodeSet &ids) const
 returns the set of parents of a set of nodes More...
 
NodeSet family (NodeId id) const
 returns the set of nodes which consists in the node and its parents More...
 
NodeSet family (const NodeSet &ids) const
 returns the set of family nodes of a set of nodes More...
 
NodeSet descendants (NodeId id) const
 returns the set of nodes with directed path outgoing from a given node More...
 
NodeSet ancestors (NodeId id) const
 returns the set of nodes with directed path ingoing to a given node More...
 
NodeSet children (const NodeSet &ids) const
 returns the set of children of a set of nodes More...
 
const NodeSetchildren (NodeId id) const
 returns the set of nodes with arc outgoing from a given node More...
 
void eraseParents (NodeId id)
 erase all the parents of a given node More...
 
void unvirtualizedEraseParents (NodeId id)
 same function as eraseParents but without any virtual call to an erase More...
 
void eraseChildren (NodeId id)
 removes all the children of a given node More...
 
void unvirtualizedEraseChildren (NodeId id)
 same function as eraseChildren but without any virtual call to an erase More...
 
template<typename VAL >
ArcProperty< VAL > arcsProperty (VAL(*f)(const Arc &), Size size=0) const
 a method to create a hashMap of VAL from a set of arcs (using for every arc, say x, the VAL f(x)) More...
 
template<typename VAL >
ArcProperty< VAL > arcsProperty (const VAL &a, Size size=0) const
 a method to create a hashMap of VAL from a set of arcs (using for every arc, say x, the VAL a) More...
 
template<typename VAL >
List< VAL > listMapArcs (VAL(*f)(const Arc &)) const
 a method to create a list of VAL from a set of arcs (using for every arc, say x, the VAL f(x)) More...
 
std::vector< NodeIddirectedPath (NodeId node1, NodeId node2) const
 returns a directed path from node1 to node2 belonging to the set of arcs More...
 
std::vector< NodeIddirectedUnorientedPath (NodeId node1, NodeId node2) const
 returns an unoriented (directed) path from node1 to node2 in the arc set More...
 

Public Types

typedef NodeGraphPartIterator NodeIterator
 
typedef NodeGraphPartIterator NodeConstIterator
 
typedef NodeGraphPartIteratorSafe NodeIteratorSafe
 
typedef NodeGraphPartIteratorSafe NodeConstIteratorSafe
 
typedef EdgeSetIterator EdgeIterator
 
typedef ArcSetIterator ArcIterator
 
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...
 

Protected Member Functions

void eraseSetOfArcs_ (const ArcSet &set)
 a (virtualized) function to remove a given set of arcs More...
 
void unvirtualizedEraseSetOfArcs_ (const ArcSet &set)
 similar to eraseSetOfArcs_ except that it is unvirtualized More...
 

Detailed Description

Base class for mixed graphs.

Usage example:
// creating empty graphs
MixedGraph g1,g2;
// adding nodes, arcs and edges to g1
NodeId i1=g1.addNode();
NodeId i2=g1.addNode();
NodeId i3=g1.addNode();
g1.addArc( i1,i2 );
g1.addArc( i1,i3 );
g1.addArc( i2,i3 );
g1.addEdge( i1,i2 );
g1.addEdge( i1,i3 );
g1.addEdge( i2,i3 );
//throw an InvalidNode
// g1.addArc( i1+i2+i3,i1 );
// g1.addEdge( i1+i2+i3,i1 );
// copying graphs
MixedGraph g3 = g1;
g2 = g1;
MixedGraph 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 arcs and edges)
g1.clear();
// remove some arc
g4.eraseArc( Arc ( i1,i3 ) );
// remove some edge
g4.eraseEdge( Edge ( i1,i3 ) );
// remove node
g2.eraseNode( i2 );
// parse a graph
for ( const auto nod : g3.nodes() )
cerr << nod << endl;
for ( const auto arc : g3.arcs() )
cerr << arc << endl;
for ( const auto edg : g3.edges()) )
cerr << edg << endl;
const NodeSet& a=g3.parents( 3 );
for ( const auto iter : a)
cerr << " - "<<iter;
cerr<<endl;
const NodeSet& a=g3.neighbours( 3 );
for ( NodeSetIterator iter = a.begin( ); iter != a.end(); ++iter )
cerr << " - "<<*iter;
cerr<<endl;
// remove all the arcs that are parent of a given node
g3.eraseParents( 2 );
// remove all the edges that are adjacent to a given node
g3.eraseNeighbours( 2 );

Definition at line 126 of file mixedGraph.h.

Member Typedef Documentation

◆ ArcIterator

Definition at line 80 of file arcGraphPart.h.

◆ 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

◆ MixedGraph() [1/4]

gum::MixedGraph::MixedGraph ( Size  nodes_size = HashTableConst::default_size,
bool  nodes_resize_policy = true,
Size  arcs_size = HashTableConst::default_size,
bool  arcs_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
arcs_sizethe size of the hash table used to store all the arcs
arcs_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 36 of file mixedGraph.cpp.

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

41  :
42  // Note that we need to initialize the NodeGraphPart by ourselves
43  // because
44  // it is a virtual inherited class (see C++ FAQ Lite #25.12 for details)
45  NodeGraphPart(nodes_size, nodes_resize_policy),
46  UndiGraph(edges_size, edges_resize_policy),
47  DiGraph(arcs_size, arcs_resize_policy) { // for debugging purposes
48  GUM_CONSTRUCTOR(MixedGraph);
49  }
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
Definition: diGraph.cpp:36
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
MixedGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true, Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
Definition: mixedGraph.cpp:36
+ Here is the call graph for this function:

◆ MixedGraph() [2/4]

gum::MixedGraph::MixedGraph ( const UndiGraph g)
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
arcs_sizethe size of the hash table used to store all the arcs
arcs_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 51 of file mixedGraph.cpp.

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

51  : NodeGraphPart(g), UndiGraph(g), DiGraph() {
52  GUM_CONSTRUCTOR(MixedGraph);
53  }
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
Definition: diGraph.cpp:36
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
MixedGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true, Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
Definition: mixedGraph.cpp:36
+ Here is the call graph for this function:

◆ MixedGraph() [3/4]

gum::MixedGraph::MixedGraph ( const DiGraph g)
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
arcs_sizethe size of the hash table used to store all the arcs
arcs_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 55 of file mixedGraph.cpp.

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

55  : NodeGraphPart(g), UndiGraph(), DiGraph(g) {
56  GUM_CONSTRUCTOR(MixedGraph);
57  }
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
Definition: diGraph.cpp:36
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
MixedGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true, Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
Definition: mixedGraph.cpp:36
+ Here is the call graph for this function:

◆ MixedGraph() [4/4]

gum::MixedGraph::MixedGraph ( const MixedGraph g)

copy constructor

Parameters
gthe MixedGraph to copy

Definition at line 59 of file mixedGraph.cpp.

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

59  :
60  NodeGraphPart(g), UndiGraph(g), DiGraph(g) { // for debugging purposes
61  GUM_CONS_CPY(MixedGraph);
62  }
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
Definition: diGraph.cpp:36
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
MixedGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true, Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
Definition: mixedGraph.cpp:36
+ Here is the call graph for this function:

◆ ~MixedGraph()

gum::MixedGraph::~MixedGraph ( )
virtual

destructor

Definition at line 64 of file mixedGraph.cpp.

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

64  { // for debugging purposes
65  GUM_DESTRUCTOR(MixedGraph);
66  }
MixedGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true, Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
Definition: mixedGraph.cpp:36
+ Here is the call graph for this function:

Member Function Documentation

◆ addArc()

INLINE void gum::DiGraph::addArc ( const NodeId  tail,
const NodeId  head 
)
virtualinherited

insert a new arc into the directed graph

Parameters
tailthe id of the tail of the new inserted arc
headthe id of the head of the new inserted arc
Warning
if the arc already exists, nothing is done. In particular, no exception is raised.
Exceptions
InvalidNodeif head or tail does not belong to the graph nodes

Reimplemented from gum::ArcGraphPart.

Reimplemented in gum::DAG.

Definition at line 34 of file diGraph_inl.h.

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

34  {
35  if (!exists(head)) { GUM_ERROR(InvalidNode, "no head node : " << head) }
36 
37  if (!exists(tail)) { GUM_ERROR(InvalidNode, "no tail node : " << tail) }
38 
39  ArcGraphPart::addArc(tail, head);
40  }
bool exists(const NodeId id) const
alias for existsNode
virtual void addArc(NodeId tail, NodeId head)
insert a new arc into the ArcGraphPart
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ addEdge()

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

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)) { GUM_ERROR(InvalidNode, "Node (" << first << ") does not exist.") }
36 
37  if (!exists(second)) { GUM_ERROR(InvalidNode, "Node (" << second << ") does not exist.") }
38 
39  EdgeGraphPart::addEdge(second, first);
40  }
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:51
+ 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 238 of file nodeGraphPart_inl.h.

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

238  {
239  NodeId newNode;
240 
241  // fill the first hole if holes exist
242  if (_holes_ && (!_holes_->empty())) {
243  newNode = *(_holes_->begin());
244  _eraseHole_(newNode);
245  } else {
246  newNode = _boundVal_;
247  ++_boundVal_;
249  }
250 
251  GUM_EMIT1(onNodeAdded, newNode);
252 
253  return newNode;
254  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:700
void _updateEndIteratorSafe_()
updating endIterator (always at max+1)
#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:498
Signaler1< NodeId > onNodeAdded
void _eraseHole_(NodeId id)
to delete hole.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ 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 256 of file nodeGraphPart_inl.h.

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

256  {
257  std::vector< NodeId > v;
258  v.reserve(N);
259  for (Idx i = 0; i < N; i++)
260  v.push_back(this->addNode());
261  return v;
262  }
+ 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  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
void _updateEndIteratorSafe_()
updating endIterator (always at max+1)
#define GUM_EMIT1(signal, arg1)
Definition: signaler1.h:41
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
Size _holes_size_
value for holes configuration
Signaler1< NodeId > onNodeAdded
bool _inHoles_(NodeId id) const
void _eraseHole_(NodeId id)
to delete hole.
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:606
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
bool _holes_resize_policy_
value for holes configuration
+ Here is the call graph for this function:

◆ adjacents()

NodeSet gum::MixedGraph::adjacents ( const NodeId  id) const

returns the set of node adjacent to a given node

Note that the set of node returned may be empty.

Parameters
idthe node to which the edges are adjacent

Definition at line 227 of file mixedGraph.cpp.

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

227  {
228  return neighbours(id) + parents(id) + children(id);
229  }
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
const NodeSet & neighbours(const NodeId id) const
returns the set of node neighbours to a given node
+ Here is the call graph for this function:

◆ ancestors()

NodeSet gum::ArcGraphPart::ancestors ( NodeId  id) const
inherited

returns the set of nodes with directed path ingoing to a given node

Note that the set of nodes returned may be empty if no path within the ArcGraphPart is ingoing to the given node.

Parameters
idthe node which is the head of a directed path with the returned nodes

Definition at line 172 of file arcGraphPart.cpp.

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

172  {
173  NodeSet res;
174  NodeSet tmp;
175  for (auto next: parents(id))
176  tmp.insert(next);
177 
178  while (!tmp.empty()) {
179  auto current = *(tmp.begin());
180  tmp.erase(current);
181  res.insert(current);
182  for (auto next: parents(current)) {
183  if (!tmp.contains(next) && !res.contains(next)) { tmp.insert(next); }
184  }
185  }
186  return res;
187  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
+ Here is the call graph for this function:

◆ arcs()

INLINE const ArcSet & gum::ArcGraphPart::arcs ( ) const
inherited

returns the set of arcs stored within the ArcGraphPart

Definition at line 38 of file arcGraphPart_inl.h.

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

38 { return _arcs_; }
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
+ Here is the call graph for this function:

◆ arcsProperty() [1/2]

template<typename VAL >
ArcProperty< VAL > gum::ArcGraphPart::arcsProperty ( VAL(*)(const Arc &)  f,
Size  size = 0 
) const
inherited

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

Parameters
fa function assigning a VAL to any arc
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 arcs. If you do not specify this parameter, the method will assign it for you.

◆ arcsProperty() [2/2]

template<typename VAL >
ArcProperty< VAL > gum::ArcGraphPart::arcsProperty ( const VAL &  a,
Size  size = 0 
) const
inherited

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

Parameters
athe default value assigned to each arc 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 arcs. If you do not specify this parameter, the method will assign it for you.

◆ 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 340 of file nodeGraphPart_inl.h.

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

340  {
341  NodeSet son(sizeNodes());
342 
343  if (!empty()) {
344  for (NodeId n = 0; n < _boundVal_; ++n) {
345  if (!_inHoles_(n)) son.insert(n);
346  }
347  }
348 
349  return son;
350  }
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
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
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 314 of file nodeGraphPart_inl.h.

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

314  {
315  NodeGraphPartIterator it(*this);
316  it.validate_(); // stop the iterator at the first not-in-holes
317  return it;
318  }
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 302 of file nodeGraphPart_inl.h.

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

302  {
303  NodeGraphPartIteratorSafe it(*this);
304  it.validate_(); // stop the iterator at the first not-in-holes
305  return it;
306  }
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 291 of file nodeGraphPart_inl.h.

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

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

◆ children() [1/2]

INLINE NodeSet gum::ArcGraphPart::children ( const NodeSet ids) const
inherited

returns the set of children of a set of nodes

Definition at line 66 of file arcGraphPart_inl.h.

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

66  {
67  NodeSet res;
68  for (const auto node: ids)
69  res += children(node);
70  return res;
71  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
+ Here is the call graph for this function:

◆ children() [2/2]

INLINE const NodeSet & gum::ArcGraphPart::children ( NodeId  id) const
inherited

returns the set of nodes with arc outgoing from a given node

Note that the set of arcs returned may be empty if no arc within the ArcGraphPart is outgoing from the given node.

Parameters
idthe node which is the tail of the arcs returned

Definition at line 89 of file arcGraphPart_inl.h.

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

89  {
90  _checkChildren_(id);
91  return *(_children_[id]);
92  }
NodeProperty< NodeSet *> _children_
for each arc, the set of its children
Definition: arcGraphPart.h:307
void _checkChildren_(NodeId id) const
when the ArcGraphPart contains no arc outgoing from a given node, this function adds an empty set ent...
+ Here is the call graph for this function:

◆ clear()

INLINE void gum::MixedGraph::clear ( )
virtual

removes all the nodes, arcs and edges from the graph

Reimplemented from gum::DiGraph.

Definition at line 48 of file mixedGraph_inl.h.

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

48  {
52  }
void clearArcs()
removes all the arcs from the ArcGraphPart
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:

◆ clearArcs()

void gum::ArcGraphPart::clearArcs ( )
inherited

removes all the arcs from the ArcGraphPart

Definition at line 78 of file arcGraphPart.cpp.

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

78  {
79  for (const auto& elt: _parents_)
80  delete elt.second;
81 
82  _parents_.clear();
83 
84  for (const auto& elt: _children_)
85  delete elt.second;
86 
87  _children_.clear();
88 
89  // we need this copy only if at least one onArcDeleted listener exists
90  if (onArcDeleted.hasListener()) {
91  ArcSet tmp = _arcs_;
92  _arcs_.clear();
93 
94  for (const auto& arc: tmp)
95  GUM_EMIT2(onArcDeleted, arc.tail(), arc.head());
96  } else {
97  _arcs_.clear();
98  }
99  }
NodeProperty< NodeSet *> _children_
for each arc, the set of its children
Definition: arcGraphPart.h:307
Set< Arc > ArcSet
Some typdefs and define for shortcuts ...
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:41
NodeProperty< NodeSet *> _parents_
for each arc, the sets of its parents
Definition: arcGraphPart.h:304
Signaler2< NodeId, NodeId > onArcDeleted
Definition: arcGraphPart.h:83
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:361
+ 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
Signaler2< NodeId, NodeId > onEdgeDeleted
Definition: edgeGraphPart.h:79
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:361
NodeProperty< NodeSet *> _neighbours_
for each node, the set of its adjacent edges
+ 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 293 of file nodeGraphPart_inl.h.

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

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

◆ descendants()

NodeSet gum::ArcGraphPart::descendants ( NodeId  id) const
inherited

returns the set of nodes with directed path outgoing from a given node

Note that the set of nodes returned may be empty if no path within the ArcGraphPart is outgoing from the given node.

Parameters
idthe node which is the tail of a directed path with the returned nodes

Definition at line 154 of file arcGraphPart.cpp.

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

154  {
155  NodeSet res;
156  NodeSet tmp;
157  for (auto next: children(id))
158  tmp.insert(next);
159 
160  while (!tmp.empty()) {
161  auto current = *(tmp.begin());
162  tmp.erase(current);
163  res.insert(current);
164  for (auto next: children(current)) {
165  if (!tmp.contains(next) && !res.contains(next)) { tmp.insert(next); }
166  }
167  }
168  return res;
169  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
+ Here is the call graph for this function:

◆ directedPath()

std::vector< NodeId > gum::ArcGraphPart::directedPath ( NodeId  node1,
NodeId  node2 
) const
inherited

returns a directed path from node1 to node2 belonging to the set of arcs

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 190 of file arcGraphPart.cpp.

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

190  {
191  // not recursive version => use a FIFO for simulating the recursion
192  List< NodeId > nodeFIFO;
193  nodeFIFO.pushBack(n2);
194 
195  // mark[node] = successor if visited, else mark[node] does not exist
196  NodeProperty< NodeId > mark;
197  mark.insert(n2, n2);
198 
199  NodeId current;
200 
201  while (!nodeFIFO.empty()) {
202  current = nodeFIFO.front();
203  nodeFIFO.popFront();
204 
205  // check the parents
206 
207  for (const auto new_one: parents(current)) {
208  if (mark.exists(new_one)) // if this node is already marked, do not
209  continue; // check it again
210 
211  mark.insert(new_one, current);
212 
213  if (new_one == n1) {
214  std::vector< NodeId > v;
215 
216  for (current = n1; current != n2; current = mark[current])
217  v.push_back(current);
218 
219  v.push_back(n2);
220 
221  return v;
222  }
223 
224  nodeFIFO.pushBack(new_one);
225  }
226  }
227 
228  GUM_ERROR(NotFound, "no path found")
229  }
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ directedUnorientedPath()

std::vector< NodeId > gum::ArcGraphPart::directedUnorientedPath ( NodeId  node1,
NodeId  node2 
) const
inherited

returns an unoriented (directed) path from node1 to node2 in the arc 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 231 of file arcGraphPart.cpp.

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

231  {
232  // not recursive version => use a FIFO for simulating the recursion
233  List< NodeId > nodeFIFO;
234  nodeFIFO.pushBack(n2);
235 
236  // mark[node] = successor if visited, else mark[node] does not exist
237  NodeProperty< NodeId > mark;
238  mark.insert(n2, n2);
239 
240  NodeId current;
241 
242  while (!nodeFIFO.empty()) {
243  current = nodeFIFO.front();
244  nodeFIFO.popFront();
245 
246  // check the parents
247  for (const auto new_one: parents(current)) {
248  if (mark.exists(new_one)) // the node has already been visited
249  continue;
250 
251  mark.insert(new_one, current);
252 
253  if (new_one == n1) {
254  std::vector< NodeId > v;
255 
256  for (current = n1; current != n2; current = mark[current])
257  v.push_back(current);
258 
259  v.push_back(n2);
260 
261  return v;
262  }
263 
264  nodeFIFO.pushBack(new_one);
265  }
266 
267  // check the children
268  for (const auto new_one: children(current)) {
269  if (mark.exists(new_one)) // the node has already been visited
270  continue;
271 
272  mark.insert(new_one, current);
273 
274  if (new_one == n1) {
275  std::vector< NodeId > v;
276 
277  for (current = n1; current != n2; current = mark[current])
278  v.push_back(current);
279 
280  v.push_back(n2);
281 
282  return v;
283  }
284 
285  nodeFIFO.pushBack(new_one);
286  }
287  }
288 
289  GUM_ERROR(NotFound, "no path found")
290  }
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ 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 289 of file nodeGraphPart_inl.h.

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

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

◆ emptyArcs()

INLINE bool gum::ArcGraphPart::emptyArcs ( ) const
inherited

indicates wether the ArcGraphPart contains any arc

Definition at line 34 of file arcGraphPart_inl.h.

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

34 { return _arcs_.empty(); }
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:700
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
+ 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(); }
EdgeSet _edges_
the set of all the edges contained within the EdgeGraphPart
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:700
+ 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 287 of file nodeGraphPart_inl.h.

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

287 { 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 320 of file nodeGraphPart_inl.h.

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

320  {
321  return _endIteratorSafe_;
322  }
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 310 of file nodeGraphPart_inl.h.

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

310  {
311  return _endIteratorSafe_;
312  }
NodeGraphPartIteratorSafe _endIteratorSafe_
the end iterator (used to speed-up parsings of the NodeGraphPart)
+ Here is the call graph for this function:

◆ eraseArc()

INLINE void gum::ArcGraphPart::eraseArc ( const Arc arc)
virtualinherited

removes an arc from the ArcGraphPart

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

Definition at line 106 of file arcGraphPart_inl.h.

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

106  {
107  // ASSUMING tail and head exists in _parents_ anf _children_
108  // (if not, it is an error)
109  if (existsArc(arc)) {
110  NodeId tail = arc.tail(), head = arc.head();
111  _parents_[head]->erase(tail);
112  _children_[tail]->erase(head);
113  _arcs_.erase(arc);
114  GUM_EMIT2(onArcDeleted, tail, head);
115  }
116  }
NodeProperty< NodeSet *> _children_
for each arc, the set of its children
Definition: arcGraphPart.h:307
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:649
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:41
NodeProperty< NodeSet *> _parents_
for each arc, the sets of its parents
Definition: arcGraphPart.h:304
Signaler2< NodeId, NodeId > onArcDeleted
Definition: arcGraphPart.h:83
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ eraseChildren()

INLINE void gum::ArcGraphPart::eraseChildren ( NodeId  id)
inherited

removes all the children of a given node

Parameters
idthe node all the children of which will be removed
Warning
although this method is not virtual, it calls method eraseArc( const Arc& arc ) and, as such, has a "virtual" behaviour. If you do not wish it to have this "virtual" behaviour, call instead method unvirtualizedEraseChildren
if no arc is a parent of id, nothing is done. In particular, no exception is thrown.

Definition at line 137 of file arcGraphPart_inl.h.

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

137  {
138  if (_children_.exists(id)) {
139  NodeSet& children = *(_children_[id]);
140 
141  for (auto iter = children.beginSafe(); // safe iterator needed here
142  iter != children.endSafe();
143  ++iter) {
144  // warning: use this erase so that you actually use the vritualized
145  // arc removal function
146  eraseArc(Arc(id, *iter));
147  }
148  }
149  }
NodeProperty< NodeSet *> _children_
for each arc, the set of its children
Definition: arcGraphPart.h:307
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
+ 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 61 of file edgeGraphPart_inl.h.

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

61  {
62  if (existsEdge(edge)) {
63  // ASSUMING first and second exists in _neighbours_ (if not, it is an
64  // error)
65  NodeId id1 = edge.first(), id2 = edge.second();
66 
67  _neighbours_[id1]->erase(id2);
68  _neighbours_[id2]->erase(id1);
69  _edges_.erase(edge);
70  GUM_EMIT2(onEdgeDeleted, id1, id2);
71  }
72  }
EdgeSet _edges_
the set of all the edges contained within the EdgeGraphPart
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:649
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:41
bool existsEdge(const Edge &edge) const
indicates whether a given edge exists
Signaler2< NodeId, NodeId > onEdgeDeleted
Definition: edgeGraphPart.h:79
NodeProperty< NodeSet *> _neighbours_
for each node, the set of its adjacent edges
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 79 of file edgeGraphPart_inl.h.

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

79  {
80  if (_neighbours_.exists(id)) {
81  const NodeSet& set = neighbours(id);
82 
83  for (auto iter = set.beginSafe(); iter != set.endSafe();
84  ++iter) { // safe iterator needed here
85  // warning: use this erase so that you actually use the virtualized
86  // edge removal function
87  eraseEdge(Edge(*iter, id));
88  }
89  }
90  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & neighbours(const NodeId id) const
returns the set of node neighbours 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::MixedGraph::eraseNode ( const NodeId  id)
virtual

remove a node as well as its adjacent arcs and 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::DiGraph.

Definition at line 54 of file mixedGraph_inl.h.

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

54  {
59  }
void unvirtualizedEraseChildren(NodeId id)
same function as eraseChildren but without any virtual call to an erase
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
void unvirtualizedEraseParents(NodeId id)
same function as eraseParents but without any virtual call to an erase
+ Here is the call graph for this function:

◆ eraseParents()

INLINE void gum::ArcGraphPart::eraseParents ( NodeId  id)
inherited

erase all the parents of a given node

Parameters
idthe node all the parents of which will be removed
Warning
although this method is not virtual, it calls method eraseArc( const Arc& arc ) and, as such, has a "virtual" behaviour. If you do not wish it to have this "virtual" behaviour, call instead method unvirtualizedEraseParents
if no arc is a parent of id, nothing is done. In particular, no exception is thrown.

Definition at line 123 of file arcGraphPart_inl.h.

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

123  {
124  if (_parents_.exists(id)) {
125  NodeSet& parents = *(_parents_[id]);
126 
127  for (auto iter = parents.beginSafe(); // safe iterator needed here
128  iter != parents.endSafe();
129  ++iter) {
130  // warning: use this erase so that you actually use the virtualized
131  // arc removal function
132  eraseArc(Arc(*iter, id));
133  }
134  }
135  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
NodeProperty< NodeSet *> _parents_
for each arc, the sets of its parents
Definition: arcGraphPart.h:304
+ Here is the call graph for this function:

◆ eraseSetOfArcs_()

INLINE void gum::ArcGraphPart::eraseSetOfArcs_ ( const ArcSet set)
protectedinherited

a (virtualized) function to remove a given set of arcs

Warning
this function uses eraseArc, which is a virtual function. Hence the behaviour of this function is that of a virtual function

Definition at line 118 of file arcGraphPart_inl.h.

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

118  {
119  for (const auto& arc: set)
120  eraseArc(arc);
121  }
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
+ 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 277 of file nodeGraphPart_inl.h.

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

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

◆ existsArc() [1/2]

INLINE bool gum::ArcGraphPart::existsArc ( const Arc arc) const
inherited

indicates whether a given arc exists

Parameters
arcthe arc we test whether or not it belongs to the ArcGraphPart

Definition at line 40 of file arcGraphPart_inl.h.

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

40 { return _arcs_.contains(arc); }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:558
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
+ Here is the call graph for this function:

◆ existsArc() [2/2]

INLINE bool gum::ArcGraphPart::existsArc ( NodeId  tail,
NodeId  head 
) const
inherited

indicates whether a given arc exists

Parameters
tailthe tail of the arc we test the existence in the ArcGraphPart
headthe head of the arc we test the existence in the ArcGraphPart

Definition at line 42 of file arcGraphPart_inl.h.

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

42  {
43  return _parents_.exists(head) && _parents_[head]->exists(tail);
44  }
NodeProperty< NodeSet *> _parents_
for each arc, the sets of its parents
Definition: arcGraphPart.h:304
+ 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 { return _edges_.contains(edge); }
EdgeSet _edges_
the set of all the edges contained within the EdgeGraphPart
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:558
+ 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 42 of file edgeGraphPart_inl.h.

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

42  {
43  return _neighbours_.exists(first) && _neighbours_[first]->exists(second);
44  }
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 271 of file nodeGraphPart_inl.h.

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

271  {
272  if (node >= _boundVal_) return false;
273 
274  return (!_inHoles_(node));
275  }
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:

◆ family() [1/2]

INLINE NodeSet gum::ArcGraphPart::family ( NodeId  id) const
inherited

returns the set of nodes which consists in the node and its parents

Note that the set of nodes returned may be empty if no path within the ArcGraphPart is outgoing from the given node.

Parameters
idthe node which is the tail of a directed path with the returned nodes

Definition at line 59 of file arcGraphPart_inl.h.

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

59  {
60  _checkParents_(id);
61  NodeSet res{id};
62  return res + parents(id);
63  }
void _checkParents_(NodeId id) const
when the ArcGraphPart contains no arc ingoing into a given node, this function adds an empty set entr...
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
+ Here is the call graph for this function:

◆ family() [2/2]

INLINE NodeSet gum::ArcGraphPart::family ( const NodeSet ids) const
inherited

returns the set of family nodes of a set of nodes

Definition at line 82 of file arcGraphPart_inl.h.

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

82  {
83  NodeSet res;
84  for (const auto node: ids)
85  res += family(node);
86  return res;
87  }
NodeSet family(NodeId id) const
returns the set of nodes which consists in the node and its parents
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
+ Here is the call graph for this function:

◆ hasDirectedPath()

bool gum::DiGraph::hasDirectedPath ( const NodeId  from,
const NodeId  to 
)
inherited

checks whether there exists a directed path from from to to

If from==to, this function checks if a directed cycle containing from exists.

Parameters
from
to
Returns
true if a directed path exists

Definition at line 131 of file diGraph.cpp.

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

131  {
132  if (!exists(from)) return false;
133 
134  // not recursive version => use a FIFO for simulating the recursion
135  List< NodeId > nodeFIFO;
136  nodeFIFO.pushBack(from);
137 
138  NodeSet marked;
139  marked.insert(from);
140 
141  NodeId new_one;
142 
143  while (!nodeFIFO.empty()) {
144  new_one = nodeFIFO.front();
145  // std::cout<<new_one<<std::endl;
146  nodeFIFO.popFront();
147 
148  for (const auto chi: children(new_one)) {
149  if (chi == to) return true;
150 
151  if (!marked.contains(chi)) {
152  nodeFIFO.pushBack(chi);
153  marked.insert(chi);
154  }
155  }
156  }
157 
158  return false;
159  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
bool exists(const NodeId id) const
alias for existsNode
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:606
+ Here is the call graph for this function:

◆ hasUndirectedCycle()

bool gum::UndiGraph::hasUndirectedCycle ( ) const
inherited

checks whether the graph contains cycles

Definition at line 57 of file undiGraph.cpp.

57  {
58  List< std::pair< NodeId, NodeId > > open_nodes;
59  NodeProperty< bool > examined_nodes = nodesProperty(false);
60  std::pair< NodeId, NodeId > thePair;
61  NodeId current, from_current;
62 
63  for (const auto node: nodes()) {
64  // check if the node has already been examined (if this is not the case,
65  // this means that we are on a new connected component)
66  if (!examined_nodes[node]) {
67  // indicates that we are examining a new node
68  examined_nodes[node] = true;
69 
70  // check recursively all the nodes of node's connected component
71  thePair.first = node;
72  thePair.second = node;
73  open_nodes.insert(thePair);
74 
75  while (!open_nodes.empty()) {
76  // get a node to propagate
77  thePair = open_nodes.front();
78  open_nodes.popFront();
79 
80  current = thePair.first;
81  from_current = thePair.second;
82 
83  // check the neighbours
84  for (const auto new_node: neighbours(current))
85 
86  // avoid to check the node we are coming from
87  if (new_node != from_current) {
88  if (examined_nodes[new_node])
89  return true;
90  else {
91  examined_nodes[new_node] = true;
92  thePair.first = new_node;
93  thePair.second = current;
94  open_nodes.insert(thePair);
95  }
96  }
97  }
98  }
99  }
100 
101  return false;
102  }
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 node neighbours 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 node neighbours 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:606
+ 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().

183  {
184  NodeSet visited;
185  NodeSet temp;
186 
187  if (except.contains(n2)) return false;
188 
189  temp.insert(n1);
190  while (!temp.empty()) {
191  NodeId current = *(temp.begin());
192  if (current == n2) return true;
193  temp.erase(current);
194  visited.insert(current);
195  for (auto next: neighbours(current)) {
196  if (!temp.contains(next) && !visited.contains(next) && !except.contains(next))
197  temp.insert(next);
198  }
199  }
200  return false;
201  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & neighbours(const NodeId id) const
returns the set of node neighbours 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:606
+ 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 203 of file edgeGraphPart.cpp.

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

205  {
206  NodeSet visited;
207  NodeSet temp;
208 
209  for (auto n: n1)
210  temp.insert(n);
211 
212  while (!temp.empty()) {
213  NodeId current = *(temp.begin());
214  if (n2.contains(current)) return true;
215  temp.erase(current);
216  visited.insert(current);
217  for (auto next: neighbours(current)) {
218  if (!temp.contains(next) && !visited.contains(next) && !except.contains(next))
219  temp.insert(next);
220  }
221  }
222  return false;
223  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & neighbours(const NodeId id) const
returns the set of node neighbours 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:606
+ Here is the call graph for this function:

◆ listMapArcs()

template<typename VAL >
List< VAL > gum::ArcGraphPart::listMapArcs ( VAL(*)(const Arc &)  f) const
inherited

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

Parameters
fa function assigning a VAL to any arc

◆ 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

◆ mixedOrientedPath()

std::vector< NodeId > gum::MixedGraph::mixedOrientedPath ( NodeId  node1,
NodeId  node2 
) const

returns a mixed edge/directed arc path from node1 to node2 in the arc/edge set

This function returns, if any, a path from node1 to node2, using edges and/or arcs (wrt the direction of th arcs)

Parameters
node1the id from which the path begins
node2the id to which the path ends if no path can be found between the two nodes, the returned vector is empty

Definition at line 77 of file mixedGraph.cpp.

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

77  {
78  std::vector< NodeId > v;
79  // not recursive version => use a FIFO for simulating the recursion
80  List< NodeId > node_fifo;
81  node_fifo.pushBack(n2);
82 
83  // mark[node] = successor if visited, else mark[node] does not exist
84  NodeProperty< NodeId > mark;
85  mark.insert(n2, n2);
86 
87  NodeId current;
88  while (!node_fifo.empty()) {
89  current = node_fifo.front();
90  node_fifo.popFront();
91 
92  // check the neighbours
93  for (const auto new_one: neighbours(current)) {
94  if (mark.exists(new_one)) // if the node has already been visited
95  continue; // do not check it again
96 
97  mark.insert(new_one, current);
98 
99  if (new_one == n1) {
100  for (current = n1; current != n2; current = mark[current])
101  v.push_back(current);
102  v.push_back(n2);
103  return v;
104  }
105 
106  node_fifo.pushBack(new_one);
107  }
108 
109  // check the parents
110  for (const auto new_one: parents(current)) {
111  if (mark.exists(new_one)) // if this node is already marked, do not
112  continue; // check it again
113 
114  mark.insert(new_one, current);
115 
116  if (new_one == n1) {
117  for (current = n1; current != n2; current = mark[current])
118  v.push_back(current);
119  v.push_back(n2);
120  return v;
121  }
122 
123  node_fifo.pushBack(new_one);
124  }
125  }
126 
127  return v;
128  }
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
const NodeSet & neighbours(const NodeId id) const
returns the set of node neighbours to a given node
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ mixedUnorientedPath()

std::vector< NodeId > gum::MixedGraph::mixedUnorientedPath ( NodeId  node1,
NodeId  node2 
) const

returns a mixed/directed path from node1 to node2 in the arc/edge set

This function returns, if any, a path from node1 to node2, using edges and/or arcs (not necessarily following the direction of th arcs)

Parameters
node1the id from which the path begins
node2the id to which the path ends if no path can be found between the two nodes, the returned vector is empty.

Definition at line 130 of file mixedGraph.cpp.

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

130  {
131  std::vector< NodeId > v;
132  // not recursive version => use a FIFO for simulating the recursion
133  List< NodeId > node_fifo;
134  node_fifo.pushBack(n2);
135 
136  // mark[node] = successor if visited, else mark[node] does not exist
137  NodeProperty< NodeId > mark;
138  mark.insert(n2, n2);
139 
140  NodeId current;
141 
142  while (!node_fifo.empty()) {
143  current = node_fifo.front();
144  node_fifo.popFront();
145 
146  // check the neighbours
147  for (const auto new_one: neighbours(current)) {
148  if (mark.exists(new_one)) // if the node has already been visited
149  continue; // do not check it again
150 
151  mark.insert(new_one, current);
152 
153  if (new_one == n1) {
154  for (current = n1; current != n2; current = mark[current])
155  v.push_back(current);
156  v.push_back(n2);
157  return v;
158  }
159 
160  node_fifo.pushBack(new_one);
161  }
162 
163  // check the parents
164  for (const auto new_one: parents(current)) {
165  if (mark.exists(new_one)) // the node has already been visited
166  continue;
167 
168  mark.insert(new_one, current);
169  if (new_one == n1) {
170  for (current = n1; current != n2; current = mark[current])
171  v.push_back(current);
172  v.push_back(n2);
173  return v;
174  }
175  node_fifo.pushBack(new_one);
176  }
177 
178  // check the children
179  for (const auto new_one: children(current)) {
180  if (mark.exists(new_one)) // the node has already been visited
181  continue;
182 
183  mark.insert(new_one, current);
184 
185  if (new_one == n1) {
186  for (current = n1; current != n2; current = mark[current])
187  v.push_back(current);
188  v.push_back(n2);
189  return v;
190  }
191 
192  node_fifo.pushBack(new_one);
193  }
194  }
195 
196  return v;
197  }
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
const NodeSet & neighbours(const NodeId id) const
returns the set of node neighbours to a given node
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ neighbours()

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

returns the set of node neighbours to a given node

Note that the set of nodes 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 74 of file edgeGraphPart_inl.h.

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

74  {
76  return *(_neighbours_[id]);
77  }
void _checkNeighbours_(const NodeId id) const
when the EdgeGraphPart contains no edge adjacent to a given node, this function adds an empty set ent...
NodeProperty< NodeSet *> _neighbours_
for each node, the set of its adjacent edges
+ 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 211 of file nodeGraphPart_inl.h.

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

211  {
212  NodeId next = 0;
213 
214  // return the first hole if holes exist
215  if (_holes_ && (!_holes_->empty()))
216  next = *(_holes_->begin());
217  else // in other case
218  next = _boundVal_;
219 
220  return next;
221  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:700
iterator begin() const
The usual unsafe begin iterator to parse the set.
Definition: set_tpl.h:498
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 352 of file nodeGraphPart_inl.h.

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

352  {
353  return *(static_cast< const NodeGraphPart* >(this));
354  }
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
inherited

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 node neighbours 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/6]

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 107 of file edgeGraphPart_inl.h.

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

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

◆ operator!=() [2/6]

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

tests whether two ArcGraphParts contain different arcs

Parameters
pthe ArcGraphPart that we compare with this

Definition at line 182 of file arcGraphPart_inl.h.

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

182 { return _arcs_ != p._arcs_; }
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
+ Here is the call graph for this function:

◆ operator!=() [3/6]

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

tests whether two UndiGraphs are different

Parameters
gthe UndiGraph with which "this" is compared

Definition at line 69 of file undiGraph_inl.h.

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

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

◆ operator!=() [4/6]

INLINE bool gum::DiGraph::operator!= ( const DiGraph g) const
inherited

tests whether two DiGraphs are different

Parameters
gthe DiGraph with which "this" is compared

Definition at line 81 of file diGraph_inl.h.

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

81 { return !operator==(p); }
bool operator==(const DiGraph &g) const
tests whether two DiGraphs are identical (same nodes, same arcs)
Definition: diGraph_inl.h:77
+ Here is the call graph for this function:

◆ operator!=() [5/6]

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

tests whether two MixedGraphs are different

Parameters
gthe MixedGraph with which "this" is compared

Definition at line 66 of file mixedGraph_inl.h.

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

66 { return !operator==(p); }
bool operator==(const MixedGraph &g) const
tests whether two MixedGraphs are identical (same nodes, arcs and edges)
+ Here is the call graph for this function:

◆ operator!=() [6/6]

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 338 of file nodeGraphPart_inl.h.

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

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

◆ operator=()

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

copy operator

Parameters
gthe MixedGraph to copy

Definition at line 31 of file mixedGraph_inl.h.

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

31  {
32  // avoid self assigment
33  if (this != &g) {
34  // remove the old graph properly
38 
39  // fill the new graph
43  }
44 
45  return *this;
46  }
NodeGraphPart & operator=(const NodeGraphPart &p)
copy operator
EdgeGraphPart & operator=(const EdgeGraphPart &s)
copy operator
ArcGraphPart & operator=(const ArcGraphPart &s)
copy operator
void clearArcs()
removes all the arcs from the ArcGraphPart
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:

◆ operator==() [1/6]

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 103 of file edgeGraphPart_inl.h.

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

103  {
104  return _edges_ == p._edges_;
105  }
EdgeSet _edges_
the set of all the edges contained within the EdgeGraphPart
+ Here is the call graph for this function:

◆ operator==() [2/6]

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

tests whether two ArcGraphParts contain the same arcs

Parameters
pthe ArcGraphPart that we compare with this

Definition at line 180 of file arcGraphPart_inl.h.

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

180 { return _arcs_ == p._arcs_; }
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
+ Here is the call graph for this function:

◆ operator==() [3/6]

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

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

Parameters
gthe UndiGraph with which "this" is compared

Definition at line 65 of file undiGraph_inl.h.

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

65  {
67  }
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==() [4/6]

INLINE bool gum::DiGraph::operator== ( const DiGraph g) const
inherited

tests whether two DiGraphs are identical (same nodes, same arcs)

Parameters
gthe DiGraph with which "this" is compared

Definition at line 77 of file diGraph_inl.h.

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

77  {
79  }
bool operator==(const NodeGraphPart &p) const
check whether two NodeGraphParts contain the same nodes
bool operator==(const ArcGraphPart &p) const
tests whether two ArcGraphParts contain the same arcs
+ Here is the call graph for this function:

◆ operator==() [5/6]

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

tests whether two MixedGraphs are identical (same nodes, arcs and edges)

Parameters
gthe MixedGraph with which "this" is compared

Definition at line 61 of file mixedGraph_inl.h.

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

61  {
64  }
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
bool operator==(const ArcGraphPart &p) const
tests whether two ArcGraphParts contain the same arcs
+ Here is the call graph for this function:

◆ operator==() [6/6]

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 324 of file nodeGraphPart_inl.h.

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

324  {
325  if (_boundVal_ != p._boundVal_) return false;
326 
327  if (_holes_)
328  if (p._holes_)
329  return (*_holes_ == *p._holes_);
330  else
331  return false;
332  else if (p._holes_)
333  return false;
334 
335  return true;
336  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
+ Here is the call graph for this function:

◆ parents() [1/2]

INLINE const NodeSet & gum::ArcGraphPart::parents ( NodeId  id) const
inherited

returns the set of nodes with arc ingoing to a given node

Note that the set of arcs returned may be empty if no arc within the ArcGraphPart is ingoing into the given node.

Parameters
idthe node toward which the arcs returned are pointing

Definition at line 54 of file arcGraphPart_inl.h.

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

54  {
55  _checkParents_(id);
56  return *(_parents_[id]);
57  }
void _checkParents_(NodeId id) const
when the ArcGraphPart contains no arc ingoing into a given node, this function adds an empty set entr...
NodeProperty< NodeSet *> _parents_
for each arc, the sets of its parents
Definition: arcGraphPart.h:304
+ Here is the call graph for this function:

◆ parents() [2/2]

INLINE NodeSet gum::ArcGraphPart::parents ( const NodeSet ids) const
inherited

returns the set of parents of a set of nodes

Definition at line 74 of file arcGraphPart_inl.h.

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

74  {
75  NodeSet res;
76  for (const auto node: ids)
77  res += parents(node);
78  return res;
79  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
+ Here is the call graph for this function:

◆ partialUndiGraph()

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

returns the partial graph formed by the nodes given in parameter

Definition at line 139 of file undiGraph.cpp.

139  {
140  UndiGraph partialGraph;
141 
142  for (const auto node: nodes) {
143  partialGraph.addNodeWithId(node);
144 
145  for (const auto nei: neighbours(node))
146  if (nodes.contains(nei) && partialGraph.existsNode(nei)) partialGraph.addEdge(node, nei);
147  }
148 
149  return partialGraph;
150  }
const NodeSet & neighbours(const NodeId id) const
returns the set of node neighbours 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  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
void _updateEndIteratorSafe_()
updating endIterator (always at max+1)
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
Size _holes_size_
value for holes configuration
virtual void clear()
alias for clearNodes
bool _holes_resize_policy_
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 269 of file nodeGraphPart_inl.h.

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

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

◆ sizeArcs()

INLINE Size gum::ArcGraphPart::sizeArcs ( ) const
inherited

indicates the number of arcs stored within the ArcGraphPart

Definition at line 36 of file arcGraphPart_inl.h.

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

36 { return _arcs_.size(); }
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:694
+ 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:694
+ 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 265 of file nodeGraphPart_inl.h.

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

265  {
266  return (_holes_) ? (_boundVal_ - _holes_->size()) : _boundVal_;
267  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
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:694
+ Here is the call graph for this function:

◆ toDot()

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

to friendly display mixed graph in DOT format

Reimplemented from gum::DiGraph.

Definition at line 199 of file mixedGraph.cpp.

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

199  {
200  std::stringstream output;
201  std::stringstream nodeStream;
202  std::stringstream edgeStream;
203  List< NodeId > treatedNodes;
204  output << "digraph \""
205  << "no_name\" {" << std::endl;
206  nodeStream << "node [shape = ellipse];" << std::endl;
207  std::string tab = " ";
208 
209  for (const auto node: nodes()) {
210  nodeStream << tab << node << ";";
211 
212  for (const auto nei: neighbours(node))
213  if (!treatedNodes.exists(nei))
214  edgeStream << tab << node << " -> " << nei << " [dir=none];" << std::endl;
215 
216  for (const auto chi: children(node))
217  edgeStream << tab << node << " -> " << chi << ";" << std::endl;
218 
219  treatedNodes.insert(node);
220  }
221 
222  output << nodeStream.str() << std::endl << edgeStream.str() << std::endl << "}" << std::endl;
223 
224  return output.str();
225  }
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
const NodeSet & neighbours(const NodeId id) const
returns the set of node neighbours to a given node
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
+ Here is the call graph for this function:

◆ topologicalOrder()

const Sequence< NodeId > & gum::DiGraph::topologicalOrder ( bool  clear = true) const
inherited

The topological order stays the same as long as no variable or arcs are added or erased src the topology.

Parameters
clearIf false returns the previously created topology.
Exceptions
InvalidDirectedCycleRaised if this DiGraph contains cycles.

Definition at line 88 of file diGraph.cpp.

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

88  {
89  if (clear || (_mutableTopologicalOrder_ == nullptr)) { // we have to call topologicalOrder_
90  if (_mutableTopologicalOrder_ == nullptr) {
92  } else {
93  // clear is True
95  }
96 
98  }
99 
101  }
void clear()
Clear the sequence.
Definition: sequence_tpl.h:264
Sequence< NodeId > * _mutableTopologicalOrder_
The topology sequence of this Directed Graphical Model.
Definition: diGraph.h:209
void _topologicalOrder_() const
Returns a topological order of this DAGModel.
Definition: diGraph.cpp:103
+ Here is the call graph for this function:

◆ toString()

std::string gum::MixedGraph::toString ( ) const
virtual

to friendly display the content of the MixedGraph

Reimplemented from gum::DiGraph.

Definition at line 68 of file mixedGraph.cpp.

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

68  {
69  std::string s = NodeGraphPart::toString();
70  s += " , ";
72  s += " , ";
74  return s;
75  }
std::string toString() const
to friendly display the content of the ArcGraphPart
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
+ Here is the call graph for this function:

◆ 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 125 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 node neighbours to a given node
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ unvirtualizedEraseChildren()

INLINE void gum::ArcGraphPart::unvirtualizedEraseChildren ( NodeId  id)
inherited

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

Parameters
idthe node whose outgoing arcs will be removed

Definition at line 168 of file arcGraphPart_inl.h.

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

168  {
169  if (_children_.exists(id)) {
170  NodeSet& children = *(_children_[id]);
171 
172  for (auto iter = children.beginSafe(); // safe iterator needed here
173  iter != children.endSafe();
174  ++iter) {
175  ArcGraphPart::eraseArc(Arc(id, *iter));
176  }
177  }
178  }
NodeProperty< NodeSet *> _children_
for each arc, the set of its children
Definition: arcGraphPart.h:307
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
+ 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 92 of file edgeGraphPart_inl.h.

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

92  {
93  if (_neighbours_.exists(id)) {
94  const NodeSet& set = neighbours(id);
95 
96  for (auto iter = set.beginSafe(); iter != set.endSafe();
97  ++iter) { // safe iterator needed here
98  EdgeGraphPart::eraseEdge(Edge(*iter, id));
99  }
100  }
101  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & neighbours(const NodeId id) const
returns the set of node neighbours 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:

◆ unvirtualizedEraseParents()

INLINE void gum::ArcGraphPart::unvirtualizedEraseParents ( NodeId  id)
inherited

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

Parameters
idthe node whose ingoing arcs will be removed

Definition at line 156 of file arcGraphPart_inl.h.

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

156  {
157  if (_parents_.exists(id)) {
158  NodeSet& parents = *(_parents_[id]);
159 
160  for (auto iter = parents.beginSafe(); // safe iterator needed here
161  iter != parents.endSafe();
162  ++iter) {
163  ArcGraphPart::eraseArc(Arc(*iter, id));
164  }
165  }
166  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
NodeProperty< NodeSet *> _parents_
for each arc, the sets of its parents
Definition: arcGraphPart.h:304
+ Here is the call graph for this function:

◆ unvirtualizedEraseSetOfArcs_()

INLINE void gum::ArcGraphPart::unvirtualizedEraseSetOfArcs_ ( const ArcSet set)
protectedinherited

similar to eraseSetOfArcs_ except that it is unvirtualized

Warning
this function uses ArcGraphPart::eraseArc, hence, as compared with eraseSetOfArcs_, it removes the arcs without calling a virtual eraseArc

Definition at line 151 of file arcGraphPart_inl.h.

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

151  {
152  for (const auto& arc: set)
154  }
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
+ Here is the call graph for this function:

Member Data Documentation

◆ onArcAdded

Signaler2< NodeId, NodeId > gum::ArcGraphPart::onArcAdded
inherited

Definition at line 82 of file arcGraphPart.h.

◆ onArcDeleted

Signaler2< NodeId, NodeId > gum::ArcGraphPart::onArcDeleted
inherited

Definition at line 83 of file arcGraphPart.h.

◆ 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: