60 template <
typename GUM_ELEMENT,
61 template <
typename >
class FUNCTOR,
62 template <
typename >
class TerminalNodePolicy >
67 const GUM_ELEMENT neutral) :
74 template <
typename GUM_ELEMENT,
75 template <
typename >
class FUNCTOR,
76 template <
typename >
class TerminalNodePolicy >
84 template <
typename GUM_ELEMENT,
85 template <
typename >
class FUNCTOR,
86 template <
typename >
class TerminalNodePolicy >
98 if (
_rd_->variablesSequence().exists(curVar))
99 _rd_->manager()->moveTo(curVar,
_rd_->variablesSequence().size() - 1);
102 if (
_rd_->isTerminalNode(
_rd_->root())) {
104 for (
Idx curVarModality = 0; curVarModality < curVar->
domainSize(); ++curVarModality)
107 NodeId newSonId =
_rd_->manager()->addTerminalNode(newVal);
108 _rd_->manager()->setRootNode(newSonId);
110 if (
_rd_->variablesSequence().exists(curVar))
_rd_->erase(*curVar);
116 if (
_rd_->node(
_rd_->root())->nodeVar() == curVar) {
119 for (
Idx curVarModality = 0; curVarModality < curVar->
domainSize(); ++curVarModality)
122 NodeId newSonId =
_rd_->manager()->addTerminalNode(newVal);
124 _rd_->manager()->eraseNode(
_rd_->root(), newSonId,
false);
126 if (
_rd_->variablesSequence().exists(curVar))
_rd_->erase(*curVar);
132 std::vector< NodeId > filo;
133 filo.push_back(
_rd_->root());
135 while (!filo.empty()) {
136 NodeId curNodeId = filo.back();
141 for (
Idx modality = 0; modality < curNode->
nodeVar()->domainSize(); ++modality) {
142 NodeId oldSonId = curNode->
son(modality);
144 if (!visitedNode.
exists(oldSonId)) {
145 NodeId newSonId = oldSonId;
147 if (!
_rd_->isTerminalNode(oldSonId)) {
148 if (
_rd_->node(oldSonId)->nodeVar() != curVar) {
149 filo.push_back(oldSonId);
153 for (
Idx curVarModality = 0; curVarModality < curVar->
domainSize();
157 newSonId =
_rd_->manager()->addTerminalNode(newVal);
159 _rd_->manager()->eraseNode(oldSonId, newSonId,
false);
160 _rd_->manager()->setSon(curNodeId, modality, newSonId);
164 GUM_ELEMENT newVal =
_neutral_, oldVal =
_rd_->nodeValue(oldSonId);
165 for (
Idx curVarModality = 0; curVarModality < curVar->
domainSize(); ++curVarModality)
168 newSonId =
_rd_->manager()->addTerminalNode(newVal);
169 _rd_->manager()->setSon(curNodeId, modality, newSonId);
172 visitedNode.
insert(oldSonId, newSonId);
175 if (
_rd_->node(curNodeId)->son(modality) != visitedNode[oldSonId])
176 _rd_->manager()->setSon(curNodeId, modality, visitedNode[oldSonId]);
181 if (
_rd_->variablesSequence().exists(curVar))
_rd_->erase(*curVar);
Base class for discrete random variable.
virtual Size domainSize() const =0
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
Structure used to represent a node internal structure.
const DiscreteVariable * nodeVar() const
Returns the node variable.
NodeId son(Idx modality) const
Returns the son at a given index.
virtual void copy(const MultiDimContainer< GUM_ELEMENT > &src)
Removes all variables in this MultiDimContainer and copy the content of src, variables included.
const MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > * _src_
One of the two function graphs used for the Projection.
const GUM_ELEMENT _neutral_
The function to be performed on the leaves.
MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > * _rd_
The resulting function graph.
const FUNCTOR< GUM_ELEMENT > _function_
The function to be performed on the leaves.
~MultiDimFunctionGraphProjector()
Default destructor.
const gum::VariableSet & _delVars_
The list of variables on which the projection is performed.
MultiDimFunctionGraphProjector(const MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > *src, const gum::VariableSet &delVars, const GUM_ELEMENT neutral)
Default constructor.
MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > * project()
Computes and builds the Function Graph that is the result of the Projection.
static MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > * getReducedAndOrderedInstance()
Returns a reduced and ordered instance.
Safe iterators for the Set class.
Base class for discrete random variable.
Size Idx
Type for indexes.
Size NodeId
Type for node ids.
Headers of the InternalNode class.
Class used to compute the projection of a function graph.
gum is the global namespace for all aGrUM entities
Set< const DiscreteVariable * > VariableSet