![]() |
aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
|
Class implementingting a function graph manager. More...
#include <multiDimFunctionGraphManager.h>
Public Member Functions | |
| void | clean () |
| Removes var without nodes in the diagram. | |
Private Attributes | |
| MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * | _functionGraph_ |
| The multidimdecisiongraph supposed to be edited. | |
Constructors / Destructors | |
| MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > * | MultiDimFunctionGraph () |
| This friend methods from is the only way to get an instance of a manager. | |
| MultiDimFunctionGraphManager (MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *master) | |
| Default constructor. | |
| virtual | ~MultiDimFunctionGraphManager () |
| Class destructor. | |
Nodes manipulation methods. | |
| NodeId | addInternalNode_ (const DiscreteVariable *var, NodeId *sons) |
| Adds an internal node. | |
| void | setRootNode (const NodeId &root) |
| Sets root node of decision diagram. | |
| NodeId | addInternalNode (const DiscreteVariable *var) |
| Inserts a new non terminal node in graph. | |
| virtual NodeId | addInternalNode (const DiscreteVariable *var, NodeId *sons)=0 |
| 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_SCALAR &value) |
| Adds a value to the MultiDimFunctionGraph. | |
| void | eraseNode (NodeId id, NodeId replacingId=0, bool updateParents=true) |
| Erases a node from the diagram. | |
Manipulation methods. | |
| 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. | |
| 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 | _adjacentSwap_ (const DiscreteVariable *x, const DiscreteVariable *y) |
| Swap two adjacent variable. | |
Redundancy methods. | |
| NodeId | nodeRedundancyCheck_ (const DiscreteVariable *var, NodeId *sonsMap) |
| Check for redundancy. | |
| void | reduce_ () |
| Ensures that every isomorphic subgraphs are merged together. | |
| virtual void | reduce ()=0 |
| Ensures that every isomorphic subgraphs are merged together. | |
| 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. | |
Class implementingting a function graph manager.
This class provides methods to edit a Function Graph. Any modification on a MultiDimFunctionGraph graph must be done via this class.
This class is a singleton and its unique instance ca be accessed using the MultiDimFunctionGraph::getManager() method.
To do so :
| GUM_SCALAR | The type of scalars stored in the multidimensional table. |
| TerminalNodePolicy | The terminal node policy to use. |
Definition at line 97 of file multiDimFunctionGraphManager.h.
|
explicitprotected |
Default constructor.
You have to call MultiDimFunctionGraph::getManager() to get the instance of MultiDimFunctionGraphManager bound to your function graph.
Definition at line 61 of file multiDimFunctionGraphManager_tpl.h.
References MultiDimFunctionGraphManager(), and _functionGraph_.
Referenced by MultiDimFunctionGraphManager(), gum::MultiDimFunctionGraphROManager< GUM_SCALAR, TerminalNodePolicy >::MultiDimFunctionGraphROManager(), gum::MultiDimFunctionGraphTreeManager< GUM_SCALAR, TerminalNodePolicy >::MultiDimFunctionGraphTreeManager(), ~MultiDimFunctionGraphManager(), and minimizeSize().
|
virtual |
Class destructor.
Definition at line 70 of file multiDimFunctionGraphManager_tpl.h.
References MultiDimFunctionGraphManager(), and ~MultiDimFunctionGraphManager().
Referenced by ~MultiDimFunctionGraphManager().
|
private |
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.
| x | The first variable to swap. |
| y | The second variable to swap. |
Definition at line 311 of file multiDimFunctionGraphManager_tpl.h.
References _adjacentSwap_(), and _functionGraph_.
Referenced by _adjacentSwap_().
|
private |
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.
| var | The node to check for. |
| sons | The node sons. |
Definition at line 461 of file multiDimFunctionGraphManager_tpl.h.
References _checkIsomorphism_(), _functionGraph_, gum::DiscreteVariable::domainSize(), gum::Link< T >::element(), gum::Link< T >::nextLink(), and gum::InternalNode::son().
Referenced by _checkIsomorphism_(), and nodeRedundancyCheck_().
|
private |
Checks if node has the same child for every variable value.
| var | The node to check for. |
| sons | The node sons. |
Definition at line 485 of file multiDimFunctionGraphManager_tpl.h.
References _isRedundant_(), and gum::DiscreteVariable::domainSize().
Referenced by _isRedundant_(), and nodeRedundancyCheck_().
| INLINE NodeId gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::addInternalNode | ( | const DiscreteVariable * | var | ) |
Inserts a new non terminal node in graph.
NodeId of this node is generated automatically.
| var | Associated variable |
Definition at line 96 of file multiDimFunctionGraphManager_tpl.h.
References _functionGraph_.
Referenced by gum::AdaptiveRMaxPlaner::_visitLearner_(), and gum::MultiDimFunctionGraphGenerator::generate().
|
pure virtual |
Inserts a new non terminal node in graph.
NodeId of this node is generated automatically.
| var | The associated variable. |
| sons | A table of size var->domainSize() containing nodeid of sons nodes. |
| OperationNotAllowed | Raised if MultiDimFunctionGraph has no variable yet. |
Implemented in gum::MultiDimFunctionGraphROManager< GUM_SCALAR, TerminalNodePolicy >, and gum::MultiDimFunctionGraphTreeManager< GUM_SCALAR, TerminalNodePolicy >.
| INLINE NodeId gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::addInternalNode | ( | const DiscreteVariable * | var, |
| NodeId | nid ) |
Inserts a new non terminal node in graph.
NodeId of this node is generated automatically.
| var | The ssociated variable. |
| nid | The desired id for that node. |
| OperationNotAllowed | Raised if MultiDimFunctionGraph has no variable yet. |
Definition at line 83 of file multiDimFunctionGraphManager_tpl.h.
References _functionGraph_.
|
protected |
Adds an internal node.
| var | The node to add. |
| sons | The node sons. |
Definition at line 107 of file multiDimFunctionGraphManager_tpl.h.
References _functionGraph_, and gum::InternalNode::nbSons().
Referenced by gum::MultiDimFunctionGraphTreeManager< GUM_SCALAR, TerminalNodePolicy >::addInternalNode(), and nodeRedundancyCheck_().
| INLINE NodeId gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::addTerminalNode | ( | const GUM_SCALAR & | value | ) |
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.
| value | The value added by copy. |
Definition at line 123 of file multiDimFunctionGraphManager_tpl.h.
References _functionGraph_.
Referenced by gum::AdaptiveRMaxPlaner::_visitLearner_(), and gum::MultiDimFunctionGraphGenerator::generate().
| INLINE void gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::clean | ( | ) |
Removes var without nodes in the diagram.
Definition at line 558 of file multiDimFunctionGraphManager_tpl.h.
References _functionGraph_, gum::SequenceImplementation< Key, Gen >::begin(), clean(), and gum::SequenceImplementation< Key, Gen >::end().
Referenced by gum::AdaptiveRMaxPlaner::_makeRMaxFunctionGraphs_(), clean(), and gum::MultiDimFunctionGraphGenerator::generate().
| void gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::eraseNode | ( | NodeId | id, |
| NodeId | replacingId = 0, | ||
| bool | updateParents = true ) |
Erases a node from the diagram.
| id | The id of the variable to erase. |
| replacingId | Offers the possibility to reroute any parent to the given node. |
| updateParents | Indicates if such remapping has to be done. |
| NotFound | Raised if node isn't in diagram. |
Definition at line 135 of file multiDimFunctionGraphManager_tpl.h.
|
protected |
Remaps all arcs going to ou going from the first given node to the second node, then delete first node.
| x | The variable from which all arcs are removed. |
| y | The variable for which all of x arcs are added. |
Definition at line 413 of file multiDimFunctionGraphManager_tpl.h.
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_().
| void gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::minimizeSize | ( | ) |
Performs a sifting in search of a(local) minimal size.
Definition at line 225 of file multiDimFunctionGraphManager_tpl.h.
References MultiDimFunctionGraphManager(), and minimizeSize().
Referenced by minimizeSize().
| void gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::moveTo | ( | const DiscreteVariable * | x, |
| Idx | desiredPos ) |
Changes var position in variable sequence.
| x | The varaible to change. |
| desiredPos | The new posiition. |
Definition at line 282 of file multiDimFunctionGraphManager_tpl.h.
References moveTo().
Referenced by moveTo().
|
protected |
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.
| var | The node to add in the graph. |
| sonsMap | The node sons. |
Definition at line 440 of file multiDimFunctionGraphManager_tpl.h.
References _checkIsomorphism_(), _isRedundant_(), addInternalNode_(), gum::DiscreteVariable::domainSize(), nodeRedundancyCheck_(), and SOA_DEALLOCATE.
Referenced by gum::MultiDimFunctionGraphROManager< GUM_SCALAR, TerminalNodePolicy >::addInternalNode(), and nodeRedundancyCheck_().
|
pure virtual |
Ensures that every isomorphic subgraphs are merged together.
Implemented in gum::MultiDimFunctionGraphROManager< GUM_SCALAR, TerminalNodePolicy >, and gum::MultiDimFunctionGraphTreeManager< GUM_SCALAR, TerminalNodePolicy >.
Referenced by gum::AdaptiveRMaxPlaner::_makeRMaxFunctionGraphs_(), and gum::MultiDimFunctionGraphGenerator::generate().
|
protected |
Ensures that every isomorphic subgraphs are merged together.
Definition at line 495 of file multiDimFunctionGraphManager_tpl.h.
References _functionGraph_, gum::Link< T >::element(), migrateNode_(), gum::Link< T >::nextLink(), reduce_(), and gum::InternalNode::son().
Referenced by gum::MultiDimFunctionGraphROManager< GUM_SCALAR, TerminalNodePolicy >::reduce(), and reduce_().
| INLINE void gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::setRootNode | ( | const NodeId & | root | ) |
Sets root node of decision diagram.
| root | The node to set as root. |
Definition at line 76 of file multiDimFunctionGraphManager_tpl.h.
References _functionGraph_.
Referenced by gum::AdaptiveRMaxPlaner::_makeRMaxFunctionGraphs_(), gum::MultiDimFunctionGraphGenerator::generate(), and migrateNode_().
| INLINE void gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::setSon | ( | const NodeId & | node, |
| const Idx & | modality, | ||
| const NodeId & | sonNode ) |
Sets nodes son for given modality to designated son node.
| node | The node to which a node is added. |
| modality | The modality for which sonNode is added to node. |
| sonNode | The node to add as a son to node. |
Definition at line 182 of file multiDimFunctionGraphManager_tpl.h.
References _functionGraph_, GUM_ERROR, and setSon().
Referenced by gum::MultiDimFunctionGraphGenerator::generate(), migrateNode_(), and setSon().
|
friend |
This friend methods from is the only way to get an instance of a manager.
See class description for more info.
|
private |
The multidimdecisiongraph supposed to be edited.
Definition at line 334 of file multiDimFunctionGraphManager.h.
Referenced by MultiDimFunctionGraphManager(), _adjacentSwap_(), _checkIsomorphism_(), addInternalNode(), addInternalNode(), addInternalNode_(), addTerminalNode(), clean(), migrateNode_(), reduce_(), setRootNode(), and setSon().