aGrUM  0.16.0
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 Attributes

Signaler1< NodeIdonNodeAdded
 
Signaler1< NodeIdonNodeDeleted
 

Public Member Functions

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

Public Types

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

Friends

class NodeGraphPartIterator
 
class NodeGraphPartIteratorSafe
 
class gum_tests::NodeGraphPartTestSuite
 to enable testunits to use __check More...
 

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 and Christophe GONZALES
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;

Definition at line 256 of file nodeGraphPart.h.

Member Typedef Documentation

◆ 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

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

References __holes, and __updateEndIteratorSafe().

38  :
39  __holes_size(holes_size), __holes_resize_policy(holes_resize_policy),
40  __endIteratorSafe(*this), __boundVal(0) {
41  __holes = nullptr;
42  GUM_CONSTRUCTOR(NodeGraphPart);
44  }
NodeSet * __holes
the set of nodes not contained in the NodeGraphPart in the interval 1..__max
NodeGraphPartIteratorSafe __endIteratorSafe
the end iterator (used to speed-up parsings of the NodeGraphPart)
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)
NodeGraphPart(Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true)
default constructor
+ Here is the call graph for this function:

◆ NodeGraphPart() [2/2]

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

copy constructor

Parameters
sthe NodeGraphPart to be copied

Definition at line 46 of file nodeGraphPart.cpp.

References __holes, and __updateEndIteratorSafe().

46  :
47  __holes_size(s.__holes_size), __holes_resize_policy(s.__holes_resize_policy),
48  __endIteratorSafe(*this), __boundVal(s.__boundVal) {
49  __holes = nullptr;
50 
51  if (s.__holes) __holes = new NodeSet(*s.__holes);
52 
54 
55  GUM_CONS_CPY(NodeGraphPart);
56  }
NodeSet * __holes
the set of nodes not contained in the NodeGraphPart in the interval 1..__max
NodeGraphPartIteratorSafe __endIteratorSafe
the end iterator (used to speed-up parsings of the NodeGraphPart)
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)
NodeGraphPart(Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true)
default constructor
+ Here is the call graph for this function:

◆ ~NodeGraphPart()

gum::NodeGraphPart::~NodeGraphPart ( )
virtual

destructor

Definition at line 58 of file nodeGraphPart.cpp.

References __holes.

58  {
59  if (__holes) delete __holes;
60 
61  GUM_DESTRUCTOR(NodeGraphPart);
62  }
NodeSet * __holes
the set of nodes not contained in the NodeGraphPart in the interval 1..__max
NodeGraphPart(Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true)
default constructor

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

References __boundVal, __holes, __holes_resize_policy, __holes_size, __updateEndIteratorSafe(), gum::Set< Key, Alloc >::contains(), gum::Set< Key, Alloc >::empty(), gum::Set< Key, Alloc >::erase(), and gum::Set< Key, Alloc >::insert().

77  {
78  // we assume that the node exists
79  if (node + 1 == __boundVal) {
80  // we remove the max : no new hole and maybe a bunch of holes to remove
81  --__boundVal;
82 
83  if (__holes) {
84  while (__holes->contains(__boundVal - 1)) {
85  // a bunch of holes to remove. We do not use inHoles for optimisation
86  // :
87  // not to repeat the test if (__holes) each time
89  }
90 
91  if (__holes->empty()) {
92  delete __holes;
93  __holes = nullptr;
94  }
95  }
96 
98  } else {
100 
101  __holes->insert(node);
102  }
103  }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:581
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
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
bool __holes_resize_policy
value for __holes configuration
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:656
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)
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
+ Here is the call graph for this function:

◆ __clearNodes()

void gum::NodeGraphPart::__clearNodes ( )
private

code for clearing nodes (called twice)

Definition at line 155 of file nodeGraphPart.cpp.

References __boundVal, __holes, __inHoles(), __updateEndIteratorSafe(), bound(), GUM_EMIT1, and onNodeDeleted.

