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

Class for node sets in graph. More...

#include <nodeGraphPart.h>

Inheritance diagram for gum::NodeGraphPart:
Collaboration diagram for gum::NodeGraphPart:

Public Types

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

Constructors / Destructors
 NodeGraphPart (Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true)
 default constructor
 NodeGraphPart (const NodeGraphPart &s)
 copy constructor
virtual ~NodeGraphPart ()
 destructor
Operators
NodeGraphPartoperator= (const NodeGraphPart &p)
 copy operator
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
virtual void eraseNode (const NodeId id)
 erase the 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
virtual void clear ()
 alias for clearNodes
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
virtual std::string toString () const
 a function to display the set of nodes
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))

Public Attributes

Signaler1< NodeIdonNodeAdded
Signaler1< NodeIdonNodeDeleted

Private Member Functions

void _updateEndIteratorSafe_ ()
 updating endIterator (always at max+1)
void _clearNodes_ ()
 code for clearing nodes (called twice)
void _eraseHole_ (NodeId id)
 to delete hole.
void _addHole_ (NodeId id)
 to add a hole.
Introspection
bool _inHoles_ (NodeId id) const
Size _sizeHoles_ () const

Private Attributes

NodeSet_holes_
 the set of nodes not contained in the NodeGraphPart in the interval 1.
Size _holes_size_
 value for holes configuration
bool _holes_resize_policy_
 value for holes configuration
NodeGraphPartIteratorSafe _endIteratorSafe_
 the end iterator (used to speed-up parsings of the NodeGraphPart)
NodeId _boundVal_
 the id below which NodeIds may belong to the NodeGraphPart

Friends

class NodeGraphPartIterator
class NodeGraphPartIteratorSafe
class gum_tests::NodeGraphPartTestSuite
 to enable testunits to use check

Detailed Description

Class for node sets in graph.

NodeGraphPart represents the set of nodes of all the graphs. It is built to be as light as possible and it implements its own NodeId factory. The set of NodeId is 0 ... ( bound-1) minus the NodeIds in holes.

Author
Pierre-Henri WUILLEMIN(_at_LIP6) & Christophe GONZALES(_at_AMU)
Usage example:
// create an empty node list
// add 2 elements
NodeId id_a=nodes1.addNode( );
NodeId id_b=nodes1.addNode( );
// checks if there exists a node with ID = 6
if ( !nodes1.exists( 6 ) ) std::cerr << "no node with ID 6" << std::endl;
// check if the set of nodes is empty
if ( !nodes1.empty() || ( nodes1.size() != 0 ) )
std::cerr << "nodes1 is not empty" << std::endl;
// copy a set of nodes
NodeGraphPart nodes2 = nodes1, nodes3;
nodes3 = nodes1;
// remove elements from list3
nodes3.eraseNode( id_a );
nodes3.eraseNode( id_b );
// remove all the elements from the list
nodes1.clear();
for ( NodeGraphPart::iterator it=nodes2.beginNodes();
it!=nodes2.endNodes();++it ) {
std::cerr<<*it<<" ";
}
std::cerr<<"list : "<<nodes2.listMapNodes(getDouble)<<std::endl;
std::cerr<<"hashmap : "<<nodes2.hashMapNodes(getDouble)<<std::endl;
Size size() const
alias for sizeNodes
virtual void clear()
alias for clearNodes
virtual void eraseNode(const NodeId id)
erase the node with the given id
bool exists(const NodeId id) const
alias for existsNode
bool empty() const
alias for emptyNodes
virtual NodeId addNode()
insert a new node and return its id
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,...
NodeGraphPart(Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true)
default constructor
Size NodeId
Type for node ids.

Definition at line 271 of file nodeGraphPart.h.

Member Typedef Documentation

◆ 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

◆ NodeConstIteratorSafe

◆ NodeIterator

◆ NodeIteratorSafe

Constructor & Destructor Documentation

◆ NodeGraphPart() [1/2]

gum::NodeGraphPart::NodeGraphPart ( Size holes_size = HashTableConst::default_size,
bool holes_resize_policy = true )
explicit

default constructor

A NodeGrphPart does not store all its nodes. To be lighter in terms of memory consumption, it store its maximal NodeId and the set of NodeIds between 0 and this maximum that do not actually belong to the set of its nodes (the so-called set of holes). In practice, it turns out that the set of holes is most often very small.

Parameters
holes_sizethe size of the hash table used to store all holes
holes_resize_policythe resizing policy of this hash table

Definition at line 57 of file nodeGraphPart.cpp.

57 :
58 _holes_size_(holes_size), _holes_resize_policy_(holes_resize_policy),
59 _endIteratorSafe_(*this), _boundVal_(0) {
60 _holes_ = nullptr;
61 GUM_CONSTRUCTOR(NodeGraphPart);
63 }
NodeGraphPartIteratorSafe _endIteratorSafe_
the end iterator (used to speed-up parsings of the NodeGraphPart)
void _updateEndIteratorSafe_()
updating endIterator (always at max+1)
Size _holes_size_
value for holes configuration
bool _holes_resize_policy_
value for holes configuration
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

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

Referenced by gum::DiGraph::DiGraph(), gum::DiGraph::DiGraph(), NodeGraphPart(), NodeGraphPart(), gum::UndiGraph::UndiGraph(), gum::UndiGraph::UndiGraph(), ~NodeGraphPart(), nodes(), gum::prm::gspan::Pattern::nodes(), operator!=(), operator=(), operator==(), populateNodes(), and populateNodesFromProperty().

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

◆ NodeGraphPart() [2/2]

gum::NodeGraphPart::NodeGraphPart ( const NodeGraphPart & s)

copy constructor

Parameters
sthe NodeGraphPart to be copied

Definition at line 65 of file nodeGraphPart.cpp.

65 :
66 _holes_size_(s._holes_size_), _holes_resize_policy_(s._holes_resize_policy_),
67 _endIteratorSafe_(*this), _boundVal_(s._boundVal_) {
68 _holes_ = nullptr;
69
70 if (s._holes_) _holes_ = new NodeSet(*s._holes_);
71
73
74 GUM_CONS_CPY(NodeGraphPart);
75 }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...

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

Here is the call graph for this function:

◆ ~NodeGraphPart()

gum::NodeGraphPart::~NodeGraphPart ( )
virtual

destructor

Definition at line 77 of file nodeGraphPart.cpp.

77 {
78 if (_holes_) delete _holes_;
79
80 GUM_DESTRUCTOR(NodeGraphPart);
81 }

References NodeGraphPart(), and _holes_.

Here is the call graph for this function:

Member Function Documentation

◆ _addHole_()

void gum::NodeGraphPart::_addHole_ ( NodeId id)
private

to add a hole.

Warning
id is assumed not to be already a hole

Definition at line 96 of file nodeGraphPart.cpp.

96 {
97 // we assume that the node exists
98 if (node + 1 == _boundVal_) {
99 // we remove the max : no new hole and maybe a bunch of holes to remove
100 --_boundVal_;
101
102 if (_holes_) {
103 while (_holes_->contains(_boundVal_ - 1)) {
104 // a bunch of holes to remove. We do not use inHoles for optimisation
105 // :
106 // not to repeat the test if ( _holes_) each time
107 _holes_->erase(--_boundVal_);
108 }
109
110 if (_holes_->empty()) {
111 delete _holes_;
112 _holes_ = nullptr;
113 }
114 }
115
117 } else {
119
120 _holes_->insert(node);
121 }
122 }

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

Referenced by eraseNode(), and gum_tests::NodeGraphPartTestSuite.

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

◆ _clearNodes_()

void gum::NodeGraphPart::_clearNodes_ ( )
private

code for clearing nodes (called twice)

Definition at line 174 of file nodeGraphPart.cpp.

174 {
176 _boundVal_ = 0;
177
178 if (onNodeDeleted.hasListener()) {
179 for (NodeId n = 0; n < bound; ++n) {
180 if (!_inHoles_(n)) GUM_EMIT1(onNodeDeleted, n);
181 }
182 }
183
185
186 delete (_holes_);
187 _holes_ = nullptr;
188 }
Signaler1< NodeId > onNodeDeleted
NodeId bound() const
returns a number n such that all node ids are strictly lower than n
bool _inHoles_(NodeId id) const
#define GUM_EMIT1(signal, arg1)
Definition signaler1.h:61

