aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
multiDimFunctionGraph_tpl.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40#pragma once
41
42
52
53namespace gum {
54
55 // Default constructor.
56 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
58 bool isReduced) :
59 MultiDimImplementation< GUM_SCALAR >(), _name_("MultiDimFunctionGraph"),
60 _tableName_("NO NAME"), _model_(500, true), _manager_(nullptr), _root_(0),
61 _internalNodeMap_(500, true, false), _var2NodeIdMap_(500, true, false),
62 _isReduced_(isReduced) {
63 GUM_CONSTRUCTOR(MultiDimFunctionGraph);
64 _manager_ = nullptr;
65 // Pop up a first node so that id 0 is unavailable
66 _model_.addNode();
67 }
68
69 // Copy constructor.
70 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
73 MultiDimImplementation< GUM_SCALAR >(), _name_("MultiDimFunctionGraph"),
74 _tableName_("No NAME"), _model_(500, true), _manager_(nullptr), _root_(0),
75 _internalNodeMap_(500, true, false), _var2NodeIdMap_(500, true, false),
77 GUM_CONS_CPY(MultiDimFunctionGraph);
78 copy(from);
79 }
80
81 // Copy Operator.
82 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
89
90 // Destructor.
91 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
93 // Manager deletion
94 GUM_DESTRUCTOR(MultiDimFunctionGraph);
95 if (_manager_ != nullptr) delete _manager_;
96 this->clear();
97 }
98
99 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
107
108 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
110 return _name_;
111 }
112
113 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
114 INLINE void
116 const GUM_SCALAR& value) const {
118 "Function Graph can't be edited so "
119 "easily.\nMultiDimFunctionGraphManager "
120 "provides the framework to edit a "
121 "Function Graph.")
122 }
124 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
125 INLINE void
128 "Function Graph can't be edited so "
129 "easily.\nMultiDimFunctionGraphManager "
130 "provides the framework to edit a "
131 "Function Graph.")
132 }
133
134 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
136 const std::vector< GUM_SCALAR >& v) const {
138 "Function Graph can't be edited so "
139 "easily.\nMultiDimFunctionGraphManager "
140 "provides the framework to editaa "
141 "Function Graph.")
142 }
143
144 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
146 std::initializer_list< GUM_SCALAR > l) const {
148 "Function Graph can't be edited so "
149 "easily.\nMultiDimFunctionGraphManager "
150 "provides the framework to edit a "
151 "Function Graph.")
153
154 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
155 INLINE void
161
162 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
163 INLINE void
165 if (this->_var2NodeIdMap_.exists(&v)) {
166 while (_var2NodeIdMap_[&v]->list() != nullptr) {
167 manager()->eraseNode(_var2NodeIdMap_[&v]->list()->element());
168 }
169 delete _var2NodeIdMap_[&v];
171 }
172
174 }
175
176 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
178 return _internalNodeMap_.size(); // + _valueMap_.size();
179 }
181 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
183 const Instantiation& i,
184 const DiscreteVariable* const var,
185 Idx oldval,
186 Idx newval) {}
187
188 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
191
192 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
196 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
200 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
204 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
207
208 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
210 const Instantiation* i) const {
211 std::stringstream sBuff;
212 sBuff << (*i) << " = " << this->get(*i);
213 return sBuff.str();
214 }
215
216 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
219 Instantiation* p_i) const {
221 "You cannot copy another type of multiDim "
222 "into a MultiDimFunctionGraph.");
223 }
224
225 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
229 "You cannot copy another type of multiDim "
230 "into a MultiDimFunctionGraph.");
231 }
232
233 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
236 if (this->_isReduced_ != src.isReducedAndOrdered())
238 "Cannot copy a Reduced and Ordered "
239 "function graph into Tree function graph "
240 "(or vice-versa).")
241
242 this->clear();
243
244 // New variables insertion
246 = src.variablesSequence().beginSafe();
247 varIter != src.variablesSequence().endSafe();
248 ++varIter)
249 this->add(**varIter);
251 std::vector< NodeId > lifo;
253
254 if (src.isTerminalNode(src.root()))
255 this->manager()->setRootNode(this->manager()->addTerminalNode(src.nodeValue(src.root())));
256 else {
257 this->manager()->setRootNode(
258 this->manager()->addInternalNode(src.node(src.root())->nodeVar()));
259 src2dest.insert(src.root(), this->root());
260 lifo.push_back(src.root());
261 }
262
263 // Depth-first exploration and copy
264 while (!lifo.empty()) {
265 NodeId currentSrcNodeId = lifo.back();
266 lifo.pop_back();
267
268 const InternalNode* currentSrcNode = src.node(currentSrcNodeId);
269
270 for (Idx index = 0; index < currentSrcNode->nbSons(); ++index) {
271 if (!src2dest.existsFirst(currentSrcNode->son(index))) {
272 NodeId srcSonNodeId = currentSrcNode->son(index), destSonNodeId = 0;
273 if (src.isTerminalNode(srcSonNodeId)) {
274 destSonNodeId = this->manager()->addTerminalNode(src.nodeValue(srcSonNodeId));
275 } else {
276 destSonNodeId = this->manager()->addInternalNode(src.node(srcSonNodeId)->nodeVar());
277 lifo.push_back(srcSonNodeId);
278 }
279 src2dest.insert(srcSonNodeId, destSonNodeId);
280 }
281 this->manager()->setSon(src2dest.second(currentSrcNodeId),
282 index,
283 src2dest.second(currentSrcNode->son(index)));
284 }
285 }
286
287 manager()->clean();
288 }
290 // Copies src diagrams structure into this diagrams.
291 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
295 if (this->_isReduced_ != src.isReducedAndOrdered())
297 "Cannot copy a Reduced and Ordered "
298 "function graph into Tree function graph "
299 "(or vice-versa).")
300
301 this->clear();
302
303 // New variables insertion
305 = src.variablesSequence().beginSafe();
306 varIter != src.variablesSequence().endSafe();
307 ++varIter) {
308 if ((*varIter)->domainSize() != reassign.second(*varIter)->domainSize())
310 "Var " << (*varIter)->name() << " and var " << reassign.second(*varIter)->name()
311 << " have different domain sizes (" << (*varIter)->domainSize()
312 << "!=" << reassign.second(*varIter)->domainSize() << ")")
313 this->add(*(reassign.second(*varIter)));
314 }
315
316 std::vector< NodeId > lifo;
318
319 if (src.isTerminalNode(src.root())) {
320 this->manager()->setRootNode(this->manager()->addTerminalNode(src.nodeValue(src.root())));
321 } else {
322 this->manager()->setRootNode(
323 this->manager()->addInternalNode(reassign.second(src.node(src.root())->nodeVar())));
324 src2dest.insert(src.root(), this->root());
325 lifo.push_back(src.root());
327
328 // Depth-first exploration and copy
329 while (!lifo.empty()) {
330 NodeId currentSrcNodeId = lifo.back();
331 lifo.pop_back();
333 const InternalNode* currentSrcNode = src.node(currentSrcNodeId);
334
335 for (Idx index = 0; index < currentSrcNode->nbSons(); ++index) {
336 if (!src2dest.existsFirst(currentSrcNode->son(index))) {
337 NodeId srcSonNodeId = currentSrcNode->son(index), destSonNodeId = 0;
338 if (src.isTerminalNode(srcSonNodeId)) {
339 destSonNodeId = this->manager()->addTerminalNode(src.nodeValue(srcSonNodeId));
340 } else {
341 destSonNodeId = this->manager()->addInternalNode(
342 reassign.second(src.node(srcSonNodeId)->nodeVar()));
343 lifo.push_back(srcSonNodeId);
344 }
345 src2dest.insert(srcSonNodeId, destSonNodeId);
346 }
347 this->manager()->setSon(src2dest.second(currentSrcNodeId),
348 index,
349 src2dest.second(currentSrcNode->son(index)));
350 }
351 }
353 manager()->clean();
354 }
355
356 // Copies src diagrams and multiply every value by the given scalar.
357 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
360 GUM_SCALAR gamma) {
361 if (this->_isReduced_ != src.isReducedAndOrdered())
363 "Cannot copy a Reduced and Ordered "
364 "function graph into Tree function graph "
365 "(or vice-versa).")
366
367 this->clear();
368
369 // New variables insertion
370 for (SequenceIteratorSafe< const DiscreteVariable* > varIter
371 = src.variablesSequence().beginSafe();
372 varIter != src.variablesSequence().endSafe();
373 ++varIter)
374 this->add(**varIter);
375
376 std::vector< NodeId > lifo;
377 HashTable< NodeId, NodeId > src2dest;
378
379 if (src.isTerminalNode(src.root()))
380 this->manager()->setRootNode(
381 this->manager()->addTerminalNode(gamma * src.nodeValue(src.root())));
382 else {
383 this->manager()->setRootNode(
384 this->manager()->addInternalNode(src.node(src.root())->nodeVar()));
385 src2dest.insert(src.root(), this->root());
386 lifo.push_back(src.root());
387 }
388
389 // Depth-first exploration an copy
390 while (!lifo.empty()) {
391 NodeId currentSrcNodeId = lifo.back();
392 lifo.pop_back();
393
394 const InternalNode* currentSrcNode = src.node(currentSrcNodeId);
395
396 for (Idx index = 0; index < currentSrcNode->nbSons(); ++index) {
397 if (!src2dest.exists(currentSrcNode->son(index))) {
398 NodeId srcSonNodeId = currentSrcNode->son(index), destSonNodeId = 0;
399 if (src.isTerminalNode(srcSonNodeId)) {
400 destSonNodeId = this->manager()->addTerminalNode(gamma * src.nodeValue(srcSonNodeId));
401 } else {
402 destSonNodeId = this->manager()->addInternalNode(src.node(srcSonNodeId)->nodeVar());
403 lifo.push_back(srcSonNodeId);
404 }
405 src2dest.insert(srcSonNodeId, destSonNodeId);
406 }
407 this->manager()->setSon(src2dest[currentSrcNodeId],
408 index,
409 src2dest[currentSrcNode->son(index)]);
410 }
411 }
412
413 manager()->clean();
414 }
415
416 // Clears the function graph
417 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
419 _model_.clear();
420 // Always discard the nodeId 0
421 _model_.addNode();
422
423 this->clearAllTerminalNodes();
424
425 // Nodes cleaning
427 nodeIter != _internalNodeMap_.end();
428 ++nodeIter) {
429 delete nodeIter.val();
430 }
431 _internalNodeMap_.clear();
432
433 // Cleaning the list of nodes for each variables
435 = _var2NodeIdMap_.begin();
436 varIter != _var2NodeIdMap_.end();
437 ++varIter) {
438 delete varIter.val();
439 }
440 _var2NodeIdMap_.clear();
441
443 = this->variablesSequence().rbeginSafe();
444 varIter != this->variablesSequence().rendSafe();
445 --varIter) {
446 this->erase(**varIter);
447 }
448 }
449
450 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
451 INLINE std::string
453 std::stringstream output;
454 std::stringstream terminalStream;
455 std::stringstream nonTerminalStream;
456 std::stringstream arcstream;
457 // std::stringstream defaultarcstream;
458 output << std::endl << "digraph \" " << _tableName_ << "\" {" << std::endl;
459
460 terminalStream << "node [shape = box];" << std::endl;
461 nonTerminalStream << "node [shape = ellipse];" << std::endl;
462 std::string tab = " ";
463
464 for (NodeGraphPart::NodeIterator nodeIter = _model_.begin(); nodeIter != _model_.end();
465 ++nodeIter)
466 if (*nodeIter != 0) {
467 if (this->isTerminalNode((NodeId)*nodeIter))
468 terminalStream << tab << *nodeIter << ";" << tab << *nodeIter << " [label=\"" << *nodeIter
469 << " - " << std::setprecision(30) << this->terminalNodeValue(*nodeIter)
470 << "\"]"
471 << ";" << std::endl;
472 else {
473 InternalNode* currentNode = _internalNodeMap_[*nodeIter];
474 nonTerminalStream << tab << *nodeIter << ";" << tab << *nodeIter << " [label=\""
475 << *nodeIter << " - " << currentNode->nodeVar()->name() << "\"]"
476 << ";" << std::endl;
477
478 // if (arcMap_[*nodeIter] != NULL)
480 for (Idx sonIter = 0; sonIter < currentNode->nbSons(); ++sonIter) {
481 if (!sonMap.exists(currentNode->son(sonIter)))
482 sonMap.insert(currentNode->son(sonIter), new LinkedList< Idx >());
483 sonMap[currentNode->son(sonIter)]->addLink(sonIter);
484 }
485
486 for (auto sonIter = sonMap.beginSafe(); sonIter != sonMap.endSafe(); ++sonIter) {
487 arcstream << tab << *nodeIter << " -> " << sonIter.key() << " [label=\" ";
488 Link< Idx >* modaIter = sonIter.val()->list();
489 while (modaIter) {
490 arcstream << currentNode->nodeVar()->label(modaIter->element()) << ", ";
491 modaIter = modaIter->nextLink();
492 }
493 arcstream << "\",color=\"#0000ff\"]"
494 << ";" << std::endl;
495 delete sonIter.val();
496 }
497
498 if (withBackArcs) {
499 Link< Parent >* parentIter = currentNode->parents();
500 while (parentIter != nullptr) {
501 arcstream << tab << *nodeIter << " -> " << parentIter->element().parentId
502 << " [label=\"" << parentIter->element().modality << "\",color=\"#ff0000\"]"
503 << ";" << std::endl;
504 parentIter = parentIter->nextLink();
505 }
506 }
507 }
508 }
509
510 output << terminalStream.str() << std::endl
511 << nonTerminalStream.str() << std::endl
512 << arcstream.str() << std::endl
513 << "}" << std::endl;
514
515 return output.str();
516 }
517
518 // Returns a const reference to the manager of this diagram
519 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
520 INLINE const NodeGraphPart&
524
525 // Returns a const reference to the manager of this diagram
526 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
536
537 // Returns the id of the root node from the diagram
538 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
542
543 // Indicates if given node is terminal or not
544 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
549
550 // Indicates if given node is terminal or not
551 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
553 const NodeId& node) const {
554 return this->_internalNodeMap_.exists(node);
555 }
556
557 // Returns value associated to given node.
558 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
559 INLINE const GUM_SCALAR&
561 if (!isTerminalNode(n))
562 GUM_ERROR(InvalidArgument, "Id " << n << " is not bound to any terminal node")
563 return this->terminalNodeValue(n);
564 }
565
566 // Returns internalNode structure associated to that nodeId
567 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
568 INLINE const InternalNode*
570 if (!isInternalNode(n))
571 GUM_ERROR(InvalidArgument, "Id " << n << " is not bound to any terminal node")
572 return this->_internalNodeMap_[n];
573 }
574
575 // Returns the list of node associated to given variable
576 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
577 INLINE const LinkedList< NodeId >*
579 const DiscreteVariable* var) const {
580 if (!this->variablesSequence().exists(var))
582 "Var " << var->name() << " has not been inserted in the function graph")
583 return _var2NodeIdMap_[var];
584 }
585
586 // Returns the name of the table represented by this structure.
587 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
588 INLINE const std::string&
592
593 // Sets the name of the table represented by this structure.
594 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
599
600 // Returns true if this MultiDimFunctionGraph is reduced and Ordered.
601 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
605
606 // Returns a reduced and ordered instance.
607 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
612
613 // Returns an arborescent instance
614 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
619
620 // Not implemented yet
621 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
622 INLINE void
627
628 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
630 const Instantiation& inst) const {
631 GUM_ERROR(OperationNotAllowed, "You can't edit a function by other mean than the manager")
632 }
633
634 // Return a data, given a Instantiation.
635 template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
637 const Instantiation& inst) const {
638 NodeId currentNodeId = _root_;
639 InternalNode* currentNode = nullptr;
640 while (!isTerminalNode(currentNodeId)) {
641 currentNode = _internalNodeMap_[currentNodeId];
642 currentNodeId = currentNode->son(inst.val(*(currentNode->nodeVar())));
643 }
644 return this->terminalNodeValue(currentNodeId);
645 }
646
647} // namespace gum
Unsafe Iterators for hashtables.
Definition hashTable.h:2428
bool existsFirst(const T1 &first) const
Returns true if first is the first element in a pair in the gum::Bijection.
void insert(const T1 &first, const T2 &second)
Inserts a new association in the gum::Bijection.
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
Set of pairs of elements with fast search for both elements.
Definition bijection.h:1594
Base class for discrete random variable.
virtual std::string label(Idx i) const =0
get the indice-th label. This method is pure virtual.
const GUM_SCALAR & terminalNodeValue(const NodeId &n) const
Returns the value of the terminal node that has the given id.
void addTerminalNode(const NodeId &n, const GUM_SCALAR &v)
Insert a new terminal node with given value.
const GUM_SCALAR & value() const
Returns the value of the current terminal nodes pointed by the constant safe iterator.
void clearAllTerminalNodes()
Erase all terminal nodes.
bool existsTerminalNodeWithId(const NodeId &n) const
Returns true if a terminal node matching this id exists.
The class for generic Hash Tables.
Definition hashTable.h:637
const iterator_safe & endSafe() noexcept
Returns the safe iterator pointing to the end of the hashtable.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
iterator_safe beginSafe()
Returns the safe iterator pointing to the beginning of the hashtable.
Class for assigning/browsing values to tuples of discrete variables.
Idx val(Idx i) const
Returns the current value of the variable at position i.
Structure used to represent a node internal structure.
const DiscreteVariable * nodeVar() const
Returns the node variable.
Idx nbSons() const
Returns the number of sons.
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.
Abstract base class for all multi dimensionnal containers.
virtual std::string toString() const
Returns a representation of this MultiDimContainer.
Class implementingting a function graph manager.
NodeId addInternalNode(const DiscreteVariable *var)
Inserts a new non terminal node in graph.
MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > * manager()
Returns a const reference to the manager of this diagram.
bool _isReduced_
Wheter the MultiDimFunctionGraphManager is reduced or not.
MultiDimFunctionGraph(bool isReduced=true)
Default constructor.
virtual void changeNotification(const Instantiation &i, const DiscreteVariable *const var, Idx oldval, Idx newval)
Listen to changes in a given Instantiation.
std::string toDot(bool withBackArcs=false) const
Returns a const reference to the manager of this diagram.
virtual void setDecNotification(const Instantiation &i)
Listen to increment in each recorded Instantiation.
virtual void set(const Instantiation &i, const GUM_SCALAR &value) const
virtual void setChangeNotification(const Instantiation &i)
Listen to an assignment of a value in a Instantiation.
bool isTerminalNode(const NodeId &node) const
void setTableName(const std::string &name)
Sets the name of the table represented by this structure.
bool isInternalNode(const NodeId &node) const
Indicates if given node is terminal or not.
virtual Size realSize() const
Returns the real number of parameters used for this table.
virtual void setIncNotification(const Instantiation &i)
Listen to increment in a given Instantiation.
static MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * getTreeInstance()
Returns an arborescent instance.
static MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * getReducedAndOrderedInstance()
Returns a reduced and ordered instance.
MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > * _manager_
A reference to the manager that edits this function graph.
const InternalNode * node(NodeId n) const
Returns internalNode structure associated to that nodeId.
virtual void copy(const MultiDimContainer< GUM_SCALAR > &src)
HashTable< NodeId, InternalNode * > _internalNodeMap_
Associates each non-terminal node to a variable.
HashTable< const DiscreteVariable *, LinkedList< NodeId > * > _var2NodeIdMap_
Mapping between var and node.
virtual void setLastNotification(const Instantiation &i)
Listen to setLast in a given Instantiation.
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > & operator=(const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > &from)
Copy Operator.
const LinkedList< NodeId > * varNodeListe(const DiscreteVariable *var) const
Returns the list of node associated to given variable.
bool isReducedAndOrdered() const
Returns true if this MultiDimFunctionGraph is reduced and Ordered.
virtual void erase(const DiscreteVariable &v)
Removes a var from the variables of the multidimensional matrix.
std::string _tableName_
The name of the data structure.
GUM_SCALAR & get_(const Instantiation &inst) const
std::string _name_
The name of the data structure.
void copyAndMultiplyByScalar(const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > &src, GUM_SCALAR gamma)
Copies src diagrams and multiply every value by the given scalar.
const NodeGraphPart & model() const
Returns a const reference to the manager of this diagram.
void copyAndReassign(const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > &src, const Bijection< const DiscreteVariable *, const DiscreteVariable * > &reassign)
Copies src diagrams structure into this diagrams.
virtual void add(const DiscreteVariable &v)
Adds a new var to the variables of the multidimensional matrix.
const std::string & tableName() const
Returns the name of the table represented by this structure.
virtual void populate(const std::vector< GUM_SCALAR > &v) const
NodeId _root_
The root node of the function graph.
virtual void replace_(const DiscreteVariable *x, const DiscreteVariable *y)
virtual void fill(const GUM_SCALAR &d) const
virtual const std::string & name() const
Returns the real name of the multiDim implementation.
virtual void copyFrom(const MultiDimContainer< GUM_SCALAR > &src, Instantiation *p_i=(Instantiation *) 0) const
void clear()
Clears the function graph.
virtual MultiDimContainer< GUM_SCALAR > * newFactory() const
Creates an empty clone of this MultiDimContainer.
NodeGraphPart _model_
Indicates available nodeIds.
virtual GUM_SCALAR get(const Instantiation &i) const
Returns the value pointed by i.
virtual void setFirstNotification(const Instantiation &i)
Listen to setFirst in a given Instantiation.
MultiDimImplementation()
Default constructor.
virtual void add(const DiscreteVariable &v) override
Adds a new var to the variables of the multidimensional matrix.
virtual const Sequence< const DiscreteVariable * > & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.
virtual void erase(const DiscreteVariable &v) override
Removes a var from the variables of the multidimensional matrix.
Class for node sets in graph.
NodeGraphPartIterator NodeIterator
Exception : operation not allowed.
Safe iterators for Sequence.
Definition sequence.h:1134
const std::string & name() const
returns the name of the variable
#define GUM_ERROR(type, msg)
Definition exceptions.h:72
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size Idx
Type for indexes.
Definition types.h:79
Size NodeId
Type for node ids.
Headers of MultiDimFunctionGraph.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
STL namespace.