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

Base class for mixed graphs. More...

#include <mixedGraph.h>

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

Public Types

using EdgeIterator = EdgeSetIterator
using ArcIterator = ArcSetIterator
using NodeIterator = NodeGraphPartIterator
using NodeConstIterator = NodeGraphPartIterator
using NodeIteratorSafe = NodeGraphPartIteratorSafe
using NodeConstIteratorSafe = NodeGraphPartIteratorSafe
using node_iterator = NodeGraphPartIterator
 types for STL compliance
using node_const_iterator = NodeGraphPartIterator
 types for STL compliance
using node_iterator_safe = NodeGraphPartIteratorSafe
 types for STL compliance
using node_const_iterator_safe = NodeGraphPartIteratorSafe
 types for STL compliance

Public Member Functions

bool hasDirectedPath (NodeId from, NodeId to)
 checks whether there exists a directed path from from to to
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
 MixedGraph (const UndiGraph &g)
 default constructor
 MixedGraph (const DiGraph &g)
 default constructor
 MixedGraph (const MixedGraph &g)
 copy constructor
virtual ~MixedGraph ()
 destructor
Operators
MixedGraphoperator= (const MixedGraph &g)
 copy operator
bool operator== (const MixedGraph &g) const
 tests whether two MixedGraphs are identical (same nodes, arcs and edges)
Accessors/Modifiers
void eraseNode (const NodeId node) override
 remove a node as well as its adjacent arcs and edges from the graph
void clear () override
 removes all the nodes, arcs and edges from the graph
std::vector< NodeIdmixedOrientedPath (NodeId node1, NodeId node2) const
 returns a mixed edge/directed arc path from node1 to node2 in the arc/edge set
bool hasMixedOrientedPath (NodeId node1, NodeId node2) const
 returns true if a mixed edge/directed arc path from node1 to node2 in the arc/edge set exists.
std::vector< NodeIdmixedUnorientedPath (NodeId node1, NodeId node2) const
 returns a mixed/directed path from node1 to node2 in the arc/edge set
std::string toDot () const override
 to friendly display mixed graph in DOT format
std::string toString () const override
 to friendly display the content of the MixedGraph
NodeSet boundary (NodeId node) const
 returns the set of node adjacent to a given node
NodeSet chainComponent (NodeId node) const
 returns the set of nodes reachable by undirected path
Operators
bool operator== (const UndiGraph &g) const
 tests whether two UndiGraphs are identical (same nodes, same edges)
bool operator!= (const UndiGraph &g) const
 tests whether two UndiGraphs are different
Operators
bool operator== (const EdgeGraphPart &p) const
 tests whether two EdgeGraphParts contain the same edges
Accessors/Modifiers
void addEdge (NodeId first, NodeId second) override
 insert a new edge into the undirected graph
bool hasUndirectedCycle () const
 checks whether the graph contains cycles
virtual UndiGraph partialUndiGraph (NodeSet nodes)
 returns the partial graph formed by the nodes given in parameter
NodeProperty< NodeIdnodes2ConnectedComponent () const
 returns a property {node:id of connected component}
Accessors/Modifiers
virtual void eraseEdge (const Edge &edge)
 removes an edge from the EdgeGraphPart
bool existsEdge (const Edge &edge) const
 indicates whether a given edge exists
bool existsEdge (NodeId n1, NodeId n2) const
 indicates whether a given edge exists
bool emptyEdges () const
 indicates wether the EdgeGraphPart contains any edge
virtual void clearEdges ()
 removes all the edges from the EdgeGraphPart
Size sizeEdges () const
 indicates the number of edges stored within the EdgeGraphPart
const EdgeSetedges () const
 returns the set of edges stored within the EdgeGraphPart
const NodeSetneighbours (NodeId id) const
 returns the set of node neighbours to a given node
void eraseNeighbours (NodeId id)
 erase all the edges adjacent to a given node
void unvirtualizedEraseNeighbours (NodeId id)
 same function as eraseNeighbours but without any virtual call to an erase
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))
template<typename VAL>
EdgeProperty< VAL > edgesProperty (const VAL &val, 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)
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))
std::vector< NodeIdundirectedPath (NodeId node1, NodeId node2) const
 returns a possible path from node1 to node2 in the edge set
bool hasUndirectedPath (NodeId n1, NodeId n2) const
 return true if n1 and n2 are connected (by an undirected path) in the graph.
bool hasUndirectedPath (NodeId n1, NodeId n2, const NodeSet &except) const
 return true if n1 and n2 are connected (by an undirected path not using the nodes of except) in the graph.
bool hasUndirectedPath (const NodeSet &n1, const NodeSet &n2, const NodeSet &except) const
 return true if n1 and n2 are connected (by an undirected path not using the nodes of except) in the graph.
Operators
bool operator== (const DiGraph &g) const
 tests whether two DiGraphs are identical (same nodes, same arcs)
Operators
bool operator== (const ArcGraphPart &p) const
 tests whether two ArcGraphParts contain the same arcs
Accessors/Modifiers

tests whether two DiGraphs are different

Parameters
gthe DiGraph with which "this" is compared
virtual void addArc (const NodeId tail, const NodeId head)
 insert a new arc into the directed graph
Sequence< NodeIdtopologicalOrder () const
 Build and return a topological order.
Accessors/Modifiers
virtual void eraseArc (const Arc &arc)
 removes an arc from the ArcGraphPart
bool existsArc (const Arc &arc) const
 indicates whether a given arc exists
bool existsArc (NodeId tail, NodeId head) const
 indicates whether a given arc exists
bool emptyArcs () const
 indicates wether the ArcGraphPart contains any arc
void clearArcs ()
 removes all the arcs from the ArcGraphPart
Size sizeArcs () const
 indicates the number of arcs stored within the ArcGraphPart
const ArcSetarcs () const
 returns the set of arcs stored within the ArcGraphPart
const NodeSetparents (NodeId id) const
 returns the set of nodes with arc ingoing to a given node
NodeSet parents (const NodeSet &ids) const
 returns the set of parents of a set of nodes
NodeSet family (NodeId id) const
 returns the set of nodes which consists in the node and its parents
NodeSet family (const NodeSet &ids) const
 returns the set of family nodes of a set of nodes
NodeSet descendants (NodeId id) const
 returns the set of nodes with directed path outgoing from a given node
NodeSet ancestors (NodeId id) const
 returns the set of nodes with directed path ingoing to a given node
NodeSet children (const NodeSet &ids) const
 returns the set of children of a set of nodes
const NodeSetchildren (NodeId id) const
 returns the set of nodes with arc outgoing from a given node
void eraseParents (NodeId id)
 erase all the parents of a given node
void unvirtualizedEraseParents (NodeId id)
 same function as eraseParents but without any virtual call to an erase
void eraseChildren (NodeId id)
 removes all the children of a given node
void unvirtualizedEraseChildren (NodeId id)
 same function as eraseChildren but without any virtual call to an erase
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))
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)
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))
std::vector< NodeIddirectedPath (NodeId node1, NodeId node2) const
 returns a directed path from node1 to node2 belonging to the set of arcs
std::vector< NodeIddirectedUnorientedPath (NodeId node1, NodeId node2) const
 returns an unoriented (directed) path from node1 to node2 in the arc set
Operators
bool operator== (const NodeGraphPart &p) const
 check whether two NodeGraphParts contain the same nodes
bool operator!= (const NodeGraphPart &p) const
 check whether two NodeGraphParts contain different nodes
Accessors/Modifiers
void populateNodes (const NodeGraphPart &s)
 populateNodes clears *this and fills it with the same nodes as "s"
template<typename T>
void populateNodesFromProperty (const NodeProperty< T > &h)
 populateNodesFromProperty clears *this and fills it with the keys of "h"
NodeId nextNodeId () const
 returns a new node id, not yet used by any node
virtual NodeId addNode ()
 insert a new node and return its id
std::vector< NodeIdaddNodes (Size n)
 insert n nodes
virtual void addNodeWithId (const NodeId id)
 try to insert a node with the given id
bool existsNode (const NodeId id) const
 returns true iff the NodeGraphPart contains the given nodeId
bool exists (const NodeId id) const
 alias for existsNode
bool emptyNodes () const
 indicates whether there exists nodes in the NodeGraphPart
bool empty () const
 alias for emptyNodes
virtual void clearNodes ()
 remove all the nodes from the NodeGraphPart
Size sizeNodes () const
 returns the number of nodes in the NodeGraphPart
Size size () const
 alias for sizeNodes
NodeId bound () const
 returns a number n such that all node ids are strictly lower than n
NodeSet asNodeSet () const
 returns a copy of the set of nodes represented by the NodeGraphPart
const NodeGraphPartnodes () const
 return *this as a NodeGraphPart
node_iterator_safe beginSafe () const
 a begin iterator to parse the set of nodes contained in the NodeGraphPart
const node_iterator_safeendSafe () const noexcept
 the end iterator to parse the set of nodes contained in the NodeGraphPart
node_iterator begin () const noexcept
 a begin iterator to parse the set of nodes contained in the NodeGraphPart
const node_iteratorend () const noexcept
 the end iterator to parse the set of nodes contained in the NodeGraphPart
template<typename VAL>
NodeProperty< VAL > nodesPropertyFromFunction (VAL(*f)(const NodeId &), Size size=0) const
 a method to create a HashTable with key:NodeId and value:VAL
template<typename VAL>
NodeProperty< VAL > nodesPropertyFromVal (const VAL &a, Size size=0) const
 a method to create a hashMap with key:NodeId and value:VAL
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))

Static Public Member Functions

Constructors / Destructors
static UndiGraph completeGraph (int n)
 create a complete UndiGraph with n nodes
Constructors / Destructors
static DiGraph completeGraph (int n)
 Build a complete DiGraph with n nodes.

Public Attributes

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

Protected Member Functions

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

Private Member Functions

void _checkNeighbours_ (NodeId id)
 when the EdgeGraphPart contains no edge adjacent to a given node, this function adds an empty set entry to neighbours[id]
void _clearEdges_ ()
void _checkParents_ (NodeId id)
 when the ArcGraphPart contains no arc ingoing into a given node, this function adds an empty set entry to parents[id]
void _checkChildren_ (NodeId id)
 when the ArcGraphPart contains no arc outgoing from a given node, this function adds an empty set entry to children[id]

Private Attributes

EdgeSet _edges_
 the set of all the edges contained within the EdgeGraphPart
NodeProperty< NodeSet * > _neighbours_
 for each node, the set of its adjacent edges
Set< Arc_arcs_
 the set of all the arcs contained within the ArcGraphPart
NodeProperty< NodeSet * > _parents_
 for each arc, the sets of its parents
NodeProperty< NodeSet * > _children_
 for each arc, the set of its children

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
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
void eraseParents(NodeId id)
erase all the parents of a given node
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
The base class for all directed edges.
virtual void addArc(const NodeId tail, const NodeId head)
insert a new arc into the directed graph
Definition diGraph_inl.h:55
virtual void eraseEdge(const Edge &edge)
removes an edge from the EdgeGraphPart
void eraseNeighbours(NodeId id)
erase all the edges adjacent to a given node
const EdgeSet & edges() const
returns the set of edges stored within the EdgeGraphPart
const NodeSet & neighbours(NodeId id) const
returns the set of node neighbours to a given node
The base class for all undirected edges.
void eraseNode(const NodeId node) override
remove a node as well as its adjacent arcs and edges from the graph
void clear() override
removes all the nodes, arcs and edges from the graph
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
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
bool empty() const
alias for emptyNodes
virtual NodeId addNode()
insert a new node and return its id
iterator begin() const
The usual unsafe begin iterator to parse the set.
Definition set_tpl.h:438
const iterator & end() const noexcept
The usual unsafe end iterator to parse the set.
Definition set_tpl.h:450
void addEdge(NodeId first, NodeId second) override
insert a new edge into the undirected graph
Size NodeId
Type for node ids.
NodeSet::const_iterator NodeSetIterator
Some typdefs and define for shortcuts ...
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...

Definition at line 146 of file mixedGraph.h.

Member Typedef Documentation

◆ ArcIterator

Definition at line 100 of file arcGraphPart.h.

◆ EdgeIterator

Definition at line 96 of file edgeGraphPart.h.

◆ node_const_iterator

types for STL compliance

Definition at line 276 of file nodeGraphPart.h.

◆ node_const_iterator_safe

types for STL compliance

Definition at line 278 of file nodeGraphPart.h.

◆ node_iterator

types for STL compliance

Definition at line 275 of file nodeGraphPart.h.

◆ node_iterator_safe

types for STL compliance

Definition at line 277 of file nodeGraphPart.h.

◆ NodeConstIterator

Definition at line 285 of file nodeGraphPart.h.

◆ NodeConstIteratorSafe

◆ NodeIterator

Definition at line 284 of file nodeGraphPart.h.

◆ NodeIteratorSafe

Constructor & Destructor Documentation

◆ MixedGraph() [1/4]

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

default constructor

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

Definition at line 56 of file mixedGraph.cpp.

61 :
62 // Note that we need to initialize the NodeGraphPart by ourselves
63 // because
64 // it is a virtual inherited class (see C++ FAQ Lite #25.12 for details)
65 NodeGraphPart(nodes_size, nodes_resize_policy), UndiGraph(edges_size, edges_resize_policy),
66 DiGraph(arcs_size, arcs_resize_policy) { // for debugging purposes
67 GUM_CONSTRUCTOR(MixedGraph);
68 }
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:69
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:72

References gum::DiGraph::DiGraph(), MixedGraph(), and gum::UndiGraph::UndiGraph().

Referenced by MixedGraph(), MixedGraph(), MixedGraph(), MixedGraph(), gum::PDAG::PDAG(), gum::PDAG::PDAG(), gum::PDAG::PDAG(), gum::PDAG::PDAG(), gum::PDAG::PDAG(), ~MixedGraph(), operator=(), and operator==().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MixedGraph() [2/4]

gum::MixedGraph::MixedGraph ( const UndiGraph & g)
explicit

default constructor

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

Definition at line 70 of file mixedGraph.cpp.

70 : NodeGraphPart(g), UndiGraph(g), DiGraph() {
71 GUM_CONSTRUCTOR(MixedGraph);
72 }

References gum::DiGraph::DiGraph(), MixedGraph(), and gum::UndiGraph::UndiGraph().

Here is the call graph for this function:

◆ MixedGraph() [3/4]

gum::MixedGraph::MixedGraph ( const DiGraph & g)
explicit

default constructor

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

Definition at line 74 of file mixedGraph.cpp.

74 : NodeGraphPart(g), UndiGraph(), DiGraph(g) {
75 GUM_CONSTRUCTOR(MixedGraph);
76 }

References gum::DiGraph::DiGraph(), MixedGraph(), and gum::UndiGraph::UndiGraph().

Here is the call graph for this function:

◆ MixedGraph() [4/4]

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

copy constructor

Parameters
gthe MixedGraph to copy

Definition at line 78 of file mixedGraph.cpp.

78 :
79 NodeGraphPart(g), UndiGraph(g), DiGraph(g) { // for debugging purposes
80 GUM_CONS_CPY(MixedGraph);
81 }

References gum::DiGraph::DiGraph(), MixedGraph(), and gum::UndiGraph::UndiGraph().

Here is the call graph for this function:

◆ ~MixedGraph()

gum::MixedGraph::~MixedGraph ( )
virtual

destructor

Definition at line 83 of file mixedGraph.cpp.

83 { // for debugging purposes
84 GUM_DESTRUCTOR(MixedGraph);
85 }

References MixedGraph().

Here is the call graph for this function:

Member Function Documentation

◆ _checkChildren_()

INLINE void gum::ArcGraphPart::_checkChildren_ ( NodeId id)
privateinherited

when the ArcGraphPart contains no arc outgoing from a given node, this function adds an empty set entry to children[id]

Parameters
idthe node whose children[id] is checked

Definition at line 71 of file arcGraphPart_inl.h.

71 {
72 if (!_children_.exists(id)) { _children_.insert(id, new NodeSet); }
73 }
NodeProperty< NodeSet * > _children_
for each arc, the set of its children

References _children_.

Referenced by addArc().

Here is the caller graph for this function:

◆ _checkNeighbours_()

INLINE void gum::EdgeGraphPart::_checkNeighbours_ ( NodeId id)
privateinherited

when the EdgeGraphPart contains no edge adjacent to a given node, this function adds an empty set entry to neighbours[id]

Parameters
idthe node whose neighbours[id] is checked

Definition at line 67 of file edgeGraphPart_inl.h.

67 {
68 if (!_neighbours_.exists(id)) { _neighbours_.insert(id, new NodeSet); }
69 }
NodeProperty< NodeSet * > _neighbours_
for each node, the set of its adjacent edges

References _neighbours_.

Referenced by addEdge().

Here is the caller graph for this function:

◆ _checkParents_()

INLINE void gum::ArcGraphPart::_checkParents_ ( NodeId id)
privateinherited

when the ArcGraphPart contains no arc ingoing into a given node, this function adds an empty set entry to parents[id]

Parameters
idthe node whose parents[id] is checked

Definition at line 67 of file arcGraphPart_inl.h.

67 {
68 if (!_parents_.exists(id)) { _parents_.insert(id, new NodeSet); }
69 }
NodeProperty< NodeSet * > _parents_
for each arc, the sets of its parents

References _parents_.

Referenced by addArc().

Here is the caller graph for this function:

◆ _clearEdges_()

void gum::EdgeGraphPart::_clearEdges_ ( )
privateinherited

Definition at line 88 of file edgeGraphPart.cpp.

88 {
89 for (const auto& elt: _neighbours_)
90 delete elt.second;
91
92 _neighbours_.clear();
93
94 if (onEdgeDeleted.hasListener()) {
95 EdgeSet tmp = _edges_;
96 _edges_.clear();
97
98 for (const auto& edge: tmp)
99 GUM_EMIT2(onEdgeDeleted, edge.first(), edge.second());
100 } else {
101 _edges_.clear();
102 }
103 }
EdgeSet _edges_
the set of all the edges contained within the EdgeGraphPart
Signaler2< NodeId, NodeId > onEdgeDeleted
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
#define GUM_EMIT2(signal, arg1, arg2)
Definition signaler2.h:61

References _edges_, _neighbours_, GUM_EMIT2, and onEdgeDeleted.

Referenced by ~EdgeGraphPart(), and clearEdges().

Here is the caller 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, gum::PDAG, and gum::prm::gspan::Pattern.

Definition at line 55 of file diGraph_inl.h.

55 {
56 if (!exists(head)) { GUM_ERROR(InvalidNode, "no head node : " << head) }
57
58 if (!exists(tail)) { GUM_ERROR(InvalidNode, "no tail node : " << tail) }
59
60 ArcGraphPart::addArc(tail, head);
61 }
virtual void addArc(NodeId tail, 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:72

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

Referenced by gum::MeekRules::_applyMeekRules_(), gum::EssentialGraph::_buildEssentialGraph_(), gum::learning::Miic::_orientingVstructureMiic_(), gum::learning::SimpleMiic::_orientingVstructureMiic_(), gum::MeekRules::_propagatesOrientationInChainOfRemainingEdges_(), gum::learning::Miic::_propagatingOrientationMiic_(), gum::learning::SimpleMiic::_propagatingOrientationMiic_(), gum::DAG::addArc(), gum::PDAG::addArc(), gum::prm::gspan::Pattern::addArc(), completeGraph(), gum::learning::SimpleMiic::learnPDAG(), gum::learning::SimpleMiic::learnStructure(), gum::learning::SimpleMiic::orientationLatents_(), gum::learning::Miic::orientationMiic_(), gum::learning::SimpleMiic::orientationMiic_(), gum::learning::IBNLearner::prepareMiic_(), gum::learning::SimpleMiic::propagatesOrientationInChainOfRemainingEdges_(), and gum::learning::SimpleMiic::propagatesRemainingOrientableEdges_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addEdge()

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

insert a new edge into the undirected graph

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

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

Reimplemented from gum::EdgeGraphPart.

Definition at line 55 of file undiGraph_inl.h.

55 {
56 if (!exists(first)) { GUM_ERROR(InvalidNode, "Node (" << first << ") does not exist.") }
57
58 if (!exists(second)) { GUM_ERROR(InvalidNode, "Node (" << second << ") does not exist.") }
59
60 EdgeGraphPart::addEdge(second, first);
61 }
virtual void addEdge(NodeId n1, NodeId n2)
insert a new edge into the EdgeGraphPart

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::prm::GSpan< GUM_SCALAR >::_sortPatterns_(), gum::StaticTriangulation::_triangulate_(), completeGraph(), gum::DAG::moralGraph(), gum::PDAG::moralGraph(), gum::InfluenceDiagram< GUM_SCALAR >::moralGraph_(), gum::DAG::moralizedAncestralGraph(), partialUndiGraph(), gum::learning::IBNLearner::prepareMiic_(), and gum::EssentialGraph::skeleton().

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

258 {
259 NodeId newNode;
260
261 // fill the first hole if holes exist
262 if (_holes_ && (!_holes_->empty())) {
263 newNode = *(_holes_->begin());
264 _eraseHole_(newNode);
265 } else {
266 newNode = _boundVal_;
267 ++_boundVal_;
269 }
270
271 GUM_EMIT1(onNodeAdded, newNode);
272
273 return newNode;
274 }
Signaler1< NodeId > onNodeAdded
void _eraseHole_(NodeId id)
to delete hole.
void _updateEndIteratorSafe_()
updating endIterator (always at max+1)
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
#define GUM_EMIT1(signal, arg1)
Definition signaler1.h:61

References _boundVal_, _eraseHole_(), _holes_, _updateEndIteratorSafe_(), GUM_EMIT1, and onNodeAdded.

Referenced by gum::prm::gspan::DFSTree< GUM_SCALAR >::_addChild_(), gum::prm::StructuredInference< GUM_SCALAR >::_addEdgesInReducedGraph_(), gum::prm::gspan::StrictSearch< GUM_SCALAR >::_buildPatternGraph_(), gum::prm::StructuredInference< GUM_SCALAR >::_buildPatternGraph_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClassDag_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClassDag_(), and gum::prm::gspan::DFSTree< GUM_SCALAR >::addRoot().

Here is the call graph for this function:
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 276 of file nodeGraphPart_inl.h.

276 {
277 std::vector< NodeId > v;
278 v.reserve(N);
279 for (Idx i = 0; i < N; i++)
280 v.push_back(this->addNode());
281 return v;
282 }
Size Idx
Type for indexes.
Definition types.h:79

Referenced by gum::DiGraph::completeGraph(), and gum::UndiGraph::completeGraph().

Here is the caller graph for this function:

◆ addNodeWithId()

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

try to insert a node with the given id

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

Reimplemented in gum::CliqueGraph.

Definition at line 151 of file nodeGraphPart.cpp.

151 {
152 if (id >= _boundVal_) {
153 if (id > _boundVal_) { // we have to add holes
155
156 for (NodeId i = _boundVal_; i < id; ++i)
157 _holes_->insert(i);
158 }
159
160 _boundVal_ = id + 1;
161
163 } else {
164 if (_inHoles_(id)) { // we fill a hole
165 _eraseHole_(id);
166 } else {
167 GUM_ERROR(DuplicateElement, "Id " << id << " is already used")
168 }
169 }
170
172 }
Size _holes_size_
value for holes configuration
bool _holes_resize_policy_
value for holes configuration
bool _inHoles_(NodeId id) const

References _boundVal_, _eraseHole_(), _holes_, _holes_resize_policy_, _holes_size_, _inHoles_(), _updateEndIteratorSafe_(), GUM_EMIT1, GUM_ERROR, and onNodeAdded.

Referenced by gum::learning::StructuralConstraintDAG::StructuralConstraintDAG(), gum::EssentialGraph::_buildEssentialGraph_(), gum::prm::GSpan< GUM_SCALAR >::_sortPatterns_(), gum::prm::gspan::Pattern::addNodeWithLabel(), gum::learning::IBNLearner::learnDag_(), gum::learning::SimpleMiic::learnStructure(), gum::InfluenceDiagram< GUM_SCALAR >::moralGraph_(), gum::DAG::moralizedAncestralGraph(), gum::PDAG::moralizedAncestralGraph(), gum::UndiGraph::partialUndiGraph(), gum::learning::IBNLearner::prepareMiic_(), gum::MeekRules::propagateToCPDAG(), gum::MeekRules::propagateToDAG(), gum::rec_ancestral(), and gum::EssentialGraph::skeleton().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ancestors()

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

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

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

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

Definition at line 191 of file arcGraphPart.cpp.

191 {
192 NodeSet res;
193 NodeSet tmp;
194 for (auto next: parents(id))
195 tmp.insert(next);
196
197 while (!tmp.empty()) {
198 auto current = *(tmp.begin());
199 tmp.erase(current);
200 res.insert(current);
201 for (auto next: parents(current)) {
202 if (!tmp.contains(next) && !res.contains(next)) { tmp.insert(next); }
203 }
204 }
205 return res;
206 }
void insert(const Key &k)
Inserts a new element into the set.
Definition set_tpl.h:539

References gum::Set< Key >::begin(), gum::Set< Key >::contains(), gum::Set< Key >::empty(), gum::Set< Key >::erase(), gum::Set< Key >::insert(), and parents().

Referenced by gum::DAGmodel::ancestors().

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

59{ return _arcs_; }
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart

References _arcs_.

Referenced by gum::EssentialGraph::_buildEssentialGraph_(), gum::prm::ClassBayesNet< GUM_SCALAR >::_init_(), gum::prm::gspan::Pattern::arcs(), gum::learning::SimpleMiic::learnStructure(), gum::DAG::moralGraph(), gum::PDAG::moralGraph(), gum::MeekRules::propagateToCPDAG(), gum::MeekRules::propagateToDAG(), and gum::DiGraph::toDot().

Here is the caller graph for this function:

◆ arcsProperty() [1/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.

◆ arcsProperty() [2/2]

template<typename VAL>
ArcProperty< VAL > gum::ArcGraphPart::arcsProperty ( VAL(* )(const Arc &),
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.

◆ 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())
NodeSet asNodeSet() const
returns a copy of the set of nodes represented by the NodeGraphPart
as this is faster and consumes much less memory.

Definition at line 356 of file nodeGraphPart_inl.h.

356 {
357 NodeSet son(sizeNodes());
358
359 if (!empty()) {
360 for (NodeId n = 0; n < _boundVal_; ++n) {
361 if (!_inHoles_(n)) son.insert(n);
362 }
363 }
364
365 return son;
366 }
Size sizeNodes() const
returns the number of nodes in the NodeGraphPart

References _boundVal_, _inHoles_(), empty(), gum::Set< Key >::insert(), and sizeNodes().

Referenced by gum::MarginalTargetedInference< GUM_SCALAR >::MarginalTargetedInference(), gum::MarginalTargetedMRFInference< GUM_SCALAR >::MarginalTargetedMRFInference(), and gum::ImportanceSampling< GUM_SCALAR >::unsharpenBN_().

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

333 {
334 NodeGraphPartIterator it(*this);
335 it.validate_(); // stop the iterator at the first not-in-holes
336 return it;
337 }
friend class NodeGraphPartIterator

References NodeGraphPartIterator, and gum::NodeGraphPartIterator::validate_().

Referenced by gum::Estimator< GUM_SCALAR >::Estimator(), populateNodesFromProperty(), and gum::Estimator< GUM_SCALAR >::setFromBN().

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

321 {
323 it.validate_(); // stop the iterator at the first not-in-holes
324 return it;
325 }
friend class NodeGraphPartIteratorSafe

References NodeGraphPartIteratorSafe, and gum::NodeGraphPartIterator::validate_().

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

310{ return _boundVal_; }

References _boundVal_.

Referenced by _clearNodes_().

Here is the caller graph for this function:

◆ boundary()

INLINE NodeSet gum::MixedGraph::boundary ( NodeId node) const

returns the set of node adjacent to a given node

Note that the set of node returned may be empty.

Parameters
idthe node to which the edges are adjacent

Definition at line 86 of file mixedGraph_inl.h.

86 {
87 return neighbours(node) + parents(node) + children(node);
88 }
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes

References gum::ArcGraphPart::children(), gum::EdgeGraphPart::neighbours(), and gum::ArcGraphPart::parents().

Referenced by gum::MeekRules::_isOrientable_(), and gum::learning::SimpleMiic::isOrientable_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ chainComponent()

NodeSet gum::MixedGraph::chainComponent ( NodeId node) const

returns the set of nodes reachable by undirected path

Note that the set of node returned may be empty.

Parameters
idthe node to which the edges are adjacent

Definition at line 260 of file mixedGraph.cpp.

260 {
261 NodeSet res;
262 NodeSet stack{node};
263
264 while (!stack.empty()) {
265 const NodeId n = *(stack.begin());
266 stack.erase(n);
267 if (!res.exists(n)) {
268 res.insert(n);
269 stack += neighbours(n);
270 }
271 }
272
273 return res;
274 }

References gum::Set< Key >::begin(), gum::Set< Key >::empty(), gum::Set< Key >::erase(), gum::Set< Key >::exists(), gum::Set< Key >::insert(), and gum::EdgeGraphPart::neighbours().

Referenced by gum::PDAG::toDot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ children() [1/2]

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

returns the set of children of a set of nodes

Definition at line 86 of file arcGraphPart_inl.h.

86 {
87 NodeSet res;
88 for (const auto node: ids)
89 res += children(node);
90 return res;
91 }

References children().

Referenced by ArcGraphPart(), gum::prm::ClassDependencyGraph< GUM_SCALAR >::_addArcs_(), gum::EssentialGraph::_buildEssentialGraph_(), gum::prm::gspan::Pattern::_expandCodeIsMinimal_(), gum::prm::SVE< GUM_SCALAR >::_initElimOrder_(), gum::prm::SVED< GUM_SCALAR >::_initElimOrder_(), gum::DAG::_minimalCondSetVisitDn_(), gum::DAG::_minimalCondSetVisitUp_(), gum::prm::gspan::Pattern::_not_rec_(), gum::MeekRules::_propagatesOrientationInChainOfRemainingEdges_(), gum::prm::gspan::Pattern::_rec_(), gum::BarrenNodesFinder::barrenNodes(), gum::MixedGraph::boundary(), children(), descendants(), directedUnorientedPath(), eraseChildren(), gum::DiGraph::hasDirectedPath(), gum::PDAG::hasMixedReallyOrientedPath(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::initialize_(), gum::prm::PRMClassElementContainer< double >::isInputNode(), gum::prm::gspan::Pattern::isMinimal(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::makeInferenceNodeToNeighbours_(), gum::DAG::minimalCondSet(), gum::MixedGraph::mixedUnorientedPath(), gum::learning::SimpleMiic::propagatesOrientationInChainOfRemainingEdges_(), gum::rec_hasMixedReallyOrientedPath(), gum::BayesBall::relevantTensors(), gum::dSeparationAlgorithm::relevantTensors(), gum::prm::gspan::Pattern::remove(), gum::BayesBall::requisiteNodes(), gum::dSeparationAlgorithm::requisiteNodes(), gum::DAGCycleDetector::setDAG(), gum::MixedGraph::toDot(), gum::PDAG::toDot(), and unvirtualizedEraseChildren().

Here is the call graph for this function:

◆ children() [2/2]

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

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

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

Parameters
idthe node which is the tail of the arcs returned

Definition at line 109 of file arcGraphPart_inl.h.

109 {
110 if (_children_.exists(id)) return *_children_[id];
111 else return emptyNodeSet;
112 }
const NodeSet emptyNodeSet
Some typdefs and define for shortcuts ...

References _children_, and gum::emptyNodeSet.

◆ clear()

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

removes all the nodes, arcs and edges from the graph

Reimplemented from gum::NodeGraphPart.

Definition at line 68 of file mixedGraph_inl.h.

68 {
72 }
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

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

Here is the call graph for this function:

◆ clearArcs()

void gum::ArcGraphPart::clearArcs ( )
inherited

removes all the arcs from the ArcGraphPart

Definition at line 98 of file arcGraphPart.cpp.

98 {
99 for (const auto& elt: _parents_)
100 delete elt.second;
101
102 _parents_.clear();
103
104 for (const auto& elt: _children_)
105 delete elt.second;
106
107 _children_.clear();
108
109 // we need this copy only if at least one onArcDeleted listener exists
110 if (onArcDeleted.hasListener()) {
111 ArcSet tmp = _arcs_;
112 _arcs_.clear();
113
114 for (const auto& arc: tmp)
115 GUM_EMIT2(onArcDeleted, arc.tail(), arc.head());
116 } else {
117 _arcs_.clear();
118 }
119 }
Signaler2< NodeId, NodeId > onArcDeleted
Set< Arc > ArcSet
Some typdefs and define for shortcuts ...

References _arcs_, _children_, _parents_, GUM_EMIT2, and onArcDeleted.

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

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 86 of file edgeGraphPart.cpp.

References _clearEdges_().

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

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

312{ _clearNodes_(); }
void _clearNodes_()
code for clearing nodes (called twice)

References _clearNodes_().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ completeGraph() [1/2]

DiGraph gum::DiGraph::completeGraph ( int n)
staticinherited

Build a complete DiGraph with n nodes.

Parameters
intn
Returns
the complete DiGraph

Definition at line 57 of file diGraph.cpp.

57 {
58 DiGraph g;
59 g.addNodes(n);
60
61 for (int j = 0; j < n; ++j) {
62 for (int k = j + 1; k < n; ++k) {
63 g.addArc(j, k);
64 }
65 }
66 return g;
67 }

References DiGraph(), addArc(), and gum::NodeGraphPart::addNodes().

Here is the call graph for this function:

◆ completeGraph() [2/2]

UndiGraph gum::UndiGraph::completeGraph ( int n)
staticinherited

create a complete UndiGraph with n nodes

Parameters
nint
Returns
the complete UndiGraph

Definition at line 60 of file undiGraph.cpp.

60 {
61 UndiGraph g;
62 g.addNodes(n);
63
64 for (int j = 0; j < n; ++j) {
65 for (int k = j + 1; k < n; ++k) {
66 g.addEdge(j, k);
67 }
68 }
69 return g;
70 }

References UndiGraph(), addEdge(), and gum::NodeGraphPart::addNodes().

Here is the call graph for this function:

◆ descendants()

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

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

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

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

Definition at line 174 of file arcGraphPart.cpp.

174 {
175 NodeSet res;
176 NodeSet tmp;
177 for (auto next: children(id))
178 tmp.insert(next);
179
180 while (!tmp.empty()) {
181 auto current = *(tmp.begin());
182 tmp.erase(current);
183 res.insert(current);
184 for (auto next: children(current)) {
185 if (!tmp.contains(next) && !res.contains(next)) { tmp.insert(next); }
186 }
187 }
188 return res;
189 }

References gum::Set< Key >::begin(), children(), gum::Set< Key >::contains(), gum::Set< Key >::empty(), gum::Set< Key >::erase(), and gum::Set< Key >::insert().

Referenced by gum::DAGmodel::descendants().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ directedPath()

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

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

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

Definition at line 208 of file arcGraphPart.cpp.

208 {
209 // not recursive version => use a FIFO for simulating the recursion
210 List< NodeId > nodeFIFO;
211 nodeFIFO.pushBack(n2);
212
213 // mark[node] = successor if visited, else mark[node] does not exist
215 mark.insert(n2, n2);
216
217 NodeId current;
218
219 while (!nodeFIFO.empty()) {
220 current = nodeFIFO.front();
221 nodeFIFO.popFront();
222
223 // check the parents
224
225 for (const auto new_one: parents(current)) {
226 if (mark.exists(new_one)) // if this node is already marked, do not
227 continue; // check it again
228
229 mark.insert(new_one, current);
230
231 if (new_one == n1) {
232 std::vector< NodeId > v;
233
234 for (current = n1; current != n2; current = mark[current])
235 v.push_back(current);
236
237 v.push_back(n2);
238
239 return v;
240 }
241
242 nodeFIFO.pushBack(new_one);
243 }
244 }
245
246 GUM_ERROR(NotFound, "no path found")
247 }
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.

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

Referenced by gum::learning::SimpleMiic::orientationLatents_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ directedUnorientedPath()

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

returns an unoriented (directed) path from node1 to node2 in the arc set

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

Definition at line 249 of file arcGraphPart.cpp.

249 {
250 // not recursive version => use a FIFO for simulating the recursion
251 List< NodeId > nodeFIFO;
252 nodeFIFO.pushBack(n2);
253
254 // mark[node] = successor if visited, else mark[node] does not exist
256 mark.insert(n2, n2);
257
258 NodeId current;
259
260 while (!nodeFIFO.empty()) {
261 current = nodeFIFO.front();
262 nodeFIFO.popFront();
263
264 // check the parents
265 for (const auto new_one: parents(current)) {
266 if (mark.exists(new_one)) // the node has already been visited
267 continue;
268
269 mark.insert(new_one, current);
270
271 if (new_one == n1) {
272 std::vector< NodeId > v;
273
274 for (current = n1; current != n2; current = mark[current])
275 v.push_back(current);
276
277 v.push_back(n2);
278
279 return v;
280 }
281
282 nodeFIFO.pushBack(new_one);
283 }
284
285 // check the children
286 for (const auto new_one: children(current)) {
287 if (mark.exists(new_one)) // the node has already been visited
288 continue;
289
290 mark.insert(new_one, current);
291
292 if (new_one == n1) {
293 std::vector< NodeId > v;
294
295 for (current = n1; current != n2; current = mark[current])
296 v.push_back(current);
297
298 v.push_back(n2);
299
300 return v;
301 }
302
303 nodeFIFO.pushBack(new_one);
304 }
305 }
306
307 GUM_ERROR(NotFound, "no path found")
308 }

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

Here is the call graph for this function:

◆ edges()

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

◆ edgesProperty() [1/2]

template<typename VAL>
EdgeProperty< VAL > gum::EdgeGraphPart::edgesProperty ( const VAL & val,
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.

◆ edgesProperty() [2/2]

template<typename VAL>
EdgeProperty< VAL > gum::EdgeGraphPart::edgesProperty ( VAL(* )(const Edge &),
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.

◆ empty()

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

alias for emptyNodes

Definition at line 308 of file nodeGraphPart_inl.h.

308{ return emptyNodes(); }
bool emptyNodes() const
indicates whether there exists nodes in the NodeGraphPart

References emptyNodes().

Referenced by asNodeSet(), gum::PDAG::cSeparation(), gum::DAG::dSeparation(), gum::prm::gspan::Pattern::remove(), and gum::PDAG::toDot().

Here is the call graph for this function:
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 55 of file arcGraphPart_inl.h.

55{ return _arcs_.empty(); }

References _arcs_.

◆ emptyEdges()

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

indicates wether the EdgeGraphPart contains any edge

Definition at line 55 of file edgeGraphPart_inl.h.

55{ return _edges_.empty(); }

References _edges_.

◆ emptyNodes()

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

indicates whether there exists nodes in the NodeGraphPart

Definition at line 306 of file nodeGraphPart_inl.h.

306{ return (sizeNodes() == 0); }

References sizeNodes().

Referenced by empty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ end()

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

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

Definition at line 339 of file nodeGraphPart_inl.h.

339 {
340 return _endIteratorSafe_;
341 }
NodeGraphPartIteratorSafe _endIteratorSafe_
the end iterator (used to speed-up parsings of the NodeGraphPart)

References _endIteratorSafe_, and NodeGraphPartIterator.

Referenced by gum::Estimator< GUM_SCALAR >::Estimator(), populateNodesFromProperty(), and gum::Estimator< GUM_SCALAR >::setFromBN().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ endSafe()

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

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

Definition at line 329 of file nodeGraphPart_inl.h.

329 {
330 return _endIteratorSafe_;
331 }

References _endIteratorSafe_, and NodeGraphPartIteratorSafe.

Here is the call graph for this function:

◆ eraseArc()

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

removes an arc from the ArcGraphPart

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

Definition at line 126 of file arcGraphPart_inl.h.

126 {
127 // ASSUMING tail and head exists in _parents_ anf _children_
128 // (if not, it is an error)
129 if (existsArc(arc)) {
130 NodeId tail = arc.tail();
131 NodeId head = arc.head();
132 _parents_[head]->erase(tail);
133 _children_[tail]->erase(head);
134 _arcs_.erase(arc);
135 GUM_EMIT2(onArcDeleted, tail, head);
136 }
137 }
bool existsArc(const Arc &arc) const
indicates whether a given arc exists

References _arcs_, _children_, _parents_, existsArc(), GUM_EMIT2, gum::Arc::head(), onArcDeleted, and gum::Arc::tail().

Referenced by gum::EssentialGraph::_buildEssentialGraph_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClassDag_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClassDag_(), gum::MeekRules::_orientDoubleHeadedArcs_(), gum::BarrenNodesFinder::barrenNodes(), eraseChildren(), eraseParents(), eraseSetOfArcs_(), gum::learning::IBNLearner::learnDag_(), gum::learning::GreedyHillClimbing::learnStructure(), gum::learning::LocalSearchWithTabuList::learnStructure(), gum::learning::SimpleMiic::learnStructure(), gum::learning::SimpleMiic::orientationLatents_(), gum::learning::Miic::orientationMiic_(), gum::learning::SimpleMiic::orientationMiic_(), gum::learning::Miic::orientDoubleHeadedArcs_(), gum::prm::gspan::Pattern::pop_back(), unvirtualizedEraseChildren(), unvirtualizedEraseParents(), and unvirtualizedEraseSetOfArcs_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eraseChildren()

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

removes all the children of a given node

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

Definition at line 158 of file arcGraphPart_inl.h.

158 {
159 if (_children_.exists(id)) {
160 const NodeSet& children = *(_children_[id]);
161
162 for (auto iter = children.beginSafe(); // safe iterator needed here
163 iter != children.endSafe();
164 ++iter) {
165 // warning: use this erase so that you actually use the virtualized
166 // arc removal function
167 eraseArc(Arc(id, *iter));
168 }
169 }
170 }

References _children_, children(), and eraseArc().

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

82 {
83 if (existsEdge(edge)) {
84 // ASSUMING first and second exists in _neighbours_ (if not, it is an
85 // error)
86 NodeId id1 = edge.first();
87 NodeId id2 = edge.second();
88
89 _neighbours_[id1]->erase(id2);
90 _neighbours_[id2]->erase(id1);
91 _edges_.erase(edge);
92 GUM_EMIT2(onEdgeDeleted, id1, id2);
93 }
94 }
bool existsEdge(const Edge &edge) const
indicates whether a given edge exists

References _edges_, _neighbours_, existsEdge(), gum::Edge::first(), GUM_EMIT2, onEdgeDeleted, and gum::Edge::second().

Referenced by gum::MeekRules::_applyMeekRules_(), gum::learning::Miic::_orientingVstructureMiic_(), gum::learning::SimpleMiic::_orientingVstructureMiic_(), gum::MeekRules::_propagatesOrientationInChainOfRemainingEdges_(), gum::learning::Miic::_propagatingOrientationMiic_(), gum::learning::SimpleMiic::_propagatingOrientationMiic_(), gum::prm::GSpan< GUM_SCALAR >::discoverPatterns(), eraseNeighbours(), gum::learning::Miic::initiation_(), gum::learning::SimpleMiic::initiation_(), gum::learning::Miic::iteration_(), gum::learning::SimpleMiic::iteration_(), gum::learning::SimpleMiic::learnPDAG(), gum::learning::SimpleMiic::learnStructure(), gum::learning::SimpleMiic::orientationLatents_(), gum::learning::Miic::orientationMiic_(), gum::learning::SimpleMiic::orientationMiic_(), gum::learning::SimpleMiic::propagatesOrientationInChainOfRemainingEdges_(), gum::learning::SimpleMiic::propagatesRemainingOrientableEdges_(), and unvirtualizedEraseNeighbours().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eraseNeighbours()

INLINE void gum::EdgeGraphPart::eraseNeighbours ( 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 101 of file edgeGraphPart_inl.h.

101 {
102 if (_neighbours_.exists(id)) {
103 const NodeSet& set = *(_neighbours_[id]);
104
105 for (auto iter = set.beginSafe(); iter != set.endSafe();
106 ++iter) { // safe iterator needed here
107 // warning: use this erases so that you actually use the virtualized
108 // edge removal function
109 eraseEdge(Edge(*iter, id));
110 }
111 }
112 }

References _neighbours_, gum::Set< Key >::beginSafe(), gum::Set< Key >::endSafe(), and eraseEdge().

Here is the call graph for this function:

◆ eraseNode()

INLINE void gum::MixedGraph::eraseNode ( const NodeId node)
overridevirtual

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::NodeGraphPart.

Definition at line 74 of file mixedGraph_inl.h.

74 {
79 }
void unvirtualizedEraseChildren(NodeId id)
same function as eraseChildren but without any virtual call to an erase
void unvirtualizedEraseParents(NodeId id)
same function as eraseParents but without any virtual call to an erase
void unvirtualizedEraseNeighbours(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

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

Here is the call graph for this function:

◆ eraseParents()

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

erase all the parents of a given node

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

Definition at line 144 of file arcGraphPart_inl.h.

144 {
145 if (_parents_.exists(id)) {
146 const NodeSet& parents = *(_parents_[id]);
147
148 for (auto iter = parents.beginSafe(); // safe iterator needed here
149 iter != parents.endSafe();
150 ++iter) {
151 // warning: use this erase so that you actually use the virtualized
152 // arc removal function
153 eraseArc(Arc(*iter, id));
154 }
155 }
156 }

References _parents_, eraseArc(), and parents().

Here is the call graph for this function:

◆ eraseSetOfArcs_()

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

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

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

Definition at line 139 of file arcGraphPart_inl.h.

139 {
140 for (const auto& arc: set)
141 eraseArc(arc);
142 }

References eraseArc().

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

296{ return existsNode(node); }
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId

References existsNode().

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::_removeNode_(), gum::DiGraph::addArc(), gum::prm::gspan::Pattern::addArc(), gum::UndiGraph::addEdge(), gum::prm::gspan::Pattern::exists(), gum::DiGraph::hasDirectedPath(), gum::learning::IBNLearner::learnDag_(), and gum::DAG::moralizedAncestralGraph().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ existsArc() [1/2]

◆ existsArc() [2/2]

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

indicates whether a given arc exists

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

Definition at line 63 of file arcGraphPart_inl.h.

63 {
64 return _parents_.exists(head) && _parents_[head]->exists(tail);
65 }

References _parents_.

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

61{ return _edges_.contains(edge); }

References _edges_.

Referenced by gum::prm::GSpan< GUM_SCALAR >::_sortPatterns_(), gum::EssentialGraph::_strongly_protected_(), gum::StaticTriangulation::_triangulate_(), eraseEdge(), gum::learning::Miic::orientationMiic_(), gum::learning::SimpleMiic::orientationMiic_(), gum::learning::Miic::unshieldedTriples_(), gum::learning::SimpleMiic::unshieldedTriples_(), gum::learning::Miic::unshieldedTriplesMiic_(), and gum::learning::SimpleMiic::unshieldedTriplesMiic_().

Here is the caller graph for this function:

◆ existsEdge() [2/2]

INLINE bool gum::EdgeGraphPart::existsEdge ( NodeId n1,
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 63 of file edgeGraphPart_inl.h.

63 {
64 return _neighbours_.exists(first) && _neighbours_[first]->exists(second);
65 }

References _neighbours_.

◆ existsNode()

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

returns true iff the NodeGraphPart contains the given nodeId

Definition at line 290 of file nodeGraphPart_inl.h.

290 {
291 if (node >= _boundVal_) return false;
292
293 return (!_inHoles_(node));
294 }

References _boundVal_, and _inHoles_().

Referenced by eraseNode(), exists(), gum::PDAG::moralizedAncestralGraph(), gum::UndiGraph::partialUndiGraph(), and gum::rec_ancestral().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ family() [1/2]

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

returns the set of family nodes of a set of nodes

Definition at line 102 of file arcGraphPart_inl.h.

102 {
103 NodeSet res;
104 for (const auto node: ids)
105 res += family(node);
106 return res;
107 }
NodeSet family(NodeId id) const
returns the set of nodes which consists in the node and its parents

References family().

Here is the call graph for this function:

◆ family() [2/2]

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

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

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

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

Definition at line 80 of file arcGraphPart_inl.h.

80 {
81 NodeSet res{id};
82 return res + parents(id);
83 }

References parents().

Referenced by family().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasDirectedPath()

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

checks whether there exists a directed path from from to to

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

Parameters
from
to
Returns
true if a directed path exists

Definition at line 151 of file diGraph.cpp.

151 {
152 if (!exists(from)) return false;
153
154 // not recursive version => use a FIFO for simulating the recursion
155 List< NodeId > nodeFIFO;
156 nodeFIFO.pushBack(from);
157
158 NodeSet marked;
159 marked.insert(from);
160
161 NodeId new_one;
162
163 while (!nodeFIFO.empty()) {
164 new_one = nodeFIFO.front();
165 nodeFIFO.popFront();
166
167 for (const auto chi: children(new_one)) {
168 if (chi == to) return true;
169
170 if (!marked.contains(chi)) {
171 nodeFIFO.pushBack(chi);
172 marked.insert(chi);
173 }
174 }
175 }
176
177 return false;
178 }

References gum::ArcGraphPart::children(), gum::Set< Key >::contains(), gum::List< Val >::empty(), gum::NodeGraphPart::exists(), gum::List< Val >::front(), gum::Set< Key >::insert(), gum::List< Val >::popFront(), and gum::List< Val >::pushBack().

Referenced by gum::DAG::addArc(), and gum::PDAG::addArc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasMixedOrientedPath()

bool gum::MixedGraph::hasMixedOrientedPath ( NodeId node1,
NodeId node2 ) const

returns true if a mixed edge/directed arc path from node1 to node2 in the arc/edge set exists.

Parameters
node1the id from which the path begins
node2the id to which the path ends

Definition at line 149 of file mixedGraph.cpp.

149 {
150 // not recursive version => use a FIFO for simulating the recursion
151 List< NodeId > node_fifo;
152 node_fifo.pushBack(n2);
153
154 // mark[node] = successor if visited, else mark[node] does not exist
156 mark.insert(n2, n2);
157
158 NodeId current;
159 while (!node_fifo.empty()) {
160 current = node_fifo.front();
161 node_fifo.popFront();
162
163 // check the neighbours
164 for (const auto new_one: neighbours(current)) {
165 if (mark.exists(new_one)) // if the node has already been visited
166 continue; // do not check it again
167
168 mark.insert(new_one, current);
169
170 if (new_one == n1) { return true; }
171
172 node_fifo.pushBack(new_one);
173 }
174
175 // check the parents
176 for (const auto new_one: parents(current)) {
177 if (mark.exists(new_one)) // if this node is already marked, do not
178 continue; // check it again
179
180 mark.insert(new_one, current);
181
182 if (new_one == n1) { return true; }
183
184 node_fifo.pushBack(new_one);
185 }
186 }
187
188 return false;
189 }

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

Here is the call graph for this function:

◆ hasUndirectedCycle()

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

checks whether the graph contains cycles

Definition at line 90 of file undiGraph.cpp.

90 {
91 List< std::pair< NodeId, NodeId > > open_nodes;
92 NodeProperty< bool > examined_nodes = nodesPropertyFromVal(false);
93 std::pair< NodeId, NodeId > thePair;
94 NodeId current, from_current;
95
96 for (const auto node: nodes()) {
97 // check if the node has already been examined (if this is not the case,
98 // this means that we are on a new connected component)
99 if (!examined_nodes[node]) {
100 // indicates that we are examining a new node
101 examined_nodes[node] = true;
102
103 // check recursively all the nodes of node's connected component
104 thePair.first = node;
105 thePair.second = node;
106 open_nodes.insert(thePair);
107
108 while (!open_nodes.empty()) {
109 // get a node to propagate
110 thePair = open_nodes.front();
111 open_nodes.popFront();
112
113 current = thePair.first;
114 from_current = thePair.second;
115
116 // check the neighbours
117 for (const auto new_node: neighbours(current))
118
119 // avoid to check the node we are coming from
120 if (new_node != from_current) {
121 if (examined_nodes[new_node]) return true;
122 else {
123 examined_nodes[new_node] = true;
124 thePair.first = new_node;
125 thePair.second = current;
126 open_nodes.insert(thePair);
127 }
128 }
129 }
130 }
131 }
132
133 return false;
134 }
NodeProperty< VAL > nodesPropertyFromVal(const VAL &a, Size size=0) const
a method to create a hashMap with key:NodeId and value:VAL

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

Here is the call graph for this function:

◆ hasUndirectedPath() [1/3]

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

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

Parameters
n1NodeSet
n2NodeSet
exceptNodeSet
Returns
bool

Definition at line 222 of file edgeGraphPart.cpp.

224 {
225 NodeSet visited;
226 NodeSet temp;
227
228 for (auto n: n1)
229 temp.insert(n);
230
231 while (!temp.empty()) {
232 NodeId current = *(temp.begin());
233 if (n2.contains(current)) return true;
234 temp.erase(current);
235 visited.insert(current);
236 for (auto next: neighbours(current)) {
237 if (!temp.contains(next) && !visited.contains(next) && !except.contains(next))
238 temp.insert(next);
239 }
240 }
241 return false;
242 }

References gum::Set< Key >::begin(), gum::Set< Key >::contains(), gum::Set< Key >::empty(), gum::Set< Key >::erase(), gum::Set< Key >::insert(), and neighbours().

Here is the call graph for this function:

◆ hasUndirectedPath() [2/3]

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

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

Parameters
n1NodeId
n2NodeId
Returns
bool

Definition at line 185 of file edgeGraphPart.cpp.

185 {
186 NodeSet visited;
187 NodeSet temp;
188
189 temp.insert(n1);
190 while (!temp.empty()) {
191 NodeId current = *(temp.begin());
192 if (current == n2) return true;
193 temp.erase(current);
194 visited.insert(current);
195 for (auto next: neighbours(current)) {
196 if (!temp.contains(next) && !visited.contains(next)) temp.insert(next);
197 }
198 }
199 return false;
200 }

References gum::Set< Key >::begin(), gum::Set< Key >::contains(), gum::Set< Key >::empty(), gum::Set< Key >::erase(), gum::Set< Key >::insert(), and neighbours().

Referenced by gum::UGmodel::isIndependent(), and gum::UGmodel::isIndependent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasUndirectedPath() [3/3]

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

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

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

Definition at line 202 of file edgeGraphPart.cpp.

202 {
203 NodeSet visited;
204 NodeSet temp;
205
206 if (except.contains(n2)) return false;
207
208 temp.insert(n1);
209 while (!temp.empty()) {
210 NodeId current = *(temp.begin());
211 if (current == n2) return true;
212 temp.erase(current);
213 visited.insert(current);
214 for (auto next: neighbours(current)) {
215 if (!temp.contains(next) && !visited.contains(next) && !except.contains(next))
216 temp.insert(next);
217 }
218 }
219 return false;
220 }

References gum::Set< Key >::begin(), gum::Set< Key >::contains(), gum::Set< Key >::empty(), gum::Set< Key >::erase(), gum::Set< Key >::insert(), and neighbours().

Here is the call graph for this function:

◆ listMapArcs()

template<typename VAL>
List< VAL > gum::ArcGraphPart::listMapArcs ( VAL(* )(const Arc &)) 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 &)) 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 &)) 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

References listMapNodes().

Referenced by listMapNodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mixedOrientedPath()

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

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

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

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

Definition at line 96 of file mixedGraph.cpp.

96 {
97 std::vector< NodeId > v;
98 // not recursive version => use a FIFO for simulating the recursion
99 List< NodeId > node_fifo;
100 node_fifo.pushBack(n2);
101
102 // mark[node] = successor if visited, else mark[node] does not exist
104 mark.insert(n2, n2);
105
106 NodeId current;
107 while (!node_fifo.empty()) {
108 current = node_fifo.front();
109 node_fifo.popFront();
110
111 // check the neighbours
112 for (const auto new_one: neighbours(current)) {
113 if (mark.exists(new_one)) // if the node has already been visited
114 continue; // do not check it again
115
116 mark.insert(new_one, current);
117
118 if (new_one == n1) {
119 for (current = n1; current != n2; current = mark[current])
120 v.push_back(current);
121 v.push_back(n2);
122 return v;
123 }
124
125 node_fifo.pushBack(new_one);
126 }
127
128 // check the parents
129 for (const auto new_one: parents(current)) {
130 if (mark.exists(new_one)) // if this node is already marked, do not
131 continue; // check it again
132
133 mark.insert(new_one, current);
134
135 if (new_one == n1) {
136 for (current = n1; current != n2; current = mark[current])
137 v.push_back(current);
138 v.push_back(n2);
139 return v;
140 }
141
142 node_fifo.pushBack(new_one);
143 }
144 }
145
146 return v;
147 }

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

Referenced by gum::MeekRules::_isOrientable_(), and gum::learning::SimpleMiic::isOrientable_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mixedUnorientedPath()

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

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

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

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

Definition at line 191 of file mixedGraph.cpp.

191 {
192 std::vector< NodeId > v;
193 // not recursive version => use a FIFO for simulating the recursion
194 List< NodeId > node_fifo;
195 node_fifo.pushBack(n2);
196
197 // mark[node] = successor if visited, else mark[node] does not exist
199 mark.insert(n2, n2);
200
201 NodeId current;
202
203 while (!node_fifo.empty()) {
204 current = node_fifo.front();
205 node_fifo.popFront();
206
207 // check the neighbours
208 for (const auto new_one: neighbours(current)) {
209 if (mark.exists(new_one)) // if the node has already been visited
210 continue; // do not check it again
211
212 mark.insert(new_one, current);
213
214 if (new_one == n1) {
215 for (current = n1; current != n2; current = mark[current])
216 v.push_back(current);
217 v.push_back(n2);
218 return v;
219 }
220
221 node_fifo.pushBack(new_one);
222 }
223
224 // check the parents
225 for (const auto new_one: parents(current)) {
226 if (mark.exists(new_one)) // the node has already been visited
227 continue;
228
229 mark.insert(new_one, current);
230 if (new_one == n1) {
231 for (current = n1; current != n2; current = mark[current])
232 v.push_back(current);
233 v.push_back(n2);
234 return v;
235 }
236 node_fifo.pushBack(new_one);
237 }
238
239 // check the children
240 for (const auto new_one: children(current)) {
241 if (mark.exists(new_one)) // the node has already been visited
242 continue;
243
244 mark.insert(new_one, current);
245
246 if (new_one == n1) {
247 for (current = n1; current != n2; current = mark[current])
248 v.push_back(current);
249 v.push_back(n2);
250 return v;
251 }
252
253 node_fifo.pushBack(new_one);
254 }
255 }
256
257 return v;
258 }

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

Here is the call graph for this function:

◆ neighbours()

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

returns the set of node neighbours to a given node

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

Parameters
idthe node to which the edges are adjacent

Definition at line 96 of file edgeGraphPart_inl.h.

96 {
97 if (_neighbours_.exists(id)) return *(_neighbours_[id]);
98 else return emptyNodeSet;
99 }

References _neighbours_, and gum::emptyNodeSet.

Referenced by gum::MeekRules::_applyMeekRules_(), gum::BinaryJoinTreeConverterDefault::_convertClique_(), gum::BinaryJoinTreeConverterDefault::_convertConnectedComponent_(), gum::MeekRules::_critereMinParents_(), gum::BinaryJoinTreeConverterDefault::_markConnectedComponent_(), gum::MeekRules::_propagatesOrientationInChainOfRemainingEdges_(), gum::prm::StructuredInference< GUM_SCALAR >::_removeBarrenNodes_(), gum::prm::GSpan< GUM_SCALAR >::_sortPatterns_(), gum::prm::GSpan< GUM_SCALAR >::_subgraph_mining_(), gum::StaticTriangulation::_triangulate_(), gum::MixedGraph::boundary(), gum::MixedGraph::chainComponent(), gum::MixedGraph::hasMixedOrientedPath(), gum::PDAG::hasMixedReallyOrientedPath(), gum::UndiGraph::hasUndirectedCycle(), hasUndirectedPath(), hasUndirectedPath(), hasUndirectedPath(), gum::learning::SimpleMiic::learnPDAG(), gum::learning::SimpleMiic::learnStructure(), gum::MixedGraph::mixedOrientedPath(), gum::MixedGraph::mixedUnorientedPath(), gum::PDAG::moralGraph(), gum::UndiGraph::nodes2ConnectedComponent(), gum::UndiGraph::partialUndiGraph(), gum::learning::SimpleMiic::propagatesOrientationInChainOfRemainingEdges_(), gum::learning::SimpleMiic::propagatesRemainingOrientableEdges_(), gum::rec_ancestral(), gum::rec_hasMixedReallyOrientedPath(), gum::MixedGraph::toDot(), gum::PDAG::toDot(), gum::UndiGraph::toDot(), undirectedPath(), gum::learning::Miic::unshieldedTriples_(), gum::learning::SimpleMiic::unshieldedTriples_(), gum::learning::Miic::unshieldedTriplesMiic_(), and gum::learning::SimpleMiic::unshieldedTriplesMiic_().

◆ 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);
NodeId nextNodeId() const
returns a new node id, not yet used by any node
is basically not thread safe !!
Returns
a node id not yet used by any node within the NodeGraphPart

Definition at line 232 of file nodeGraphPart_inl.h.

232 {
233 NodeId next = 0;
234
235 // return the first hole if holes exist
236 if (_holes_ && (!_holes_->empty())) next = *(_holes_->begin());
237 else // in other case
238 next = _boundVal_;
239
240 return next;
241 }

References _boundVal_, and _holes_.

◆ nodes()

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

return *this as a NodeGraphPart

Definition at line 368 of file nodeGraphPart_inl.h.

368 {
369 return *(static_cast< const NodeGraphPart* >(this));
370 }

References NodeGraphPart().

Referenced by gum::MeekRules::_complete_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClassDag_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClassDag_(), gum::prm::ClassBayesNet< GUM_SCALAR >::_init_(), gum::prm::SVE< GUM_SCALAR >::_initElimOrder_(), gum::prm::SVED< GUM_SCALAR >::_initElimOrder_(), gum::prm::SVE< GUM_SCALAR >::_initLiftedNodes_(), gum::MeekRules::_orientDoubleHeadedArcs_(), gum::MeekRules::_propagates_(), gum::prm::GSpan< GUM_SCALAR >::_sortPatterns_(), gum::prm::PRMFactory< GUM_SCALAR >::addAttribute(), gum::UndiGraph::hasUndirectedCycle(), gum::DAG::moralGraph(), gum::PDAG::moralGraph(), gum::DAG::moralizedAncestralGraph(), gum::PDAG::moralizedAncestralGraph(), gum::prm::gspan::Pattern::nodes(), gum::UndiGraph::nodes2ConnectedComponent(), gum::learning::Miic::orientDoubleHeadedArcs_(), gum::UndiGraph::partialUndiGraph(), gum::learning::IBNLearner::prepareMiic_(), gum::MeekRules::propagateToDAG(), gum::DiGraph::toDot(), gum::MixedGraph::toDot(), gum::PDAG::toDot(), and gum::UndiGraph::toDot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nodes2ConnectedComponent()

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

returns a property {node:id of connected component}

Definition at line 184 of file undiGraph.cpp.

184 {
186
187 NodeId numCC = 0;
188 for (const auto node: nodes()) {
189 if (res.exists(node)) continue;
190 NodeSet nodes{node};
191 while (!nodes.empty()) {
192 auto actual = *(nodes.begin());
193 nodes.erase(actual);
194 res.insert(actual, numCC);
195 for (const auto nei: neighbours(actual)) {
196 if (!res.exists(nei))
197 if (!nodes.exists(nei)) nodes.insert(nei);
198 }
199 }
200 numCC += 1;
201 }
202
203 return res;
204 }

References gum::HashTable< Key, Val >::exists(), gum::HashTable< Key, Val >::insert(), gum::EdgeGraphPart::neighbours(), and gum::NodeGraphPart::nodes().

Here is the call graph for this function:

◆ nodesPropertyFromFunction()

template<typename VAL>
NodeProperty< VAL > gum::NodeGraphPart::nodesPropertyFromFunction ( VAL(* )(const NodeId &),
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.

References nodesPropertyFromFunction(), and size().

Referenced by nodesPropertyFromFunction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nodesPropertyFromVal()

template<typename VAL>
NodeProperty< VAL > gum::NodeGraphPart::nodesPropertyFromVal ( 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.

References nodesPropertyFromVal(), and size().

Referenced by gum::BinaryJoinTreeConverterDefault::convert(), gum::UndiGraph::hasUndirectedCycle(), and nodesPropertyFromVal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator!=() [1/2]

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.

354{ return !operator==(p); }
bool operator==(const NodeGraphPart &p) const
check whether two NodeGraphParts contain the same nodes

References NodeGraphPart(), and operator==().

Here is the call graph for this function:

◆ operator!=() [2/2]

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

90{ return !operator==(p); }
bool operator==(const UndiGraph &g) const
tests whether two UndiGraphs are identical (same nodes, same edges)

References UndiGraph(), and operator==().

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 51 of file mixedGraph_inl.h.

51 {
52 // avoid self assignment
53 if (this != &g) {
54 // remove the old graph properly
58
59 // fill the new graph
63 }
64
65 return *this;
66 }
ArcGraphPart & operator=(const ArcGraphPart &s)
copy operator
EdgeGraphPart & operator=(const EdgeGraphPart &s)
copy operator
NodeGraphPart & operator=(const NodeGraphPart &p)
copy operator

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

Referenced by gum::PDAG::operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator==() [1/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 201 of file arcGraphPart_inl.h.

201{ return _arcs_ == p._arcs_; }

References ArcGraphPart(), and _arcs_.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator==() [2/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 89 of file diGraph_inl.h.

89 {
91 }
bool operator==(const ArcGraphPart &p) const
tests whether two ArcGraphParts contain the same arcs

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

Here is the call graph for this function:

◆ operator==() [3/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 125 of file edgeGraphPart_inl.h.

125 {
126 return _edges_ == p._edges_;
127 }

References EdgeGraphPart(), and _edges_.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator==() [4/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 81 of file mixedGraph_inl.h.

81 {
84 }
bool operator==(const EdgeGraphPart &p) const
tests whether two EdgeGraphParts contain the same edges

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

Here is the call graph for this function:

◆ operator==() [5/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 343 of file nodeGraphPart_inl.h.

343 {
344 if (_boundVal_ != p._boundVal_) return false;
345
346 if (_holes_)
347 if (p._holes_) return (*_holes_ == *p._holes_);
348 else return false;
349 else if (p._holes_) return false;
350
351 return true;
352 }

References NodeGraphPart(), _boundVal_, and _holes_.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator==() [6/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 86 of file undiGraph_inl.h.

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

Referenced by operator!=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parents() [1/2]

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

returns the set of parents of a set of nodes

Definition at line 94 of file arcGraphPart_inl.h.

94 {
95 NodeSet res;
96 for (const auto node: ids)
97 res += parents(node);
98 return res;
99 }

References parents().

Here is the call graph for this function:

◆ parents() [2/2]

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

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

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

Parameters
idthe node toward which the arcs returned are pointing

Definition at line 75 of file arcGraphPart_inl.h.

75 {
76 if (_parents_.exists(id)) return *(_parents_[id]);
77 else return emptyNodeSet;
78 }

References _parents_, and gum::emptyNodeSet.

Referenced by gum::MeekRules::_complete_(), gum::MeekRules::_critereMinParents_(), gum::learning::Miic::_existsDirectedPath_(), gum::learning::SimpleMiic::_existsDirectedPath_(), gum::MeekRules::_existsDirectedPath_(), gum::learning::Miic::_existsNonTrivialDirectedPath_(), gum::learning::SimpleMiic::_existsNonTrivialDirectedPath_(), gum::prm::gspan::Pattern::_expandCodeIsMinimal_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClass_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClassDag_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClassDag_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClasses_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateCluster_(), gum::prm::SVE< GUM_SCALAR >::_initElimOrder_(), gum::prm::SVED< GUM_SCALAR >::_initElimOrder_(), gum::prm::SVE< GUM_SCALAR >::_initLiftedNodes_(), gum::prm::SVED< GUM_SCALAR >::_initLiftedNodes_(), gum::MeekRules::_isOrientable_(), gum::DAG::_minimalCondSetVisitDn_(), gum::DAG::_minimalCondSetVisitUp_(), gum::prm::gspan::Pattern::_not_rec_(), gum::MeekRules::_orientDoubleHeadedArcs_(), gum::MeekRules::_propagates_(), gum::learning::Miic::_propagatingOrientationMiic_(), gum::learning::SimpleMiic::_propagatingOrientationMiic_(), gum::prm::gspan::Pattern::_rec_(), gum::EssentialGraph::_strongly_protected_(), ancestors(), gum::BarrenNodesFinder::barrenNodes(), gum::MixedGraph::boundary(), directedPath(), directedUnorientedPath(), eraseParents(), family(), gum::MixedGraph::hasMixedOrientedPath(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::initialize_(), gum::prm::PRMClassElementContainer< double >::isInputNode(), gum::learning::Miic::isMaxIndegree_(), gum::prm::gspan::Pattern::isMinimal(), gum::learning::SimpleMiic::isOrientable_(), gum::learning::SimpleMiic::learnPDAG(), gum::learning::SimpleMiic::learnStructure(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::makeInferenceNodeToNeighbours_(), gum::DAG::minimalCondSet(), gum::MixedGraph::mixedOrientedPath(), gum::MixedGraph::mixedUnorientedPath(), gum::DAG::moralGraph(), gum::PDAG::moralGraph(), gum::DAG::moralizedAncestralGraph(), gum::learning::Miic::orientDoubleHeadedArcs_(), gum::prm::gspan::DFSTree< GUM_SCALAR >::parent(), gum::prm::gspan::DFSTree< GUM_SCALAR >::parent(), parents(), gum::rec_ancestral(), gum::BayesBall::relevantTensors(), gum::dSeparationAlgorithm::relevantTensors(), gum::prm::gspan::Pattern::remove(), gum::BayesBall::requisiteNodes(), gum::dSeparationAlgorithm::requisiteNodes(), gum::prm::gspan::Pattern::rightmostPath(), gum::DAGCycleDetector::setDAG(), and unvirtualizedEraseParents().

◆ partialUndiGraph()

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

returns the partial graph formed by the nodes given in parameter

Definition at line 171 of file undiGraph.cpp.

171 {
172 UndiGraph partialGraph;
173
174 for (const auto node: nodes) {
175 partialGraph.addNodeWithId(node);
176
177 for (const auto nei: neighbours(node))
178 if (nodes.contains(nei) && partialGraph.existsNode(nei)) partialGraph.addEdge(node, nei);
179 }
180
181 return partialGraph;
182 }

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

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

83 {
84 clear(); // "virtual" flush of the nodes set
85 _holes_size_ = s._holes_size_;
86 _holes_resize_policy_ = s._holes_resize_policy_;
87
88 if (s._holes_) _holes_ = new NodeSet(*s._holes_);
89
90 _boundVal_ = s._boundVal_;
91
93 }
virtual void clear()
alias for clearNodes

References NodeGraphPart(), _boundVal_, _holes_, _holes_resize_policy_, _holes_size_, _updateEndIteratorSafe_(), and clear().

Referenced by gum::DAG::moralGraph(), gum::PDAG::moralGraph(), and operator=().

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.

References NodeGraphPart(), begin(), end(), and toString().

Here is the call graph for this function:

◆ size()

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

◆ sizeArcs()

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

indicates the number of arcs stored within the ArcGraphPart

Definition at line 57 of file arcGraphPart_inl.h.

57{ return _arcs_.size(); }

References _arcs_.

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

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

57{ return _edges_.size(); }

References _edges_.

◆ sizeNodes()

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

returns the number of nodes in the NodeGraphPart

Definition at line 284 of file nodeGraphPart_inl.h.

284 {
285 return (_holes_) ? (_boundVal_ - _holes_->size()) : _boundVal_;
286 }

References _boundVal_, and _holes_.

Referenced by gum::BinaryJoinTreeConverterDefault::_markConnectedComponent_(), asNodeSet(), gum::BinaryJoinTreeConverterDefault::convert(), emptyNodes(), and size().

Here is the caller graph for this function:

◆ toDot()

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

to friendly display mixed graph in DOT format

Reimplemented from gum::UndiGraph.

Reimplemented in gum::PDAG.

Definition at line 276 of file mixedGraph.cpp.

276 {
277 std::stringstream output;
278 std::stringstream nodeStream;
279 std::stringstream edgeStream;
280
281 NodeSet treatedNodes;
282
283 output << "digraph \""
284 << "no_name\" {" << std::endl;
285 nodeStream << "node [shape = ellipse];" << std::endl;
286 std::string tab = " ";
287
288 for (const auto node: nodes()) {
289 nodeStream << tab << node << ";";
290
291 for (const auto nei: neighbours(node))
292 if (!treatedNodes.exists(nei))
293 edgeStream << tab << node << " -> " << nei << " [dir=none];" << std::endl;
294
295 for (const auto chi: children(node))
296 edgeStream << tab << node << " -> " << chi << ";" << std::endl;
297
298 treatedNodes.insert(node);
299 }
300
301 output << nodeStream.str() << std::endl << edgeStream.str() << std::endl << "}" << std::endl;
302
303 return output.str();
304 }

References gum::ArcGraphPart::children(), gum::Set< Key >::exists(), gum::Set< Key >::insert(), gum::EdgeGraphPart::neighbours(), and gum::NodeGraphPart::nodes().

Here is the call graph for this function:

◆ topologicalOrder()

Sequence< NodeId > gum::DiGraph::topologicalOrder ( ) const
inherited

Build and return a topological order.

Exceptions
InvalidDirectedCycleRaised if this DiGraph contains cycles.

Definition at line 111 of file diGraph.cpp.

111 {
112 Sequence< NodeId > topologicalOrder;
113 const auto& dag = *this;
114
115 if (dag.empty()) return topologicalOrder;
116
117 auto border = std::vector< NodeId >();
118 border.reserve(dag.size() / 2);
119 auto count = dag.nodesPropertyFromVal< Size >(0, dag.size());
120 for (const auto node: dag.nodes()) {
121 if (dag.parents(node).empty()) { border.push_back(node); }
122 count[node] = dag.parents(node).size();
123 }
124
125 if (border.empty()) {
126 GUM_ERROR(InvalidDirectedCycle, "cycles prevent the creation of a topological ordering.");
127 }
128
129 while (!border.empty()) {
130 const auto root = border.back();
131 border.pop_back();
132
133 if (topologicalOrder.exists(root)) {
134 GUM_ERROR(InvalidDirectedCycle, "cycles prevent the creation of a topological ordering.");
135 }
136 topologicalOrder.insert(root);
137
138 for (const auto child: dag.children(root)) {
139 if (count[child] == 1) { border.push_back(child); }
140 if (count[child] == 0) {
141 GUM_ERROR(InvalidDirectedCycle, "cycles prevent the creation of a topological ordering.");
142 }
143 count[child]--;
144 }
145 }
146
147 GUM_ASSERT(topologicalOrder.size() == dag.size());
148 return topologicalOrder;
149 }
Sequence< NodeId > topologicalOrder() const
Build and return a topological order.
Definition diGraph.cpp:111
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74

References GUM_ERROR, and topologicalOrder().

Referenced by gum::IBayesNet< double >::arcs(), gum::learning::SimpleMiic::learnPDAG(), gum::learning::SimpleMiic::learnStructure(), and topologicalOrder().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString()

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

to friendly display the content of the MixedGraph

Reimplemented from gum::NodeGraphPart.

Definition at line 87 of file mixedGraph.cpp.

87 {
88 std::string s = NodeGraphPart::toString();
89 s += " , ";
91 s += " , ";
93 return s;
94 }
std::string toString() const
to friendly display the content of the ArcGraphPart
virtual std::string toString() const
to friendly display the content of the EdgeGraphPart
virtual std::string toString() const
a function to display the set of nodes

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

Referenced by gum::operator<<().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ undirectedPath()

std::vector< NodeId > gum::EdgeGraphPart::undirectedPath ( NodeId node1,
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 145 of file edgeGraphPart.cpp.

145 {
146 // not recursive version => use a FIFO for simulating the recursion
147 List< NodeId > nodeFIFO;
148 nodeFIFO.pushBack(n2);
149
150 // mark[node] = predecessor if visited, else mark[node] does not exist
152 mark.insert(n2, n2);
153
154 NodeId current;
155
156 while (!nodeFIFO.empty()) {
157 current = nodeFIFO.front();
158 nodeFIFO.popFront();
159
160 // check the neighbour
161 for (const auto new_one: neighbours(current)) {
162 if (mark.exists(new_one)) // if this node is already marked, stop
163 continue;
164
165 mark.insert(new_one, current);
166
167 if (new_one == n1) {
168 std::vector< NodeId > v;
169
170 for (current = n1; current != n2; current = mark[current])
171 v.push_back(current);
172
173 v.push_back(n2);
174
175 return v;
176 }
177
178 nodeFIFO.pushBack(new_one);
179 }
180 }
181
182 GUM_ERROR(NotFound, "no path found")
183 }

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

Here is the call graph for this function:

◆ unvirtualizedEraseChildren()

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

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

Parameters
idthe node whose outgoing arcs will be removed

Definition at line 189 of file arcGraphPart_inl.h.

189 {
190 if (_children_.exists(id)) {
191 const NodeSet& children = *(_children_[id]);
192
193 for (auto iter = children.beginSafe(); // safe iterator needed here
194 iter != children.endSafe();
195 ++iter) {
196 ArcGraphPart::eraseArc(Arc(id, *iter));
197 }
198 }
199 }

References _children_, children(), and eraseArc().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unvirtualizedEraseNeighbours()

INLINE void gum::EdgeGraphPart::unvirtualizedEraseNeighbours ( 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 114 of file edgeGraphPart_inl.h.

114 {
115 if (_neighbours_.exists(id)) {
116 const NodeSet& set = *(_neighbours_[id]);
117
118 for (auto iter = set.beginSafe(); iter != set.endSafe();
119 ++iter) { // safe iterator needed here
120 EdgeGraphPart::eraseEdge(Edge(*iter, id));
121 }
122 }
123 }

References _neighbours_, gum::Set< Key >::beginSafe(), gum::Set< Key >::endSafe(), and eraseEdge().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unvirtualizedEraseParents()

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

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

Parameters
idthe node whose ingoing arcs will be removed

Definition at line 177 of file arcGraphPart_inl.h.

177 {
178 if (_parents_.exists(id)) {
179 const NodeSet& parents = *(_parents_[id]);
180
181 for (auto iter = parents.beginSafe(); // safe iterator needed here
182 iter != parents.endSafe();
183 ++iter) {
184 ArcGraphPart::eraseArc(Arc(*iter, id));
185 }
186 }
187 }

References _parents_, eraseArc(), and parents().

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

Here is the call graph for this function:
Here is the caller 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 172 of file arcGraphPart_inl.h.

172 {
173 for (const auto& arc: set)
175 }

References eraseArc().

Here is the call graph for this function:

Member Data Documentation

◆ _arcs_

Set< Arc > gum::ArcGraphPart::_arcs_
privateinherited

the set of all the arcs contained within the ArcGraphPart

Definition at line 316 of file arcGraphPart.h.

Referenced by ArcGraphPart(), ArcGraphPart(), addArc(), arcs(), clearArcs(), emptyArcs(), eraseArc(), existsArc(), operator=(), operator==(), sizeArcs(), and toString().

◆ _children_

NodeProperty< NodeSet* > gum::ArcGraphPart::_children_
privateinherited

for each arc, the set of its children

Definition at line 322 of file arcGraphPart.h.

Referenced by ArcGraphPart(), _checkChildren_(), addArc(), children(), clearArcs(), eraseArc(), eraseChildren(), operator=(), and unvirtualizedEraseChildren().

◆ _edges_

EdgeSet gum::EdgeGraphPart::_edges_
privateinherited

the set of all the edges contained within the EdgeGraphPart

Definition at line 266 of file edgeGraphPart.h.

Referenced by EdgeGraphPart(), EdgeGraphPart(), _clearEdges_(), addEdge(), edges(), emptyEdges(), eraseEdge(), existsEdge(), operator=(), operator==(), sizeEdges(), and toString().

◆ _neighbours_

NodeProperty< NodeSet* > gum::EdgeGraphPart::_neighbours_
privateinherited

for each node, the set of its adjacent edges

Definition at line 269 of file edgeGraphPart.h.

Referenced by EdgeGraphPart(), _checkNeighbours_(), _clearEdges_(), addEdge(), eraseEdge(), eraseNeighbours(), existsEdge(), neighbours(), operator=(), and unvirtualizedEraseNeighbours().

◆ _parents_

NodeProperty< NodeSet* > gum::ArcGraphPart::_parents_
privateinherited

for each arc, the sets of its parents

Definition at line 319 of file arcGraphPart.h.

Referenced by ArcGraphPart(), _checkParents_(), addArc(), clearArcs(), eraseArc(), eraseParents(), existsArc(), operator=(), parents(), and unvirtualizedEraseParents().

◆ onArcAdded

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

Definition at line 102 of file arcGraphPart.h.

Referenced by ArcGraphPart(), addArc(), and operator=().

◆ onArcDeleted

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

Definition at line 103 of file arcGraphPart.h.

Referenced by clearArcs(), and eraseArc().

◆ onEdgeAdded

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

Definition at line 98 of file edgeGraphPart.h.

Referenced by EdgeGraphPart(), addEdge(), and operator=().

◆ onEdgeDeleted

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

Definition at line 99 of file edgeGraphPart.h.

Referenced by _clearEdges_(), and eraseEdge().

◆ onNodeAdded

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

Definition at line 289 of file nodeGraphPart.h.

Referenced by addNode(), and addNodeWithId().

◆ onNodeDeleted

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

Definition at line 290 of file nodeGraphPart.h.

Referenced by _clearNodes_(), and eraseNode().


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