aGrUM  0.14.2
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

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 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...
 
const std::vector< NodeIdmixedOrientedPath (const NodeId node1, const NodeId node2) const
 returns a mixed edge/directed arc path from node1 to node2 in the arc/edge set More...
 
const std::vector< NodeIdmixedUnorientedPath (const NodeId node1, const NodeId node2) const
 returns a mixed/directed path from node1 to node2 in the arc/edge set More...
 
virtual const std::string toDot () const
 to friendly display mixed graph in DOT format More...
 
virtual const std::string toString () const
 to friendly display the content of the MixedGraph 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
virtual void addEdge (const NodeId first, const NodeId second)
 insert a new edge into the undirected graph More...
 
bool hasUndirectedCycle () const
 checks whether the graph contains cycles More...
 
virtual UndiGraph partialUndiGraph (NodeSet nodesSet)
 returns the partial graph formed by the nodes given in parameter 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 edges adjacent to a given node More...
 
void eraseNeighbours (const NodeId id)
 erase all the edges adjacent to a given node More...
 
void unvirtualizedEraseNeighbours (const NodeId id)
 same function as eraseNeighbours but without any virtual call to an erase More...
 
template<typename VAL >
EdgeProperty< VAL > edgesProperty (VAL(*f)(const Edge &), Size size=0) const
 a method to create a hashMap of VAL from a set of edges (using for every edge, say x, the VAL f(x)) More...
 
template<typename VAL >
EdgeProperty< VAL > edgesProperty (const VAL &a, Size size=0) const
 a method to create a hashMap of VAL from a set of edges (using for every edge, say x, the VAL a) More...
 
template<typename VAL >
List< VAL > listMapEdges (VAL(*f)(const Edge &)) const
 a method to create a list of VAL from a set of edges (using for every edge, say x, the VAL f(x)) More...
 
const std::vector< NodeIdundirectedPath (const NodeId node1, const NodeId node2) const
 returns a possible path from node1 to node2 in the edge set More...
 
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 (const NodeId tail, const 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 (const NodeId id) const
 returns the set of nodes with arc ingoing to a given node More...
 
const NodeSetchildren (const NodeId id) const
 returns the set of nodes with arc outgoing from a given node More...
 
void eraseParents (const NodeId id)
 erase all the parents of a given node More...
 
void unvirtualizedEraseParents (const NodeId id)
 same function as eraseParents but without any virtual call to an erase More...
 
void eraseChildren (const NodeId id)
 removes all the children of a given node More...
 
void unvirtualizedEraseChildren (const 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...
 
const std::vector< NodeIddirectedPath (const NodeId node1, const NodeId node2) const
 returns a directed path from node1 to node2 belonging to the set of arcs More...
 
const std::vector< NodeIddirectedUnorientedPath (const NodeId node1, const 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 124 of file mixedGraph.h.

Member Typedef Documentation

◆ ArcIterator

Definition at line 78 of file arcGraphPart.h.

◆ EdgeIterator

Definition at line 74 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/2]

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 34 of file mixedGraph.cpp.

39  :
40  // Note that we need to initialize the NodeGraphPart by ourselves
41  // because
42  // it is a virtual inherited class (see C++ FAQ Lite #25.12 for details)
43  NodeGraphPart(nodes_size, nodes_resize_policy),
44  UndiGraph(edges_size, edges_resize_policy),
45  DiGraph(arcs_size, arcs_resize_policy) {
46  // for debugging purposes
47  GUM_CONSTRUCTOR(MixedGraph);
48  }
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:34
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:37
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:34

◆ MixedGraph() [2/2]

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

copy constructor

Parameters
gthe MixedGraph to copy

Definition at line 50 of file mixedGraph.cpp.

50  :
51  NodeGraphPart(g), UndiGraph(g), DiGraph(g) {
52  // for debugging purposes
53  GUM_CONS_CPY(MixedGraph);
54  }
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:34
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:37
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:34

◆ ~MixedGraph()

gum::MixedGraph::~MixedGraph ( )
virtual

destructor

Definition at line 56 of file mixedGraph.cpp.

56  {
57  // for debugging purposes
58  GUM_DESTRUCTOR(MixedGraph);
59  }
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:34

Member Function Documentation

◆ _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 88 of file arcGraphPart_inl.h.

References gum::ArcGraphPart::eraseArc().

88  {
89  for (const auto arc : set)
90  eraseArc(arc);
91  }
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
+ 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 121 of file arcGraphPart_inl.h.

References gum::ArcGraphPart::eraseArc().

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

◆ 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 32 of file diGraph_inl.h.

References gum::ArcGraphPart::addArc(), gum::NodeGraphPart::exists(), and GUM_ERROR.

Referenced by gum::EssentialGraph::__buildEssentialGraph(), gum::MarkovBlanket::__buildMarkovBlanket(), gum::learning::Miic::_orientation_3off2(), gum::learning::Miic::_orientation_latents(), gum::learning::Miic::_orientation_miic(), gum::learning::Miic::_propagatesHead(), gum::prm::gspan::Pattern::addArc(), gum::DAG::addArc(), and gum::DAGCycleDetector::addArc().

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

◆ addEdge()

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

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.

Reimplemented in gum::CliqueGraph.

Definition at line 32 of file undiGraph_inl.h.

References gum::EdgeGraphPart::addEdge(), gum::NodeGraphPart::exists(), and GUM_ERROR.

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::__addEdgesInReducedGraph(), gum::EssentialGraph::__buildEssentialGraph(), gum::prm::gspan::StrictSearch< GUM_SCALAR >::__buildPatternGraph(), gum::prm::StructuredInference< GUM_SCALAR >::__buildPatternGraph(), gum::SpanningForestPrim::__computeInAComponent(), gum::prm::gspan::DFSTree< GUM_SCALAR >::__initialiaze_root(), gum::DAGmodel::__moralGraph(), gum::learning::genericBNLearner::__prepare_miic_3off2(), gum::prm::GSpan< GUM_SCALAR >::__sortPatterns(), gum::StaticTriangulation::__triangulate(), gum::InfluenceDiagram< GUM_SCALAR >::_moralGraph(), gum::prm::StructuredInference< GUM_SCALAR >::CData::CData(), gum::prm::gspan::DFSTree< GUM_SCALAR >::growPattern(), gum::prm::gspan::EdgeGrowth< GUM_SCALAR >::insert(), gum::prm::gspan::InterfaceGraph< GUM_SCALAR >::InterfaceGraph(), gum::DAG::moralGraph(), gum::UndiGraph::partialUndiGraph(), and gum::StaticTriangulation::triangulatedGraph().

32  {
33  if (!exists(first)) { GUM_ERROR(InvalidNode, "first node"); }
34 
35  if (!exists(second)) { GUM_ERROR(InvalidNode, "second node"); }
36 
37  EdgeGraphPart::addEdge(second, first);
38  }
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:52
+ Here is the call graph for this function:
+ Here is the caller 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 250 of file nodeGraphPart_inl.h.

References GUM_EMIT1.

Referenced by gum::prm::gspan::DFSTree< GUM_SCALAR >::__addChild(), gum::prm::StructuredInference< GUM_SCALAR >::__addEdgesInReducedGraph(), gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::__addInterface2Dag(), gum::prm::ClassDependencyGraph< GUM_SCALAR >::__addNode(), gum::prm::o3prm::O3TypeFactory< GUM_SCALAR >::__addTypes2Dag(), gum::prm::gspan::StrictSearch< GUM_SCALAR >::__buildPatternGraph(), gum::prm::StructuredInference< GUM_SCALAR >::__buildPatternGraph(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAndAddNodesToDag(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::gspan::DFSTree< GUM_SCALAR >::__initialiaze_root(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_insertNode(), gum::prm::gspan::DFSTree< GUM_SCALAR >::addRoot(), gum::prm::gspan::DFSTree< GUM_SCALAR >::growPattern(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::IncrementalGraphLearner(), gum::prm::gspan::EdgeGrowth< GUM_SCALAR >::insert(), and gum::LeafAggregator::update().

250  {
251  NodeId newNode;
252 
253  // fill the first hole if holes exist
254  if (__holes && (!__holes->empty())) {
255  newNode = *(__holes->begin());
256  __eraseHole(newNode);
257  } else {
258  newNode = __boundVal;
259  ++__boundVal;
261  }
262 
263  GUM_EMIT1(onNodeAdded, newNode);
264 
265  return newNode;
266  }
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:704
NodeSet * __holes
the set of nodes not contained in the NodeGraphPart in the interval 1..__max
#define GUM_EMIT1(signal, arg1)
Definition: signaler1.h:40
iterator begin() const
The usual unsafe begin iterator to parse the set.
Definition: set_tpl.h:514
NodeId __boundVal
the id below which NodeIds may belong to the NodeGraphPart
void __updateEndIteratorSafe()
updating endIterator (always at __max+1)
Signaler1< NodeId > onNodeAdded
void __eraseHole(NodeId id)
to delete hole.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the caller 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 268 of file nodeGraphPart_inl.h.

268  {
269  std::vector< NodeId > v;
270  v.reserve(N);
271  for (Idx i = 0; i < N; i++)
272  v.push_back(this->addNode());
273  return v;
274  }

◆ 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 129 of file nodeGraphPart.cpp.

References gum::NodeGraphPart::__boundVal, gum::NodeGraphPart::__eraseHole(), gum::NodeGraphPart::__holes, gum::NodeGraphPart::__holes_resize_policy, gum::NodeGraphPart::__holes_size, gum::NodeGraphPart::__inHoles(), gum::NodeGraphPart::__updateEndIteratorSafe(), GUM_EMIT1, GUM_ERROR, gum::Set< Key, Alloc >::insert(), and gum::NodeGraphPart::onNodeAdded.

Referenced by gum::EssentialGraph::__buildEssentialGraph(), gum::MarkovBlanket::__buildMarkovBlanket(), gum::SpanningForestPrim::__computeInAComponent(), gum::learning::genericBNLearner::__learnDAG(), gum::learning::genericBNLearner::__prepare_miic_3off2(), gum::prm::GSpan< GUM_SCALAR >::__sortPatterns(), gum::InfluenceDiagram< GUM_SCALAR >::_addNode(), gum::InfluenceDiagram< GUM_SCALAR >::_moralGraph(), gum::prm::gspan::Pattern::addNodeWithLabel(), gum::prm::StructuredInference< GUM_SCALAR >::CData::CData(), gum::InfluenceDiagram< GUM_SCALAR >::getDecisionGraph(), gum::BayesNetFragment< GUM_SCALAR >::installNode(), gum::prm::gspan::InterfaceGraph< GUM_SCALAR >::InterfaceGraph(), gum::learning::Miic::learnStructure(), gum::UndiGraph::partialUndiGraph(), and gum::learning::StructuralConstraintDAG::StructuralConstraintDAG().

129  {
130  if (id >= __boundVal) {
131  if (id > __boundVal) { // we have to add holes
133 
134  for (NodeId i = __boundVal; i < id; ++i)
135  __holes->insert(i);
136  }
137 
138  __boundVal = id + 1;
139 
141  } else {
142  if (__inHoles(id)) { // we fill a hole
143  __eraseHole(id);
144  } else {
145  GUM_ERROR(DuplicateElement, "Id " << id << " is already used");
146  }
147  }
148 
149  GUM_EMIT1(onNodeAdded, id);
150  }
NodeSet * __holes
the set of nodes not contained in the NodeGraphPart in the interval 1..__max
#define GUM_EMIT1(signal, arg1)
Definition: signaler1.h:40
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
bool __holes_resize_policy
value for __holes configuration
bool __inHoles(NodeId id) const
NodeId __boundVal
the id below which NodeIds may belong to the NodeGraphPart
Size __holes_size
value for __holes configuration
void __updateEndIteratorSafe()
updating endIterator (always at __max+1)
Signaler1< NodeId > onNodeAdded
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:610
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:
+ Here is the caller 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 36 of file arcGraphPart_inl.h.

References gum::ArcGraphPart::__arcs.

Referenced by gum::MarkovBlanket::arcs(), gum::EssentialGraph::arcs(), gum::DAGmodel::arcs(), gum::prm::gspan::Pattern::arcs(), gum::learning::DAG2BNLearner< ALLOC >::createBN(), gum::DAG::moralGraph(), and gum::DiGraph::toDot().

36 { return __arcs; }
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:266
+ Here is the caller 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 358 of file nodeGraphPart_inl.h.

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

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder().

358  {
359  NodeSet son(sizeNodes());
360 
361  if (!empty()) {
362  for (NodeId n = 0; n < __boundVal; ++n) {
363  if (!__inHoles(n)) son.insert(n);
364  }
365  }
366 
367  return son;
368  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
bool __inHoles(NodeId id) const
NodeId __boundVal
the id below which NodeIds may belong to the NodeGraphPart
bool empty() const
alias for emptyNodes
Size sizeNodes() const
returns the number of nodes in the NodeGraphPart
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:
+ Here is the caller 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 330 of file nodeGraphPart_inl.h.

References gum::NodeGraphPartIterator::_validate().

Referenced by gum::prm::gspan::DFSTree< GUM_SCALAR >::parent().

330  {
331  NodeGraphPartIterator it(*this);
332  it._validate(); // stop the iterator at the first not-in-holes
333  return it;
334  }
friend class NodeGraphPartIterator
+ Here is the call graph for this function:
+ Here is the caller 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 316 of file nodeGraphPart_inl.h.

References gum::NodeGraphPartIterator::_validate().

316  {
317  NodeGraphPartIteratorSafe it(*this);
318  it._validate(); // stop the iterator at the first not-in-holes
319  return it;
320  }
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 305 of file nodeGraphPart_inl.h.

Referenced by gum::NodeGraphPart::__clearNodes(), gum::StaticTriangulation::__computeEliminationTree(), gum::NodeGraphPartIterator::_setPos(), and gum::NodeGraphPartIterator::_validate().

305 { return __boundVal; }
NodeId __boundVal
the id below which NodeIds may belong to the NodeGraphPart
+ Here is the caller graph for this function:

◆ children()

INLINE const NodeSet & gum::ArcGraphPart::children ( const 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 59 of file arcGraphPart_inl.h.

References gum::ArcGraphPart::__checkChildren(), and gum::ArcGraphPart::__children.

Referenced by gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__AR(), gum::EssentialGraph::__buildEssentialGraph(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__connect(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__directedPath(), gum::prm::gspan::Pattern::__expandCodeIsMinimal(), gum::DAG::__hasDirectedPath(), gum::prm::gspan::Pattern::__not_rec(), gum::prm::gspan::Pattern::__rec(), gum::InfluenceDiagram< GUM_SCALAR >::_getChildrenDecision(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::_initialize(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::_makeInferenceNodeToNeighbours(), gum::ArcGraphPart::ArcGraphPart(), gum::MarkovBlanket::children(), gum::EssentialGraph::children(), gum::DAGmodel::children(), gum::ArcGraphPart::directedUnorientedPath(), gum::InfluenceDiagram< GUM_SCALAR >::erase(), gum::ArcGraphPart::eraseChildren(), gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween(), gum::prm::gspan::Pattern::isMinimal(), mixedUnorientedPath(), gum::BayesBall::relevantPotentials(), gum::dSeparation::relevantPotentials(), gum::prm::gspan::Pattern::remove(), gum::BayesBall::requisiteNodes(), gum::dSeparation::requisiteNodes(), gum::MarkovBlanket::toDot(), gum::EssentialGraph::toDot(), gum::InfluenceDiagram< GUM_SCALAR >::toDot(), toDot(), and gum::ArcGraphPart::unvirtualizedEraseChildren().

59  {
60  __checkChildren(id);
61  return *(__children[id]);
62  }
void __checkChildren(const NodeId id) const
when the ArcGraphPart contains no arc outgoing from a given node, this function adds an empty set ent...
NodeProperty< NodeSet *> __children
for each arc, the set of its children
Definition: arcGraphPart.h:272
+ 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 46 of file mixedGraph_inl.h.

References gum::ArcGraphPart::clearArcs(), gum::EdgeGraphPart::clearEdges(), and gum::NodeGraphPart::clearNodes().

Referenced by gum::EssentialGraph::__buildEssentialGraph().

46  {
50  }
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:
+ Here is the caller graph for this function:

◆ clearArcs()

void gum::ArcGraphPart::clearArcs ( )
inherited

removes all the arcs from the ArcGraphPart

Definition at line 76 of file arcGraphPart.cpp.

References gum::ArcGraphPart::__arcs, gum::ArcGraphPart::__children, gum::ArcGraphPart::__parents, gum::Set< Key, Alloc >::clear(), GUM_EMIT2, and gum::ArcGraphPart::onArcDeleted.

Referenced by gum::DiGraph::clear(), clear(), gum::ArcGraphPart::operator=(), operator=(), and gum::ArcGraphPart::~ArcGraphPart().

76  {
77  for (const auto& elt : __parents)
78  delete elt.second;
79 
80  __parents.clear();
81 
82  for (const auto& elt : __children)
83  delete elt.second;
84 
85  __children.clear();
86 
87  // we need this copy only if at least one onArcDeleted listener exists
88  if (onArcDeleted.hasListener()) {
89  ArcSet tmp = __arcs;
90  __arcs.clear();
91 
92  for (const auto& arc : tmp)
93  GUM_EMIT2(onArcDeleted, arc.tail(), arc.head());
94  } else {
95  __arcs.clear();
96  }
97  }
Set< Arc > ArcSet
Some typdefs and define for shortcuts ...
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:40
NodeProperty< NodeSet *> __parents
for each arc, the sets of its parents
Definition: arcGraphPart.h:269
NodeProperty< NodeSet *> __children
for each arc, the set of its children
Definition: arcGraphPart.h:272
Signaler2< NodeId, NodeId > onArcDeleted
Definition: arcGraphPart.h:81
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:372
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:266
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clearEdges()

void gum::EdgeGraphPart::clearEdges ( )
virtualinherited

removes all the edges from the EdgeGraphPart

Reimplemented in gum::CliqueGraph.

Definition at line 64 of file edgeGraphPart.cpp.

References gum::EdgeGraphPart::__edges, gum::EdgeGraphPart::__neighbours, gum::Set< Key, Alloc >::clear(), GUM_EMIT2, and gum::EdgeGraphPart::onEdgeDeleted.

Referenced by gum::UndiGraph::clear(), clear(), gum::EdgeGraphPart::operator=(), operator=(), and gum::EdgeGraphPart::~EdgeGraphPart().

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

◆ clearNodes()

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

remove all the nodes from the NodeGraphPart

Definition at line 307 of file nodeGraphPart_inl.h.

Referenced by gum::DiGraph::clear(), gum::UndiGraph::clear(), clear(), and operator=().

307 { __clearNodes(); }
void __clearNodes()
code for clearing nodes (called twice)
+ Here is the caller graph for this function:

◆ directedPath()

const std::vector< NodeId > gum::ArcGraphPart::directedPath ( const NodeId  node1,
const 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 152 of file arcGraphPart.cpp.

References gum::List< Val, Alloc >::empty(), gum::HashTable< Key, Val, Alloc >::exists(), gum::List< Val, Alloc >::front(), GUM_ERROR, gum::HashTable< Key, Val, Alloc >::insert(), gum::ArcGraphPart::parents(), gum::List< Val, Alloc >::popFront(), and gum::List< Val, Alloc >::pushBack().

Referenced by gum::learning::Miic::_orientation_latents().

153  {
154  // not recursive version => use a FIFO for simulating the recursion
155  List< NodeId > nodeFIFO;
156  nodeFIFO.pushBack(n2);
157 
158  // mark[node] = successor if visited, else mark[node] does not exist
159  NodeProperty< NodeId > mark;
160  mark.insert(n2, n2);
161 
162  NodeId current;
163 
164  while (!nodeFIFO.empty()) {
165  current = nodeFIFO.front();
166  nodeFIFO.popFront();
167 
168  // check the parents
169 
170  for (const auto new_one : parents(current)) {
171  if (mark.exists(new_one)) // if this node is already marked, do not
172  continue; // check it again
173 
174  mark.insert(new_one, current);
175 
176  if (new_one == n1) {
177  std::vector< NodeId > v;
178 
179  for (current = n1; current != n2; current = mark[current])
180  v.push_back(current);
181 
182  v.push_back(n2);
183 
184  return v;
185  }
186 
187  nodeFIFO.pushBack(new_one);
188  }
189  }
190 
191  GUM_ERROR(NotFound, "no path found");
192  }
const NodeSet & parents(const 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:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ directedUnorientedPath()

const std::vector< NodeId > gum::ArcGraphPart::directedUnorientedPath ( const NodeId  node1,
const 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 195 of file arcGraphPart.cpp.

References gum::ArcGraphPart::children(), gum::List< Val, Alloc >::empty(), gum::HashTable< Key, Val, Alloc >::exists(), gum::List< Val, Alloc >::front(), GUM_ERROR, gum::HashTable< Key, Val, Alloc >::insert(), gum::ArcGraphPart::parents(), gum::List< Val, Alloc >::popFront(), and gum::List< Val, Alloc >::pushBack().

195  {
196  // not recursive version => use a FIFO for simulating the recursion
197  List< NodeId > nodeFIFO;
198  nodeFIFO.pushBack(n2);
199 
200  // mark[node] = successor if visited, else mark[node] does not exist
201  NodeProperty< NodeId > mark;
202  mark.insert(n2, n2);
203 
204  NodeId current;
205 
206  while (!nodeFIFO.empty()) {
207  current = nodeFIFO.front();
208  nodeFIFO.popFront();
209 
210  // check the parents
211  for (const auto new_one : parents(current)) {
212  if (mark.exists(new_one)) // the node has already been visited
213  continue;
214 
215  mark.insert(new_one, current);
216 
217  if (new_one == n1) {
218  std::vector< NodeId > v;
219 
220  for (current = n1; current != n2; current = mark[current])
221  v.push_back(current);
222 
223  v.push_back(n2);
224 
225  return v;
226  }
227 
228  nodeFIFO.pushBack(new_one);
229  }
230 
231  // check the children
232  for (const auto new_one : children(current)) {
233  if (mark.exists(new_one)) // the node has already been visited
234  continue;
235 
236  mark.insert(new_one, current);
237 
238  if (new_one == n1) {
239  std::vector< NodeId > v;
240 
241  for (current = n1; current != n2; current = mark[current])
242  v.push_back(current);
243 
244  v.push_back(n2);
245 
246  return v;
247  }
248 
249  nodeFIFO.pushBack(new_one);
250  }
251  }
252 
253  GUM_ERROR(NotFound, "no path found");
254  }
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ 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 36 of file edgeGraphPart_inl.h.

References gum::EdgeGraphPart::__edges.

Referenced by gum::StaticTriangulation::__computeMaxPrimeJunctionTree(), gum::learning::Miic::_initiation(), gum::BarrenNodesFinder::barrenNodes(), gum::EssentialGraph::edges(), and gum::SpanningForestPrim::edgesInSpanningForest().

36 { return __edges; }
EdgeSet __edges
the set of all the edges contained within the EdgeGraphPart
+ Here is the caller 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.

Referenced by gum::DefaultJunctionTreeStrategy::__computeJunctionTree().

+ Here is the caller graph for this function:

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

Referenced by gum::prm::gspan::Pattern::remove().

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

◆ emptyArcs()

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

indicates wether the ArcGraphPart contains any arc

Definition at line 32 of file arcGraphPart_inl.h.

References gum::ArcGraphPart::__arcs, and gum::Set< Key, Alloc >::empty().

32 { return __arcs.empty(); }
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:704
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:266
+ 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 32 of file edgeGraphPart_inl.h.

References gum::EdgeGraphPart::__edges, and gum::Set< Key, Alloc >::empty().

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

◆ emptyNodes()

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

indicates whether there exists nodes in the NodeGraphPart

Definition at line 301 of file nodeGraphPart_inl.h.

301 { return (sizeNodes() == 0); }
Size sizeNodes() const
returns the number of nodes in the NodeGraphPart

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

336  {
337  return __endIteratorSafe;
338  }
NodeGraphPartIteratorSafe __endIteratorSafe
the end iterator (used to speed-up parsings of the NodeGraphPart)

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

326  {
327  return __endIteratorSafe;
328  }
NodeGraphPartIteratorSafe __endIteratorSafe
the end iterator (used to speed-up parsings of the NodeGraphPart)

◆ 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 76 of file arcGraphPart_inl.h.

References gum::ArcGraphPart::__arcs, gum::ArcGraphPart::__children, gum::ArcGraphPart::__parents, gum::Set< Key, Alloc >::erase(), gum::ArcGraphPart::existsArc(), GUM_EMIT2, gum::Arc::head(), gum::ArcGraphPart::onArcDeleted, and gum::Arc::tail().

Referenced by gum::EssentialGraph::__buildEssentialGraph(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::learning::genericBNLearner::__learnDAG(), gum::ArcGraphPart::_eraseSetOfArcs(), gum::learning::Miic::_orientation_3off2(), gum::learning::Miic::_orientation_latents(), gum::learning::Miic::_orientation_miic(), gum::BayesNetFragment< GUM_SCALAR >::_uninstallArc(), gum::ArcGraphPart::_unvirtualizedEraseSetOfArcs(), gum::DAGCycleDetector::eraseArc(), gum::InfluenceDiagram< GUM_SCALAR >::eraseArc(), gum::ArcGraphPart::eraseChildren(), gum::ArcGraphPart::eraseParents(), gum::learning::GreedyHillClimbing::learnStructure(), gum::learning::LocalSearchWithTabuList::learnStructure(), gum::prm::gspan::Pattern::pop_back(), gum::BayesNet< double >::reverseArc(), gum::ArcGraphPart::unvirtualizedEraseChildren(), and gum::ArcGraphPart::unvirtualizedEraseParents().

76  {
77  // ASSUMING tail and head exists in __parents anf __children
78  // (if not, it is an error)
79  if (existsArc(arc)) {
80  NodeId tail = arc.tail(), head = arc.head();
81  __parents[head]->erase(tail);
82  __children[tail]->erase(head);
83  __arcs.erase(arc);
84  GUM_EMIT2(onArcDeleted, tail, head);
85  }
86  }
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:653
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:40
NodeProperty< NodeSet *> __parents
for each arc, the sets of its parents
Definition: arcGraphPart.h:269
NodeProperty< NodeSet *> __children
for each arc, the set of its children
Definition: arcGraphPart.h:272
Signaler2< NodeId, NodeId > onArcDeleted
Definition: arcGraphPart.h:81
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:266
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:
+ Here is the caller graph for this function:

◆ eraseChildren()

INLINE void gum::ArcGraphPart::eraseChildren ( const 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 107 of file arcGraphPart_inl.h.

References gum::ArcGraphPart::__children, gum::Set< Key, Alloc >::beginSafe(), gum::ArcGraphPart::children(), gum::Set< Key, Alloc >::endSafe(), and gum::ArcGraphPart::eraseArc().

107  {
108  if (__children.exists(id)) {
109  NodeSet& children = *(__children[id]);
110 
111  for (auto iter = children.beginSafe(); // safe iterator needed here
112  iter != children.endSafe();
113  ++iter) {
114  // warning: use this erase so that you actually use the vritualized
115  // arc removal function
116  eraseArc(Arc(id, *iter));
117  }
118  }
119  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
NodeProperty< NodeSet *> __children
for each arc, the set of its children
Definition: arcGraphPart.h:272
+ 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 62 of file edgeGraphPart_inl.h.

References gum::EdgeGraphPart::__edges, gum::EdgeGraphPart::__neighbours, gum::Set< Key, Alloc >::erase(), gum::EdgeGraphPart::existsEdge(), gum::Edge::first(), GUM_EMIT2, gum::EdgeGraphPart::onEdgeDeleted, and gum::Edge::second().

Referenced by gum::learning::Miic::_initiation(), gum::learning::Miic::_iteration(), gum::learning::Miic::_orientation_3off2(), gum::learning::Miic::_orientation_latents(), gum::learning::Miic::_orientation_miic(), gum::learning::Miic::_propagatesHead(), gum::EdgeGraphPart::eraseNeighbours(), and gum::EdgeGraphPart::unvirtualizedEraseNeighbours().

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

References gum::EdgeGraphPart::__neighbours, gum::EdgeGraphPart::eraseEdge(), and gum::EdgeGraphPart::neighbours().

80  {
81  if (__neighbours.exists(id)) {
82  const NodeSet& set = neighbours(id);
83 
84  for (auto iter = set.beginSafe(); iter != set.endSafe();
85  ++iter) { // safe iterator needed here
86  // warning: use this erase so that you actually use the virtualized
87  // edge removal function
88  eraseEdge(Edge(*iter, id));
89  }
90  }
91  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeProperty< NodeSet *> __neighbours
for each node, the set of its adjacent edges
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
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 52 of file mixedGraph_inl.h.

References gum::NodeGraphPart::eraseNode(), gum::ArcGraphPart::unvirtualizedEraseChildren(), gum::EdgeGraphPart::unvirtualizedEraseNeighbours(), and gum::ArcGraphPart::unvirtualizedEraseParents().

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

◆ eraseParents()

INLINE void gum::ArcGraphPart::eraseParents ( const 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 93 of file arcGraphPart_inl.h.

References gum::ArcGraphPart::__parents, gum::Set< Key, Alloc >::beginSafe(), gum::Set< Key, Alloc >::endSafe(), gum::ArcGraphPart::eraseArc(), and gum::ArcGraphPart::parents().

93  {
94  if (__parents.exists(id)) {
95  NodeSet& parents = *(__parents[id]);
96 
97  for (auto iter = parents.beginSafe(); // safe iterator needed here
98  iter != parents.endSafe();
99  ++iter) {
100  // warning: use this erase so that you actually use the virtualized
101  // arc removal function
102  eraseArc(Arc(*iter, id));
103  }
104  }
105  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
NodeProperty< NodeSet *> __parents
for each arc, the sets of its parents
Definition: arcGraphPart.h:269
+ 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 289 of file nodeGraphPart_inl.h.

Referenced by gum::MarkovBlanket::__buildMarkovBlanket(), gum::prm::ClassBayesNet< GUM_SCALAR >::__get(), gum::DAG::__hasDirectedPath(), gum::learning::genericBNLearner::__learnDAG(), gum::prm::StructuredInference< GUM_SCALAR >::__removeNode(), gum::NodeGraphPartIterator::_setPos(), gum::prm::gspan::Pattern::addArc(), gum::DiGraph::addArc(), gum::UndiGraph::addEdge(), and gum::prm::gspan::Pattern::exists().

289  {
290  return existsNode(node);
291  }
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
+ Here is the caller 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 38 of file arcGraphPart_inl.h.

References gum::ArcGraphPart::__arcs, and gum::Set< Key, Alloc >::contains().

Referenced by gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__AorR(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__AR(), gum::MarkovBlanket::__buildMarkovBlanket(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__connect(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__directedPath(), gum::learning::Miic::__existsDirectedPath(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__jump_multi(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__jump_poly(), gum::prm::gspan::Pattern::__not_rec(), gum::prm::gspan::Pattern::__rec(), gum::learning::Miic::_orientation_3off2(), gum::learning::Miic::_orientation_latents(), gum::learning::Miic::_orientation_miic(), gum::learning::Miic::_updateProbaTriples(), gum::DAGCycleDetector::addArc(), gum::ArcGraphPart::eraseArc(), gum::DAGCycleDetector::eraseArc(), gum::InfluenceDiagram< GUM_SCALAR >::eraseArc(), and gum::prm::gspan::Pattern::exists().

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

◆ existsArc() [2/2]

INLINE bool gum::ArcGraphPart::existsArc ( const NodeId  tail,
const 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::ArcGraphPart::__parents.

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

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

References gum::EdgeGraphPart::__edges, and gum::Set< Key, Alloc >::contains().

Referenced by gum::StaticTriangulation::__computeMaxPrimeMergings(), gum::prm::GSpan< GUM_SCALAR >::__sortPatterns(), gum::EssentialGraph::__strongly_protected(), gum::StaticTriangulation::__triangulate(), gum::learning::Miic::_orientation_3off2(), gum::learning::Miic::_orientation_miic(), gum::EdgeGraphPart::eraseEdge(), gum::StaticTriangulation::fillIns(), and gum::prm::gspan::InterfaceGraph< GUM_SCALAR >::InterfaceGraph().

38  {
39  return __edges.contains(edge);
40  }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:578
EdgeSet __edges
the set of all the edges contained within the EdgeGraphPart
+ Here is the call graph for this function:
+ Here is the caller 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::EdgeGraphPart::__neighbours.

43  {
44  return __neighbours.exists(first) && __neighbours[first]->exists(second);
45  }
NodeProperty< NodeSet *> __neighbours
for each node, the set of its adjacent edges

◆ existsNode()

◆ hasUndirectedCycle()

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

checks whether the graph contains cycles

Definition at line 52 of file undiGraph.cpp.

References gum::List< Val, Alloc >::empty(), gum::List< Val, Alloc >::front(), gum::List< Val, Alloc >::insert(), gum::EdgeGraphPart::neighbours(), gum::NodeGraphPart::nodes(), gum::NodeGraphPart::nodesProperty(), and gum::List< Val, Alloc >::popFront().

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

const std::vector< NodeId > gum::MixedGraph::mixedOrientedPath ( const NodeId  node1,
const 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 (following the direction of th 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 71 of file mixedGraph.cpp.

References gum::List< Val, Alloc >::empty(), gum::HashTable< Key, Val, Alloc >::exists(), gum::List< Val, Alloc >::front(), GUM_ERROR, gum::HashTable< Key, Val, Alloc >::insert(), gum::EdgeGraphPart::neighbours(), gum::ArcGraphPart::parents(), gum::List< Val, Alloc >::popFront(), and gum::List< Val, Alloc >::pushBack().

71  {
72  // not recursive version => use a FIFO for simulating the recursion
73  List< NodeId > nodeFIFO;
74  nodeFIFO.pushBack(n2);
75 
76  // mark[node] = successor if visited, else mark[node] does not exist
77  NodeProperty< NodeId > mark;
78  mark.insert(n2, n2);
79 
80  NodeId current;
81 
82  while (!nodeFIFO.empty()) {
83  current = nodeFIFO.front();
84  nodeFIFO.popFront();
85 
86  // check the neighbours
87  for (const auto new_one : neighbours(current)) {
88  if (mark.exists(new_one)) // if the node has already been visited
89  continue; // do not check it again
90 
91  mark.insert(new_one, current);
92 
93  if (new_one == n1) {
94  std::vector< NodeId > v;
95 
96  for (current = n1; current != n2; current = mark[current])
97  v.push_back(current);
98 
99  v.push_back(n2);
100 
101  return v;
102  }
103 
104  nodeFIFO.pushBack(new_one);
105  }
106 
107  // check the parents
108  for (const auto new_one : parents(current)) {
109  if (mark.exists(new_one)) // if this node is already marked, do not
110  continue; // check it again
111 
112  mark.insert(new_one, current);
113 
114  if (new_one == n1) {
115  std::vector< NodeId > v;
116 
117  for (current = n1; current != n2; current = mark[current])
118  v.push_back(current);
119 
120  v.push_back(n2);
121 
122  return v;
123  }
124 
125  nodeFIFO.pushBack(new_one);
126  }
127  }
128 
129  GUM_ERROR(NotFound, "no path found");
130  }
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
const NodeSet & parents(const 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:52
+ Here is the call graph for this function:

◆ mixedUnorientedPath()

const std::vector< NodeId > gum::MixedGraph::mixedUnorientedPath ( const NodeId  node1,
const 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
Exceptions
NotFoundexception is raised if no path can be found between the two nodes

Definition at line 133 of file mixedGraph.cpp.

References gum::ArcGraphPart::children(), gum::List< Val, Alloc >::empty(), gum::HashTable< Key, Val, Alloc >::exists(), gum::List< Val, Alloc >::front(), GUM_ERROR, gum::HashTable< Key, Val, Alloc >::insert(), gum::EdgeGraphPart::neighbours(), gum::ArcGraphPart::parents(), gum::List< Val, Alloc >::popFront(), and gum::List< Val, Alloc >::pushBack().

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

◆ neighbours()

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

returns the set of edges adjacent to a given node

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

Parameters
idthe node to which the edges are adjacent

Definition at line 75 of file edgeGraphPart_inl.h.

References gum::EdgeGraphPart::__checkNeighbours(), and gum::EdgeGraphPart::__neighbours.

Referenced by gum::DefaultJunctionTreeStrategy::__computeJunctionTree(), gum::StaticTriangulation::__computeMaxPrimeMergings(), gum::BinaryJoinTreeConverterDefault::__convertClique(), gum::BinaryJoinTreeConverterDefault::__convertConnectedComponent(), gum::SpanningForestPrim::__exploreNode(), gum::prm::gspan::DFSTree< GUM_SCALAR >::__initialiaze_root(), gum::BinaryJoinTreeConverterDefault::__markConnectedComponent(), gum::prm::StructuredInference< GUM_SCALAR >::__removeBarrenNodes(), gum::prm::GSpan< GUM_SCALAR >::__sortPatterns(), gum::EssentialGraph::__strongly_protected(), gum::StaticTriangulation::__triangulate(), gum::learning::Miic::_propagatesHead(), gum::EdgeGraphPart::eraseNeighbours(), gum::prm::gspan::DFSTree< GUM_SCALAR >::growPattern(), gum::UndiGraph::hasUndirectedCycle(), gum::learning::Miic::learnStructure(), mixedOrientedPath(), mixedUnorientedPath(), gum::EssentialGraph::neighbours(), gum::prm::gspan::DFSTree< GUM_SCALAR >::NeighborDegreeSort::operator()(), gum::UndiGraph::partialUndiGraph(), gum::EssentialGraph::toDot(), gum::UndiGraph::toDot(), toDot(), gum::EdgeGraphPart::undirectedPath(), and gum::EdgeGraphPart::unvirtualizedEraseNeighbours().

75  {
77  return *(__neighbours[id]);
78  }
NodeProperty< NodeSet *> __neighbours
for each node, the set of its adjacent edges
void __checkNeighbours(const NodeId id) const
when the EdgeGraphPart contains no edge adjacent to a given node, this function adds an empty set ent...
+ Here is the call graph for this function:
+ Here is the caller 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 223 of file nodeGraphPart_inl.h.

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::_addNode().

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

◆ nodes()

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

return *this as a NodeGraphPart

Definition at line 370 of file nodeGraphPart_inl.h.

Referenced by gum::MarkovBlanket::__buildMarkovBlanket(), gum::SpanningForestPrim::__compute(), gum::StaticTriangulation::__computeMaxPrimeJunctionTree(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::GSpan< GUM_SCALAR >::__sortPatterns(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::__threadUpdate(), gum::InfluenceDiagram< GUM_SCALAR >::_moralGraph(), gum::InfluenceDiagram< GUM_SCALAR >::_removeTables(), gum::prm::StructuredInference< GUM_SCALAR >::CData::CData(), gum::StaticTriangulation::fillIns(), gum::InfluenceDiagram< GUM_SCALAR >::getDecisionGraph(), gum::prm::gspan::DFSTree< GUM_SCALAR >::growPattern(), gum::UndiGraph::hasUndirectedCycle(), gum::DAG::moralGraph(), gum::MarkovBlanket::nodes(), gum::EssentialGraph::nodes(), gum::prm::gspan::Pattern::nodes(), gum::MarkovBlanket::toDot(), gum::EssentialGraph::toDot(), gum::InfluenceDiagram< GUM_SCALAR >::toDot(), gum::UndiGraph::toDot(), gum::DiGraph::toDot(), and toDot().

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

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

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::_getChildrenDecision(), gum::BarrenNodesFinder::barrenNodes(), gum::BinaryJoinTreeConverterDefault::convert(), gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween(), and gum::UndiGraph::hasUndirectedCycle().

+ Here is the caller graph for this function:

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

References gum::EdgeGraphPart::__edges.

108  {
109  return __edges != p.__edges;
110  }
EdgeSet __edges
the set of all the edges contained within the EdgeGraphPart

◆ 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 154 of file arcGraphPart_inl.h.

References gum::ArcGraphPart::__arcs.

154  {
155  return __arcs != p.__arcs;
156  }
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:266

◆ 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 67 of file undiGraph_inl.h.

References gum::UndiGraph::operator==().

67  {
68  return !operator==(p);
69  }
bool operator==(const UndiGraph &g) const
tests whether two UndiGraphs are identical (same nodes, same edges)
Definition: undiGraph_inl.h:63
+ 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 80 of file diGraph_inl.h.

References gum::DiGraph::operator==().

80  {
81  return !operator==(p);
82  }
bool operator==(const DiGraph &g) const
tests whether two DiGraphs are identical (same nodes, same arcs)
Definition: diGraph_inl.h:76
+ 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 64 of file mixedGraph_inl.h.

References operator==().

64  {
65  return !operator==(p);
66  }
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 354 of file nodeGraphPart_inl.h.

References gum::NodeGraphPartIterator::operator==().

354  {
355  return !operator==(p);
356  }
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 29 of file mixedGraph_inl.h.

References gum::ArcGraphPart::clearArcs(), gum::EdgeGraphPart::clearEdges(), gum::NodeGraphPart::clearNodes(), gum::EdgeGraphPart::operator=(), gum::ArcGraphPart::operator=(), and gum::NodeGraphPart::operator=().

29  {
30  // avoid self assigment
31  if (this != &g) {
32  // remove the old graph properly
36 
37  // fill the new graph
41  }
42 
43  return *this;
44  }
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 104 of file edgeGraphPart_inl.h.

References gum::EdgeGraphPart::__edges.

Referenced by gum::UndiGraph::operator==(), and operator==().

104  {
105  return __edges == p.__edges;
106  }
EdgeSet __edges
the set of all the edges contained within the EdgeGraphPart
+ Here is the caller 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 150 of file arcGraphPart_inl.h.

References gum::ArcGraphPart::__arcs.

Referenced by gum::DiGraph::operator==(), and operator==().

150  {
151  return __arcs == p.__arcs;
152  }
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:266
+ Here is the caller 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 63 of file undiGraph_inl.h.

References gum::EdgeGraphPart::operator==(), and gum::NodeGraphPart::operator==().

Referenced by gum::UndiGraph::operator!=().

63  {
65  }
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:
+ Here is the caller 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 76 of file diGraph_inl.h.

References gum::ArcGraphPart::operator==(), and gum::NodeGraphPart::operator==().

Referenced by gum::DiGraph::operator!=().

76  {
78  }
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:
+ Here is the caller 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 59 of file mixedGraph_inl.h.

References gum::EdgeGraphPart::operator==(), gum::ArcGraphPart::operator==(), and gum::NodeGraphPart::operator==().

Referenced by operator!=().

59  {
62  }
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:
+ Here is the caller 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 340 of file nodeGraphPart_inl.h.

References gum::NodeGraphPart::__boundVal, and gum::NodeGraphPart::__holes.

Referenced by gum::UndiGraph::operator==(), gum::DiGraph::operator==(), and operator==().

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

◆ parents()

INLINE const NodeSet & gum::ArcGraphPart::parents ( const 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::ArcGraphPart::__checkParents(), and gum::ArcGraphPart::__parents.

Referenced by gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__AR(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__connect(), gum::learning::Miic::__existsDirectedPath(), gum::prm::gspan::Pattern::__expandCodeIsMinimal(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClass(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClasses(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateCluster(), gum::prm::gspan::Pattern::__not_rec(), gum::prm::gspan::Pattern::__rec(), gum::EssentialGraph::__strongly_protected(), gum::InfluenceDiagram< GUM_SCALAR >::_copyTables(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::_initialize(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::_makeInferenceNodeToNeighbours(), gum::InfluenceDiagram< GUM_SCALAR >::_moralGraph(), gum::learning::Miic::_orientation_miic(), gum::learning::Miic::_propagatesHead(), gum::BarrenNodesFinder::barrenNodes(), gum::ArcGraphPart::directedPath(), gum::ArcGraphPart::directedUnorientedPath(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::drawSamples(), gum::ArcGraphPart::eraseParents(), gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder(), gum::prm::gspan::Pattern::isMinimal(), gum::learning::Miic::learnStructure(), mixedOrientedPath(), mixedUnorientedPath(), gum::DAG::moralGraph(), gum::prm::gspan::DFSTree< GUM_SCALAR >::parent(), gum::MarkovBlanket::parents(), gum::EssentialGraph::parents(), gum::DAGmodel::parents(), gum::BayesBall::relevantPotentials(), gum::dSeparation::relevantPotentials(), gum::prm::gspan::Pattern::remove(), gum::BayesBall::requisiteNodes(), gum::dSeparation::requisiteNodes(), gum::prm::gspan::Pattern::rightmostPath(), and gum::ArcGraphPart::unvirtualizedEraseParents().

54  {
55  __checkParents(id);
56  return *(__parents[id]);
57  }
void __checkParents(const 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:269
+ Here is the call graph for this function:

◆ partialUndiGraph()

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

returns the partial graph formed by the nodes given in parameter

Definition at line 136 of file undiGraph.cpp.

References gum::UndiGraph::addEdge(), gum::NodeGraphPart::addNodeWithId(), gum::NodeGraphPart::existsNode(), and gum::EdgeGraphPart::neighbours().

136  {
137  UndiGraph partialGraph;
138 
139  for (const auto node : nodesSet) {
140  partialGraph.addNodeWithId(node);
141 
142  for (const auto nei : neighbours(node))
143  if (nodesSet.contains(nei) && partialGraph.existsNode(nei))
144  partialGraph.addEdge(node, nei);
145  }
146 
147  return partialGraph;
148  }
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
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:37
+ Here is the call graph for this function:

◆ 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 61 of file nodeGraphPart.cpp.

References gum::NodeGraphPart::__boundVal, gum::NodeGraphPart::__holes, gum::NodeGraphPart::__holes_resize_policy, gum::NodeGraphPart::__holes_size, gum::NodeGraphPart::__updateEndIteratorSafe(), and gum::NodeGraphPart::clear().

Referenced by gum::DAGmodel::__moralGraph(), and gum::DAG::moralGraph().

61  {
62  clear(); // "virtual" flush of the nodes set
63  __holes_size = s.__holes_size;
64  __holes_resize_policy = s.__holes_resize_policy;
65 
66  if (s.__holes) __holes = new NodeSet(*s.__holes);
67 
68  __boundVal = s.__boundVal;
69 
71  }
NodeSet * __holes
the set of nodes not contained in the NodeGraphPart in the interval 1..__max
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
bool __holes_resize_policy
value for __holes configuration
NodeId __boundVal
the id below which NodeIds may belong to the NodeGraphPart
Size __holes_size
value for __holes configuration
void __updateEndIteratorSafe()
updating endIterator (always at __max+1)
virtual void clear()
alias for clearNodes
+ Here is the call graph for this function:
+ Here is the caller 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()

◆ sizeArcs()

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

indicates the number of arcs stored within the ArcGraphPart

Definition at line 34 of file arcGraphPart_inl.h.

References gum::ArcGraphPart::__arcs, and gum::Set< Key, Alloc >::size().

Referenced by gum::MarkovBlanket::sizeArcs(), gum::EssentialGraph::sizeArcs(), gum::DAGmodel::sizeArcs(), gum::prm::gspan::Pattern::sizeArcs(), and gum::InfluenceDiagram< GUM_SCALAR >::toString().

34 { return __arcs.size(); }
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:698
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:266
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sizeEdges()

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

indicates the number of edges stored within the EdgeGraphPart

Definition at line 34 of file edgeGraphPart_inl.h.

References gum::EdgeGraphPart::__edges, and gum::Set< Key, Alloc >::size().

Referenced by gum::EssentialGraph::sizeEdges().

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

◆ sizeNodes()

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

returns the number of nodes in the NodeGraphPart

Definition at line 277 of file nodeGraphPart_inl.h.

Referenced by gum::BinaryJoinTreeConverterDefault::__markConnectedComponent(), gum::BarrenNodesFinder::barrenNodes(), gum::BinaryJoinTreeConverterDefault::convert(), gum::EliminationSequenceStrategy::setGraph(), gum::MarkovBlanket::sizeNodes(), and gum::EssentialGraph::sizeNodes().

277  {
278  return (__holes) ? (__boundVal - __holes->size()) : __boundVal;
279  }
NodeSet * __holes
the set of nodes not contained in the NodeGraphPart in the interval 1..__max
NodeId __boundVal
the id below which NodeIds may belong to the NodeGraphPart
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:698
+ Here is the caller graph for this function:

◆ toDot()

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

to friendly display mixed graph in DOT format

Reimplemented from gum::DiGraph.

Definition at line 214 of file mixedGraph.cpp.

References gum::ArcGraphPart::children(), gum::List< Val, Alloc >::exists(), gum::List< Val, Alloc >::insert(), gum::EdgeGraphPart::neighbours(), and gum::NodeGraphPart::nodes().

214  {
215  std::stringstream output;
216  std::stringstream nodeStream;
217  std::stringstream edgeStream;
218  List< NodeId > treatedNodes;
219  output << "digraph \""
220  << "no_name\" {" << std::endl;
221  nodeStream << "node [shape = ellipse];" << std::endl;
222  std::string tab = " ";
223 
224  for (const auto node : nodes()) {
225  nodeStream << tab << node << ";";
226 
227  for (const auto nei : neighbours(node))
228  if (!treatedNodes.exists(nei))
229  edgeStream << tab << node << " -> " << nei << " [dir=none];"
230  << std::endl;
231 
232  for (const auto chi : children(node))
233  edgeStream << tab << node << " -> " << chi << ";" << std::endl;
234 
235  treatedNodes.insert(node);
236  }
237 
238  output << nodeStream.str() << std::endl
239  << edgeStream.str() << std::endl
240  << "}" << std::endl;
241 
242  return output.str();
243  }
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
+ 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::DiGraph::__mutableTopologicalOrder, gum::DiGraph::__topologicalOrder(), and gum::SequenceImplementation< Key, Alloc, Gen >::clear().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__setO3ClassCreationOrder(), gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::__setO3InterfaceCreationOrder(), gum::prm::o3prm::O3TypeFactory< GUM_SCALAR >::__setO3TypeCreationOrder(), gum::learning::Miic::learnStructure(), and gum::DAGmodel::topologicalOrder().

88  {
89  if (clear
91  == nullptr)) { // we have to call _topologicalOrder
92  if (__mutableTopologicalOrder == nullptr) {
94  } else {
95  // clear is True
97  }
98 
100  }
101 
103  }
void clear()
Clear the sequence.
Definition: sequence_tpl.h:268
Sequence< NodeId > * __mutableTopologicalOrder
The topology sequence of this Directed Graphical Model.
Definition: diGraph.h:198
void __topologicalOrder() const
Returns a topological order of this DAGModel.
Definition: diGraph.cpp:105
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toString()

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

to friendly display the content of the MixedGraph

Reimplemented from gum::DiGraph.

Definition at line 61 of file mixedGraph.cpp.

References gum::EdgeGraphPart::toString(), gum::ArcGraphPart::toString(), and gum::NodeGraphPart::toString().

Referenced by gum::operator<<().

61  {
62  std::string s = NodeGraphPart::toString();
63  s += " , ";
65  s += " , ";
67  return s;
68  }
const std::string toString() const
to friendly display the content of the ArcGraphPart
std::string toString() const
a function to display the set of nodes
const std::string toString() const
to friendly display the content of the EdgeGraphPart
+ Here is the call graph for this function:
+ Here is the caller 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 124 of file edgeGraphPart.cpp.

References gum::List< Val, Alloc >::empty(), gum::HashTable< Key, Val, Alloc >::exists(), gum::List< Val, Alloc >::front(), GUM_ERROR, gum::HashTable< Key, Val, Alloc >::insert(), gum::EdgeGraphPart::neighbours(), gum::List< Val, Alloc >::popFront(), and gum::List< Val, Alloc >::pushBack().

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

◆ unvirtualizedEraseChildren()

INLINE void gum::ArcGraphPart::unvirtualizedEraseChildren ( const 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 138 of file arcGraphPart_inl.h.

References gum::ArcGraphPart::__children, gum::Set< Key, Alloc >::beginSafe(), gum::ArcGraphPart::children(), gum::Set< Key, Alloc >::endSafe(), and gum::ArcGraphPart::eraseArc().

Referenced by gum::DiGraph::eraseNode(), and eraseNode().

138  {
139  if (__children.exists(id)) {
140  NodeSet& children = *(__children[id]);
141 
142  for (auto iter = children.beginSafe(); // safe iterator needed here
143  iter != children.endSafe();
144  ++iter) {
145  ArcGraphPart::eraseArc(Arc(id, *iter));
146  }
147  }
148  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
NodeProperty< NodeSet *> __children
for each arc, the set of its children
Definition: arcGraphPart.h:272
+ Here is the call graph for this function:
+ Here is the caller 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 93 of file edgeGraphPart_inl.h.

References gum::EdgeGraphPart::__neighbours, gum::EdgeGraphPart::eraseEdge(), and gum::EdgeGraphPart::neighbours().

Referenced by gum::UndiGraph::eraseNode(), and eraseNode().

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

◆ unvirtualizedEraseParents()

INLINE void gum::ArcGraphPart::unvirtualizedEraseParents ( const 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 126 of file arcGraphPart_inl.h.

References gum::ArcGraphPart::__parents, gum::Set< Key, Alloc >::beginSafe(), gum::Set< Key, Alloc >::endSafe(), gum::ArcGraphPart::eraseArc(), and gum::ArcGraphPart::parents().

Referenced by gum::DiGraph::eraseNode(), and eraseNode().

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

Member Data Documentation

◆ onArcAdded

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

◆ onArcDeleted

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

Definition at line 81 of file arcGraphPart.h.

Referenced by gum::ArcGraphPart::clearArcs(), and gum::ArcGraphPart::eraseArc().

◆ onEdgeAdded

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

◆ onEdgeDeleted

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

◆ onNodeAdded

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

Definition at line 271 of file nodeGraphPart.h.

Referenced by gum::NodeGraphPart::addNodeWithId().

◆ onNodeDeleted

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

Definition at line 272 of file nodeGraphPart.h.

Referenced by gum::NodeGraphPart::__clearNodes().


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