aGrUM 3.1.1
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-2026 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-2026 *
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
41#pragma once
42
43
53
54namespace gum {
55
56 // Default constructor.
57 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
59 MultiDimImplementation< GUM_ELEMENT >(), _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_ELEMENT, template < class > class TerminalNodePolicy >
73 MultiDimImplementation< GUM_ELEMENT >(), _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_ELEMENT, template < class > class TerminalNodePolicy >
89
90 // Destructor.
91 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
93 // Manager deletion
94 GUM_DESTRUCTOR(MultiDimFunctionGraph);
95 if (_manager_ != nullptr) delete _manager_;
96 this->clear();
97 }
98
99 // GCC false positive: deep inlining of newFactory() through Tensor copy-ctor loses virtual
100 // dispatch, making GCC believe a MultiDimFunctionGraph (larger) is accessed on a MultiDimArray
101 // allocation (512 bytes). The access is safe at runtime because the virtual call is correct.
102#ifdef __GNUC__
103# pragma GCC diagnostic push
104# pragma GCC diagnostic ignored "-Warray-bounds"
105#endif
106 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
109 if (_isReduced_)
110 return MultiDimFunctionGraph< GUM_ELEMENT,
111 TerminalNodePolicy >::getReducedAndOrderedInstance();
113 }
114#ifdef __GNUC__
115# pragma GCC diagnostic pop
116#endif
117
118 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
120 return _name_;
121 }
122
123 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
125 const Instantiation& i,
126 const GUM_ELEMENT& value) const {
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_ELEMENT, template < class > class TerminalNodePolicy >
137 "Function Graph can't be edited so "
138 "easily.\nMultiDimFunctionGraphManager "
139 "provides the framework to edit a "
140 "Function Graph.")
141 }
142
143 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
145 const std::vector< GUM_ELEMENT >& v) const {
147 "Function Graph can't be edited so "
148 "easily.\nMultiDimFunctionGraphManager "
149 "provides the framework to editaa "
150 "Function Graph.")
151 }
153 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
155 std::initializer_list< GUM_ELEMENT > l) const {
157 "Function Graph can't be edited so "
158 "easily.\nMultiDimFunctionGraphManager "
159 "provides the framework to edit a "
160 "Function Graph.")
161 }
162
163 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
169
170 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
172 if (this->_var2NodeIdMap_.exists(&v)) {
173 while (_var2NodeIdMap_[&v]->list() != nullptr) {
174 manager()->eraseNode(_var2NodeIdMap_[&v]->list()->element());
175 }
176 delete _var2NodeIdMap_[&v];
177 _var2NodeIdMap_.erase(&v);
179
181 }
183 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
185 return _internalNodeMap_.size(); // + _valueMap_.size();
187
188 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
194
195 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
198
199 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
202
203 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
206
207 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
210
211 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
214
215 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
217 const Instantiation* i) const {
218 std::stringstream sBuff;
219 sBuff << (*i) << " = " << this->get(*i);
220 return sBuff.str();
221 }
222
223 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
226 Instantiation* p_i) const {
228 "You cannot copy another type of multiDim "
229 "into a MultiDimFunctionGraph.");
230 }
231
232 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
236 "You cannot copy another type of multiDim "
237 "into a MultiDimFunctionGraph.");
238 }
239
240 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
243 if (this->_isReduced_ != src.isReducedAndOrdered())
245 "Cannot copy a Reduced and Ordered "
246 "function graph into Tree function graph "
247 "(or vice-versa).")
248
249 this->clear();
250
251 // New variables insertion
252 for (SequenceIteratorSafe< const DiscreteVariable* > varIter
253 = src.variablesSequence().beginSafe();
254 varIter != src.variablesSequence().endSafe();
255 ++varIter)
256 this->add(**varIter);
257
258 std::vector< NodeId > lifo;
259 Bijection< NodeId, NodeId > src2dest;
260
261 if (src.isTerminalNode(src.root()))
262 this->manager()->setRootNode(this->manager()->addTerminalNode(src.nodeValue(src.root())));
263 else {
264 this->manager()->setRootNode(
265 this->manager()->addInternalNode(src.node(src.root())->nodeVar()));
266 src2dest.insert(src.root(), this->root());
267 lifo.push_back(src.root());
268 }
269
270 // Depth-first exploration and copy
271 while (!lifo.empty()) {
272 NodeId currentSrcNodeId = lifo.back();
273 lifo.pop_back();
274
275 const InternalNode* currentSrcNode = src.node(currentSrcNodeId);
276
277 for (Idx index = 0; index < currentSrcNode->nbSons(); ++index) {
278 if (!src2dest.existsFirst(currentSrcNode->son(index))) {
279 NodeId srcSonNodeId = currentSrcNode->son(index), destSonNodeId = 0;
280 if (src.isTerminalNode(srcSonNodeId)) {
281 destSonNodeId = this->manager()->addTerminalNode(src.nodeValue(srcSonNodeId));
282 } else {
283 destSonNodeId = this->manager()->addInternalNode(src.node(srcSonNodeId)->nodeVar());
284 lifo.push_back(srcSonNodeId);
285 }
286 src2dest.insert(srcSonNodeId, destSonNodeId);
287 }
288 this->manager()->setSon(src2dest.second(currentSrcNodeId),
289 index,
290 src2dest.second(currentSrcNode->son(index)));
291 }
292 }
293
294 manager()->clean();
295 }
296
297 // Copies src diagrams structure into this diagrams.
298 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
302 if (this->_isReduced_ != src.isReducedAndOrdered())
304 "Cannot copy a Reduced and Ordered "
305 "function graph into Tree function graph "
306 "(or vice-versa).")
307
308 this->clear();
309
310 // New variables insertion
311 for (SequenceIteratorSafe< const DiscreteVariable* > varIter
312 = src.variablesSequence().beginSafe();
313 varIter != src.variablesSequence().endSafe();
314 ++varIter) {
315 if ((*varIter)->domainSize() != reassign.second(*varIter)->domainSize())
317 "Var " << (*varIter)->name() << " and var " << reassign.second(*varIter)->name()
318 << " have different domain sizes (" << (*varIter)->domainSize()
319 << "!=" << reassign.second(*varIter)->domainSize() << ")")
320 this->add(*(reassign.second(*varIter)));
322
323 std::vector< NodeId > lifo;
325
326 if (src.isTerminalNode(src.root())) {
327 this->manager()->setRootNode(this->manager()->addTerminalNode(src.nodeValue(src.root())));
328 } else {
329 this->manager()->setRootNode(
330 this->manager()->addInternalNode(reassign.second(src.node(src.root())->nodeVar())));
331 src2dest.insert(src.root(), this->root());
332 lifo.push_back(src.root());
334
335 // Depth-first exploration and copy
336 while (!lifo.empty()) {
337 NodeId currentSrcNodeId = lifo.back();
338 lifo.pop_back();
339
340 const InternalNode* currentSrcNode = src.node(currentSrcNodeId);
342 for (Idx index = 0; index < currentSrcNode->nbSons(); ++index) {
343 if (!src2dest.existsFirst(currentSrcNode->son(index))) {
344 NodeId srcSonNodeId = currentSrcNode->son(index), destSonNodeId = 0;
345 if (src.isTerminalNode(srcSonNodeId)) {
346 destSonNodeId = this->manager()->addTerminalNode(src.nodeValue(srcSonNodeId));
347 } else {
348 destSonNodeId = this->manager()->addInternalNode(
349 reassign.second(src.node(srcSonNodeId)->nodeVar()));
350 lifo.push_back(srcSonNodeId);
351 }
352 src2dest.insert(srcSonNodeId, destSonNodeId);
353 }
354 this->manager()->setSon(src2dest.second(currentSrcNodeId),
355 index,
356 src2dest.second(currentSrcNode->son(index)));
357 }
358 }
359
360 manager()->clean();
362
363 // Copies src diagrams and multiply every value by the given scalar.
364 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
367 GUM_ELEMENT gamma) {
368 if (this->_isReduced_ != src.isReducedAndOrdered())
370 "Cannot copy a Reduced and Ordered "
371 "function graph into Tree function graph "
372 "(or vice-versa).")
373
374 this->clear();
375
376 // New variables insertion
378 = src.variablesSequence().beginSafe();
379 varIter != src.variablesSequence().endSafe();
380 ++varIter)
381 this->add(**varIter);
382
383 std::vector< NodeId > lifo;
384 HashTable< NodeId, NodeId > src2dest;
385
386 if (src.isTerminalNode(src.root()))
387 this->manager()->setRootNode(
388 this->manager()->addTerminalNode(gamma * src.nodeValue(src.root())));
389 else {
390 this->manager()->setRootNode(
391 this->manager()->addInternalNode(src.node(src.root())->nodeVar()));
392 src2dest.insert(src.root(), this->root());
393 lifo.push_back(src.root());
394 }
395
396 // Depth-first exploration an copy
397 while (!lifo.empty()) {
398 NodeId currentSrcNodeId = lifo.back();
399 lifo.pop_back();
400
401 const InternalNode* currentSrcNode = src.node(currentSrcNodeId);
402
403 for (Idx index = 0; index < currentSrcNode->nbSons(); ++index) {
404 if (!src2dest.exists(currentSrcNode->son(index))) {
405 NodeId srcSonNodeId = currentSrcNode->son(index), destSonNodeId = 0;
406 if (src.isTerminalNode(srcSonNodeId)) {
407 destSonNodeId = this->manager()->addTerminalNode(gamma * src.nodeValue(srcSonNodeId));
408 } else {
409 destSonNodeId = this->manager()->addInternalNode(src.node(srcSonNodeId)->nodeVar());
410 lifo.push_back(srcSonNodeId);
411 }
412 src2dest.insert(srcSonNodeId, destSonNodeId);
413 }
414 this->manager()->setSon(src2dest[currentSrcNodeId],
415 index,
416 src2dest[currentSrcNode->son(index)]);
417 }
418 }
419
420 manager()->clean();
421 }
422
423 // Clears the function graph
424 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
426 _model_.clear();
427 // Always discard the nodeId 0
428 _model_.addNode();
429
430 this->clearAllTerminalNodes();
431
432 // Nodes cleaning
434 nodeIter != _internalNodeMap_.end();
435 ++nodeIter) {
436 delete nodeIter.val();
437 }
438 _internalNodeMap_.clear();
439
440 // Cleaning the list of nodes for each variables
442 = _var2NodeIdMap_.begin();
443 varIter != _var2NodeIdMap_.end();
444 ++varIter) {
445 delete varIter.val();
446 }
447 _var2NodeIdMap_.clear();
448
450 = this->variablesSequence().rbeginSafe();
451 varIter != this->variablesSequence().rendSafe();
452 --varIter) {
453 this->erase(**varIter);
454 }
455 }
456
457 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
458 std::string
460 std::stringstream output;
461 std::stringstream terminalStream;
462 std::stringstream nonTerminalStream;
463 std::stringstream arcstream;
464 // std::stringstream defaultarcstream;
465 output << '\n' << "digraph \" " << _tableName_ << "\" {" << '\n';
466
467 terminalStream << "node [shape = box];" << '\n';
468 nonTerminalStream << "node [shape = ellipse];" << '\n';
469 std::string tab = " ";
470
471 for (NodeGraphPart::NodeIterator nodeIter = _model_.begin(); nodeIter != _model_.end();
472 ++nodeIter)
473 if (*nodeIter != 0) {
474 if (this->isTerminalNode((NodeId)*nodeIter))
475 terminalStream << tab << *nodeIter << ";" << tab << *nodeIter << " [label=\"" << *nodeIter
476 << " - " << std::setprecision(30) << this->terminalNodeValue(*nodeIter)
477 << "\"]"
478 << ";" << '\n';
479 else {
480 InternalNode* currentNode = _internalNodeMap_[*nodeIter];
481 nonTerminalStream << tab << *nodeIter << ";" << tab << *nodeIter << " [label=\""
482 << *nodeIter << " - " << currentNode->nodeVar()->name() << "\"]"
483 << ";" << '\n';
484
485 // if (arcMap_[*nodeIter] != NULL)
487 for (Idx sonIter = 0; sonIter < currentNode->nbSons(); ++sonIter) {
488 if (!sonMap.exists(currentNode->son(sonIter)))
489 sonMap.insert(currentNode->son(sonIter), new LinkedList< Idx >());
490 sonMap[currentNode->son(sonIter)]->addLink(sonIter);
491 }
492
493 for (auto sonIter = sonMap.beginSafe(); sonIter != sonMap.endSafe(); ++sonIter) {
494 arcstream << tab << *nodeIter << " -> " << sonIter.key() << " [label=\" ";
495 Link< Idx >* modaIter = sonIter.val()->list();
496 while (modaIter) {
497 arcstream << currentNode->nodeVar()->label(modaIter->element()) << ", ";
498 modaIter = modaIter->nextLink();
499 }
500 arcstream << "\",color=\"#0000ff\"]"
501 << ";" << '\n';
502 delete sonIter.val();
503 }
504
505 if (withBackArcs) {
506 Link< Parent >* parentIter = currentNode->parents();
507 while (parentIter != nullptr) {
508 arcstream << tab << *nodeIter << " -> " << parentIter->element().parentId
509 << " [label=\"" << parentIter->element().modality << "\",color=\"#ff0000\"]"
510 << ";" << '\n';
511 parentIter = parentIter->nextLink();
512 }
513 }
514 }
515 }
516
517 output << terminalStream.str() << '\n'
518 << nonTerminalStream.str() << '\n'
519 << arcstream.str() << '\n'
520 << "}" << '\n';
521
522 return output.str();
523 }
524
525 // Returns a const reference to the manager of this diagram
526 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
530
531 // Returns a const reference to the manager of this diagram
532 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
543
544 // Returns the id of the root node from the diagram
545 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
549
550 // Indicates if given node is terminal or not
551 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
556
557 // Indicates if given node is terminal or not
558 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
563
564 // Returns value associated to given node.
565 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
566 const GUM_ELEMENT&
568 if (!isTerminalNode(n))
569 GUM_ERROR(InvalidArgument, "Id " << n << " is not bound to any terminal node")
570 return this->terminalNodeValue(n);
571 }
572
573 // Returns internalNode structure associated to that nodeId
574 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
575 const InternalNode*
577 if (!isInternalNode(n))
578 GUM_ERROR(InvalidArgument, "Id " << n << " is not bound to any terminal node")
579 return this->_internalNodeMap_[n];
580 }
581
582 // Returns the list of node associated to given variable
583 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
586 const DiscreteVariable* var) const {
587 if (!this->variablesSequence().exists(var))
589 "Var " << var->name() << " has not been inserted in the function graph")
590 return _var2NodeIdMap_[var];
591 }
592
593 // Returns the name of the table represented by this structure.
594 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
598
599 // Sets the name of the table represented by this structure.
600 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
605
606 // Returns true if this MultiDimFunctionGraph is reduced and Ordered.
607 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
611
612 // Returns a reduced and ordered instance.
613 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
618
619 // Returns an arborescent instance
620 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
625
626 // Not implemented yet
627 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
633
634 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
636 const Instantiation& inst) const {
637 GUM_ERROR(OperationNotAllowed, "You can't edit a function by other mean than the manager")
638 }
639
640 // Return a data, given a Instantiation.
641 template < typename GUM_ELEMENT, template < class > class TerminalNodePolicy >
643 const Instantiation& inst) const {
644 NodeId currentNodeId = _root_;
645 InternalNode* currentNode = nullptr;
646 while (!isTerminalNode(currentNodeId)) {
647 currentNode = _internalNodeMap_[currentNodeId];
648 currentNodeId = currentNode->son(inst.val(*(currentNode->nodeVar())));
649 }
650 return this->terminalNodeValue(currentNodeId);
651 }
652
653} // namespace gum
Unsafe Iterators for hashtables.
Definition hashTable.h:2465
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
void insert(const T1 &first, const T2 &second)
Inserts a new association in the gum::Bijection.
Set of pairs of elements with fast search for both elements.
Definition bijection.h:1640
Base class for discrete random variable.
virtual std::string label(Idx i) const =0
get the indice-th label. This method is pure virtual.
bool existsTerminalNodeWithId(const NodeId &n) const override
Returns true if a terminal node matching this id exists.
const GUM_ELEMENT & terminalNodeValue(const NodeId &n) const override
Returns the value of the terminal node that has the given id.
void addTerminalNode(const NodeId &n, const double &v) override
void clearAllTerminalNodes() override
Erase all terminal nodes.
const GUM_ELEMENT & value() const override
Returns the value of the current terminal nodes pointed by the constant safe iterator.
The class for generic Hash Tables.
Definition hashTable.h:640
iterator_safe beginSafe()
Returns the safe iterator pointing to the beginning of 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.
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.
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.
NodeGraphPart _model_
Indicates available nodeIds.
NodeId _root_
The root node of the function graph.
Size realSize() const override
Returns the real number of parameters used for this table.
HashTable< NodeId, InternalNode * > _internalNodeMap_
Associates each non-terminal node to a variable.
~MultiDimFunctionGraph() override
Class destructor.
void clear()
Clears the function graph.
std::string toDot(bool withBackArcs=false) const
Returns a const reference to the manager of this diagram.
static MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > * getTreeInstance()
Returns an arborescent instance.
HashTable< const DiscreteVariable *, LinkedList< NodeId > * > _var2NodeIdMap_
Mapping between var and node.
void copyFrom(const MultiDimContainer< GUM_ELEMENT > &src, Instantiation *p_i=(Instantiation *) 0) const override
void setFirstNotification(const Instantiation &i) override
Listen to setFirst in a given Instantiation.
void setChangeNotification(const Instantiation &i) override
Listen to an assignment of a value in a Instantiation.
MultiDimFunctionGraph(bool isReduced=true)
Default constructor.
void add(const DiscreteVariable &v) override
Adds a new var to the variables of the multidimensional matrix.
void replace_(const DiscreteVariable *x, const DiscreteVariable *y) override
void setTableName(std::string_view name)
Sets the name of the table represented by this structure.
void copy(const MultiDimContainer< GUM_ELEMENT > &src) override
MultiDimContainer< GUM_ELEMENT > * newFactory() const override
Creates an empty clone of this MultiDimContainer.
MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > & operator=(const MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > &from)
Copy Operator.
bool isInternalNode(const NodeId &node) const
Indicates if given node is terminal or not.
const LinkedList< NodeId > * varNodeListe(const DiscreteVariable *var) const
Returns the list of node associated to given variable.
MultiDimFunctionGraphManager< GUM_ELEMENT, TerminalNodePolicy > * _manager_
A reference to the manager that edits this function graph.
void copyAndMultiplyByScalar(const MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > &src, GUM_ELEMENT gamma)
Copies src diagrams and multiply every value by the given scalar.
void set(const Instantiation &i, const GUM_ELEMENT &value) const override
void setDecNotification(const Instantiation &i) override
Listen to increment in each recorded Instantiation.
void setLastNotification(const Instantiation &i) override
Listen to setLast in a given Instantiation.
void changeNotification(const Instantiation &i, const DiscreteVariable *const var, Idx oldval, Idx newval) override
Listen to changes in a given Instantiation.
const std::string & tableName() const
Returns the name of the table represented by this structure.
const std::string & name() const override
Returns the real name of the multiDim implementation.
bool isReducedAndOrdered() const
Returns true if this MultiDimFunctionGraph is reduced and Ordered.
std::string _name_
The name of the data structure.
bool isTerminalNode(const NodeId &node) const
GUM_ELEMENT & get_(const Instantiation &inst) const override
void copyAndReassign(const MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > &src, const Bijection< const DiscreteVariable *, const DiscreteVariable * > &reassign)
Copies src diagrams structure into this diagrams.
bool _isReduced_
Wheter the MultiDimFunctionGraphManager is reduced or not.
void fill(const GUM_ELEMENT &d) const override
void erase(const DiscreteVariable &v) override
Removes a var from the variables of the multidimensional matrix.
const NodeGraphPart & model() const
Returns a const reference to the manager of this diagram.
void populate(const std::vector< GUM_ELEMENT > &v) const override
void setIncNotification(const Instantiation &i) override
Listen to increment in a given Instantiation.
std::string _tableName_
The name of the data structure.
GUM_ELEMENT get(const Instantiation &i) const override
Returns the value pointed by i.
const InternalNode * node(NodeId n) const
Returns internalNode structure associated to that nodeId.
MultiDimFunctionGraphManager< GUM_ELEMENT, TerminalNodePolicy > * manager()
Returns a const reference to the manager of this diagram.
static MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > * getReducedAndOrderedInstance()
Returns a reduced and ordered instance.
void erase(const DiscreteVariable &v) override
Removes a var from the variables of the multidimensional matrix.
const Sequence< const DiscreteVariable * > & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.
void add(const DiscreteVariable &v) override
Adds a new var to the variables of the multidimensional matrix.
MultiDimImplementation()
Default constructor.
Class for node sets in graph.
NodeGraphPartIterator NodeIterator
Exception : operation not allowed.
Safe iterators for Sequence.
Definition sequence.h:1148
const std::string & name() const
returns the name of the variable
#define GUM_ERROR(type, msg)
Definition exceptions.h:76
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.