59 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
68 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
75 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
82 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
95 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
106 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
114 for (
Idx i = 0; i < newNodeStruct->
nbSons(); i++)
122 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
124 const GUM_SCALAR& value) {
134 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
138 bool updateParents) {
146 Link< NodeId >* nodeIter = _functionGraph_->_var2NodeIdMap_[*iterVar]->list();
147 while (nodeIter != nullptr) {
148 for (Idx modality = 0; modality < (*iterVar)->domainSize(); ++modality)
149 if (_functionGraph_->node(nodeIter->element())->son(modality) == eraseId)
150 setSon(nodeIter->element(), modality, replacingId);
152 nodeIter = nodeIter->nextLink();
155 _functionGraph_->eraseTerminalNode(eraseId);
158 InternalNode* eraseNode = _functionGraph_->_internalNodeMap_[eraseId];
161 Link< Parent >* picle = eraseNode->parents();
162 while (picle !=
nullptr) {
163 setSon(picle->element().parentId, picle->element().modality, replacingId);
164 picle = picle->nextLink();
168 _functionGraph_->_var2NodeIdMap_[_functionGraph_->_internalNodeMap_[eraseId]->nodeVar()]
169 ->searchAndRemoveLink(eraseId);
171 delete _functionGraph_->_internalNodeMap_[eraseId];
172 _functionGraph_->_internalNodeMap_.erase(eraseId);
175 _functionGraph_->_model_.eraseNode(eraseId);
177 if (_functionGraph_->_root_ == eraseId) _functionGraph_->_root_ = replacingId;
181 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
199 && modality >
_functionGraph_->_internalNodeMap_[node]->nodeVar()->domainSize() - 1)
201 "Modality " << modality <<
"is higher than domain size "
203 <<
"minus 1 of variable "
214 <<
" is after variable "
216 <<
"in Function Graph order.")
220 _functionGraph_->_internalNodeMap_[sonNode]->addParent(node, modality);
224 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
233 const Link< NodeId >* curElem = _functionGraph_->_var2NodeIdMap_[*varIter]->list();
235 for (; curElem != nullptr; nbElem++, curElem = curElem->nextLink())
237 varLvlSize.insert(*varIter, nbElem);
238 siftingSeq.insert(*varIter);
239 Idx pos = siftingSeq.pos(*varIter);
240 while (pos > 0 && varLvlSize[siftingSeq.atPos(pos - 1)] > nbElem) {
241 siftingSeq.swap(pos - 1, pos);
248 sifIter != siftingSeq.
endSafe();
251 Idx currentPos = _functionGraph_->variablesSequence().pos(*sifIter);
252 Idx bestSize = _functionGraph_->realSize();
253 Idx bestPos = currentPos;
257 while (currentPos > 0) {
258 moveTo(*sifIter, currentPos - 1);
259 currentPos = _functionGraph_->variablesSequence().pos(*sifIter);
260 if (_functionGraph_->realSize() < bestSize) {
261 bestPos = currentPos;
262 bestSize = _functionGraph_->realSize();
267 while (currentPos < _functionGraph_->variablesSequence().size() - 1) {
268 moveTo(*sifIter, currentPos + 1);
271 bestPos = currentPos;
276 moveTo(*sifIter, bestPos);
281 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
289 currentPos != desiredPos;
299 currentPos != desiredPos;
310 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
321 NodeId* currentNewXNodeSons =
nullptr;
324 NodeId* currentNewYNodeSons =
nullptr;
325 NodeId currentNewYNodeId = 0;
328 while (oldxNodes->
list()) {
337 for (indy = 0; indy < y->
domainSize(); ++indy) {
343 for (indx = 0; indx < x->
domainSize(); ++indx) {
344 currentNewXNodeSons[indx] = currentOldXNode->
son(indx);
347 currentNewXNodeSons[indx]
352 currentNewYNodeSons[indy] = nodeRedundancyCheck_(x, currentNewXNodeSons);
356 currentNewYNodeId = currentNewYNodeSons[0];
357 if (_isRedundant_(y, currentNewYNodeSons)) {
358 migrateNode_(oldxNodes->
list()->
element(), currentNewYNodeId);
361 currentNewYNodeId = _checkIsomorphism_(y, currentNewYNodeSons);
362 if (currentNewYNodeId != 0) {
363 migrateNode_(oldxNodes->
list()->
element(), currentNewYNodeId);
367 for (Idx i = 0; i < currentOldXNode->
nodeVar()->domainSize(); ++i) {
368 if (_functionGraph_->_internalNodeMap_.exists(currentOldXNode->
son(i))) {
369 _functionGraph_->_internalNodeMap_[currentOldXNode->
son(i)]->removeParent(
375 currentOldXNode->
setNode(y, currentNewYNodeSons);
377 for (Idx i = 0; i < currentOldXNode->
nodeVar()->domainSize(); ++i) {
378 if (_functionGraph_->_internalNodeMap_.exists(currentNewYNodeSons[i])) {
379 _functionGraph_->_internalNodeMap_[currentNewYNodeSons[i]]->addParent(
385 _functionGraph_->_var2NodeIdMap_[y]->addLink(oldxNodes->
list()->
element());
393 while (oldyNodes->
list()) {
395 if (_functionGraph_->_internalNodeMap_[curId]->parents() ==
nullptr) {
396 for (Idx i = 0; i < _functionGraph_->_internalNodeMap_[curId]->nodeVar()->domainSize(); ++i)
397 if (_functionGraph_->_internalNodeMap_.exists(
398 _functionGraph_->_internalNodeMap_[curId]->son(i)))
399 _functionGraph_->_internalNodeMap_[_functionGraph_->_internalNodeMap_[curId]->son(i)]
400 ->removeParent(curId, i);
401 delete _functionGraph_->_internalNodeMap_[curId];
402 _functionGraph_->_internalNodeMap_.erase(curId);
403 _functionGraph_->_model_.eraseNode(curId);
405 _functionGraph_->_var2NodeIdMap_[y]->addLink(curId);
412 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
415 const NodeId& destination) {
419 while (picle !=
nullptr) {
438 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
443 NodeId newNode = sonsIds[0];
460 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
469 while (currentElem !=
nullptr) {
474 while (i < var->domainSize() && sons[i] == nody->
son(i))
478 currentElem = currentElem->
nextLink();
484 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
489 if (sons[m] != sons[0])
return false;
494 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
502 for (SequenceIterator< const DiscreteVariable* > varIter
508 while (currentNodeId !=
nullptr) {
509 nextNodeId = currentNodeId->
nextLink();
515 for (currentInd = 1; currentInd < (*varIter)->domainSize(); currentInd++) {
516 if (currentNode->
son(currentInd) != currentNode->
son(0)) {
522 if (theSame ==
true) {
525 currentNodeId = nextNodeId;
535 while (anotherNodeId->
nextLink() !=
nullptr) {
536 nextNodeId = anotherNodeId->
nextLink();
540 for (modality = 0; modality < (*varIter)->domainSize(); ++modality) {
541 if (anotherNode->
son(modality) != currentNode->
son(modality))
break;
542 if (modality == (*varIter)->domainSize() - 1) {
549 anotherNodeId = nextNodeId;
552 currentNodeId = currentNodeId->
nextLink();
557 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
560 for (SequenceIterator< const DiscreteVariable* > varIter = oldSequence.
begin();
561 varIter != oldSequence.
end();
570 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
578 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
584 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
591 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
598 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
605 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
611 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
618 template <
typename GUM_SCALAR,
template <
class >
class TerminalNodePolicy >
Base class for discrete random variable.
virtual Size domainSize() const =0
The class for generic Hash Tables.
Structure used to represent a node internal structure.
void setNode(const DiscreteVariable *v, NodeId *sons)
Allows you to respecify the node, changing its attached variable as well as its son map.
const DiscreteVariable * nodeVar() const
Returns the node variable.
Idx nbSons() const
Returns the number of sons.
static NodeId * allocateNodeSons(const DiscreteVariable *v)
Allocates a table of nodeid of the size given in parameter.
NodeId son(Idx modality) const
Returns the son at a given index.
Link< Parent > * parents()
Returns the list of parents.
Exception: at least one argument passed to a function is not what was expected.
Exception : node does not exist.
Link of a chain list allocated using the SmallObjectAllocator.
const Link< T > * nextLink() const
Returns next link.
const T & element() const
Returns the element stored in this link.
void searchAndRemoveLink(const T &elem)
Removes a element from the list.
const Link< T > * list() const
Returns the first link in the chained list.
Class implementingting a function graph manager.
void eraseNode(NodeId id, NodeId replacingId=0, bool updateParents=true)
Erases a node from the diagram.
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.
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * _functionGraph_
The multidimdecisiongraph supposed to be edited.
void _adjacentSwap_(const DiscreteVariable *x, const DiscreteVariable *y)
void reduce_()
Ensures that every isomorphic subgraphs are merged together.
virtual ~MultiDimFunctionGraphManager()
Class destructor.
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...
void moveTo(const DiscreteVariable *x, Idx desiredPos)
void clean()
Removes var without nodes in the diagram.
void setRootNode(const NodeId &root)
Sets root node of decision diagram.
void minimizeSize()
Performs a sifting in search of a(local) minimal size.
NodeId addTerminalNode(const GUM_SCALAR &value)
Adds a value to the MultiDimFunctionGraph.
MultiDimFunctionGraphManager(MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *master)
Default constructor.
NodeId addInternalNode(const DiscreteVariable *var)
Inserts a new non terminal node in graph.
NodeId _checkIsomorphism_(const DiscreteVariable *var, NodeId *sons)
Checks if a similar node does not already exists in the graph.
void setSon(const NodeId &node, const Idx &modality, const NodeId &sonNode)
Sets nodes son for given modality to designated son node.
NodeId nodeRedundancyCheck_(const DiscreteVariable *var, NodeId *sonsMap)
Check for redundancy.
MultiDimFunctionGraphROManager(MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *master)
virtual void reduce()
Ensures that every isomorphic subgraphs are merged together.
virtual NodeId addInternalNode(const DiscreteVariable *var, NodeId *sons)
Inserts a new non terminal node in graph.
~MultiDimFunctionGraphROManager()
MultiDimFunctionGraphTreeManager(MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *master)
Class constructor.
virtual NodeId addInternalNode(const DiscreteVariable *var, NodeId *sons)
Inserts a new non terminal node in graph.
virtual void reduce()
Ensures that every isomorphic subgraphs are merged together.
~MultiDimFunctionGraphTreeManager()
Class destructor.
Exception : the element we looked for cannot be found.
Exception : operation not allowed.
const iterator & end() const noexcept
Returns the unsafe end iterator.
iterator_safe beginSafe() const
Returns a safe begin iterator.
iterator begin() const
Returns an unsafe begin iterator.
const iterator_safe & endSafe() const noexcept
Returns the safe end iterator.
Safe iterators for Sequence.
The generic class for storing (ordered) sequences of objects.
#define GUM_ERROR(type, msg)
Size Idx
Type for indexes.
Size NodeId
Type for node ids.
Headers of the Link and LinkedList classes.
Headers of MultiDimFunctionGraphManager.
gum is the global namespace for all aGrUM entities
Header file of gum::Sequence, a class for storing (ordered) sequences of objects.
#define SOA_DEALLOCATE(x, y)