155  {
157  __boundVal = 0;
158 
159  if (onNodeDeleted.hasListener()) {
160  for (NodeId n = 0; n < bound; ++n) {
161  if (!__inHoles(n)) GUM_EMIT1(onNodeDeleted, n);
162  }
163  }
164 
166 
167  delete (__holes);
168  __holes = nullptr;
169  }
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
bool __inHoles(NodeId id) const
NodeId __boundVal
the id below which NodeIds may belong to the NodeGraphPart
void __updateEndIteratorSafe()
updating endIterator (always at __max+1)
NodeId bound() const
returns a number n such that all node ids are strictly lower than n
Signaler1< NodeId > onNodeDeleted
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ Here is the call 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 239 of file nodeGraphPart_inl.h.

Referenced by addNodeWithId().

239  {
240  __holes->erase(id);
241 
242  if (__holes->empty()) {
243  delete __holes;
244  __holes = nullptr;
245  }
246  }
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
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:656
+ 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 377 of file nodeGraphPart_inl.h.

Referenced by __clearNodes(), gum::NodeGraphPartIterator::_validate(), addNodeWithId(), and toString().

377  {
378  return __holes && __holes->contains(id);
379  }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:581
NodeSet * __holes
the set of nodes not contained in the NodeGraphPart in the interval 1..__max
+ Here is the caller graph for this function:

◆ __sizeHoles()

INLINE Size gum::NodeGraphPart::__sizeHoles ( ) const
private
Returns
the size of __holes

Definition at line 382 of file nodeGraphPart_inl.h.

382  {
383  return __holes ? __holes->size() : (Size)0;
384  }
NodeSet * __holes
the set of nodes not contained in the NodeGraphPart in the interval 1..__max
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:701

◆ __updateEndIteratorSafe()

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

updating endIterator (always at __max+1)

Definition at line 325 of file nodeGraphPart_inl.h.

Referenced by __addHole(), __clearNodes(), addNodeWithId(), NodeGraphPart(), and populateNodes().

325  {
327  }
NodeGraphPartIteratorSafe __endIteratorSafe
the end iterator (used to speed-up parsings of the NodeGraphPart)
void _setPos(NodeId id) noexcept
this function is used by NodeGraphPart to update
NodeId __boundVal
the id below which NodeIds may belong to the NodeGraphPart
+ 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 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)

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

Definition at line 132 of file nodeGraphPart.cpp.

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

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

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
noexcept

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

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

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 __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::NodeGraphPart::clear ( )
virtual

alias for clearNodes

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

Definition at line 317 of file nodeGraphPart_inl.h.

Referenced by populateNodes().

317 { __clearNodes(); }
void __clearNodes()
code for clearing nodes (called twice)
+ 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 310 of file nodeGraphPart_inl.h.

Referenced by gum::DiGraph::clear(), gum::UndiGraph::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:

◆ empty()

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

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:

◆ emptyNodes()

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

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
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  }
NodeGraphPartIteratorSafe __endIteratorSafe
the end iterator (used to speed-up parsings of the NodeGraphPart)

◆ 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  }
NodeGraphPartIteratorSafe __endIteratorSafe
the end iterator (used to speed-up parsings of the NodeGraphPart)

◆ 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::MixedGraph, gum::DiGraph, gum::UndiGraph, and gum::CliqueGraph.

Definition at line 296 of file nodeGraphPart_inl.h.

References GUM_EMIT1.

Referenced by gum::LeafAggregator::__removeContext(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_removeNode(), gum::UndiGraph::eraseNode(), gum::DiGraph::eraseNode(), and gum::MixedGraph::eraseNode().

296  {
297  if (!existsNode(node)) return;
298 
299  __addHole(node);
300 
301  GUM_EMIT1(onNodeDeleted, node);
302  }
#define GUM_EMIT1(signal, arg1)
Definition: signaler1.h:42
void __addHole(NodeId id)
to add a hole.
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
Signaler1< NodeId > onNodeDeleted
+ Here is the caller graph for this function:

◆ exists()

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

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(), gum::UndiGraph::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:

◆ existsNode()

◆ listMapNodes()

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

◆ 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);
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

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(), gum::UndiGraph::hasUndirectedCycle(), gum::DAG::moralGraph(), gum::MarkovBlanket::nodes(), gum::EssentialGraph::nodes(), gum::prm::gspan::Pattern::nodes(), gum::MarkovBlanket::toDot(), gum::EssentialGraph::toDot(), gum::InfluenceDiagram< GUM_SCALAR >::toDot(), gum::UndiGraph::toDot(), gum::DiGraph::toDot(), and 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

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

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

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

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

