aGrUM  0.14.2
multiDimFunctionGraph.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  ***************************************************************************/
27 #ifndef GUM_MULTI_DIM_FUNCTION_GRAPH_H
28 #define GUM_MULTI_DIM_FUNCTION_GRAPH_H
29 
30 #include <agrum/core/bijection.h>
31 #include <agrum/core/list.h>
33 #include <agrum/core/types.h>
34 
36 
38 
45 
46 namespace gum {
47 
48  template < typename GUM_SCALAR, template < typename > class TerminalNodePolicy >
50 
51  template < typename GUM_SCALAR, template < typename > class TerminalNodePolicy >
53 
54  template < typename GUM_SCALAR, template < typename > class TerminalNodePolicy >
56 
75  template < typename GUM_SCALAR,
76  template < typename > class TerminalNodePolicy =
79  : public MultiDimImplementation< GUM_SCALAR >
80  , public TerminalNodePolicy< GUM_SCALAR > {
81  public:
83  const static GUM_SCALAR defaultValue;
84 
85  public:
86  // =========================================================================
88  // =========================================================================
90 
91  private:
96  MultiDimFunctionGraph(bool isReduced = true);
97 
98  public:
105 
113 
118 
120  // =========================================================================
122  // =========================================================================
124 
129  virtual void set(const Instantiation& i, const GUM_SCALAR& value) const;
130 
135  virtual void fill(const GUM_SCALAR& d) const;
136 
141  virtual void populate(const std::vector< GUM_SCALAR >& v) const;
146  virtual void populate(std::initializer_list< GUM_SCALAR > v) const;
147 
152  virtual void copyFrom(const MultiDimContainer< GUM_SCALAR >& src,
153  Instantiation* p_i = (Instantiation*)0) const;
154 
159  virtual void copy(const MultiDimContainer< GUM_SCALAR >& src);
160 
162  // =========================================================================
164  // =========================================================================
166 
168 
169  virtual GUM_SCALAR get(const Instantiation& i) const;
170 
171  virtual const std::string& name() const;
172 
173  virtual void add(const DiscreteVariable& v);
174 
175  virtual void erase(const DiscreteVariable& v);
176 
177  virtual Size realSize() const;
178 
179  virtual void changeNotification(const Instantiation& i,
180  const DiscreteVariable* const var,
181  Idx oldval,
182  Idx newval);
183 
184  virtual void setFirstNotification(const Instantiation& i);
185 
186  virtual void setLastNotification(const Instantiation& i);
187 
188  virtual void setIncNotification(const Instantiation& i);
189 
190  virtual void setDecNotification(const Instantiation& i);
191 
192  virtual void setChangeNotification(const Instantiation& i);
193 
194  virtual const std::string toString(const Instantiation* i) const;
195 
197  // =========================================================================
199  // =========================================================================
201 
209 
223  void copyAndReassign(
226  reassign);
227 
236  GUM_SCALAR gamma);
237 
241  void clear();
242 
244  // =========================================================================
246  // =========================================================================
248 
255  std::string toDot(bool withBackArcs = false) const;
256 
261  const NodeGraphPart& model() const;
262 
268 
273  const NodeId& root() const;
274 
280  bool isTerminalNode(const NodeId& node) const;
281 
287  bool isInternalNode(const NodeId& node) const;
288 
295  const GUM_SCALAR& nodeValue(NodeId n) const;
296 
303  const InternalNode* node(NodeId n) const;
304 
311  const LinkedList< NodeId >* varNodeListe(const DiscreteVariable* var) const;
312 
317  const std::string& tableName() const;
318 
323  void setTableName(const std::string& name);
324 
331  bool isReducedAndOrdered() const;
332 
345 
351  getTreeInstance();
352 
354 
355  protected:
360  virtual void _replace(const DiscreteVariable* x, const DiscreteVariable* y);
361 
367  GUM_SCALAR& _get(const Instantiation& inst) const;
368 
369  private:
371  std::string __name;
372 
374  std::string __tableName;
375 
378 
381 
384 
387 
390 
393 
394  friend class MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >;
395  };
396 
397 
398 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
399 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
400  // extern template class MultiDimFunctionGraph<float>;
401 # endif
402 #endif
403 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
404 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
405  // extern template class MultiDimFunctionGraph<double>;
406 # endif
407 #endif
408 } // namespace gum
409 
411 
412 #endif // GUM_MULTI_DIM_FUNCTION_GRAPH_H
Template trick for efficient development.
Headers of MultiDimFunctionGraphManager.
Provides basic types used in aGrUM.
bool isInternalNode(const NodeId &node) const
Indicates if given node is terminal or not.
bool isTerminalNode(const NodeId &node) const
Indicates if given node is terminal or not.
Headers of gum::SmallObjectAllocator.
virtual void populate(const std::vector< GUM_SCALAR > &v) const
static const GUM_SCALAR defaultValue
Only for proper initialization of a certain returned value.
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.
virtual Size realSize() const
Returns the real number of parameters used for this table.
const InternalNode * node(NodeId n) const
Returns internalNode structure associated to that nodeId.
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.
NodeId __root
The root node of the function graph.
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.
Headers of the ExactTerminalNodePolicy.
GUM_SCALAR & _get(const Instantiation &inst) const
virtual void _replace(const DiscreteVariable *x, const DiscreteVariable *y)
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > & operator=(const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > &from)
Copy Operator.
virtual const std::string toString() const
Returns a representation of this MultiDimContainer.
Headers of the InternalNode class.
virtual void erase(const DiscreteVariable &v)
Removes a var from the variables of the multidimensional matrix.
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.
Headers of gum::MultiDimImplementation.
The class for generic Hash Tables.
Definition: hashTable.h:676
Headers of the ITerminalNodePolicy.
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.
virtual void add(const DiscreteVariable &v)
Adds a new var to the variables of the multidimensional matrix.
Class implementingting a function graph manager.
std::string __name
The name of the data structure.
Generic class for manipulating lists.
const GUM_SCALAR & nodeValue(NodeId n) const
Returns value associated to given node.
HashTable< const DiscreteVariable *, LinkedList< NodeId > *> __var2NodeIdMap
Mapping between var and node.
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
const NodeId & root() const
Returns the id of the root node from the diagram.
Class implementingting a function graph.
const LinkedList< NodeId > * varNodeListe(const DiscreteVariable *var) const
Returns the list of node associated to given variable.
Class for node sets in graph.
virtual const std::string & name() const
Returns the real name of the multiDim implementation.
Template methods of MultiDimFunctionGraph.
virtual void copy(const MultiDimContainer< GUM_SCALAR > &src)
virtual MultiDimContainer< GUM_SCALAR > * newFactory() const
Creates an empty clone of this MultiDimContainer.
virtual void setLastNotification(const Instantiation &i)
Listen to setLast in a given Instantiation.
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:80
virtual void copyFrom(const MultiDimContainer< GUM_SCALAR > &src, Instantiation *p_i=(Instantiation *) 0) const
Chain list allocated using the SmallObjectAllocator.
Definition: link.h:131
HashTable< NodeId, InternalNode *> __internalNodeMap
Associates each non-terminal node to a variable.
static MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * getTreeInstance()
Returns an arborescent instance.
std::string __tableName
The name of the data structure.
const std::string & tableName() const
Returns the name of the table represented by this structure.
virtual void changeNotification(const Instantiation &i, const DiscreteVariable *const var, Idx oldval, Idx newval)
Listen to changes in a given Instantiation.
<agrum/multidim/multiDimImplementation.h>
Size Idx
Type for indexes.
Definition: types.h:50
std::string toDot(bool withBackArcs=false) const
Returns a const reference to the manager of this diagram.
MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > * manager()
Returns a const reference to the manager of this diagram.
Implementation of a Terminal Node Policy that maps nodeid directly to value.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
void setTableName(const std::string &name)
Sets the name of the table represented by this structure.
bool isReducedAndOrdered() const
Returns true if this MultiDimFunctionGraph is reduced and Ordered.
virtual void setIncNotification(const Instantiation &i)
Listen to increment in a given Instantiation.
const NodeGraphPart & model() const
Returns a const reference to the manager of this diagram.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
Set of pairs of elements with fast search for both elements.
static MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * getReducedAndOrderedInstance()
Returns a reduced and ordered instance.
virtual void fill(const GUM_SCALAR &d) const
some utils for topology : NodeId, Edge, Arc and consorts ...
void clear()
Clears the function graph.