aGrUM  0.14.2
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 52 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 596 of file multiDimFunctionGraphManager_tpl.h.

References gum::MultiDimFunctionGraphROManager< GUM_SCALAR, TerminalNodePolicy >::~MultiDimFunctionGraphROManager().

Referenced by gum::MultiDimFunctionGraphTreeManager< GUM_SCALAR, TerminalNodePolicy >::reduce().

597  :
598  MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >(master) {
599  GUM_CONSTRUCTOR(MultiDimFunctionGraphROManager);
600  }
MultiDimFunctionGraphROManager(MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *master)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ~MultiDimFunctionGraphROManager()

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

Definition at line 604 of file multiDimFunctionGraphManager_tpl.h.

References gum::MultiDimFunctionGraphROManager< GUM_SCALAR, TerminalNodePolicy >::addInternalNode().

Referenced by gum::MultiDimFunctionGraphROManager< GUM_SCALAR, TerminalNodePolicy >::MultiDimFunctionGraphROManager().

604  {
605  GUM_DESTRUCTOR(MultiDimFunctionGraphROManager);
606  }
MultiDimFunctionGraphROManager(MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *master)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Function Documentation

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

Referenced by gum::MultiDimFunctionGraphManager< bool, ExactTerminalNodePolicy >::addInternalNode(), and gum::MultiDimFunctionGraphTreeManager< GUM_SCALAR, TerminalNodePolicy >::addInternalNode().

84  {
85  InternalNode* newNodeStruct = new InternalNode(var, sons);
86  NodeId nid = __functionGraph->__model.addNode();
87  __functionGraph->__internalNodeMap.insert(nid, newNodeStruct);
88  __functionGraph->__var2NodeIdMap[var]->addLink(nid);
89  for (Idx i = 0; i < newNodeStruct->nbSons(); i++)
90  if (!__functionGraph->isTerminalNode(sons[i]))
91  __functionGraph->__internalNodeMap[sons[i]]->addParent(nid, i);
92 
93  return nid;
94  }
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * __functionGraph
The multidimdecisiongraph supposed to be edited.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the caller graph for this function:

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

407  {
408  InternalNode* org = __functionGraph->__internalNodeMap[origin];
409  // Upating parents after the change
410  Link< Parent >* picle = org->parents();
411  while (picle != nullptr) {
412  setSon(picle->element().parentId, picle->element().modality, destination);
413  picle = picle->nextLink();
414  }
415 
416  // Updating sons after the change
417  for (Idx i = 0; i < org->nbSons(); ++i)
418  if (__functionGraph->__internalNodeMap.exists(org->son(i)))
419  __functionGraph->__internalNodeMap[org->son(i)]->removeParent(origin, i);
420 
421  delete org;
422  __functionGraph->__internalNodeMap.erase(origin);
423  __functionGraph->__model.eraseNode(origin);
424 
425  if (__functionGraph->root() == origin) this->setRootNode(destination);
426  }
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.

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

Referenced by gum::MultiDimFunctionGraphManager< bool, ExactTerminalNodePolicy >::_migrateNode(), and gum::MultiDimFunctionGraphROManager< GUM_SCALAR, TerminalNodePolicy >::addInternalNode().

432  {
433  NodeId newNode = sonsIds[0];
434 
435  if (__isRedundant(var, sonsIds)) {
436  SOA_DEALLOCATE(sonsIds, sizeof(NodeId) * var->domainSize());
437  } else {
438  newNode = __checkIsomorphism(var, sonsIds);
439  if (newNode == 0) {
440  newNode = _addInternalNode(var, sonsIds);
441  } else {
442  SOA_DEALLOCATE(sonsIds, sizeof(NodeId) * var->domainSize());
443  }
444  }
445 
446  return newNode;
447  }
#define SOA_DEALLOCATE(x, y)
bool __isRedundant(const DiscreteVariable *var, NodeId *sons)
Checks if node has the same child for every variable value.
NodeId _addInternalNode(const DiscreteVariable *var, NodeId *sons)
Adds an internal node.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
NodeId __checkIsomorphism(const DiscreteVariable *var, NodeId *sons)
Checks if a similar node does not already exists in the graph.
+ Here is the caller 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 485 of file multiDimFunctionGraphManager_tpl.h.

