aGrUM  0.13.2
multiDimFunctionGraph_tpl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
28 
29 namespace gum {
30 
31  // Default constructor.
32  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
33  INLINE
35  bool isReduced) :
36  MultiDimImplementation< GUM_SCALAR >(),
37  __name("MultiDimFunctionGraph"), __tableName("NO NAME"), __model(500, true),
38  __manager(nullptr), __root(0), __internalNodeMap(500, true, false),
39  __var2NodeIdMap(500, true, false), __isReduced(isReduced) {
40  GUM_CONSTRUCTOR(MultiDimFunctionGraph);
41  __manager = nullptr;
42  // Pop up a first node so that id 0 is unavailable
43  __model.addNode();
44  }
45 
46  // Copy constructor.
47  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
48  INLINE
51  MultiDimImplementation< GUM_SCALAR >(),
52  __name("MultiDimFunctionGraph"), __tableName("No NAME"), __model(500, true),
53  __manager(nullptr), __root(0), __internalNodeMap(500, true, false),
54  __var2NodeIdMap(500, true, false), __isReduced(from.isReducedAndOrdered()) {
55  GUM_CONS_CPY(MultiDimFunctionGraph);
56  copy(from);
57  }
58 
59  // Copy Operator.
60  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
64  copy(from);
65  return *this;
66  }
67 
68  // Destructor.
69  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
70  INLINE MultiDimFunctionGraph< GUM_SCALAR,
71  TerminalNodePolicy >::~MultiDimFunctionGraph() {
72  // Manager deletion
73  GUM_DESTRUCTOR(MultiDimFunctionGraph);
74  if (__manager != nullptr) delete __manager;
75  this->clear();
76  }
77 
78  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
81  if (__isReduced)
84  else
85  return MultiDimFunctionGraph< GUM_SCALAR,
86  TerminalNodePolicy >::getTreeInstance();
87  }
88 
89  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
90  INLINE const std::string&
92  return __name;
93  }
94 
95  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
97  const Instantiation& i, const GUM_SCALAR& value) const {
99  "Function Graph can't be edited so "
100  "easily.\nMultiDimFunctionGraphManager "
101  "provides the framework to edit a "
102  "Function Graph.")
103  }
104 
105  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
107  const GUM_SCALAR& d) const {
109  "Function Graph can't be edited so "
110  "easily.\nMultiDimFunctionGraphManager "
111  "provides the framework to edit a "
112  "Function Graph.")
113  }
114 
115  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
117  const std::vector< GUM_SCALAR >& v) const {
119  "Function Graph can't be edited so "
120  "easily.\nMultiDimFunctionGraphManager "
121  "provides the framework to editaa "
122  "Function Graph.")
123  }
124  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
126  std::initializer_list< GUM_SCALAR > l) 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_SCALAR, template < class > class TerminalNodePolicy >
136  const DiscreteVariable& v) {
137  if (!this->variablesSequence().exists(&v))
139 
140  if (!this->__var2NodeIdMap.exists(&v))
141  __var2NodeIdMap.insert(&v, new LinkedList< NodeId >());
142  }
143 
144  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
146  const DiscreteVariable& v) {
147  if (this->__var2NodeIdMap.exists(&v)) {
148  while (__var2NodeIdMap[&v]->list() != nullptr) {
149  manager()->eraseNode(__var2NodeIdMap[&v]->list()->element());
150  }
151  delete __var2NodeIdMap[&v];
152  __var2NodeIdMap.erase(&v);
153  }
154 
155  if (this->variablesSequence().exists(&v))
157  }
158 
159  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
160  INLINE Size
162  return __internalNodeMap.size(); // + __valueMap.size();
163  }
164 
165 
166  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
167  INLINE void
169  const Instantiation& i,
170  const DiscreteVariable* const var,
171  Idx oldval,
172  Idx newval) {}
173 
174  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
175  INLINE void
177  const Instantiation& i) {}
178 
179  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
180  INLINE void
182  const Instantiation& i) {}
183 
184  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
185  INLINE void
187  const Instantiation& i) {}
188 
189  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
190  INLINE void
192  const Instantiation& i) {}
193 
194  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
195  INLINE void
197  const Instantiation& i) {}
198 
199  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
200  INLINE const std::string
202  const Instantiation* i) const {
203  std::stringstream sBuff;
204  sBuff << (*i) << " = " << this->get(*i);
205  return sBuff.str();
206  }
207 
208  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
210  const MultiDimContainer< GUM_SCALAR >& src, Instantiation* p_i) const {
212  "You cannot copy another type of multiDim "
213  "into a MultiDimFunctionGraph.");
214  }
215 
216  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
218  const MultiDimContainer< GUM_SCALAR >& src) {
220  "You cannot copy another type of multiDim "
221  "into a MultiDimFunctionGraph.");
222  }
223 
224  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
227  if (this->__isReduced != src.isReducedAndOrdered())
229  "Cannot copy a Reduced and Ordered "
230  "function graph into Tree function graph "
231  "(or vice-versa).")
232 
233  this->clear();
234 
235  // New variables insertion
237  src.variablesSequence().beginSafe();
238  varIter != src.variablesSequence().endSafe();
239  ++varIter)
240  this->add(**varIter);
241 
242  std::vector< NodeId > lifo;
244 
245  if (src.isTerminalNode(src.root()))
246  this->manager()->setRootNode(
247  this->manager()->addTerminalNode(src.nodeValue(src.root())));
248  else {
249  this->manager()->setRootNode(
250  this->manager()->addInternalNode(src.node(src.root())->nodeVar()));
251  src2dest.insert(src.root(), this->root());
252  lifo.push_back(src.root());
253  }
254 
255  // Depth-first exploration and copy
256  while (!lifo.empty()) {
257  NodeId currentSrcNodeId = lifo.back();
258  lifo.pop_back();
259 
260  const InternalNode* currentSrcNode = src.node(currentSrcNodeId);
261 
262  for (Idx index = 0; index < currentSrcNode->nbSons(); ++index) {
263  if (!src2dest.existsFirst(currentSrcNode->son(index))) {
264  NodeId srcSonNodeId = currentSrcNode->son(index), destSonNodeId = 0;
265  if (src.isTerminalNode(srcSonNodeId)) {
266  destSonNodeId =
267  this->manager()->addTerminalNode(src.nodeValue(srcSonNodeId));
268  } else {
269  destSonNodeId =
270  this->manager()->addInternalNode(src.node(srcSonNodeId)->nodeVar());
271  lifo.push_back(srcSonNodeId);
272  }
273  src2dest.insert(srcSonNodeId, destSonNodeId);
274  }
275  this->manager()->setSon(src2dest.second(currentSrcNodeId),
276  index,
277  src2dest.second(currentSrcNode->son(index)));
278  }
279  }
280 
281  manager()->clean();
282  }
283 
284  // Copies src diagrams structure into this diagrams.
285  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
286  INLINE void
290  reassign) {
291  if (this->__isReduced != src.isReducedAndOrdered())
293  "Cannot copy a Reduced and Ordered "
294  "function graph into Tree function graph "
295  "(or vice-versa).")
296 
297  this->clear();
298 
299  // New variables insertion
301  src.variablesSequence().beginSafe();
302  varIter != src.variablesSequence().endSafe();
303  ++varIter) {
304  if ((*varIter)->domainSize() != reassign.second(*varIter)->domainSize())
306  "Var " << (*varIter)->name() << " and var "
307  << reassign.second(*varIter)->name()
308  << " have different domain sizes ("
309  << (*varIter)->domainSize()
310  << "!=" << reassign.second(*varIter)->domainSize() << ")")
311  this->add(*(reassign.second(*varIter)));
312  }
313 
314  std::vector< NodeId > lifo;
316 
317  if (src.isTerminalNode(src.root())) {
318  this->manager()->setRootNode(
319  this->manager()->addTerminalNode(src.nodeValue(src.root())));
320  } else {
321  this->manager()->setRootNode(this->manager()->addInternalNode(
322  reassign.second(src.node(src.root())->nodeVar())));
323  src2dest.insert(src.root(), this->root());
324  lifo.push_back(src.root());
325  }
326 
327  // Depth-first exploration and copy
328  while (!lifo.empty()) {
329  NodeId currentSrcNodeId = lifo.back();
330  lifo.pop_back();
331 
332  const InternalNode* currentSrcNode = src.node(currentSrcNodeId);
333 
334  for (Idx index = 0; index < currentSrcNode->nbSons(); ++index) {
335  if (!src2dest.existsFirst(currentSrcNode->son(index))) {
336  NodeId srcSonNodeId = currentSrcNode->son(index), destSonNodeId = 0;
337  if (src.isTerminalNode(srcSonNodeId)) {
338  destSonNodeId =
339  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  }
352 
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 >
361  GUM_SCALAR gamma) {
362  if (this->__isReduced != src.isReducedAndOrdered())
364  "Cannot copy a Reduced and Ordered "
365  "function graph into Tree function graph "
366  "(or vice-versa).")
367 
368  this->clear();
369 
370  // New variables insertion
372  src.variablesSequence().beginSafe();
373  varIter != src.variablesSequence().endSafe();
374  ++varIter)
375  this->add(**varIter);
376 
377  std::vector< NodeId > lifo;
379 
380  if (src.isTerminalNode(src.root()))
381  this->manager()->setRootNode(
382  this->manager()->addTerminalNode(gamma * src.nodeValue(src.root())));
383  else {
384  this->manager()->setRootNode(
385  this->manager()->addInternalNode(src.node(src.root())->nodeVar()));
386  src2dest.insert(src.root(), this->root());
387  lifo.push_back(src.root());
388  }
389 
390  // Depth-first exploration an copy
391  while (!lifo.empty()) {
392  NodeId currentSrcNodeId = lifo.back();
393  lifo.pop_back();
394 
395  const InternalNode* currentSrcNode = src.node(currentSrcNodeId);
396 
397  for (Idx index = 0; index < currentSrcNode->nbSons(); ++index) {
398  if (!src2dest.exists(currentSrcNode->son(index))) {
399  NodeId srcSonNodeId = currentSrcNode->son(index), destSonNodeId = 0;
400  if (src.isTerminalNode(srcSonNodeId)) {
401  destSonNodeId = this->manager()->addTerminalNode(
402  gamma * src.nodeValue(srcSonNodeId));
403  } else {
404  destSonNodeId =
405  this->manager()->addInternalNode(src.node(srcSonNodeId)->nodeVar());
406  lifo.push_back(srcSonNodeId);
407  }
408  src2dest.insert(srcSonNodeId, destSonNodeId);
409  }
410  this->manager()->setSon(
411  src2dest[currentSrcNodeId], index, src2dest[currentSrcNode->son(index)]);
412  }
413  }
414 
415  manager()->clean();
416  }
417 
418  // Clears the function graph
419  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
421  __model.clear();
422  // Always discard the nodeId 0
423  __model.addNode();
424 
425  this->clearAllTerminalNodes();
426 
427  // Nodes cleaning
429  __internalNodeMap.begin();
430  nodeIter != __internalNodeMap.end();
431  ++nodeIter) {
432  delete nodeIter.val();
433  }
434  __internalNodeMap.clear();
435 
436  // Cleaning the list of nodes for each variables
438  varIter = __var2NodeIdMap.begin();
439  varIter != __var2NodeIdMap.end();
440  ++varIter) {
441  delete varIter.val();
442  }
443  __var2NodeIdMap.clear();
444 
446  this->variablesSequence().rbeginSafe();
447  varIter != this->variablesSequence().rendSafe();
448  --varIter) {
449  this->erase(**varIter);
450  }
451  }
452 
453 
454  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
455  INLINE std::string
457  bool withBackArcs) const {
458  std::stringstream output;
459  std::stringstream terminalStream;
460  std::stringstream nonTerminalStream;
461  std::stringstream arcstream;
462  // std::stringstream defaultarcstream;
463  output << std::endl << "digraph \" " << __tableName << "\" {" << std::endl;
464 
465  terminalStream << "node [shape = box];" << std::endl;
466  nonTerminalStream << "node [shape = ellipse];" << std::endl;
467  std::string tab = " ";
468 
469  for (NodeGraphPart::NodeIterator nodeIter = __model.begin();
470  nodeIter != __model.end();
471  ++nodeIter)
472  if (*nodeIter != 0) {
473  if (this->isTerminalNode((NodeId)*nodeIter))
474  terminalStream << tab << *nodeIter << ";" << tab << *nodeIter
475  << " [label=\"" << *nodeIter << " - "
476  << std::setprecision(30)
477  << this->terminalNodeValue(*nodeIter) << "\"]"
478  << ";" << std::endl;
479  else {
480  InternalNode* currentNode = __internalNodeMap[*nodeIter];
481  nonTerminalStream << tab << *nodeIter << ";" << tab << *nodeIter
482  << " [label=\"" << *nodeIter << " - "
483  << currentNode->nodeVar()->name() << "\"]"
484  << ";" << std::endl;
485 
486  // if (_arcMap[*nodeIter] != NULL)
488  for (Idx sonIter = 0; sonIter < currentNode->nbSons(); ++sonIter) {
489  if (!sonMap.exists(currentNode->son(sonIter)))
490  sonMap.insert(currentNode->son(sonIter), new LinkedList< Idx >());
491  sonMap[currentNode->son(sonIter)]->addLink(sonIter);
492  }
493 
494  for (auto sonIter = sonMap.beginSafe(); sonIter != sonMap.endSafe();
495  ++sonIter) {
496  arcstream << tab << *nodeIter << " -> " << sonIter.key()
497  << " [label=\" ";
498  Link< Idx >* modaIter = sonIter.val()->list();
499  while (modaIter) {
500  arcstream << currentNode->nodeVar()->label(modaIter->element())
501  << ", ";
502  modaIter = modaIter->nextLink();
503  }
504  arcstream << "\",color=\"#0000ff\"]"
505  << ";" << std::endl;
506  delete sonIter.val();
507  }
508 
509  if (withBackArcs) {
510  Link< Parent >* parentIter = currentNode->parents();
511  while (parentIter != nullptr) {
512  arcstream << tab << *nodeIter << " -> "
513  << parentIter->element().parentId << " [label=\""
514  << parentIter->element().modality
515  << "\",color=\"#ff0000\"]"
516  << ";" << std::endl;
517  parentIter = parentIter->nextLink();
518  }
519  }
520  }
521  }
522 
523  output << terminalStream.str() << std::endl
524  << nonTerminalStream.str() << std::endl
525  << arcstream.str() << std::endl
526  << "}" << std::endl;
527 
528  return output.str();
529  }
530 
531  // Returns a const reference to the manager of this diagram
532  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
533  INLINE const NodeGraphPart&
535  return __model;
536  }
537 
538  // Returns a const reference to the manager of this diagram
539  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
542  if (__manager == nullptr) {
543  if (__isReduced)
544  __manager =
546  this);
547  else
548  __manager =
550  this);
551  }
552  return __manager;
553  }
554 
555  // Returns the id of the root node from the diagram
556  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
557  INLINE const NodeId&
559  return __root;
560  }
561 
562  // Indicates if given node is terminal or not
563  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
564  INLINE bool
566  const NodeId& node) const {
567  return this->existsTerminalNodeWithId(node);
568  }
569 
570  // Indicates if given node is terminal or not
571  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
572  INLINE bool
574  const NodeId& node) const {
575  return this->__internalNodeMap.exists(node);
576  }
577 
578  // Returns value associated to given node.
579  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
580  INLINE const GUM_SCALAR&
582  NodeId n) const {
583  if (!isTerminalNode(n))
585  "Id " << n << " is not bound to any terminal node")
586  return this->terminalNodeValue(n);
587  }
588 
589  // Returns internalNode structure associated to that nodeId
590  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
591  INLINE const InternalNode*
593  if (!isInternalNode(n))
595  "Id " << n << " is not bound to any terminal node")
596  return this->__internalNodeMap[n];
597  }
598 
599  // Returns the list of node associated to given variable
600  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
601  INLINE const LinkedList< NodeId >*
603  const DiscreteVariable* var) const {
604  if (!this->variablesSequence().exists(var))
606  "Var " << var->name()
607  << " has not been inserted in the function graph")
608  return __var2NodeIdMap[var];
609  }
610 
611  // Returns the name of the table represented by this structure.
612  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
613  INLINE const std::string&
615  return __tableName;
616  }
617 
618  // Sets the name of the table represented by this structure.
619  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
620  INLINE void
622  const std::string& name) {
623  __tableName = name;
624  }
625 
626  // Returns true if this MultiDimFunctionGraph is reduced and Ordered.
627  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
628  INLINE bool
630  const {
631  return __isReduced;
632  }
633 
634  // Returns a reduced and ordered instance.
635  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
637  MultiDimFunctionGraph< GUM_SCALAR,
638  TerminalNodePolicy >::getReducedAndOrderedInstance() {
640  }
641 
642  // Returns an arborescent instance
643  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
647  }
648 
649  // Not implemented yet
650  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
652  const DiscreteVariable* x, const DiscreteVariable* y) {
653  GUM_ERROR(OperationNotAllowed, "Not Implemented Yet")
654  }
655 
656  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
658  const Instantiation& inst) const {
660  "You can't edit a function by other mean than the manager");
661  }
662 
663  // Return a data, given a Instantiation.
664  template < typename GUM_SCALAR, template < class > class TerminalNodePolicy >
666  const Instantiation& inst) const {
667  NodeId currentNodeId = __root;
668  InternalNode* currentNode = nullptr;
669  while (!isTerminalNode(currentNodeId)) {
670  currentNode = __internalNodeMap[currentNodeId];
671  currentNodeId = currentNode->son(inst.val(*(currentNode->nodeVar())));
672  }
673  return this->terminalNodeValue(currentNodeId);
674  }
675 
676 } // namespace gum
void insert(const T1 &first, const T2 &second)
Inserts a new association in the gum::Bijection.
Safe iterators for Sequence.
Definition: sequence.h:1203
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
unsigned int NodeId
Type for node ids.
Definition: graphElements.h:97
const DiscreteVariable * nodeVar() const
Returns the node variable.
void copyAndMultiplyByScalar(const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > &src, GUM_SCALAR gamma)
Copies src diagrams and multiply every value by the given scalar.
virtual void setFirstNotification(const Instantiation &i)
Listen to setFirst in a given Instantiation.
const iterator_safe & endSafe() noexcept
Returns the safe iterator pointing to the end of the hashtable.
virtual void setChangeNotification(const Instantiation &i)
Listen to an assignment of a value in a Instantiation.
~MultiDimFunctionGraph()
Class destructor.
bool __isReduced
Wheter the MultiDimFunctionGraphManager is reduced or not.
std::string toDot(bool withBackArcs=false) const
Returns a const reference to the manager of this diagram.
NodeId __root
The root node of the function graph.
bool existsFirst(const T1 &first) const
Returns true if first is the first element in a pair in the gum::Bijection.
virtual void erase(const DiscreteVariable &v) override
Removes a var from the variables of the multidimensional matrix.
void copyAndReassign(const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > &src, const Bijection< const DiscreteVariable *, const DiscreteVariable * > &reassign)
Copies src diagrams structure into this diagrams.
MultiDimFunctionGraph(bool isReduced=true)
Default constructor.
Unsafe Iterators for hashtablesHashTableIterator provides a fast but unsafe way to parse HashTables...
Definition: hashTable.h:2747
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
virtual void _replace(const DiscreteVariable *x, const DiscreteVariable *y)
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > & operator=(const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > &from)
Copy Operator.
virtual void erase(const DiscreteVariable &v)
Removes a var from the variables of the multidimensional matrix.
bool isInternalNode(const NodeId &node) const
Indicates if given node is terminal or not.
Link< Parent > * parents()
Returns the list of parents.
Base class for discrete random variable.
NodeGraphPart __model
Indicates available nodeIds.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
Abstract base class for all multi dimensionnal containers.
const NodeGraphPart & model() const
Returns a const reference to the manager of this diagram.
virtual NodeId addNode()
insert a new node and return its id
const Key & key(const Key &key) const
Returns a reference on a given key.
virtual void copyFrom(const MultiDimContainer< GUM_SCALAR > &src, Instantiation *p_i=(Instantiation *) 0) const
virtual const std::string & name() const
Returns the real name of the multiDim implementation.
virtual void setDecNotification(const Instantiation &i)
Listen to increment in each recorded Instantiation.
MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > * __manager
A reference to the manager that edits this function graph.
node_iterator begin() const noexcept
a begin iterator to parse the set of nodes contained in the NodeGraphPart
virtual void add(const DiscreteVariable &v)
Adds a new var to the variables of the multidimensional matrix.
Unsafe iterator on the node set of a graph.
Definition: nodeGraphPart.h:55
Class implementingting a function graph manager.
const NodeId & root() const
Returns the id of the root node from the diagram.
std::string __name
The name of the data structure.
virtual MultiDimContainer< GUM_SCALAR > * newFactory() const
Creates an empty clone of this MultiDimContainer.
const std::string & tableName() const
Returns the name of the table represented by this structure.
virtual void set(const Instantiation &i, const GUM_SCALAR &value) const
HashTable< const DiscreteVariable *, LinkedList< NodeId > * > __var2NodeIdMap
Mapping between var and node.
Idx nbSons() const
Returns the number of sons.
virtual std::string label(Idx i) const =0
get the indice-th label. This method is pure virtual.
GUM_SCALAR & _get(const Instantiation &inst) const
Structure used to represent a node internal structure.
Definition: internalNode.h:100
Set of pairs of elements with fast search for both elements.
Definition: bijection.h:1803
Class implementingting a function graph.
Class for node sets in graph.
virtual void copy(const MultiDimContainer< GUM_SCALAR > &src)
virtual void add(const DiscreteVariable &v) override
Adds a new var to the variables of the multidimensional matrix.
Headers of MultiDimFunctionGraph.
virtual void clear()
alias for clearNodes
virtual const Sequence< const DiscreteVariable * > & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.
virtual void setLastNotification(const Instantiation &i)
Listen to setLast in a given Instantiation.
const GUM_SCALAR & nodeValue(NodeId n) const
Returns value associated to given node.
bool isTerminalNode(const NodeId &node) const
Indicates if given node is terminal or not.
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:80
virtual Size realSize() const
Returns the real number of parameters used for this table.
Chain list allocated using the SmallObjectAllocator.
Definition: link.h:131
NodeId son(Idx modality) const
Returns the son at a given index.
HashTable< NodeId, InternalNode * > __internalNodeMap
Associates each non-terminal node to a variable.
iterator_safe beginSafe()
Returns the safe iterator pointing to the beginning of the hashtable.
virtual void populate(const std::vector< GUM_SCALAR > &v) const
static MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * getTreeInstance()
Returns an arborescent instance.
std::string __tableName
The name of the data structure.
virtual GUM_SCALAR get(const Instantiation &i) const
Returns the value pointed by i.
virtual void changeNotification(const Instantiation &i, const DiscreteVariable *const var, Idx oldval, Idx newval)
Listen to changes in a given Instantiation.
virtual void fill(const GUM_SCALAR &d) const
virtual const std::string toString() const
Returns a representation of this MultiDimContainer.
<agrum/multidim/multiDimImplementation.h>
MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > * manager()
Returns a const reference to the manager of this diagram.
void setTableName(const std::string &name)
Sets the name of the table represented by this structure.
virtual void setIncNotification(const Instantiation &i)
Listen to increment in a given Instantiation.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
unsigned long Idx
Type for indexes.
Definition: types.h:43
const std::string & name() const
returns the name of the variable
const node_iterator & end() const noexcept
the end iterator to parse the set of nodes contained in the NodeGraphPart
const InternalNode * node(NodeId n) const
Returns internalNode structure associated to that nodeId.
Idx val(Idx i) const
Returns the current value of the variable at position i.
bool isReducedAndOrdered() const
Returns true if this MultiDimFunctionGraph is reduced and Ordered.
static MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * getReducedAndOrderedInstance()
Returns a reduced and ordered instance.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66
void clear()
Clears the function graph.
const LinkedList< NodeId > * varNodeListe(const DiscreteVariable *var) const
Returns the list of node associated to given variable.