aGrUM  0.16.0
gum::MultiDimFunctionGraphTreeManager< GUM_SCALAR, TerminalNodePolicy > Class Template Reference

#include <multiDimFunctionGraph.h>

+ Inheritance diagram for gum::MultiDimFunctionGraphTreeManager< GUM_SCALAR, TerminalNodePolicy >:
+ Collaboration diagram for gum::MultiDimFunctionGraphTreeManager< 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

 MultiDimFunctionGraphTreeManager (MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *master)
 Class constructor. More...
 
 ~MultiDimFunctionGraphTreeManager ()
 Class destructor. More...
 

Detailed Description

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

Warning
Doxygen does not like spanning command on multiple line, so we could not configure it with the correct include directive. Use the following code snippet to include this file.
Template Parameters
GUM_SCALARThe type of scalars stored in the multidimensional table.
TerminalNodePolicyThe terminal node policy to use.

Definition at line 58 of file multiDimFunctionGraph.h.

Constructor & Destructor Documentation

◆ MultiDimFunctionGraphTreeManager()

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

Class constructor.

Definition at line 570 of file multiDimFunctionGraphManager_tpl.h.

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

Referenced by gum::MultiDimFunctionGraphManager< bool, ExactTerminalNodePolicy >::clean().

571  :
572  MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >(master) {
573  GUM_CONSTRUCTOR(MultiDimFunctionGraphTreeManager);
574  }
MultiDimFunctionGraphTreeManager(MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *master)
Class constructor.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ~MultiDimFunctionGraphTreeManager()

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

Class destructor.

Definition at line 578 of file multiDimFunctionGraphManager_tpl.h.

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

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

578  {
579  GUM_DESTRUCTOR(MultiDimFunctionGraphTreeManager);
580  }
MultiDimFunctionGraphTreeManager(MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *master)
Class constructor.
+ 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 87 of file multiDimFunctionGraphManager_tpl.h.

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

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:98
+ 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 409 of file multiDimFunctionGraphManager_tpl.h.

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

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

435  {
436  NodeId newNode = sonsIds[0];
437 
438  if (__isRedundant(var, sonsIds)) {
439  SOA_DEALLOCATE(sonsIds, sizeof(NodeId) * var->domainSize());
440  } else {
441  newNode = __checkIsomorphism(var, sonsIds);
442  if (newNode == 0) {
443  newNode = _addInternalNode(var, sonsIds);
444  } else {
445  SOA_DEALLOCATE(sonsIds, sizeof(NodeId) * var->domainSize());
446  }
447  }
448 
449  return newNode;
450  }
#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:98
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 488 of file multiDimFunctionGraphManager_tpl.h.

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

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

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:98
+ 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 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::MultiDimFunctionGraphTreeManager< 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 584 of file multiDimFunctionGraphManager_tpl.h.

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

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

584  {
585  return this->_addInternalNode(var, sons);
586  }
NodeId _addInternalNode(const DiscreteVariable *var, NodeId *sons)
Adds an internal node.
+ 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 102 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().

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:98
+ 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 554 of file multiDimFunctionGraphManager_tpl.h.

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

554  {
555  Sequence< const DiscreteVariable* > oldSequence(
556  __functionGraph->variablesSequence());
557  for (SequenceIterator< const DiscreteVariable* > varIter = oldSequence.begin();
558  varIter != oldSequence.end();
559  ++varIter)
560  if (!__functionGraph->varNodeListe(*varIter)->list())
561  __functionGraph->erase(**varIter);
562  }
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 113 of file multiDimFunctionGraphManager_tpl.h.

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

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

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

271  {
272  // First we determine the position of both variable
273  // We also determine which one precede the other
274  if (__functionGraph->variablesSequence().pos(movedVar) > desiredPos)
275  for (Idx currentPos = __functionGraph->variablesSequence().pos(movedVar);
276  currentPos != desiredPos;
277  currentPos--) {
278  const DiscreteVariable* preVar =
279  __functionGraph->variablesSequence().atPos(currentPos - 1);
280  if (__functionGraph->__var2NodeIdMap[preVar]->list()
281  && __functionGraph->__var2NodeIdMap[movedVar]->list())
282  __adjacentSwap(preVar, movedVar);
283  __functionGraph->_invert(currentPos - 1, currentPos);
284  }
285  else
286  for (Idx currentPos = __functionGraph->variablesSequence().pos(movedVar);
287  currentPos != desiredPos;
288  currentPos++) {
289  const DiscreteVariable* suiVar =
290  __functionGraph->variablesSequence().atPos(currentPos + 1);
291  if (__functionGraph->__var2NodeIdMap[suiVar]->list()
292  && __functionGraph->__var2NodeIdMap[movedVar]->list())
293  __adjacentSwap(movedVar, suiVar);
294  __functionGraph->_invert(currentPos, currentPos + 1);
295  }
296  }
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::MultiDimFunctionGraphTreeManager< GUM_SCALAR, TerminalNodePolicy >::reduce ( )
virtual

Ensures that every isomorphic subgraphs are merged together.

Implements gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >.

Definition at line 590 of file multiDimFunctionGraphManager_tpl.h.

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

590  {
591  }
+ 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 56 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().

57  {
58  __functionGraph->__root = root;
59  }
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 163 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().

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,
174  "You cannot insert an arc from terminal node : " << node)
175 
176  // Check if associated modality is lower than node bound variable domain
177  // size
178  if (__functionGraph->isInternalNode(node)
179  && modality
180  > __functionGraph->__internalNodeMap[node]->nodeVar()->domainSize()
181  - 1)
182  GUM_ERROR(
183  InvalidArgument,
184  "Modality "
185  << modality << "is higher than domain size "
186  << __functionGraph->__internalNodeMap[node]->nodeVar()->domainSize()
187  << "minus 1 of variable "
188  << __functionGraph->__internalNodeMap[node]->nodeVar()->name())
189 
190  // Check if variable order is respected
191  if (__functionGraph->isInternalNode(sonNode)
192  && __functionGraph->variablesSequence().pos(
193  __functionGraph->__internalNodeMap[node]->nodeVar())
194  >= __functionGraph->variablesSequence().pos(
195  __functionGraph->__internalNodeMap[sonNode]->nodeVar()))
196  GUM_ERROR(
197  OperationNotAllowed,
198  "Variable " << __functionGraph->__internalNodeMap[node]->nodeVar()
199  << " is after variable "
200  << __functionGraph->__internalNodeMap[sonNode]->nodeVar()
201  << "in Function Graph order.")
202 
203  __functionGraph->__internalNodeMap[node]->setSon(modality, sonNode);
204  if (sonNode && !__functionGraph->isTerminalNode(sonNode))
205  __functionGraph->__internalNodeMap[sonNode]->addParent(node, modality);
206  }
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * __functionGraph
The multidimdecisiongraph supposed to be edited.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ 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: