35 template <
typename GUM_SCALAR,
39 class TerminalNodePolicy >
44 const GUM_SCALAR neutral) :
46 __delVars(delVars), __function(), __neutral(neutral) {
53 template <
typename GUM_SCALAR,
57 class TerminalNodePolicy >
66 template <
typename GUM_SCALAR,
70 class TerminalNodePolicy >
84 if (
__rd->variablesSequence().exists(curVar))
85 __rd->manager()->moveTo(curVar,
__rd->variablesSequence().size() - 1);
88 if (
__rd->isTerminalNode(
__rd->root())) {
90 for (
Idx curVarModality = 0; curVarModality < curVar->
domainSize();
94 NodeId newSonId =
__rd->manager()->addTerminalNode(newVal);
95 __rd->manager()->setRootNode(newSonId);
97 if (
__rd->variablesSequence().exists(curVar))
__rd->erase(*curVar);
103 if (
__rd->node(
__rd->root())->nodeVar() == curVar) {
106 for (
Idx curVarModality = 0; curVarModality < curVar->
domainSize();
111 NodeId newSonId =
__rd->manager()->addTerminalNode(newVal);
113 __rd->manager()->eraseNode(
__rd->root(), newSonId,
false);
115 if (
__rd->variablesSequence().exists(curVar))
__rd->erase(*curVar);
121 std::vector< NodeId > filo;
122 filo.push_back(
__rd->root());
124 while (!filo.
empty()) {
125 NodeId curNodeId = filo.back();
132 NodeId oldSonId = curNode->
son(modality);
134 if (!visitedNode.exists(oldSonId)) {
135 NodeId newSonId = oldSonId;
137 if (!
__rd->isTerminalNode(oldSonId)) {
138 if (
__rd->node(oldSonId)->nodeVar() != curVar) {
139 filo.push_back(oldSonId);
143 for (
Idx curVarModality = 0; curVarModality < curVar->
domainSize();
146 newVal,
__rd->nodeValue(curVarNode->
son(curVarModality)));
148 newSonId =
__rd->manager()->addTerminalNode(newVal);
150 __rd->manager()->eraseNode(oldSonId, newSonId,
false);
151 __rd->manager()->setSon(curNodeId, modality, newSonId);
155 GUM_SCALAR newVal =
__neutral, oldVal =
__rd->nodeValue(oldSonId);
156 for (
Idx curVarModality = 0; curVarModality < curVar->
domainSize();
160 newSonId =
__rd->manager()->addTerminalNode(newVal);
161 __rd->manager()->setSon(curNodeId, modality, newSonId);
164 visitedNode.insert(oldSonId, newSonId);
167 if (
__rd->node(curNodeId)->son(modality) != visitedNode[oldSonId])
168 __rd->manager()->setSon(curNodeId, modality, visitedNode[oldSonId]);
173 if (
__rd->variablesSequence().exists(curVar))
__rd->erase(*curVar);
Base class for discrete random variable.
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.
Headers of the InternalNode class.
Base class for discrete random variable.
gum is the global namespace for all aGrUM entities
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.
Class used to compute the projection of a function graph.
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.