aGrUM  0.14.2
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 253 of file nodeGraphPart.h.

Member Typedef Documentation

◆ node_const_iterator

types for STL compliance

Definition at line 258 of file nodeGraphPart.h.

◆ node_const_iterator_safe

types for STL compliance

Definition at line 260 of file nodeGraphPart.h.

◆ node_iterator

types for STL compliance

Definition at line 257 of file nodeGraphPart.h.

◆ node_iterator_safe

types for STL compliance

Definition at line 259 of file nodeGraphPart.h.

◆ NodeConstIterator

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

References __holes, and __updateEndIteratorSafe().

35  :
36  __holes_size(holes_size), __holes_resize_policy(holes_resize_policy),
37  __endIteratorSafe(*this), __boundVal(0) {
38  __holes = nullptr;
39  GUM_CONSTRUCTOR(NodeGraphPart);
41  }
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 43 of file nodeGraphPart.cpp.

References __holes, and __updateEndIteratorSafe().

43  :
44  __holes_size(s.__holes_size), __holes_resize_policy(s.__holes_resize_policy),
45  __endIteratorSafe(*this), __boundVal(s.__boundVal) {
46  __holes = nullptr;
47 
48  if (s.__holes) __holes = new NodeSet(*s.__holes);
49 
51 
52  GUM_CONS_CPY(NodeGraphPart);
53  }
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 55 of file nodeGraphPart.cpp.

References __holes.

55  {
56  if (__holes) delete __holes;
57 
58  GUM_DESTRUCTOR(NodeGraphPart);
59  }
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 74 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().

74  {
75  // we assume that the node exists
76  if (node + 1 == __boundVal) {
77  // we remove the max : no new hole and maybe a bunch of holes to remove
78  --__boundVal;
79 
80  if (__holes) {
81  while (__holes->contains(__boundVal - 1)) {
82  // a bunch of holes to remove. We do not use inHoles for optimisation
83  // :
84  // not to repeat the test if (__holes) each time
86  }
87 
88  if (__holes->empty()) {
89  delete __holes;
90  __holes = nullptr;
91  }
92  }
93 
95  } else {
97 
98  __holes->insert(node);
99  }
100  }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:578
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:704
NodeSet * __holes
the set of nodes not contained in the NodeGraphPart in the interval 1..__max
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:653
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:610
+ Here is the call graph for this function:

◆ __clearNodes()

void gum::NodeGraphPart::__clearNodes ( )
private

code for clearing nodes (called twice)

Definition at line 152 of file nodeGraphPart.cpp.

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

152  {
154  __boundVal = 0;
155 
156  if (onNodeDeleted.hasListener()) {
157  for (NodeId n = 0; n < bound; ++n) {
158  if (!__inHoles(n)) GUM_EMIT1(onNodeDeleted, n);
159  }
160  }
161 
163 
164  delete (__holes);
165  __holes = nullptr;
166  }
NodeSet * __holes
the set of nodes not contained in the NodeGraphPart in the interval 1..__max
#define GUM_EMIT1(signal, arg1)
Definition: signaler1.h:40
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:97
+ 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 236 of file nodeGraphPart_inl.h.

Referenced by addNodeWithId().

236  {
237  __holes->erase(id);
238 
239  if (__holes->empty()) {
240  delete __holes;
241  __holes = nullptr;
242  }
243  }
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:704
NodeSet * __holes
the set of nodes not contained in the NodeGraphPart in the interval 1..__max
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:653
+ 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 374 of file nodeGraphPart_inl.h.

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

374  {
375  return __holes && __holes->contains(id);
376  }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:578
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 379 of file nodeGraphPart_inl.h.

379  {
380  return __holes ? __holes->size() : (Size)0;
381  }
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:45
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:698

◆ __updateEndIteratorSafe()

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

updating endIterator (always at __max+1)

Definition at line 322 of file nodeGraphPart_inl.h.

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

322  {
324  }
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 250 of file nodeGraphPart_inl.h.

References GUM_EMIT1.

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

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

◆ addNodes()

INLINE std::vector< NodeId > gum::NodeGraphPart::addNodes ( Size  n)

insert n nodes

Parameters
nthe number of nodes to add
Returns
the vector of chosen ids

Definition at line 268 of file nodeGraphPart_inl.h.

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

◆ addNodeWithId()

void gum::NodeGraphPart::addNodeWithId ( const NodeId  id)
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 129 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(), and gum::learning::StructuralConstraintDAG::StructuralConstraintDAG().

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

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

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

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

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

◆ begin()

INLINE NodeGraphPartIterator gum::NodeGraphPart::begin ( ) const
noexcept

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

Definition at line 330 of file nodeGraphPart_inl.h.

References gum::NodeGraphPartIterator::_validate().

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

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

◆ beginSafe()

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

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

Definition at line 316 of file nodeGraphPart_inl.h.

References gum::NodeGraphPartIterator::_validate().

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

◆ bound()

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

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

Definition at line 305 of file nodeGraphPart_inl.h.

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

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

◆ clear()

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

alias for clearNodes

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

Definition at line 314 of file nodeGraphPart_inl.h.

Referenced by populateNodes().

314 { __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 307 of file nodeGraphPart_inl.h.

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

307 { __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 303 of file nodeGraphPart_inl.h.

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

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

◆ emptyNodes()

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

indicates whether there exists nodes in the NodeGraphPart

Definition at line 301 of file nodeGraphPart_inl.h.

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

◆ end()

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

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

Definition at line 336 of file nodeGraphPart_inl.h.

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

◆ endSafe()

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

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

Definition at line 326 of file nodeGraphPart_inl.h.

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

◆ 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 293 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().

293  {
294  if (!existsNode(node)) return;
295 
296  __addHole(node);
297 
298  GUM_EMIT1(onNodeDeleted, node);
299  }
#define GUM_EMIT1(signal, arg1)
Definition: signaler1.h:40
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 289 of file nodeGraphPart_inl.h.

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

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

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

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

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

◆ nodes()

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

return *this as a NodeGraphPart

Definition at line 370 of file nodeGraphPart_inl.h.

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

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

◆ nodesProperty() [1/2]

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

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

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

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

◆ operator=()

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

copy operator

Parameters
pthe NodeGraphPart to be copied

Definition at line 216 of file nodeGraphPart_inl.h.

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

216  {
217  // avoid self assignment
218  if (this != &p) { populateNodes(p); }
219 
220  return *this;
221  }
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 340 of file nodeGraphPart_inl.h.

References __boundVal, and __holes.

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

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

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

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

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

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

◆ populateNodesFromProperty()

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

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

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

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

◆ toString()

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

a function to display the set of nodes

Definition at line 102 of file nodeGraphPart.cpp.

References __boundVal, and __inHoles().

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

102  {
103  std::stringstream s;
104  bool first = true;
105  s << "{";
106 
107  for (NodeId id = 0; id < __boundVal; ++id) {
108  if (__inHoles(id)) continue;
109 
110  if (first) {
111  first = false;
112  } else {
113  s << ",";
114  }
115 
116  s << id;
117  }
118 
119  s << "}";
120 
121  return s.str();
122  }
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:97
+ 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 467 of file nodeGraphPart.h.

◆ NodeGraphPartIterator

friend class NodeGraphPartIterator
friend

Definition at line 462 of file nodeGraphPart.h.

◆ NodeGraphPartIteratorSafe

friend class NodeGraphPartIteratorSafe
friend

Definition at line 463 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 511 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 508 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 499 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 505 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 502 of file nodeGraphPart.h.

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

◆ onNodeAdded

Signaler1< NodeId > gum::NodeGraphPart::onNodeAdded

Definition at line 271 of file nodeGraphPart.h.

Referenced by addNodeWithId().

◆ onNodeDeleted

Signaler1< NodeId > gum::NodeGraphPart::onNodeDeleted

Definition at line 272 of file nodeGraphPart.h.

Referenced by __clearNodes().


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