aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::MultiDimFunctionGraphROManager< GUM_SCALAR, TerminalNodePolicy > Class Template Reference

#include <multiDimFunctionGraph.h>

+ Inheritance diagram for gum::MultiDimFunctionGraphROManager< GUM_SCALAR, TerminalNodePolicy >:
+ Collaboration diagram for gum::MultiDimFunctionGraphROManager< GUM_SCALAR, TerminalNodePolicy >:

Public Member Functions

void clean ()
 Removes var without nodes in the diagram. More...
 
Inherited methods
virtual NodeId addInternalNode (const DiscreteVariable *var, NodeId *sons)
 Inserts a new non terminal node in graph. More...
 
virtual void reduce ()
 Ensures that every isomorphic subgraphs are merged together. More...
 

Protected Member Functions

Redundancy methods.
NodeId nodeRedundancyCheck_ (const DiscreteVariable *var, NodeId *sonsMap)
 Check for redundancy. More...
 
void reduce_ ()
 Ensures that every isomorphic subgraphs are merged together. More...
 

Friends

MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > * MultiDimFunctionGraph ()
 This friend methods from is the only way to get an instance of a manager. More...
 

Nodes manipulation methods.

void setRootNode (const NodeId &root)
 Sets root node of decision diagram. More...
 
NodeId addInternalNode (const DiscreteVariable *var)
 Inserts a new non terminal node in graph. More...
 
NodeId addInternalNode (const DiscreteVariable *var, NodeId nid)
 Inserts a new non terminal node in graph. More...
 
NodeId addTerminalNode (const GUM_SCALAR &value)
 Adds a value to the MultiDimFunctionGraph. More...
 
void eraseNode (NodeId id, NodeId replacingId=0, bool updateParents=true)
 Erases a node from the diagram. More...
 
NodeId addInternalNode_ (const DiscreteVariable *var, NodeId *sons)
 Adds an internal node. More...
 

Manipulation methods.

void setSon (const NodeId &node, const Idx &modality, const NodeId &sonNode)
 Sets nodes son for given modality to designated son node. More...
 
void minimizeSize ()
 Performs a sifting in search of a(local) minimal size. More...
 
void moveTo (const DiscreteVariable *x, Idx desiredPos)
 Changes var position in variable sequence. More...
 
void migrateNode_ (const NodeId &x, const NodeId &y)
 Remaps all arcs going to ou going from the first given node to the second node, then delete first node. More...
 

Constructor and destructor

 MultiDimFunctionGraphROManager (MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *master)
 
 ~MultiDimFunctionGraphROManager ()
 

Detailed Description

template<typename GUM_SCALAR, template< typename > class TerminalNodePolicy>
class gum::MultiDimFunctionGraphROManager< GUM_SCALAR, TerminalNodePolicy >

Definition at line 55 of file multiDimFunctionGraph.h.

Constructor & Destructor Documentation

◆ MultiDimFunctionGraphROManager()

template<typename GUM_SCALAR , template< class > class TerminalNodePolicy>
gum::MultiDimFunctionGraphROManager< GUM_SCALAR, TerminalNodePolicy >::MultiDimFunctionGraphROManager ( MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *  master)
private

Definition at line 578 of file multiDimFunctionGraphManager_tpl.h.

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

579  :
580  MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >(master) {
581  GUM_CONSTRUCTOR(MultiDimFunctionGraphROManager);
582  }
MultiDimFunctionGraphROManager(MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *master)
+ Here is the call graph for this function:

◆ ~MultiDimFunctionGraphROManager()

template<typename GUM_SCALAR , template< class > class TerminalNodePolicy>
gum::MultiDimFunctionGraphROManager< GUM_SCALAR, TerminalNodePolicy >::~MultiDimFunctionGraphROManager ( )

Definition at line 586 of file multiDimFunctionGraphManager_tpl.h.

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

586  {
587  GUM_DESTRUCTOR(MultiDimFunctionGraphROManager);
588  }
MultiDimFunctionGraphROManager(MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *master)
+ Here is the call graph for this function:

Member Function Documentation

◆ addInternalNode() [1/3]

template<typename GUM_SCALAR , template< class > class TerminalNodePolicy>
INLINE NodeId gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::addInternalNode ( const DiscreteVariable var)
inherited

Inserts a new non terminal node in graph.

NodeId of this node is generated automatically.

Parameters
varAssociated variable
Returns
The id of the added non terminal node.

Definition at line 75 of file multiDimFunctionGraphManager_tpl.h.

76  {
77  InternalNode* newNodeStruct = new InternalNode(var);
78  NodeId nid = _functionGraph_->_model_.addNode();
79  _functionGraph_->_internalNodeMap_.insert(nid, newNodeStruct);
80  _functionGraph_->_var2NodeIdMap_[var]->addLink(nid);
81 
82  return nid;
83  }
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * _functionGraph_
The multidimdecisiongraph supposed to be edited.
Size NodeId
Type for node ids.
Definition: graphElements.h:97

◆ addInternalNode() [2/3]

template<typename GUM_SCALAR , template< class > class TerminalNodePolicy>
INLINE NodeId gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::addInternalNode ( const DiscreteVariable var,
NodeId  nid 
)
inherited

Inserts a new non terminal node in graph.

NodeId of this node is generated automatically.

Parameters
varThe ssociated variable.
nidThe desired id for that node.
Returns
Returns the id of the added non terminal node.
Exceptions
OperationNotAllowedRaised if MultiDimFunctionGraph has no variable yet.

Definition at line 62 of file multiDimFunctionGraphManager_tpl.h.

64  {
65  InternalNode* newNodeStruct = new InternalNode(var);
66 
67  _functionGraph_->_internalNodeMap_.insert(nid, newNodeStruct);
68 
69  _functionGraph_->_var2NodeIdMap_[var]->addLink(nid);
70 
71  return nid;
72  }
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * _functionGraph_
The multidimdecisiongraph supposed to be edited.

◆ addInternalNode() [3/3]

template<typename GUM_SCALAR , template< class > class TerminalNodePolicy>
NodeId gum::MultiDimFunctionGraphROManager< GUM_SCALAR, TerminalNodePolicy >::addInternalNode ( const DiscreteVariable var,
NodeId sons 
)
virtual

Inserts a new non terminal node in graph.

NodeId of this node is generated automatically.

Parameters
varThe associated variable.
sonsA table of size var->domainSize() containing nodeid of sons nodes.
Returns
Returns the id of the added non terminal node.
Exceptions
OperationNotAllowedRaised if MultiDimFunctionGraph has no variable yet.

Implements gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >.

Definition at line 591 of file multiDimFunctionGraphManager_tpl.h.

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

593  {
594  return this->nodeRedundancyCheck_(var, sons);
595  }
NodeId nodeRedundancyCheck_(const DiscreteVariable *var, NodeId *sonsMap)
Check for redundancy.
+ Here is the call graph for this function:

◆ addInternalNode_()

template<typename GUM_SCALAR , template< class > class TerminalNodePolicy>
INLINE NodeId gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::addInternalNode_ ( const DiscreteVariable var,
NodeId sons 
)
protectedinherited

Adds an internal node.

Parameters
varThe node to add.
sonsThe node sons.
Returns
Returns the added node id.

Definition at line 86 of file multiDimFunctionGraphManager_tpl.h.

88  {
89  InternalNode* newNodeStruct = new InternalNode(var, sons);
90  NodeId nid = _functionGraph_->_model_.addNode();
91  _functionGraph_->_internalNodeMap_.insert(nid, newNodeStruct);
92  _functionGraph_->_var2NodeIdMap_[var]->addLink(nid);
93  for (Idx i = 0; i < newNodeStruct->nbSons(); i++)
94  if (!_functionGraph_->isTerminalNode(sons[i]))
95  _functionGraph_->_internalNodeMap_[sons[i]]->addParent(nid, i);
96 
97  return nid;
98  }
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * _functionGraph_
The multidimdecisiongraph supposed to be edited.
Size NodeId
Type for node ids.
Definition: graphElements.h:97

◆ addTerminalNode()

template<typename GUM_SCALAR, template< class > class TerminalNodePolicy>
INLINE NodeId gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::addTerminalNode ( const GUM_SCALAR &  value)
inherited

Adds a value to the MultiDimFunctionGraph.

This will create a terminal node, which of id is returned. If a terminal node with such value already exists, its id will be return instead.

Parameters
valueThe value added by copy.
Returns
Returns he id of the terminal node hence created.

Definition at line 102 of file multiDimFunctionGraphManager_tpl.h.

103  {
104  if (_functionGraph_->existsTerminalNodeWithValue(value))
105  return _functionGraph_->terminalNodeId(value);
106 
107  NodeId node = _functionGraph_->_model_.addNode();
108  _functionGraph_->addTerminalNode(node, value);
109  return node;
110  }
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * _functionGraph_
The multidimdecisiongraph supposed to be edited.
Size NodeId
Type for node ids.
Definition: graphElements.h:97

◆ clean()

template<typename GUM_SCALAR , template< class > class TerminalNodePolicy>
INLINE void gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::clean ( )
inherited

Removes var without nodes in the diagram.

Definition at line 537 of file multiDimFunctionGraphManager_tpl.h.

537  {
538  Sequence< const DiscreteVariable* > oldSequence(_functionGraph_->variablesSequence());
539  for (SequenceIterator< const DiscreteVariable* > varIter = oldSequence.begin();
540  varIter != oldSequence.end();
541  ++varIter)
542  if (!_functionGraph_->varNodeListe(*varIter)->list()) _functionGraph_->erase(**varIter);
543  }
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * _functionGraph_
The multidimdecisiongraph supposed to be edited.

◆ eraseNode()

template<typename GUM_SCALAR , template< class > class TerminalNodePolicy>
void gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::eraseNode ( NodeId  id,
NodeId  replacingId = 0,
bool  updateParents = true 
)
inherited

Erases a node from the diagram.

Parameters
idThe id of the variable to erase.
replacingIdOffers the possibility to reroute any parent to the given node.
updateParentsIndicates if such remapping has to be done.
Exceptions
NotFoundRaised if node isn't in diagram.

Definition at line 115 of file multiDimFunctionGraphManager_tpl.h.

117  {
118  if (!_functionGraph_->_model_.exists(eraseId))
119  GUM_ERROR(NotFound, "Node : " << eraseId << " doesn't exists in the graph")
120 
121  if (_functionGraph_->isTerminalNode(eraseId)) {
122  for (auto iterVar = _functionGraph_->variablesSequence().begin();
123  iterVar != _functionGraph_->variablesSequence().end();
124  ++iterVar) {
125  Link< NodeId >* nodeIter = _functionGraph_->_var2NodeIdMap_[*iterVar]->list();
126  while (nodeIter != nullptr) {
127  for (Idx modality = 0; modality < (*iterVar)->domainSize(); ++modality)
128  if (_functionGraph_->node(nodeIter->element())->son(modality) == eraseId)
129  setSon(nodeIter->element(), modality, replacingId);
130 
131  nodeIter = nodeIter->nextLink();
132  }
133  }
134  _functionGraph_->eraseTerminalNode(eraseId);
135 
136  } else {
137  InternalNode* eraseNode = _functionGraph_->_internalNodeMap_[eraseId];
138 
139  if (updateParents) {
140  Link< Parent >* picle = eraseNode->parents();
141  while (picle != nullptr) {
142  setSon(picle->element().parentId, picle->element().modality, replacingId);
143  picle = picle->nextLink();
144  }
145  }
146 
147  _functionGraph_->_var2NodeIdMap_[_functionGraph_->_internalNodeMap_[eraseId]->nodeVar()]
148  ->searchAndRemoveLink(eraseId);
149 
150  delete _functionGraph_->_internalNodeMap_[eraseId];
151  _functionGraph_->_internalNodeMap_.erase(eraseId);
152  }
153 
154  _functionGraph_->_model_.eraseNode(eraseId);
155 
156  if (_functionGraph_->_root_ == eraseId) _functionGraph_->_root_ = replacingId;
157  }
void setSon(const NodeId &node, const Idx &modality, const NodeId &sonNode)
Sets nodes son for given modality to designated son node.
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * _functionGraph_
The multidimdecisiongraph supposed to be edited.
void eraseNode(NodeId id, NodeId replacingId=0, bool updateParents=true)
Erases a node from the diagram.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ migrateNode_()

template<typename GUM_SCALAR , template< class > class TerminalNodePolicy>
INLINE void gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::migrateNode_ ( const NodeId x,
const NodeId y 
)
protectedinherited

Remaps all arcs going to ou going from the first given node to the second node, then delete first node.

Parameters
xThe variable from which all arcs are removed.
yThe variable for which all of x arcs are added.

Definition at line 392 of file multiDimFunctionGraphManager_tpl.h.

394  {
395  InternalNode* org = _functionGraph_->_internalNodeMap_[origin];
396  // Upating parents after the change
397  Link< Parent >* picle = org->parents();
398  while (picle != nullptr) {
399  setSon(picle->element().parentId, picle->element().modality, destination);
400  picle = picle->nextLink();
401  }
402 
403  // Updating sons after the change
404  for (Idx i = 0; i < org->nbSons(); ++i)
405  if (_functionGraph_->_internalNodeMap_.exists(org->son(i)))
406  _functionGraph_->_internalNodeMap_[org->son(i)]->removeParent(origin, i);
407 
408  delete org;
409  _functionGraph_->_internalNodeMap_.erase(origin);
410  _functionGraph_->_model_.eraseNode(origin);
411 
412  if (_functionGraph_->root() == origin) this->setRootNode(destination);
413  }
void setSon(const NodeId &node, const Idx &modality, const NodeId &sonNode)
Sets nodes son for given modality to designated son node.
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * _functionGraph_
The multidimdecisiongraph supposed to be edited.
void setRootNode(const NodeId &root)
Sets root node of decision diagram.

◆ minimizeSize()

template<typename GUM_SCALAR , template< class > class TerminalNodePolicy>
void gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::minimizeSize ( )
inherited

Performs a sifting in search of a(local) minimal size.

Definition at line 204 of file multiDimFunctionGraphManager_tpl.h.

204  {
205  // Ordering variables by number of nodes asssociated to them
206  Sequence< const DiscreteVariable* > siftingSeq;
207  HashTable< const DiscreteVariable*, Idx > varLvlSize;
208  for (SequenceIteratorSafe< const DiscreteVariable* > varIter
209  = _functionGraph_->variablesSequence().beginSafe();
210  varIter != _functionGraph_->variablesSequence().endSafe();
211  ++varIter) {
212  const Link< NodeId >* curElem = _functionGraph_->_var2NodeIdMap_[*varIter]->list();
213  Idx nbElem = 0;
214  for (; curElem != nullptr; nbElem++, curElem = curElem->nextLink())
215  ;
216  varLvlSize.insert(*varIter, nbElem);
217  siftingSeq.insert(*varIter);
218  Idx pos = siftingSeq.pos(*varIter);
219  while (pos > 0 && varLvlSize[siftingSeq.atPos(pos - 1)] > nbElem) {
220  siftingSeq.swap(pos - 1, pos);
221  pos--;
222  }
223  }
224 
225  // Sifting var par var
226  for (SequenceIteratorSafe< const DiscreteVariable* > sifIter = siftingSeq.beginSafe();
227  sifIter != siftingSeq.endSafe();
228  ++sifIter) {
229  // Initialization
230  Idx currentPos = _functionGraph_->variablesSequence().pos(*sifIter);
231  Idx bestSize = _functionGraph_->realSize();
232  Idx bestPos = currentPos;
233 
234 
235  // Sifting towards upper places
236  while (currentPos > 0) {
237  moveTo(*sifIter, currentPos - 1);
238  currentPos = _functionGraph_->variablesSequence().pos(*sifIter);
239  if (_functionGraph_->realSize() < bestSize) {
240  bestPos = currentPos;
241  bestSize = _functionGraph_->realSize();
242  }
243  }
244 
245  // Sifting towards lower places
246  while (currentPos < _functionGraph_->variablesSequence().size() - 1) {
247  moveTo(*sifIter, currentPos + 1);
248  currentPos = _functionGraph_->variablesSequence().pos(*sifIter);
249  if (_functionGraph_->realSize() < bestSize) {
250  bestPos = currentPos;
251  bestSize = _functionGraph_->realSize();
252  }
253  }
254 
255  moveTo(*sifIter, bestPos);
256  }
257  }
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * _functionGraph_
The multidimdecisiongraph supposed to be edited.
void moveTo(const DiscreteVariable *x, Idx desiredPos)
Changes var position in variable sequence.

◆ moveTo()

template<typename GUM_SCALAR , template< class > class TerminalNodePolicy>
void gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::moveTo ( const DiscreteVariable x,
Idx  desiredPos 
)
inherited

Changes var position in variable sequence.

Parameters
xThe varaible to change.
desiredPosThe new posiition.

Definition at line 261 of file multiDimFunctionGraphManager_tpl.h.

263  {
264  // First we determine the position of both variable
265  // We also determine which one precede the other
266  if (_functionGraph_->variablesSequence().pos(movedVar) > desiredPos)
267  for (Idx currentPos = _functionGraph_->variablesSequence().pos(movedVar);
268  currentPos != desiredPos;
269  currentPos--) {
270  const DiscreteVariable* preVar = _functionGraph_->variablesSequence().atPos(currentPos - 1);
271  if (_functionGraph_->_var2NodeIdMap_[preVar]->list()
272  && _functionGraph_->_var2NodeIdMap_[movedVar]->list())
273  _adjacentSwap_(preVar, movedVar);
274  _functionGraph_->invert_(currentPos - 1, currentPos);
275  }
276  else
277  for (Idx currentPos = _functionGraph_->variablesSequence().pos(movedVar);
278  currentPos != desiredPos;
279  currentPos++) {
280  const DiscreteVariable* suiVar = _functionGraph_->variablesSequence().atPos(currentPos + 1);
281  if (_functionGraph_->_var2NodeIdMap_[suiVar]->list()
282  && _functionGraph_->_var2NodeIdMap_[movedVar]->list())
283  _adjacentSwap_(movedVar, suiVar);
284  _functionGraph_->invert_(currentPos, currentPos + 1);
285  }
286  }
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * _functionGraph_
The multidimdecisiongraph supposed to be edited.
void _adjacentSwap_(const DiscreteVariable *x, const DiscreteVariable *y)
Swap two adjacent variable.

◆ nodeRedundancyCheck_()

template<typename GUM_SCALAR , template< class > class TerminalNodePolicy>
INLINE NodeId gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::nodeRedundancyCheck_ ( const DiscreteVariable var,
NodeId sonsMap 
)
protectedinherited

Check for redundancy.

Checks if a similar node does not already exists in the graph or if it has the same child for every variable value. If no node is a match, this node is added to the graph.

Warning
: will free by itslef sonsMap if a match exists.
Parameters
varThe node to add in the graph.
sonsMapThe node sons.
Returns
Returns the nodes id in the graph.

Definition at line 419 of file multiDimFunctionGraphManager_tpl.h.

421  {
422  NodeId newNode = sonsIds[0];
423 
424  if (_isRedundant_(var, sonsIds)) {
425  SOA_DEALLOCATE(sonsIds, sizeof(NodeId) * var->domainSize());
426  } else {
427  newNode = _checkIsomorphism_(var, sonsIds);
428  if (newNode == 0) {
429  newNode = addInternalNode_(var, sonsIds);
430  } else {
431  SOA_DEALLOCATE(sonsIds, sizeof(NodeId) * var->domainSize());
432  }
433  }
434 
435  return newNode;
436  }
NodeId _checkIsomorphism_(const DiscreteVariable *var, NodeId *sons)
Checks if a similar node does not already exists in the graph.
bool _isRedundant_(const DiscreteVariable *var, NodeId *sons)
Checks if node has the same child for every variable value.
#define SOA_DEALLOCATE(x, y)
NodeId addInternalNode_(const DiscreteVariable *var, NodeId *sons)
Adds an internal node.
Size NodeId
Type for node ids.
Definition: graphElements.h:97

◆ reduce()

template<typename GUM_SCALAR , template< class > class TerminalNodePolicy>
void gum::MultiDimFunctionGraphROManager< GUM_SCALAR, TerminalNodePolicy >::reduce ( )
virtual

Ensures that every isomorphic subgraphs are merged together.

Implements gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >.

Definition at line 598 of file multiDimFunctionGraphManager_tpl.h.

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

598  {
599  this->reduce_();
600  }
void reduce_()
Ensures that every isomorphic subgraphs are merged together.
+ Here is the call graph for this function:

◆ reduce_()

template<typename GUM_SCALAR , template< class > class TerminalNodePolicy>
INLINE void gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::reduce_ ( )
protectedinherited

Ensures that every isomorphic subgraphs are merged together.

Definition at line 474 of file multiDimFunctionGraphManager_tpl.h.

474  {
475  Link< NodeId >* currentNodeId = nullptr;
476  Link< NodeId >* nextNodeId = nullptr;
477  InternalNode* currentNode = nullptr;
478  bool theSame = true;
479  Idx currentInd;
480 
481  for (SequenceIterator< const DiscreteVariable* > varIter
482  = _functionGraph_->variablesSequence().rbegin();
483  varIter != _functionGraph_->variablesSequence().rend();
484  --varIter) {
485  currentNodeId = _functionGraph_->_var2NodeIdMap_[*varIter]->list();
486 
487  while (currentNodeId != nullptr) {
488  nextNodeId = currentNodeId->nextLink();
489  currentNode = _functionGraph_->_internalNodeMap_[currentNodeId->element()];
490 
491  // First isomorphism to handle is the one where all node children are
492  // the same
493  theSame = true;
494  for (currentInd = 1; currentInd < (*varIter)->domainSize(); currentInd++) {
495  if (currentNode->son(currentInd) != currentNode->son(0)) {
496  theSame = false;
497  break;
498  }
499  }
500 
501  if (theSame == true) {
502  migrateNode_(currentNodeId->element(), currentNode->son(0));
503  _functionGraph_->_var2NodeIdMap_[*varIter]->searchAndRemoveLink(currentNodeId->element());
504  currentNodeId = nextNodeId;
505  continue;
506  }
507 
508  // Second isomorphism to handle is the one where two nodes have same
509  // variable and same children
510  if (nextNodeId) {
511  Link< NodeId >* anotherNodeId = currentNodeId->nextLink();
512  InternalNode* anotherNode = nullptr;
513  Idx modality = 0;
514  while (anotherNodeId->nextLink() != nullptr) {
515  nextNodeId = anotherNodeId->nextLink();
516  anotherNode = _functionGraph_->_internalNodeMap_[anotherNodeId->element()];
517 
518  // Check on the other sons
519  for (modality = 0; modality < (*varIter)->domainSize(); ++modality) {
520  if (anotherNode->son(modality) != currentNode->son(modality)) break;
521  if (modality == (*varIter)->domainSize() - 1) {
522  migrateNode_(anotherNodeId->element(), currentNodeId->element());
523  _functionGraph_->_var2NodeIdMap_[*varIter]->searchAndRemoveLink(
524  anotherNodeId->element());
525  }
526  }
527 
528  anotherNodeId = nextNodeId;
529  }
530  }
531  currentNodeId = currentNodeId->nextLink();
532  }
533  }
534  }
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * _functionGraph_
The multidimdecisiongraph supposed to be edited.
void migrateNode_(const NodeId &x, const NodeId &y)
Remaps all arcs going to ou going from the first given node to the second node, then delete first nod...
NodeId nextNodeId()
Returns the next value of an unique counter for PRM&#39;s node id.
Definition: utils_prm.cpp:64

◆ setRootNode()

template<typename GUM_SCALAR , template< class > class TerminalNodePolicy>
INLINE void gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::setRootNode ( const NodeId root)
inherited

Sets root node of decision diagram.

Parameters
rootThe node to set as root.

Definition at line 55 of file multiDimFunctionGraphManager_tpl.h.

56  {
57  _functionGraph_->_root_ = root;
58  }
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * _functionGraph_
The multidimdecisiongraph supposed to be edited.

◆ setSon()

template<typename GUM_SCALAR , template< class > class TerminalNodePolicy>
INLINE void gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::setSon ( const NodeId node,
const Idx modality,
const NodeId sonNode 
)
inherited

Sets nodes son for given modality to designated son node.

Parameters
nodeThe node to which a node is added.
modalityThe modality for which sonNode is added to node.
sonNodeThe node to add as a son to node.

Definition at line 162 of file multiDimFunctionGraphManager_tpl.h.

164  {
165  // Ensuring that both nodes exists in the graph
166  if (!_functionGraph_->_model_.exists(node))
167  GUM_ERROR(NotFound, "Node : " << node << " doesn't exists in the graph")
168  if (!_functionGraph_->_model_.exists(sonNode))
169  GUM_ERROR(NotFound, "Node : " << sonNode << " doesn't exists in the graph")
170 
171  // Check if starting node is not terminal
172  if (_functionGraph_->isTerminalNode(node))
173  GUM_ERROR(InvalidNode, "You cannot insert an arc from terminal node : " << node)
174 
175  // Check if associated modality is lower than node bound variable domain
176  // size
177  if (_functionGraph_->isInternalNode(node)
178  && modality > _functionGraph_->_internalNodeMap_[node]->nodeVar()->domainSize() - 1)
179  GUM_ERROR(InvalidArgument,
180  "Modality " << modality << "is higher than domain size "
181  << _functionGraph_->_internalNodeMap_[node]->nodeVar()->domainSize()
182  << "minus 1 of variable "
183  << _functionGraph_->_internalNodeMap_[node]->nodeVar()->name())
184 
185  // Check if variable order is respected
186  if (_functionGraph_->isInternalNode(sonNode)
187  && _functionGraph_->variablesSequence().pos(
188  _functionGraph_->_internalNodeMap_[node]->nodeVar())
189  >= _functionGraph_->variablesSequence().pos(
190  _functionGraph_->_internalNodeMap_[sonNode]->nodeVar()))
191  GUM_ERROR(OperationNotAllowed,
192  "Variable " << _functionGraph_->_internalNodeMap_[node]->nodeVar()
193  << " is after variable "
194  << _functionGraph_->_internalNodeMap_[sonNode]->nodeVar()
195  << "in Function Graph order.")
196 
197  _functionGraph_->_internalNodeMap_[node]->setSon(modality, sonNode);
198  if (sonNode && !_functionGraph_->isTerminalNode(sonNode))
199  _functionGraph_->_internalNodeMap_[sonNode]->addParent(node, modality);
200  }
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * _functionGraph_
The multidimdecisiongraph supposed to be edited.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

Friends And Related Function Documentation

◆ MultiDimFunctionGraph

template<typename GUM_SCALAR , template< typename > class TerminalNodePolicy>
MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >* MultiDimFunctionGraph ( )
friend

This friend methods from is the only way to get an instance of a manager.


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