aGrUM  0.16.0
gum::UndiGraph Class Reference

Base class for undirected graphs. More...

#include <undiGraph.h>

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

Public Attributes

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

Public Member Functions

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

Public Types

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

Detailed Description

Base class for undirected graphs.

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

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

Definition at line 109 of file undiGraph.h.

Member Typedef Documentation

◆ EdgeIterator

Definition at line 77 of file edgeGraphPart.h.

◆ node_const_iterator

types for STL compliance

Definition at line 261 of file nodeGraphPart.h.

◆ node_const_iterator_safe

types for STL compliance

Definition at line 263 of file nodeGraphPart.h.

◆ node_iterator

types for STL compliance

Definition at line 260 of file nodeGraphPart.h.

◆ node_iterator_safe

types for STL compliance

Definition at line 262 of file nodeGraphPart.h.

◆ NodeConstIterator

Definition at line 270 of file nodeGraphPart.h.

◆ NodeConstIteratorSafe

◆ NodeIterator

Definition at line 269 of file nodeGraphPart.h.

◆ NodeIteratorSafe

Constructor & Destructor Documentation

◆ UndiGraph() [1/2]

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

default constructor

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

Definition at line 40 of file undiGraph.cpp.

43  :
44  NodeGraphPart(nodes_size, nodes_resize_policy),
45  EdgeGraphPart(edges_size, edges_resize_policy) {
46  GUM_CONSTRUCTOR(UndiGraph);
47  }
EdgeGraphPart(Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
NodeGraphPart(Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true)
default constructor
UndiGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
Definition: undiGraph.cpp:40

◆ UndiGraph() [2/2]

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

copy constructor

Parameters
gthe UndiGraph to copy

Definition at line 49 of file undiGraph.cpp.

49  : NodeGraphPart(g), EdgeGraphPart(g) {
50  GUM_CONS_CPY(UndiGraph);
51  }
EdgeGraphPart(Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
NodeGraphPart(Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true)
default constructor
UndiGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
Definition: undiGraph.cpp:40

◆ ~UndiGraph()

gum::UndiGraph::~UndiGraph ( )
virtual

destructor

Definition at line 53 of file undiGraph.cpp.

53 { GUM_DESTRUCTOR(UndiGraph); }
UndiGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
Definition: undiGraph.cpp:40

Member Function Documentation

◆ addEdge()

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

insert a new edge into the undirected graph

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

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

Reimplemented from gum::EdgeGraphPart.

Reimplemented in gum::CliqueGraph.

Definition at line 35 of file undiGraph_inl.h.

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

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

35  {
36  if (!exists(first)) { GUM_ERROR(InvalidNode, "first node"); }
37 
38  if (!exists(second)) { GUM_ERROR(InvalidNode, "second node"); }
39 
40  EdgeGraphPart::addEdge(second, first);
41  }
virtual void addEdge(const NodeId n1, const NodeId n2)
insert a new edge into the EdgeGraphPart
bool exists(const NodeId id) const
alias for existsNode
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ 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 253 of file nodeGraphPart_inl.h.

References GUM_EMIT1.

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

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

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

◆ addNodeWithId()

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

try to insert a node with the given id

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

Definition at line 132 of file nodeGraphPart.cpp.

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

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

132  {
133  if (id >= __boundVal) {
134  if (id > __boundVal) { // we have to add holes
136 
137  for (NodeId i = __boundVal; i < id; ++i)
138  __holes->insert(i);
139  }
140 
141  __boundVal = id + 1;
142 
144  } else {
145  if (__inHoles(id)) { // we fill a hole
146  __eraseHole(id);
147  } else {
148  GUM_ERROR(DuplicateElement, "Id " << id << " is already used");
149  }
150  }
151 
152  GUM_EMIT1(onNodeAdded, id);
153  }
NodeSet * __holes
the set of nodes not contained in the NodeGraphPart in the interval 1..__max
#define GUM_EMIT1(signal, arg1)
Definition: signaler1.h:42
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
bool __holes_resize_policy
value for __holes configuration
bool __inHoles(NodeId id) const
NodeId __boundVal
the id below which NodeIds may belong to the NodeGraphPart
Size __holes_size
value for __holes configuration
void __updateEndIteratorSafe()
updating endIterator (always at __max+1)
Signaler1< NodeId > onNodeAdded
void __eraseHole(NodeId id)
to delete hole.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ asNodeSet()

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

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

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

Definition at line 361 of file nodeGraphPart_inl.h.

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

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

361  {
362  NodeSet son(sizeNodes());
363 
364  if (!empty()) {
365  for (NodeId n = 0; n < __boundVal; ++n) {
366  if (!__inHoles(n)) son.insert(n);
367  }
368  }
369 
370  return son;
371  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
bool __inHoles(NodeId id) const
NodeId __boundVal
the id below which NodeIds may belong to the NodeGraphPart
bool empty() const
alias for emptyNodes
Size sizeNodes() const
returns the number of nodes in the NodeGraphPart
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ 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.

References gum::NodeGraphPartIterator::_validate().

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

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

◆ beginSafe()

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

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

Definition at line 319 of file nodeGraphPart_inl.h.

References gum::NodeGraphPartIterator::_validate().

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

◆ bound()

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

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

Definition at line 308 of file nodeGraphPart_inl.h.

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

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

◆ clear()

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

removes all the nodes and edges from the graph

Reimplemented from gum::NodeGraphPart.

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

Definition at line 43 of file undiGraph_inl.h.

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

Referenced by gum::StaticTriangulation::clear(), gum::DAGmodel::moralGraph(), and operator=().

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

◆ clearEdges()

void gum::EdgeGraphPart::clearEdges ( )
virtualinherited

removes all the edges from the EdgeGraphPart

Reimplemented in gum::CliqueGraph.

Definition at line 67 of file edgeGraphPart.cpp.

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

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

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

◆ clearNodes()

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

remove all the nodes from the NodeGraphPart

Definition at line 310 of file nodeGraphPart_inl.h.

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

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

◆ edges()

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

returns the set of edges stored within the EdgeGraphPart

Definition at line 39 of file edgeGraphPart_inl.h.

References gum::EdgeGraphPart::__edges.

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

39 { return __edges; }
EdgeSet __edges
the set of all the edges contained within the EdgeGraphPart
+ Here is the caller graph for this function:

◆ edgesProperty() [1/2]

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

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

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

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

+ Here is the caller graph for this function:

◆ edgesProperty() [2/2]

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

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

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

◆ empty()

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

alias for emptyNodes

Definition at line 306 of file nodeGraphPart_inl.h.

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

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

◆ emptyEdges()

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

indicates wether the EdgeGraphPart contains any edge

Definition at line 35 of file edgeGraphPart_inl.h.

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

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

◆ emptyNodes()

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

indicates whether there exists nodes in the NodeGraphPart

Definition at line 304 of file nodeGraphPart_inl.h.

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

◆ end()

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

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

Definition at line 339 of file nodeGraphPart_inl.h.

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

◆ endSafe()

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

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

Definition at line 329 of file nodeGraphPart_inl.h.

329  {
330  return __endIteratorSafe;
331  }
NodeGraphPartIteratorSafe __endIteratorSafe
the end iterator (used to speed-up parsings of the NodeGraphPart)

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

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

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

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

◆ eraseNeighbours()

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

erase all the edges adjacent to a given node

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

Definition at line 83 of file edgeGraphPart_inl.h.

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

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

◆ eraseNode()

INLINE void gum::UndiGraph::eraseNode ( const NodeId  id)
virtual

remove a node and its adjacent edges from the graph

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

Reimplemented from gum::NodeGraphPart.

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

Definition at line 58 of file undiGraph_inl.h.

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

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::__removeNode(), and gum::StaticTriangulation::__triangulate().

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

◆ exists()

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

alias for existsNode

Definition at line 292 of file nodeGraphPart_inl.h.

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

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

◆ existsEdge() [1/2]

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

indicates whether a given edge exists

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

Definition at line 41 of file edgeGraphPart_inl.h.

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

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

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

◆ existsEdge() [2/2]

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

indicates whether a given edge exists

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

Definition at line 45 of file edgeGraphPart_inl.h.

References gum::EdgeGraphPart::__neighbours.

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

◆ existsNode()

◆ hasUndirectedCycle()

bool gum::UndiGraph::hasUndirectedCycle ( ) const

checks whether the graph contains cycles

Definition at line 55 of file undiGraph.cpp.

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

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

◆ listMapEdges()

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

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

Parameters
fa function assigning a VAL to any edge

◆ listMapNodes()

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

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

Parameters
fa function assigning a VAL to any node

◆ neighbours()

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

returns the set of edges adjacent to a given node

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

Parameters
idthe node to which the edges are adjacent

Definition at line 78 of file edgeGraphPart_inl.h.

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

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

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

◆ nextNodeId()

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

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

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

Definition at line 226 of file nodeGraphPart_inl.h.

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

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

◆ nodes()

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

return *this as a NodeGraphPart

Definition at line 373 of file nodeGraphPart_inl.h.

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

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

◆ nodesProperty() [1/2]

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

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

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

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

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

+ Here is the caller graph for this function:

◆ nodesProperty() [2/2]

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

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

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

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

◆ operator!=() [1/3]

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

tests whether two EdgeGraphParts contain different edges

Parameters
pthe EdgeGraphPart that we compare with this

Definition at line 111 of file edgeGraphPart_inl.h.

References gum::EdgeGraphPart::__edges.

111  {
112  return __edges != p.__edges;
113  }
EdgeSet __edges
the set of all the edges contained within the EdgeGraphPart

◆ operator!=() [2/3]

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

tests whether two UndiGraphs are different

Parameters
gthe UndiGraph with which "this" is compared

Definition at line 70 of file undiGraph_inl.h.

References operator==().

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

◆ operator!=() [3/3]

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

check whether two NodeGraphParts contain different nodes

Parameters
pthe NodeGraphPart to be compared with "this"

Definition at line 357 of file nodeGraphPart_inl.h.

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

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

◆ operator=()

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

copy operator

Parameters
gthe DiGraph to copy

Definition at line 48 of file undiGraph_inl.h.

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

48  {
49  if (this != &g) {
53  }
54 
55  return *this;
56  }
NodeGraphPart & operator=(const NodeGraphPart &p)
copy operator
virtual void clear()
removes all the nodes and edges from the graph
Definition: undiGraph_inl.h:43
EdgeGraphPart & operator=(const EdgeGraphPart &s)
copy operator
+ Here is the call graph for this function:

◆ operator==() [1/3]

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

tests whether two EdgeGraphParts contain the same edges

Parameters
pthe EdgeGraphPart that we compare with this

Definition at line 107 of file edgeGraphPart_inl.h.

References gum::EdgeGraphPart::__edges.

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

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

◆ operator==() [2/3]

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

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

Parameters
gthe UndiGraph with which "this" is compared

Definition at line 66 of file undiGraph_inl.h.

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

Referenced by operator!=().

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

◆ operator==() [3/3]

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

check whether two NodeGraphParts contain the same nodes

Parameters
pthe NodeGraphPart to be compared with "this"

Definition at line 343 of file nodeGraphPart_inl.h.

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

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

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

◆ partialUndiGraph()

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

returns the partial graph formed by the nodes given in parameter

Definition at line 139 of file undiGraph.cpp.

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

139  {
140  UndiGraph partialGraph;
141 
142  for (const auto node : nodesSet) {
143  partialGraph.addNodeWithId(node);
144 
145  for (const auto nei : neighbours(node))
146  if (nodesSet.contains(nei) && partialGraph.existsNode(nei))
147  partialGraph.addEdge(node, nei);
148  }
149 
150  return partialGraph;
151  }
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
UndiGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
Definition: undiGraph.cpp:40
+ 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 64 of file nodeGraphPart.cpp.

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

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

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

◆ populateNodesFromProperty()

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

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

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

◆ size()

◆ sizeEdges()

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

indicates the number of edges stored within the EdgeGraphPart

Definition at line 37 of file edgeGraphPart_inl.h.

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

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

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

◆ sizeNodes()

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

returns the number of nodes in the NodeGraphPart

Definition at line 280 of file nodeGraphPart_inl.h.

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

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

◆ toDot()

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

to friendly display graph in DOT format

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

Definition at line 109 of file undiGraph.cpp.

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

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

◆ toString()

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

to friendly display the content of the graph

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

Definition at line 102 of file undiGraph.cpp.

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

Referenced by gum::operator<<().

102  {
103  std::string s = NodeGraphPart::toString();
104  s += " , ";
106  return s;
107  }
std::string toString() const
a function to display the set of nodes
const std::string toString() const
to friendly display the content of the EdgeGraphPart
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ undirectedPath()

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

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

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

Definition at line 127 of file edgeGraphPart.cpp.

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

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

◆ unvirtualizedEraseNeighbours()

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

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

Parameters
idthe node whose ingoing arcs will be removed

Definition at line 96 of file edgeGraphPart_inl.h.

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

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

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

Member Data Documentation

◆ onEdgeAdded

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

◆ onEdgeDeleted

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

◆ onNodeAdded

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

Definition at line 274 of file nodeGraphPart.h.

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

◆ onNodeDeleted

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

Definition at line 275 of file nodeGraphPart.h.

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


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