Referenced by gum::MultiDimFunctionGraphROManager< GUM_SCALAR, TerminalNodePolicy >::reduce().

485  {
486  Link< NodeId >* currentNodeId = nullptr;
487  Link< NodeId >* nextNodeId = nullptr;
488  InternalNode* currentNode = nullptr;
489  bool theSame = true;
490  Idx currentInd;
491 
492  for (SequenceIterator< const DiscreteVariable* > varIter =
493  __functionGraph->variablesSequence().rbegin();
494  varIter != __functionGraph->variablesSequence().rend();
495  --varIter) {
496  currentNodeId = __functionGraph->__var2NodeIdMap[*varIter]->list();
497 
498  while (currentNodeId != nullptr) {
499  nextNodeId = currentNodeId->nextLink();
500  currentNode = __functionGraph->__internalNodeMap[currentNodeId->element()];
501 
502  // First isomorphism to handle is the one where all node children are
503  // the same
504  theSame = true;
505  for (currentInd = 1; currentInd < (*varIter)->domainSize(); currentInd++) {
506  if (currentNode->son(currentInd) != currentNode->son(0)) {
507  theSame = false;
508  break;
509  }
510  }
511 
512  if (theSame == true) {
513  _migrateNode(currentNodeId->element(), currentNode->son(0));
514  __functionGraph->__var2NodeIdMap[*varIter]->searchAndRemoveLink(
515  currentNodeId->element());
516  currentNodeId = nextNodeId;
517  continue;
518  }
519 
520  // Second isomorphism to handle is the one where two nodes have same
521  // variable and same children
522  if (nextNodeId) {
523  Link< NodeId >* anotherNodeId = currentNodeId->nextLink();
524  InternalNode* anotherNode = nullptr;
525  Idx modality = 0;
526  while (anotherNodeId->nextLink() != nullptr) {
527  nextNodeId = anotherNodeId->nextLink();
528  anotherNode =
529  __functionGraph->__internalNodeMap[anotherNodeId->element()];
530 
531  // Check on the other sons
532  for (modality = 0; modality < (*varIter)->domainSize(); ++modality) {
533  if (anotherNode->son(modality) != currentNode->son(modality)) break;
534  if (modality == (*varIter)->domainSize() - 1) {
535  _migrateNode(anotherNodeId->element(), currentNodeId->element());
536  __functionGraph->__var2NodeIdMap[*varIter]->searchAndRemoveLink(
537  anotherNodeId->element());
538  }
539  }
540 
541  anotherNodeId = nextNodeId;
542  }
543  }
544  currentNodeId = currentNodeId->nextLink();
545  }
546  }
547  }
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:63
+ Here is the caller graph for this function:

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

Referenced by gum::StatesCounter::__incState(), gum::IMDDI< AttributeSelection, isScalar >::__insertLeafInFunctionGraph(), gum::ITI< AttributeSelection, isScalar >::__insertNodeInFunctionGraph(), gum::StatesChecker::__insertState(), gum::ITI< AttributeSelection, isScalar >::__insertTerminalNode(), gum::IMDDI< AttributeSelection, isScalar >::__rebuildFunctionGraph(), gum::AdaptiveRMaxPlaner::__visitLearner(), gum::MultiDimFunctionGraphManager< bool, ExactTerminalNodePolicy >::addInternalNode(), gum::FMDPFactory< GUM_SCALAR >::addInternalNode(), gum::MultiDimFunctionGraphGenerator::generate(), and gum::MultiDimFunctionGraphManager< bool, ExactTerminalNodePolicy >::setRootNode().

73  {
74  InternalNode* newNodeStruct = new InternalNode(var);
75  NodeId nid = __functionGraph->__model.addNode();
76  __functionGraph->__internalNodeMap.insert(nid, newNodeStruct);
77  __functionGraph->__var2NodeIdMap[var]->addLink(nid);
78 
79  return nid;
80  }
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * __functionGraph
The multidimdecisiongraph supposed to be edited.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the caller graph for this function:

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

61  {
62  InternalNode* newNodeStruct = new InternalNode(var);
63 
64  __functionGraph->__internalNodeMap.insert(nid, newNodeStruct);
65 
66  __functionGraph->__var2NodeIdMap[var]->addLink(nid);
67 
68  return nid;
69  }
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 610 of file multiDimFunctionGraphManager_tpl.h.

References gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::_nodeRedundancyCheck().

Referenced by gum::MultiDimFunctionGraphROManager< GUM_SCALAR, TerminalNodePolicy >::~MultiDimFunctionGraphROManager().

610  {
611  return this->_nodeRedundancyCheck(var, sons);
612  }
NodeId _nodeRedundancyCheck(const DiscreteVariable *var, NodeId *sonsMap)
Check for redundancy.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

Referenced by gum::StatesCounter::__incState(), gum::IMDDI< AttributeSelection, isScalar >::__insertLeafInFunctionGraph(), gum::ITI< AttributeSelection, isScalar >::__insertTerminalNode(), gum::AdaptiveRMaxPlaner::__visitLearner(), gum::MultiDimFunctionGraphManager< bool, ExactTerminalNodePolicy >::_addInternalNode(), gum::AdaptiveRMaxPlaner::_initVFunction(), gum::FMDPFactory< GUM_SCALAR >::addTerminalNode(), gum::MultiDimFunctionGraphGenerator::generate(), gum::StatesCounter::reset(), and gum::StatesChecker::reset().

99  {
100  if (__functionGraph->existsTerminalNodeWithValue(value))
101  return __functionGraph->terminalNodeId(value);
102 
103  NodeId node = __functionGraph->__model.addNode();
104  __functionGraph->addTerminalNode(node, value);
105  return node;
106  }
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * __functionGraph
The multidimdecisiongraph supposed to be edited.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the caller graph for this function:

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

Referenced by gum::FMDPFactory< GUM_SCALAR >::__finalizeFunctionGraph(), gum::AdaptiveRMaxPlaner::__makeRMaxFunctionGraphs(), gum::IMDDI< AttributeSelection, isScalar >::__rebuildFunctionGraph(), and gum::MultiDimFunctionGraphGenerator::generate().

551  {
552  Sequence< const DiscreteVariable* > oldSequence(
553  __functionGraph->variablesSequence());
554  for (SequenceIterator< const DiscreteVariable* > varIter = oldSequence.begin();
555  varIter != oldSequence.end();
556  ++varIter)
557  if (!__functionGraph->varNodeListe(*varIter)->list())
558  __functionGraph->erase(**varIter);
559  }
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * __functionGraph
The multidimdecisiongraph supposed to be edited.
+ Here is the caller graph for this function:

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

111  {
112  if (!__functionGraph->__model.exists(eraseId))
113  GUM_ERROR(NotFound, "Node : " << eraseId << " doesn't exists in the graph")
114 
115  if (__functionGraph->isTerminalNode(eraseId)) {
116  for (auto iterVar = __functionGraph->variablesSequence().begin();
117  iterVar != __functionGraph->variablesSequence().end();
118  ++iterVar) {
119  Link< NodeId >* nodeIter =
120  __functionGraph->__var2NodeIdMap[*iterVar]->list();
121  while (nodeIter != nullptr) {
122  for (Idx modality = 0; modality < (*iterVar)->domainSize(); ++modality)
123  if (__functionGraph->node(nodeIter->element())->son(modality)
124  == eraseId)
125  setSon(nodeIter->element(), modality, replacingId);
126 
127  nodeIter = nodeIter->nextLink();
128  }
129  }
130  __functionGraph->eraseTerminalNode(eraseId);
131 
132  } else {
133  InternalNode* eraseNode = __functionGraph->__internalNodeMap[eraseId];
134 
135  if (updateParents) {
136  Link< Parent >* picle = eraseNode->parents();
137  while (picle != nullptr) {
138  setSon(
139  picle->element().parentId, picle->element().modality, replacingId);
140  picle = picle->nextLink();
141  }
142  }
143 
145  ->__var2NodeIdMap[__functionGraph->__internalNodeMap[eraseId]->nodeVar()]
146  ->searchAndRemoveLink(eraseId);
147 
148  delete __functionGraph->__internalNodeMap[eraseId];
149  __functionGraph->__internalNodeMap.erase(eraseId);
150  }
151 
152  __functionGraph->__model.eraseNode(eraseId);
153 
154  if (__functionGraph->__root == eraseId) __functionGraph->__root = replacingId;
155  }
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:52

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

208  {
209  // Ordering variables by number of nodes asssociated to them
210  Sequence< const DiscreteVariable* > siftingSeq;
211  HashTable< const DiscreteVariable*, Idx > varLvlSize;
212  for (SequenceIteratorSafe< const DiscreteVariable* > varIter =
213  __functionGraph->variablesSequence().beginSafe();
214  varIter != __functionGraph->variablesSequence().endSafe();
215  ++varIter) {
216  const Link< NodeId >* curElem =
217  __functionGraph->__var2NodeIdMap[*varIter]->list();
218  Idx nbElem = 0;
219  for (; curElem != nullptr; nbElem++, curElem = curElem->nextLink())
220  ;
221  varLvlSize.insert(*varIter, nbElem);
222  siftingSeq.insert(*varIter);
223  Idx pos = siftingSeq.pos(*varIter);
224  while (pos > 0 && varLvlSize[siftingSeq.atPos(pos - 1)] > nbElem) {
225  siftingSeq.swap(pos - 1, pos);
226  pos--;
227  }
228  }
229 
230  // Sifting var par var
231  for (SequenceIteratorSafe< const DiscreteVariable* > sifIter =
232  siftingSeq.beginSafe();
233  sifIter != siftingSeq.endSafe();
234  ++sifIter) {
235  // Initialization
236  Idx currentPos = __functionGraph->variablesSequence().pos(*sifIter);
237  Idx bestSize = __functionGraph->realSize();
238  Idx bestPos = currentPos;
239 
240 
241  // Sifting towards upper places
242  while (currentPos > 0) {
243  moveTo(*sifIter, currentPos - 1);
244  currentPos = __functionGraph->variablesSequence().pos(*sifIter);
245  if (__functionGraph->realSize() < bestSize) {
246  bestPos = currentPos;
247  bestSize = __functionGraph->realSize();
248  }
249  }
250 
251  // Sifting towards lower places
252  while (currentPos < __functionGraph->variablesSequence().size() - 1) {
253  moveTo(*sifIter, currentPos + 1);
254  currentPos = __functionGraph->variablesSequence().pos(*sifIter);
255  if (__functionGraph->realSize() < bestSize) {
256  bestPos = currentPos;
257  bestSize = __functionGraph->realSize();
258  }
259  }
260 
261  moveTo(*sifIter, bestPos);
262  }
263  }
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 267 of file multiDimFunctionGraphManager_tpl.h.

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

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

References gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::_reduce().

615  {
616  this->_reduce();
617  }
void _reduce()
Ensures that every isomorphic subgraphs are merged together.
+ Here is the call graph for this function:

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

Referenced by gum::StatesCounter::__incState(), gum::StatesChecker::__insertState(), gum::AdaptiveRMaxPlaner::__makeRMaxFunctionGraphs(), gum::IMDDI< AttributeSelection, isScalar >::__rebuildFunctionGraph(), gum::AdaptiveRMaxPlaner::_initVFunction(), gum::StructuredPlaner< double >::_makeArgMax(), gum::MultiDimFunctionGraphGenerator::generate(), gum::StatesCounter::reset(), gum::FMDPFactory< GUM_SCALAR >::setRoot(), and gum::ITI< AttributeSelection, isScalar >::updateFunctionGraph().

54  {
55  __functionGraph->__root = root;
56  }
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * __functionGraph
The multidimdecisiongraph supposed to be edited.
+ Here is the caller graph for this function:

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

Referenced by gum::StatesCounter::__incState(), gum::ITI< AttributeSelection, isScalar >::__insertNodeInFunctionGraph(), gum::StatesChecker::__insertState(), gum::FMDPFactory< GUM_SCALAR >::addArc(), and gum::MultiDimFunctionGraphGenerator::generate().

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

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: