38 template <
typename GUM_SCALAR,
42 class TerminalNodePolicy >
47 const GUM_SCALAR neutral) :
49 __delVars(delVars), __function(), __neutral(neutral) {
56 template <
typename GUM_SCALAR,
60 class TerminalNodePolicy >
69 template <
typename GUM_SCALAR,
73 class TerminalNodePolicy >
87 if (
__rd->variablesSequence().exists(curVar))
88 __rd->manager()->moveTo(curVar,
__rd->variablesSequence().size() - 1);
91 if (
__rd->isTerminalNode(
__rd->root())) {
93 for (
Idx curVarModality = 0; curVarModality < curVar->
domainSize();
97 NodeId newSonId =
__rd->manager()->addTerminalNode(newVal);
98 __rd->manager()->setRootNode(newSonId);
100 if (
__rd->variablesSequence().exists(curVar))
__rd->erase(*curVar);
106 if (
__rd->node(
__rd->root())->nodeVar() == curVar) {
109 for (
Idx curVarModality = 0; curVarModality < curVar->
domainSize();
114 NodeId newSonId =
__rd->manager()->addTerminalNode(newVal);
116 __rd->manager()->eraseNode(
__rd->root(), newSonId,
false);
118 if (
__rd->variablesSequence().exists(curVar))
__rd->erase(*curVar);
124 std::vector< NodeId > filo;
125 filo.push_back(
__rd->root());
127 while (!filo.
empty()) {
128 NodeId curNodeId = filo.back();
135 NodeId oldSonId = curNode->
son(modality);
137 if (!visitedNode.exists(oldSonId)) {
138 NodeId newSonId = oldSonId;
140 if (!
__rd->isTerminalNode(oldSonId)) {
141 if (
__rd->node(oldSonId)->nodeVar() != curVar) {
142 filo.push_back(oldSonId);
146 for (
Idx curVarModality = 0; curVarModality < curVar->
domainSize();
149 newVal,
__rd->nodeValue(curVarNode->
son(curVarModality)));
151 newSonId =
__rd->manager()->addTerminalNode(newVal);
153 __rd->manager()->eraseNode(oldSonId, newSonId,
false);
154 __rd->manager()->setSon(curNodeId, modality, newSonId);
158 GUM_SCALAR newVal =
__neutral, oldVal =
__rd->nodeValue(oldSonId);
159 for (
Idx curVarModality = 0; curVarModality < curVar->
domainSize();
163 newSonId =
__rd->manager()->addTerminalNode(newVal);
164 __rd->manager()->setSon(curNodeId, modality, newSonId);
167 visitedNode.insert(oldSonId, newSonId);
170 if (
__rd->node(curNodeId)->son(modality) != visitedNode[oldSonId])
171 __rd->manager()->setSon(curNodeId, modality, visitedNode[oldSonId]);
176 if (
__rd->variablesSequence().exists(curVar))
__rd->erase(*curVar);
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * __rd
The resulting function graph.
Safe iterators for the Set classDevelopers may consider using Set<x>::iterator_safe instead of SetIte...
const DiscreteVariable * nodeVar() const
Returns the node variable.
const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * __src
One of the two function graphs used for the Projection.
NodeId son(Idx modality) const
Returns the son at a given index.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Base class for discrete random variable.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
const FUNCTOR< GUM_SCALAR > __function
The function to be performed on the leaves.
Representation of a setA Set is a structure that contains arbitrary elements.
virtual Size domainSize() const =0
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * project()
Computes and builds the Function Graph that is the result of the Projection.
const GUM_SCALAR __neutral
The function to be performed on the leaves.
Structure used to represent a node internal structure.
Class implementingting a function graph.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
const Set< const DiscreteVariable *> & __delVars
The list of variables on which the projection is performed.
Size Idx
Type for indexes.
MultiDimFunctionGraphProjector(const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *src, const Set< const DiscreteVariable * > &delVars, const GUM_SCALAR neutral)
Default constructor.
bool empty() const noexcept
Indicates whether the hash table is empty.
Size NodeId
Type for node ids.
static MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * getReducedAndOrderedInstance()
Returns a reduced and ordered instance.
Class used to perform Function Graph projections.
~MultiDimFunctionGraphProjector()
Default destructor.