aGrUM  0.20.2
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 607 of file multiDimFunctionGraphManager_tpl.h.

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

608  :
609  MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >(master) {
610  GUM_CONSTRUCTOR(MultiDimFunctionGraphROManager);
611  }
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 615 of file multiDimFunctionGraphManager_tpl.h.

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

615  {
616  GUM_DESTRUCTOR(MultiDimFunctionGraphROManager);
617  }
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 76 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 64 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 621 of file multiDimFunctionGraphManager_tpl.h.

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

621  {
622  return this->nodeRedundancyCheck_(var, sons);
623  }
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 87 of file multiDimFunctionGraphManager_tpl.h.

87  {
88  InternalNode* newNodeStruct = new InternalNode(var, sons);
89  NodeId nid = functionGraph__->model__.addNode();
90  functionGraph__->internalNodeMap__.insert(nid, newNodeStruct);
91  functionGraph__->var2NodeIdMap__[var]->addLink(nid);
92  for (Idx i = 0; i < newNodeStruct->nbSons(); i++)
93  if (!functionGraph__->isTerminalNode(sons[i]))
94  functionGraph__->internalNodeMap__[sons[i]]->addParent(nid, i);
95 
96  return nid;
97  }
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.

102  {
103  if (functionGraph__->existsTerminalNodeWithValue(value))
104  return functionGraph__->terminalNodeId(value);
105 
106  NodeId node = functionGraph__->model__.addNode();
107  functionGraph__->addTerminalNode(node, value);
108  return node;
109  }
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 562 of file multiDimFunctionGraphManager_tpl.h.

562  {
563  Sequence< const DiscreteVariable* > oldSequence(
564  functionGraph__->variablesSequence());
565  for (SequenceIterator< const DiscreteVariable* > varIter = oldSequence.begin();
566  varIter != oldSequence.end();
567  ++varIter)
568  if (!functionGraph__->varNodeListe(*varIter)->list())
569  functionGraph__->erase(**varIter);
570  }
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 113 of file multiDimFunctionGraphManager_tpl.h.

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

◆ 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 415 of file multiDimFunctionGraphManager_tpl.h.

417  {
418  InternalNode* org = functionGraph__->internalNodeMap__[origin];
419  // Upating parents after the change
420  Link< Parent >* picle = org->parents();
421  while (picle != nullptr) {
422  setSon(picle->element().parentId, picle->element().modality, destination);
423  picle = picle->nextLink();
424  }
425 
426  // Updating sons after the change
427  for (Idx i = 0; i < org->nbSons(); ++i)
428  if (functionGraph__->internalNodeMap__.exists(org->son(i)))
429  functionGraph__->internalNodeMap__[org->son(i)]->removeParent(origin, i);
430 
431  delete org;
432  functionGraph__->internalNodeMap__.erase(origin);
433  functionGraph__->model__.eraseNode(origin);
434 
435  if (functionGraph__->root() == origin) this->setRootNode(destination);
436  }
void setSon(const NodeId &node, const Idx &modality, const NodeId &sonNode)
Sets nodes son for given modality to designated son node.
void setRootNode(const NodeId &root)
Sets root node of decision diagram.
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * functionGraph__
The multidimdecisiongraph supposed to be edited.

◆ 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 216 of file multiDimFunctionGraphManager_tpl.h.

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

◆ 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 275 of file multiDimFunctionGraphManager_tpl.h.

277  {
278  // First we determine the position of both variable
279  // We also determine which one precede the other
280  if (functionGraph__->variablesSequence().pos(movedVar) > desiredPos)
281  for (Idx currentPos = functionGraph__->variablesSequence().pos(movedVar);
282  currentPos != desiredPos;
283  currentPos--) {
284  const DiscreteVariable* preVar
285  = functionGraph__->variablesSequence().atPos(currentPos - 1);
286  if (functionGraph__->var2NodeIdMap__[preVar]->list()
287  && functionGraph__->var2NodeIdMap__[movedVar]->list())
288  adjacentSwap__(preVar, movedVar);
289  functionGraph__->invert_(currentPos - 1, currentPos);
290  }
291  else
292  for (Idx currentPos = functionGraph__->variablesSequence().pos(movedVar);
293  currentPos != desiredPos;
294  currentPos++) {
295  const DiscreteVariable* suiVar
296  = functionGraph__->variablesSequence().atPos(currentPos + 1);
297  if (functionGraph__->var2NodeIdMap__[suiVar]->list()
298  && functionGraph__->var2NodeIdMap__[movedVar]->list())
299  adjacentSwap__(movedVar, suiVar);
300  functionGraph__->invert_(currentPos, currentPos + 1);
301  }
302  }
void adjacentSwap__(const DiscreteVariable *x, const DiscreteVariable *y)
Swap two adjacent variable.
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * functionGraph__
The multidimdecisiongraph supposed to be edited.

◆ 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 442 of file multiDimFunctionGraphManager_tpl.h.

442  {
443  NodeId newNode = sonsIds[0];
444 
445  if (isRedundant__(var, sonsIds)) {
446  SOA_DEALLOCATE(sonsIds, sizeof(NodeId) * var->domainSize());
447  } else {
448  newNode = checkIsomorphism__(var, sonsIds);
449  if (newNode == 0) {
450  newNode = addInternalNode_(var, sonsIds);
451  } else {
452  SOA_DEALLOCATE(sonsIds, sizeof(NodeId) * var->domainSize());
453  }
454  }
455 
456  return newNode;
457  }
NodeId checkIsomorphism__(const DiscreteVariable *var, NodeId *sons)
Checks if a similar node does not already exists in the graph.
#define SOA_DEALLOCATE(x, y)
NodeId addInternalNode_(const DiscreteVariable *var, NodeId *sons)
Adds an internal node.
bool isRedundant__(const DiscreteVariable *var, NodeId *sons)
Checks if node has the same child for every variable value.
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 626 of file multiDimFunctionGraphManager_tpl.h.

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

626  {
627  this->reduce_();
628  }
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 496 of file multiDimFunctionGraphManager_tpl.h.

496  {
497  Link< NodeId >* currentNodeId = nullptr;
498  Link< NodeId >* nextNodeId = nullptr;
499  InternalNode* currentNode = nullptr;
500  bool theSame = true;
501  Idx currentInd;
502 
503  for (SequenceIterator< const DiscreteVariable* > varIter
504  = functionGraph__->variablesSequence().rbegin();
505  varIter != functionGraph__->variablesSequence().rend();
506  --varIter) {
507  currentNodeId = functionGraph__->var2NodeIdMap__[*varIter]->list();
508 
509  while (currentNodeId != nullptr) {
510  nextNodeId = currentNodeId->nextLink();
511  currentNode = functionGraph__->internalNodeMap__[currentNodeId->element()];
512 
513  // First isomorphism to handle is the one where all node children are
514  // the same
515  theSame = true;
516  for (currentInd = 1; currentInd < (*varIter)->domainSize(); currentInd++) {
517  if (currentNode->son(currentInd) != currentNode->son(0)) {
518  theSame = false;
519  break;
520  }
521  }
522 
523  if (theSame == true) {
524  migrateNode_(currentNodeId->element(), currentNode->son(0));
525  functionGraph__->var2NodeIdMap__[*varIter]->searchAndRemoveLink(
526  currentNodeId->element());
527  currentNodeId = nextNodeId;
528  continue;
529  }
530 
531  // Second isomorphism to handle is the one where two nodes have same
532  // variable and same children
533  if (nextNodeId) {
534  Link< NodeId >* anotherNodeId = currentNodeId->nextLink();
535  InternalNode* anotherNode = nullptr;
536  Idx modality = 0;
537  while (anotherNodeId->nextLink() != nullptr) {
538  nextNodeId = anotherNodeId->nextLink();
539  anotherNode
540  = functionGraph__->internalNodeMap__[anotherNodeId->element()];
541 
542  // Check on the other sons
543  for (modality = 0; modality < (*varIter)->domainSize(); ++modality) {
544  if (anotherNode->son(modality) != currentNode->son(modality)) break;
545  if (modality == (*varIter)->domainSize() - 1) {
546  migrateNode_(anotherNodeId->element(), currentNodeId->element());
547  functionGraph__->var2NodeIdMap__[*varIter]->searchAndRemoveLink(
548  anotherNodeId->element());
549  }
550  }
551 
552  anotherNodeId = nextNodeId;
553  }
554  }
555  currentNodeId = currentNodeId->nextLink();
556  }
557  }
558  }
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
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * functionGraph__
The multidimdecisiongraph supposed to be edited.

◆ 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 56 of file multiDimFunctionGraphManager_tpl.h.

57  {
58  functionGraph__->root__ = root;
59  }
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 166 of file multiDimFunctionGraphManager_tpl.h.

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

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: