aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
gum::MultiDimFunctionGraphTreeManager< GUM_ELEMENT, TerminalNodePolicy > Class Template Reference

#include <multiDimFunctionGraphManager.h>

Inheritance diagram for gum::MultiDimFunctionGraphTreeManager< GUM_ELEMENT, TerminalNodePolicy >:
Collaboration diagram for gum::MultiDimFunctionGraphTreeManager< GUM_ELEMENT, TerminalNodePolicy >:

Public Member Functions

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

Private Attributes

MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > * _functionGraph_
 The multidimdecisiongraph supposed to be edited.

Friends

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

Constructor and destructor

 MultiDimFunctionGraphTreeManager (MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > *master)
 Class constructor.
 ~MultiDimFunctionGraphTreeManager () override
 Class destructor.

Manipulation methods.

void _adjacentSwap_ (const DiscreteVariable *x, const DiscreteVariable *y)
 Swap two adjacent variable.
void setSon (const NodeId &node, const Idx &modality, const NodeId &sonNode)
 Sets nodes son for given modality to designated son node.
void minimizeSize ()
 Performs a sifting in search of a(local) minimal size.
void moveTo (const DiscreteVariable *x, Idx desiredPos)
 Changes var position in variable sequence.
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.

Redundancy methods.

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.
NodeId nodeRedundancyCheck_ (const DiscreteVariable *var, NodeId *sonsMap)
 Check for redundancy.
void reduce_ ()
 Ensures that every isomorphic subgraphs are merged together.

Nodes manipulation methods.

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

Detailed Description

template<typename GUM_ELEMENT, template< typename > class TerminalNodePolicy>
class gum::MultiDimFunctionGraphTreeManager< GUM_ELEMENT, 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_ELEMENTThe type of scalars stored in the multidimensional table.
TerminalNodePolicyThe terminal node policy to use.

Definition at line 357 of file multiDimFunctionGraphManager.h.

Constructor & Destructor Documentation

◆ MultiDimFunctionGraphTreeManager()

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

Class constructor.

Definition at line 569 of file multiDimFunctionGraphManager_tpl.h.

References gum::MultiDimFunctionGraphManager< GUM_ELEMENT, TerminalNodePolicy >::MultiDimFunctionGraphManager(), and MultiDimFunctionGraphTreeManager().

Referenced by MultiDimFunctionGraphTreeManager(), and ~MultiDimFunctionGraphTreeManager().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~MultiDimFunctionGraphTreeManager()

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

Class destructor.

Definition at line 578 of file multiDimFunctionGraphManager_tpl.h.

References MultiDimFunctionGraphTreeManager(), and ~MultiDimFunctionGraphTreeManager().

Referenced by ~MultiDimFunctionGraphTreeManager().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ _adjacentSwap_()

template<typename GUM_ELEMENT, template< class > class TerminalNodePolicy>
void gum::MultiDimFunctionGraphManager< GUM_ELEMENT, TerminalNodePolicy >::_adjacentSwap_ ( const DiscreteVariable * x,
const DiscreteVariable * y )
privateinherited

Swap two adjacent variable.

Order is important here. X must precede Y before the swap (at the end Y will then precede X). Not respecting this constraint leads to unattended behaviour.

Parameters
xThe first variable to swap.
yThe second variable to swap.

Definition at line 310 of file multiDimFunctionGraphManager_tpl.h.

312 {
313 LinkedList< NodeId >* oldxNodes = _functionGraph_->_var2NodeIdMap_[x];
314 _functionGraph_->_var2NodeIdMap_[x] = new LinkedList< NodeId >();
315 LinkedList< NodeId >* oldyNodes = _functionGraph_->_var2NodeIdMap_[y];
316 _functionGraph_->_var2NodeIdMap_[y] = new LinkedList< NodeId >();
317
318
319 InternalNode* currentOldXNode = nullptr;
320 NodeId* currentNewXNodeSons = nullptr;
321 Idx indx = 0;
322
323 NodeId* currentNewYNodeSons = nullptr;
325 Idx indy = 0;
326
327 while (oldxNodes->list()) {
328 // Recuperating a node associated to variables x
329 currentOldXNode = _functionGraph_->_internalNodeMap_[oldxNodes->list()->element()];
330
331 // Creating a new node associated to variable y
333
334 // Now the graph needs to be remap by inserting nodes bound to x
335 // for each values assumed by y
336 for (indy = 0; indy < y->domainSize(); ++indy) {
337 // Creating a new node bound to x that will be the son of the node
338 // tied to y for the current value assumed by y
340
341 // Iterating on the different values taht x can assumed to do the remap
342 for (indx = 0; indx < x->domainSize(); ++indx) {
344 if (!_functionGraph_->isTerminalNode(currentOldXNode->son(indx))
345 && _functionGraph_->node(currentOldXNode->son(indx))->nodeVar() == y)
347 = _functionGraph_->node(currentOldXNode->son(indx))->son(indy);
348 }
349
350 // Inserting the new node bound to x
352 }
353
354 // Replacing old node x by new node y
357 migrateNode_(oldxNodes->list()->element(), currentNewYNodeId);
358 SOA_DEALLOCATE(currentNewYNodeSons, y->domainSize() * sizeof(NodeId));
359 } else {
361 if (currentNewYNodeId != 0) {
362 migrateNode_(oldxNodes->list()->element(), currentNewYNodeId);
363 SOA_DEALLOCATE(currentNewYNodeSons, y->domainSize() * sizeof(NodeId));
364 } else {
365 // Updating the sons (they must not consider old x as their parent)
366 for (Idx i = 0; i < currentOldXNode->nodeVar()->domainSize(); ++i) {
367 if (_functionGraph_->_internalNodeMap_.exists(currentOldXNode->son(i))) {
368 _functionGraph_->_internalNodeMap_[currentOldXNode->son(i)]->removeParent(
369 oldxNodes->list()->element(),
370 i);
371 }
372 }
373 // Reaffecting old node x internal attributes to correct new one
375 // Updating new sons (they must consider the node as a parent)
376 for (Idx i = 0; i < currentOldXNode->nodeVar()->domainSize(); ++i) {
377 if (_functionGraph_->_internalNodeMap_.exists(currentNewYNodeSons[i])) {
378 _functionGraph_->_internalNodeMap_[currentNewYNodeSons[i]]->addParent(
379 oldxNodes->list()->element(),
380 i);
381 }
382 }
383
384 _functionGraph_->_var2NodeIdMap_[y]->addLink(oldxNodes->list()->element());
385 }
386 }
387
388 oldxNodes->searchAndRemoveLink(oldxNodes->list()->element());
389 }
390 delete oldxNodes;
391
392 while (oldyNodes->list()) {
393 NodeId curId = oldyNodes->list()->element();
394 if (_functionGraph_->_internalNodeMap_[curId]->parents() == nullptr) {
395 for (Idx i = 0; i < _functionGraph_->_internalNodeMap_[curId]->nodeVar()->domainSize(); ++i)
396 if (_functionGraph_->_internalNodeMap_.exists(
397 _functionGraph_->_internalNodeMap_[curId]->son(i)))
398 _functionGraph_->_internalNodeMap_[_functionGraph_->_internalNodeMap_[curId]->son(i)]
399 ->removeParent(curId, i);
400 delete _functionGraph_->_internalNodeMap_[curId];
401 _functionGraph_->_internalNodeMap_.erase(curId);
402 _functionGraph_->_model_.eraseNode(curId);
403 } else {
404 _functionGraph_->_var2NodeIdMap_[y]->addLink(curId);
405 }
406 oldyNodes->searchAndRemoveLink(curId);
407 }
408 delete oldyNodes;
409 }
static NodeId * allocateNodeSons(const DiscreteVariable *v)
Allocates a table of nodeid of the size given in parameter.
Class implementingting a function graph manager.
NodeId nodeRedundancyCheck_(const DiscreteVariable *var, NodeId *sonsMap)
Check for redundancy.
bool _isRedundant_(const DiscreteVariable *var, NodeId *sons)
Checks if node has the same child for every variable value.
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 _checkIsomorphism_(const DiscreteVariable *var, NodeId *sons)
Checks if a similar node does not already exists in the graph.
MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > * _functionGraph_
The multidimdecisiongraph supposed to be edited.
#define SOA_DEALLOCATE(x, y)

References _adjacentSwap_(), and _functionGraph_.

Referenced by _adjacentSwap_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _checkIsomorphism_()

template<typename GUM_ELEMENT, template< class > class TerminalNodePolicy>
NodeId gum::MultiDimFunctionGraphManager< GUM_ELEMENT, TerminalNodePolicy >::_checkIsomorphism_ ( const DiscreteVariable * var,
NodeId * sons )
privateinherited

Checks if a similar node does not already exists in the graph.

Tow nodes are similar if for every value assumed by the associated variable, these two nodes have the same children.

Warning
This will not free sons.
Parameters
varThe node to check for.
sonsThe node sons.
Returns
Returns the node id if found, 0 otherwhise.

Definition at line 459 of file multiDimFunctionGraphManager_tpl.h.

461 {
462 const InternalNode* nody = nullptr;
463 Idx i = 0;
464
465 // Check abscence of identical node
466 Link< NodeId >* currentElem = _functionGraph_->_var2NodeIdMap_[var]->list();
467 while (currentElem != nullptr) {
468 nody = _functionGraph_->_internalNodeMap_[currentElem->element()];
469
470 // Check on the other sons
471 i = 0;
472 while (i < var->domainSize() && sons[i] == nody->son(i))
473 ++i;
474 if (i == var->domainSize()) return currentElem->element();
475
476 currentElem = currentElem->nextLink();
477 }
478 return 0;
479 }

References _checkIsomorphism_(), _functionGraph_, gum::DiscreteVariable::domainSize(), gum::Link< T >::element(), gum::Link< T >::nextLink(), and gum::InternalNode::son().

Referenced by _checkIsomorphism_(), and nodeRedundancyCheck_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _isRedundant_()

template<typename GUM_ELEMENT, template< class > class TerminalNodePolicy>
bool gum::MultiDimFunctionGraphManager< GUM_ELEMENT, TerminalNodePolicy >::_isRedundant_ ( const DiscreteVariable * var,
NodeId * sons )
privateinherited

Checks if node has the same child for every variable value.

Warning
WON'T deallocate sons
Parameters
varThe node to check for.
sonsThe node sons.
Returns
Returns true if the node is redundant.

Definition at line 483 of file multiDimFunctionGraphManager_tpl.h.

485 {
486 for (Idx m = 1; m < var->domainSize(); m++)
487 if (sons[m] != sons[0]) return false;
488 return true;
489 }

References _isRedundant_(), and gum::DiscreteVariable::domainSize().

Referenced by _isRedundant_(), and nodeRedundancyCheck_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addInternalNode() [1/3]

template<typename GUM_ELEMENT, template< class > class TerminalNodePolicy>
NodeId gum::MultiDimFunctionGraphManager< GUM_ELEMENT, 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 95 of file multiDimFunctionGraphManager_tpl.h.

96 {
98 NodeId nid = _functionGraph_->_model_.addNode();
99 _functionGraph_->_internalNodeMap_.insert(nid, newNodeStruct);
100 _functionGraph_->_var2NodeIdMap_[var]->addLink(nid);
101
102 return nid;
103 }

References _functionGraph_.

Referenced by gum::AdaptiveRMaxPlaner::_visitLearner_(), and gum::MultiDimFunctionGraphGenerator::generate().

Here is the caller graph for this function:

◆ addInternalNode() [2/3]

template<typename GUM_ELEMENT, template< class > class TerminalNodePolicy>
NodeId gum::MultiDimFunctionGraphManager< GUM_ELEMENT, 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 82 of file multiDimFunctionGraphManager_tpl.h.

84 {
86
87 _functionGraph_->_internalNodeMap_.insert(nid, newNodeStruct);
88
89 _functionGraph_->_var2NodeIdMap_[var]->addLink(nid);
90
91 return nid;
92 }

References _functionGraph_.

◆ addInternalNode() [3/3]

template<typename GUM_ELEMENT, template< class > class TerminalNodePolicy>
NodeId gum::MultiDimFunctionGraphTreeManager< GUM_ELEMENT, TerminalNodePolicy >::addInternalNode ( const DiscreteVariable * var,
NodeId * sons )
overridevirtual

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_ELEMENT, TerminalNodePolicy >.

Definition at line 583 of file multiDimFunctionGraphManager_tpl.h.

585 {
586 return this->addInternalNode_(var, sons);
587 }
NodeId addInternalNode_(const DiscreteVariable *var, NodeId *sons)
Adds an internal node.

References gum::MultiDimFunctionGraphManager< GUM_ELEMENT, TerminalNodePolicy >::addInternalNode_().

Here is the call graph for this function:

◆ addInternalNode_()

template<typename GUM_ELEMENT, template< class > class TerminalNodePolicy>
NodeId gum::MultiDimFunctionGraphManager< GUM_ELEMENT, 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 106 of file multiDimFunctionGraphManager_tpl.h.

108 {
110 NodeId nid = _functionGraph_->_model_.addNode();
111 _functionGraph_->_internalNodeMap_.insert(nid, newNodeStruct);
112 _functionGraph_->_var2NodeIdMap_[var]->addLink(nid);
113 for (Idx i = 0; i < newNodeStruct->nbSons(); i++)
114 if (!_functionGraph_->isTerminalNode(sons[i]))
115 _functionGraph_->_internalNodeMap_[sons[i]]->addParent(nid, i);
116
117 return nid;
118 }

References _functionGraph_, and gum::InternalNode::nbSons().

Referenced by gum::MultiDimFunctionGraphTreeManager< GUM_ELEMENT, TerminalNodePolicy >::addInternalNode(), and nodeRedundancyCheck_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addTerminalNode()

template<typename GUM_ELEMENT, template< class > class TerminalNodePolicy>
NodeId gum::MultiDimFunctionGraphManager< GUM_ELEMENT, TerminalNodePolicy >::addTerminalNode ( const GUM_ELEMENT & 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 122 of file multiDimFunctionGraphManager_tpl.h.

123 {
124 if (_functionGraph_->existsTerminalNodeWithValue(value))
125 return _functionGraph_->terminalNodeId(value);
126
127 NodeId node = _functionGraph_->_model_.addNode();
128 _functionGraph_->addTerminalNode(node, value);
129 return node;
130 }

References _functionGraph_.

Referenced by gum::AdaptiveRMaxPlaner::_visitLearner_(), and gum::MultiDimFunctionGraphGenerator::generate().

Here is the caller graph for this function:

◆ clean()

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

Removes var without nodes in the diagram.

Definition at line 556 of file multiDimFunctionGraphManager_tpl.h.

556 {
559 varIter != oldSequence.end();
560 ++varIter)
561 if (!_functionGraph_->varNodeListe(*varIter)->list()) _functionGraph_->erase(**varIter);
562 }

References _functionGraph_, gum::SequenceImplementation< Key, Gen >::begin(), clean(), and gum::SequenceImplementation< Key, Gen >::end().

Referenced by gum::AdaptiveRMaxPlaner::_makeRMaxFunctionGraphs_(), clean(), and gum::MultiDimFunctionGraphGenerator::generate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eraseNode()

template<typename GUM_ELEMENT, template< class > class TerminalNodePolicy>
void gum::MultiDimFunctionGraphManager< GUM_ELEMENT, 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 134 of file multiDimFunctionGraphManager_tpl.h.

137 {
138 if (!_functionGraph_->_model_.exists(eraseId))
139 GUM_ERROR(NotFound, "Node : " << eraseId << " doesn't exists in the graph")
140
142 for (auto iterVar = _functionGraph_->variablesSequence().begin();
143 iterVar != _functionGraph_->variablesSequence().end();
144 ++iterVar) {
145 Link< NodeId >* nodeIter = _functionGraph_->_var2NodeIdMap_[*iterVar]->list();
146 while (nodeIter != nullptr) {
147 for (Idx modality = 0; modality < (*iterVar)->domainSize(); ++modality)
148 if (_functionGraph_->node(nodeIter->element())->son(modality) == eraseId)
149 setSon(nodeIter->element(), modality, replacingId);
150
151 nodeIter = nodeIter->nextLink();
152 }
153 }
154 _functionGraph_->eraseTerminalNode(eraseId);
155
156 } else {
157 InternalNode* eraseNode = _functionGraph_->_internalNodeMap_[eraseId];
158
159 if (updateParents) {
160 Link< Parent >* picle = eraseNode->parents();
161 while (picle != nullptr) {
162 setSon(picle->element().parentId, picle->element().modality, replacingId);
163 picle = picle->nextLink();
164 }
165 }
166
167 _functionGraph_->_var2NodeIdMap_[_functionGraph_->_internalNodeMap_[eraseId]->nodeVar()]
168 ->searchAndRemoveLink(eraseId);
169
170 delete _functionGraph_->_internalNodeMap_[eraseId];
171 _functionGraph_->_internalNodeMap_.erase(eraseId);
172 }
173
174 _functionGraph_->_model_.eraseNode(eraseId);
175
176 if (_functionGraph_->_root_ == eraseId) _functionGraph_->_root_ = replacingId;
177 }
void eraseNode(NodeId id, NodeId replacingId=0, bool updateParents=true)
Erases a node from the diagram.
void setSon(const NodeId &node, const Idx &modality, const NodeId &sonNode)
Sets nodes son for given modality to designated son node.
#define GUM_ERROR(type, msg)
Definition exceptions.h:76

References _functionGraph_.

◆ migrateNode_()

template<typename GUM_ELEMENT, template< class > class TerminalNodePolicy>
void gum::MultiDimFunctionGraphManager< GUM_ELEMENT, 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 412 of file multiDimFunctionGraphManager_tpl.h.

414 {
415 InternalNode* org = _functionGraph_->_internalNodeMap_[origin];
416 // Upating parents after the change
417 Link< Parent >* picle = org->parents();
418 while (picle != nullptr) {
419 setSon(picle->element().parentId, picle->element().modality, destination);
420 picle = picle->nextLink();
421 }
422
423 // Updating sons after the change
424 for (Idx i = 0; i < org->nbSons(); ++i)
425 if (_functionGraph_->_internalNodeMap_.exists(org->son(i)))
426 _functionGraph_->_internalNodeMap_[org->son(i)]->removeParent(origin, i);
427
428 delete org;
429 _functionGraph_->_internalNodeMap_.erase(origin);
430 _functionGraph_->_model_.eraseNode(origin);
431
432 if (_functionGraph_->root() == origin) this->setRootNode(destination);
433 }
void setRootNode(const NodeId &root)
Sets root node of decision diagram.

References _functionGraph_, gum::Link< T >::element(), migrateNode_(), gum::InternalNode::nbSons(), gum::Link< T >::nextLink(), gum::InternalNode::parents(), setRootNode(), setSon(), and gum::InternalNode::son().

Referenced by migrateNode_(), and reduce_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ minimizeSize()

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

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

Definition at line 224 of file multiDimFunctionGraphManager_tpl.h.

224 {
225 // Ordering variables by number of nodes asssociated to them
229 = _functionGraph_->variablesSequence().beginSafe();
230 varIter != _functionGraph_->variablesSequence().endSafe();
231 ++varIter) {
232 const Link< NodeId >* curElem = _functionGraph_->_var2NodeIdMap_[*varIter]->list();
233 Idx nbElem = 0;
234 for (; curElem != nullptr; nbElem++, curElem = curElem->nextLink())
235 ;
236 varLvlSize.insert(*varIter, nbElem);
237 siftingSeq.insert(*varIter);
238 Idx pos = siftingSeq.pos(*varIter);
239 while (pos > 0 && varLvlSize[siftingSeq.atPos(pos - 1)] > nbElem) {
240 siftingSeq.swap(pos - 1, pos);
241 pos--;
242 }
243 }
244
245 // Sifting var par var
247 sifIter != siftingSeq.endSafe();
248 ++sifIter) {
249 // Initialization
250 Idx currentPos = _functionGraph_->variablesSequence().pos(*sifIter);
251 Idx bestSize = _functionGraph_->realSize();
253
254
255 // Sifting towards upper places
256 while (currentPos > 0) {
258 currentPos = _functionGraph_->variablesSequence().pos(*sifIter);
259 if (_functionGraph_->realSize() < bestSize) {
261 bestSize = _functionGraph_->realSize();
262 }
263 }
264
265 // Sifting towards lower places
268 currentPos = _functionGraph_->variablesSequence().pos(*sifIter);
269 if (_functionGraph_->realSize() < bestSize) {
271 bestSize = _functionGraph_->realSize();
272 }
273 }
274
276 }
277 }
void moveTo(const DiscreteVariable *x, Idx desiredPos)
Changes var position in variable sequence.

References MultiDimFunctionGraphManager(), and minimizeSize().

Referenced by minimizeSize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ moveTo()

template<typename GUM_ELEMENT, template< class > class TerminalNodePolicy>
void gum::MultiDimFunctionGraphManager< GUM_ELEMENT, 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 281 of file multiDimFunctionGraphManager_tpl.h.

283 {
284 // First we determine the position of both variable
285 // We also determine which one precede the other
286 if (_functionGraph_->variablesSequence().pos(movedVar) > desiredPos)
287 for (Idx currentPos = _functionGraph_->variablesSequence().pos(movedVar);
289 currentPos--) {
290 const DiscreteVariable* preVar = _functionGraph_->variablesSequence().atPos(currentPos - 1);
291 if (_functionGraph_->_var2NodeIdMap_[preVar]->list()
292 && _functionGraph_->_var2NodeIdMap_[movedVar]->list())
295 }
296 else
297 for (Idx currentPos = _functionGraph_->variablesSequence().pos(movedVar);
299 currentPos++) {
300 const DiscreteVariable* suiVar = _functionGraph_->variablesSequence().atPos(currentPos + 1);
301 if (_functionGraph_->_var2NodeIdMap_[suiVar]->list()
302 && _functionGraph_->_var2NodeIdMap_[movedVar]->list())
305 }
306 }
void _adjacentSwap_(const DiscreteVariable *x, const DiscreteVariable *y)
Swap two adjacent variable.

References moveTo().

Referenced by moveTo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nodeRedundancyCheck_()

template<typename GUM_ELEMENT, template< class > class TerminalNodePolicy>
NodeId gum::MultiDimFunctionGraphManager< GUM_ELEMENT, 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 itself 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 438 of file multiDimFunctionGraphManager_tpl.h.

440 {
442
443 if (_isRedundant_(var, sonsIds)) {
444 SOA_DEALLOCATE(sonsIds, sizeof(NodeId) * var->domainSize());
445 } else {
447 if (newNode == 0) {
449 } else {
450 SOA_DEALLOCATE(sonsIds, sizeof(NodeId) * var->domainSize());
451 }
452 }
453
454 return newNode;
455 }

References _checkIsomorphism_(), _isRedundant_(), addInternalNode_(), gum::DiscreteVariable::domainSize(), nodeRedundancyCheck_(), and SOA_DEALLOCATE.

Referenced by gum::MultiDimFunctionGraphROManager< GUM_ELEMENT, TerminalNodePolicy >::addInternalNode(), and nodeRedundancyCheck_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reduce()

template<typename GUM_ELEMENT, template< class > class TerminalNodePolicy>
void gum::MultiDimFunctionGraphTreeManager< GUM_ELEMENT, TerminalNodePolicy >::reduce ( )
overridevirtual

Ensures that every isomorphic subgraphs are merged together.

Implements gum::MultiDimFunctionGraphManager< GUM_ELEMENT, TerminalNodePolicy >.

Definition at line 590 of file multiDimFunctionGraphManager_tpl.h.

590{}

◆ reduce_()

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

Ensures that every isomorphic subgraphs are merged together.

Definition at line 493 of file multiDimFunctionGraphManager_tpl.h.

493 {
494 Link< NodeId >* currentNodeId = nullptr;
495 Link< NodeId >* nextNodeId = nullptr;
496 InternalNode* currentNode = nullptr;
497 bool theSame = true;
499
501 = _functionGraph_->variablesSequence().rbegin();
502 varIter != _functionGraph_->variablesSequence().rend();
503 --varIter) {
504 currentNodeId = _functionGraph_->_var2NodeIdMap_[*varIter]->list();
505
506 while (currentNodeId != nullptr) {
507 nextNodeId = currentNodeId->nextLink();
508 currentNode = _functionGraph_->_internalNodeMap_[currentNodeId->element()];
509
510 // First isomorphism to handle is the one where all node children are
511 // the same
512 theSame = true;
513 for (currentInd = 1; currentInd < (*varIter)->domainSize(); currentInd++) {
514 if (currentNode->son(currentInd) != currentNode->son(0)) {
515 theSame = false;
516 break;
517 }
518 }
519
520 if (theSame == true) {
521 migrateNode_(currentNodeId->element(), currentNode->son(0));
522 _functionGraph_->_var2NodeIdMap_[*varIter]->searchAndRemoveLink(currentNodeId->element());
524 continue;
525 }
526
527 // Second isomorphism to handle is the one where two nodes have same
528 // variable and same children
529 if (nextNodeId) {
531 InternalNode* anotherNode = nullptr;
532 Idx modality = 0;
533 while (anotherNodeId->nextLink() != nullptr) {
534 nextNodeId = anotherNodeId->nextLink();
535 anotherNode = _functionGraph_->_internalNodeMap_[anotherNodeId->element()];
536
537 // Check on the other sons
538 for (modality = 0; modality < (*varIter)->domainSize(); ++modality) {
539 if (anotherNode->son(modality) != currentNode->son(modality)) break;
540 if (modality == (*varIter)->domainSize() - 1) {
541 migrateNode_(anotherNodeId->element(), currentNodeId->element());
542 _functionGraph_->_var2NodeIdMap_[*varIter]->searchAndRemoveLink(
543 anotherNodeId->element());
544 }
545 }
546
548 }
549 }
550 currentNodeId = currentNodeId->nextLink();
551 }
552 }
553 }

References _functionGraph_, gum::Link< T >::element(), migrateNode_(), gum::Link< T >::nextLink(), reduce_(), and gum::InternalNode::son().

Referenced by gum::MultiDimFunctionGraphROManager< GUM_ELEMENT, TerminalNodePolicy >::reduce(), and reduce_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setRootNode()

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

Sets root node of decision diagram.

Parameters
rootThe node to set as root.

Definition at line 75 of file multiDimFunctionGraphManager_tpl.h.

76 {
77 _functionGraph_->_root_ = root;
78 }

References _functionGraph_.

Referenced by gum::AdaptiveRMaxPlaner::_makeRMaxFunctionGraphs_(), gum::MultiDimFunctionGraphGenerator::generate(), and migrateNode_().

Here is the caller graph for this function:

◆ setSon()

template<typename GUM_ELEMENT, template< class > class TerminalNodePolicy>
void gum::MultiDimFunctionGraphManager< GUM_ELEMENT, 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 181 of file multiDimFunctionGraphManager_tpl.h.

184 {
185 // Ensuring that both nodes exists in the graph
186 if (!_functionGraph_->_model_.exists(node))
187 GUM_ERROR(NotFound, "Node : " << node << " doesn't exists in the graph")
189 GUM_ERROR(NotFound, "Node : " << sonNode << " doesn't exists in the graph")
190
191 // Check if starting node is not terminal
193 GUM_ERROR(InvalidNode, "You cannot insert an arc from terminal node : " << node)
194
195 // Check if associated modality is lower than node bound variable domain
196 // size
200 "Modality " << modality << "is higher than domain size "
202 << "minus 1 of variable "
204
205 // Check if variable order is respected
213 << " is after variable "
215 << "in Function Graph order.")
216
220 }

References _functionGraph_, GUM_ERROR, and setSon().

Referenced by gum::MultiDimFunctionGraphGenerator::generate(), migrateNode_(), and setSon().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MultiDimFunctionGraph

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

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

Member Data Documentation

◆ _functionGraph_

template<typename GUM_ELEMENT, template< typename > class TerminalNodePolicy>
MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy >* gum::MultiDimFunctionGraphManager< GUM_ELEMENT, TerminalNodePolicy >::_functionGraph_
privateinherited

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