References _boundVal_, _holes_, _inHoles_(), _updateEndIteratorSafe_(), bound(), GUM_EMIT1, and onNodeDeleted.

Referenced by clear(), clearNodes(), and gum_tests::NodeGraphPartTestSuite.

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

◆ _eraseHole_()

INLINE void gum::NodeGraphPart::_eraseHole_ ( NodeId id)
private

to delete hole.

Warning
the hole is assumed to be existing.

Definition at line 244 of file nodeGraphPart_inl.h.

244 {
245 _holes_->erase(id);
246
247 if (_holes_->empty()) {
248 delete _holes_;
249 _holes_ = nullptr;
250 }
251 }

References _holes_.

Referenced by addNode(), addNodeWithId(), and gum_tests::NodeGraphPartTestSuite.

Here is the caller graph for this function:

◆ _inHoles_()

INLINE bool gum::NodeGraphPart::_inHoles_ ( NodeId id) const
private
Returns
true if id is part of holes

Definition at line 372 of file nodeGraphPart_inl.h.

372{ return _holes_ && _holes_->contains(id); }

References _holes_.

Referenced by _clearNodes_(), addNodeWithId(), asNodeSet(), existsNode(), gum_tests::NodeGraphPartTestSuite, and toString().

Here is the caller graph for this function:

◆ _sizeHoles_()

INLINE Size gum::NodeGraphPart::_sizeHoles_ ( ) const
private
Returns
the size of holes

Definition at line 375 of file nodeGraphPart_inl.h.

375{ return _holes_ ? _holes_->size() : (Size)0; }
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74

References _holes_.

Referenced by gum_tests::NodeGraphPartTestSuite.

Here is the caller graph for this function:

◆ _updateEndIteratorSafe_()

INLINE void gum::NodeGraphPart::_updateEndIteratorSafe_ ( )
private

updating endIterator (always at max+1)

Definition at line 327 of file nodeGraphPart_inl.h.

327{ _endIteratorSafe_.setPos_(_boundVal_); }

References _boundVal_, and _endIteratorSafe_.

Referenced by NodeGraphPart(), NodeGraphPart(), _addHole_(), _clearNodes_(), addNode(), addNodeWithId(), gum_tests::NodeGraphPartTestSuite, and populateNodes().

Here is the caller graph for this function:

◆ addNode()

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

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.

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)

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)
virtual

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 }
#define GUM_ERROR(type, msg)
Definition exceptions.h:72

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:

◆ asNodeSet()

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

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())
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
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
noexcept

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

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

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:

◆ clear()

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

alias for clearNodes

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

Definition at line 319 of file nodeGraphPart_inl.h.

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

References _clearNodes_().

Referenced by populateNodes().

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

◆ clearNodes()

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

remove all the nodes from the NodeGraphPart

Definition at line 312 of file nodeGraphPart_inl.h.

312{ _clearNodes_(); }

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:

◆ empty()

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

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:

◆ emptyNodes()

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

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
noexcept

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 }

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
noexcept

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:

◆ eraseNode()

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

erase the node with the given id

If the NodeGraphPart does not contain the nodeId, then nothing is done. In particular, no exception is raised. However, the signal onNodeDeleted is fired only if a node is effectively removed.

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

Definition at line 298 of file nodeGraphPart_inl.h.

298 {
299 if (!existsNode(node)) return;
300
301 _addHole_(node);
302
304 }
void _addHole_(NodeId id)
to add a hole.
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId

References _addHole_(), existsNode(), GUM_EMIT1, and onNodeDeleted.

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

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

alias for existsNode

Definition at line 296 of file nodeGraphPart_inl.h.

296{ return existsNode(node); }

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:

◆ existsNode()

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

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:

◆ listMapNodes()

template<typename VAL>
List< VAL > gum::NodeGraphPart::listMapNodes ( VAL(* )(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))

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:

◆ nextNodeId()

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

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

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:

◆ nodesPropertyFromFunction()

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

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

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!=()

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

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=()

INLINE NodeGraphPart & gum::NodeGraphPart::operator= ( const NodeGraphPart & p)

copy operator

Parameters
pthe NodeGraphPart to be copied

Definition at line 225 of file nodeGraphPart_inl.h.

225 {
226 // avoid self assignment
227 if (this != &p) { populateNodes(p); }
228
229 return *this;
230 }
void populateNodes(const NodeGraphPart &s)
populateNodes clears *this and fills it with the same nodes as "s"

References NodeGraphPart(), and populateNodes().

Referenced by 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==()

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

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:

◆ populateNodes()

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

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 }

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)

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

◆ sizeNodes()

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

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:

◆ toString()

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

a function to display the set of nodes

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

Definition at line 124 of file nodeGraphPart.cpp.

124 {
125 std::stringstream s;
126 bool first = true;
127 s << "{";
128
129 for (NodeId id = 0; id < _boundVal_; ++id) {
130 if (_inHoles_(id)) continue;
131
132 if (first) {
133 first = false;
134 } else {
135 s << ",";
136 }
137
138 s << id;
139 }
140
141 s << "}";
142
143 return s.str();
144 }

References _boundVal_, and _inHoles_().

Referenced by gum::operator<<(), populateNodesFromProperty(), gum::DiGraph::toString(), gum::MixedGraph::toString(), and gum::UndiGraph::toString().

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

◆ gum_tests::NodeGraphPartTestSuite

friend class gum_tests::NodeGraphPartTestSuite
friend

◆ NodeGraphPartIterator

friend class NodeGraphPartIterator
friend

Definition at line 479 of file nodeGraphPart.h.

References NodeGraphPartIterator.

Referenced by begin(), end(), and NodeGraphPartIterator.

◆ NodeGraphPartIteratorSafe

friend class NodeGraphPartIteratorSafe
friend

Definition at line 480 of file nodeGraphPart.h.

References NodeGraphPartIteratorSafe.

Referenced by beginSafe(), endSafe(), and NodeGraphPartIteratorSafe.

Member Data Documentation

◆ _boundVal_

NodeId gum::NodeGraphPart::_boundVal_
private

◆ _endIteratorSafe_

NodeGraphPartIteratorSafe gum::NodeGraphPart::_endIteratorSafe_
private

the end iterator (used to speed-up parsings of the NodeGraphPart)

Definition at line 525 of file nodeGraphPart.h.

Referenced by NodeGraphPart(), NodeGraphPart(), _updateEndIteratorSafe_(), end(), and endSafe().

◆ _holes_

NodeSet* gum::NodeGraphPart::_holes_
private

the set of nodes not contained in the NodeGraphPart in the interval 1.

. max

Warning
holes may be nullptr.

Definition at line 516 of file nodeGraphPart.h.

Referenced by NodeGraphPart(), NodeGraphPart(), ~NodeGraphPart(), _addHole_(), _clearNodes_(), _eraseHole_(), _inHoles_(), _sizeHoles_(), addNode(), addNodeWithId(), nextNodeId(), operator==(), populateNodes(), and sizeNodes().

◆ _holes_resize_policy_

bool gum::NodeGraphPart::_holes_resize_policy_
private

value for holes configuration

Definition at line 522 of file nodeGraphPart.h.

Referenced by NodeGraphPart(), NodeGraphPart(), _addHole_(), addNodeWithId(), and populateNodes().

◆ _holes_size_

Size gum::NodeGraphPart::_holes_size_
private

value for holes configuration

Definition at line 519 of file nodeGraphPart.h.

Referenced by NodeGraphPart(), NodeGraphPart(), _addHole_(), addNodeWithId(), and populateNodes().

◆ onNodeAdded

Signaler1< NodeId > gum::NodeGraphPart::onNodeAdded

Definition at line 289 of file nodeGraphPart.h.

Referenced by addNode(), and addNodeWithId().

◆ onNodeDeleted

Signaler1< NodeId > gum::NodeGraphPart::onNodeDeleted

Definition at line 290 of file nodeGraphPart.h.

Referenced by _clearNodes_(), and eraseNode().


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