+ Here is the caller graph for this function:

◆ nodesProperty() [2/2]

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

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

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 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 NodeGraphPart & gum::NodeGraphPart::operator= ( const NodeGraphPart p)

copy operator

Parameters
pthe NodeGraphPart to be copied

Definition at line 219 of file nodeGraphPart_inl.h.

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

219  {
220  // avoid self assignment
221  if (this != &p) { populateNodes(p); }
222 
223  return *this;
224  }
void populateNodes(const NodeGraphPart &s)
populateNodes clears *this and fills it with the same nodes as "s"
+ 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.

References __boundVal, and __holes.

Referenced by gum::UndiGraph::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:

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

References __boundVal, __holes, __holes_resize_policy, __holes_size, __updateEndIteratorSafe(), and 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)

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

◆ sizeNodes()

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

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:

◆ toString()

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

a function to display the set of nodes

Definition at line 105 of file nodeGraphPart.cpp.

References __boundVal, and __inHoles().

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

105  {
106  std::stringstream s;
107  bool first = true;
108  s << "{";
109 
110  for (NodeId id = 0; id < __boundVal; ++id) {
111  if (__inHoles(id)) continue;
112 
113  if (first) {
114  first = false;
115  } else {
116  s << ",";
117  }
118 
119  s << id;
120  }
121 
122  s << "}";
123 
124  return s.str();
125  }
bool __inHoles(NodeId id) const
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 call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ gum_tests::NodeGraphPartTestSuite

friend class gum_tests::NodeGraphPartTestSuite
friend

to enable testunits to use __check

Definition at line 470 of file nodeGraphPart.h.

◆ NodeGraphPartIterator

friend class NodeGraphPartIterator
friend

Definition at line 465 of file nodeGraphPart.h.

◆ NodeGraphPartIteratorSafe

friend class NodeGraphPartIteratorSafe
friend

Definition at line 466 of file nodeGraphPart.h.

Member Data Documentation

◆ __boundVal

NodeId gum::NodeGraphPart::__boundVal
private

the id below which NodeIds may belong to the NodeGraphPart

Definition at line 514 of file nodeGraphPart.h.

Referenced by __addHole(), __clearNodes(), addNodeWithId(), operator==(), populateNodes(), and toString().

◆ __endIteratorSafe

NodeGraphPartIteratorSafe gum::NodeGraphPart::__endIteratorSafe
private

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

Definition at line 511 of file nodeGraphPart.h.

◆ __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 502 of file nodeGraphPart.h.

Referenced by __addHole(), __clearNodes(), addNodeWithId(), NodeGraphPart(), operator==(), populateNodes(), and ~NodeGraphPart().

◆ __holes_resize_policy

bool gum::NodeGraphPart::__holes_resize_policy
private

value for __holes configuration

Definition at line 508 of file nodeGraphPart.h.

Referenced by __addHole(), addNodeWithId(), and populateNodes().

◆ __holes_size

Size gum::NodeGraphPart::__holes_size
private

value for __holes configuration

Definition at line 505 of file nodeGraphPart.h.

Referenced by __addHole(), addNodeWithId(), and populateNodes().

◆ onNodeAdded

Signaler1< NodeId > gum::NodeGraphPart::onNodeAdded

Definition at line 274 of file nodeGraphPart.h.

Referenced by addNodeWithId().

◆ onNodeDeleted

Signaler1< NodeId > gum::NodeGraphPart::onNodeDeleted

Definition at line 275 of file nodeGraphPart.h.

Referenced by __clearNodes().


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