aGrUM  0.14.2
multiDimImplementation.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Christophe GONZALES *
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  ***************************************************************************/
26 #ifndef GUM_MULTI_DIM_IMPLEMENTATION_H
27 #define GUM_MULTI_DIM_IMPLEMENTATION_H
28 
29 #include <vector>
30 
31 #include <agrum/agrum.h>
32 
34 
35 namespace gum {
36 
37  // ===========================================================================
38  // === GUM_MULTI_DIM_IMPLEMENTATION ===
39  // ===========================================================================
62  template < typename GUM_SCALAR >
63  class MultiDimImplementation : public MultiDimContainer< GUM_SCALAR > {
64  public:
65  // =========================================================================
67  // =========================================================================
69 
74 
79  MultiDimImplementation(const MultiDimImplementation< GUM_SCALAR >& from);
80 
84  virtual ~MultiDimImplementation();
85 
87  // =========================================================================
89  // =========================================================================
91 
105  virtual const std::string& name() const = 0;
106 
113  const std::string& basename() const;
114 
125  virtual Size realSize() const = 0;
126 
140  float compressionRate() const;
141 
143  // ========================================================================
145  // ========================================================================
147  virtual Idx nbrDim() const override;
148 
149  virtual Size domainSize() const override;
150 
151  virtual void add(const DiscreteVariable& v) override;
152 
153  virtual void erase(const DiscreteVariable& v) override;
154 
155  virtual const Sequence< const DiscreteVariable* >&
156  variablesSequence() const override;
157 
158  virtual const DiscreteVariable& variable(Idx i) const override;
159  virtual const DiscreteVariable&
160  variable(const std::string& name) const override;
161 
162  virtual Idx pos(const DiscreteVariable& v) const override;
163 
164  virtual bool contains(const DiscreteVariable& v) const override;
165 
166  virtual bool empty() const override;
167 
169  // =========================================================================
171  // =========================================================================
173 
174  virtual bool registerSlave(Instantiation& slave) override;
175 
176  virtual bool unregisterSlave(Instantiation& slave) override;
177 
179  // =========================================================================
181  // =========================================================================
183 
185 
186  virtual MultiDimContainer< GUM_SCALAR >* newFactory() const override = 0;
187 
188  virtual void beginMultipleChanges() override;
189 
190  virtual void endMultipleChanges() override;
191 
192  virtual void endMultipleChanges(const GUM_SCALAR&) override;
193 
195 
196  protected:
197  // =========================================================================
199  // =========================================================================
201 
205  virtual void _commitMultipleChanges();
206 
211  virtual void _commitMultipleChanges(const GUM_SCALAR& value);
212 
217  bool _isInMultipleChangeMethod() const;
218 
223  bool _isCommitNeeded() const;
224 
231  const List< Instantiation* >& _slaves() const;
232 
242  virtual void _replace(const DiscreteVariable* x,
243  const DiscreteVariable* y) override;
244 
254  virtual void _invert(Idx p1, Idx p2);
255 
257 
261  virtual const MultiDimImplementation< GUM_SCALAR >* content() const final;
262 
266  virtual MultiDimImplementation< GUM_SCALAR >* content() final;
267 
268  private:
271 
274 
276  enum class __InternalChangeMethod : char { DIRECT_CHANGE, MULTIPLE_CHANGE };
277 
280 
283 
286 
289 
293  void __setNotCommitedChange();
294  };
295 
300  template < typename GUM_SCALAR >
301  std::ostream& operator<<(std::ostream&,
303 
304 } /* namespace gum */
305 
307 
308 #endif /* GUM_MULTI_DIM_IMPLEMENTATION_H */
float compressionRate() const
The compression ratio of the table (depending on the type of implementation).
__InternalChangeState __internalChangeState
The current change state.
virtual void erase(const DiscreteVariable &v) override
Removes a var from the variables of the multidimensional matrix.
The generic class for storing (ordered) sequences of objects.
Definition: sequence.h:1019
Size __domainSize
This MultiDimImplementation domain size.
virtual const DiscreteVariable & variable(Idx i) const override
Returns a const ref to the ith var.
bool _isCommitNeeded() const
Get the actual state of *this.
const List< Instantiation *> & _slaves() const
Returns a constant reference over the list of slaved instantiations.
Implementation of gum::MultiDimImplementation.
Base class for discrete random variable.
Generic doubly linked lists.
Definition: list.h:369
virtual bool unregisterSlave(Instantiation &slave) override
Unregister i as a slave of this MultiDimAdressable.
virtual void _invert(Idx p1, Idx p2)
Inverts variables at position p1 and p2.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
virtual bool empty() const override
Returns true if no var is in *this.
Sequence< const DiscreteVariable *> __vars
List of discrete variables (dimensions).
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
bool _isInMultipleChangeMethod() const
Get the actual change method of this MultiDimImplementation.
std::ostream & operator<<(std::ostream &output, const BayesNet< GUM_SCALAR > &bn)
Prints map&#39;s DAG in output using the Graphviz-dot format.
Definition: BayesNet_tpl.h:583
void __setNotCommitedChange()
Change the __internalChangeState to NOT_COMMITTED_CHANGE.
virtual void _replace(const DiscreteVariable *x, const DiscreteVariable *y) override
Replace variable x by y.
MultiDimImplementation()
Default constructor.
virtual const std::string & name() const =0
Returns the real name of the multiDim implementation.
List< Instantiation *> __slaveInstantiations
List of instantiations of the tuples (sequences) of variables.
virtual Size realSize() const =0
Returns the real number of parameters used for this table.
virtual void add(const DiscreteVariable &v) override
Adds a new var to the variables of the multidimensional matrix.
virtual ~MultiDimImplementation()
Class destructor.
virtual void endMultipleChanges() override
Call this method after doing important changes in this MultiDimContainer.
__InternalChangeMethod __internalChangeMethod
The current change method.
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.
virtual Idx nbrDim() const override
Returns the number of vars in the multidimensional container.
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:80
virtual void beginMultipleChanges() override
Call this method before doing important changes in this MultiDimContainer.
virtual Size domainSize() const override
Returns the product of the variables domain size.
Headers of the MultiDimContainer class.
__InternalChangeMethod
Used to represent in which change method this MultiDimImplementation is.
virtual void _commitMultipleChanges()
Synchronize content after MultipleChanges.
<agrum/multidim/multiDimImplementation.h>
virtual Idx pos(const DiscreteVariable &v) const override
Returns the index of a variable.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
virtual GUM_SCALAR get(const Instantiation &i) const
Returns the value pointed by i.
virtual bool contains(const DiscreteVariable &v) const override
Returns true if var is in *this.
__InternalChangeState
Used to represent in which change state this MultiDimImplementation is.
virtual MultiDimContainer< GUM_SCALAR > * newFactory() const override=0
Creates an empty clone of this MultiDimContainer.
const std::string & basename() const
Returns the base class name of this MultiDimImplementation.
virtual bool registerSlave(Instantiation &slave) override
Register i as a slave of this MultiDimAdressable.