aGrUM  0.16.0
multiDimImplementation.h
Go to the documentation of this file.
1 
29 #ifndef GUM_MULTI_DIM_IMPLEMENTATION_H
30 #define GUM_MULTI_DIM_IMPLEMENTATION_H
31 
32 #include <vector>
33 
34 #include <agrum/agrum.h>
35 
37 
38 namespace gum {
39 
40  // ===========================================================================
41  // === GUM_MULTI_DIM_IMPLEMENTATION ===
42  // ===========================================================================
65  template < typename GUM_SCALAR >
66  class MultiDimImplementation : public MultiDimContainer< GUM_SCALAR > {
67  public:
68  // =========================================================================
70  // =========================================================================
72 
77 
82  MultiDimImplementation(const MultiDimImplementation< GUM_SCALAR >& from);
83 
87  virtual ~MultiDimImplementation();
88 
90  // =========================================================================
92  // =========================================================================
94 
108  virtual const std::string& name() const = 0;
109 
116  const std::string& basename() const;
117 
128  virtual Size realSize() const = 0;
129 
143  float compressionRate() const;
144 
146  // ========================================================================
148  // ========================================================================
150  virtual Idx nbrDim() const override;
151 
152  virtual Size domainSize() const override;
153 
154  virtual void add(const DiscreteVariable& v) override;
155 
156  virtual void erase(const DiscreteVariable& v) override;
157 
158  virtual const Sequence< const DiscreteVariable* >&
159  variablesSequence() const override;
160 
161  virtual const DiscreteVariable& variable(Idx i) const override;
162  virtual const DiscreteVariable&
163  variable(const std::string& name) const override;
164 
165  virtual Idx pos(const DiscreteVariable& v) const override;
166 
167  virtual bool contains(const DiscreteVariable& v) const override;
168 
169  virtual bool empty() const override;
170 
172  // =========================================================================
174  // =========================================================================
176 
177  virtual bool registerSlave(Instantiation& slave) override;
178 
179  virtual bool unregisterSlave(Instantiation& slave) override;
180 
182  // =========================================================================
184  // =========================================================================
186 
188 
189  virtual MultiDimContainer< GUM_SCALAR >* newFactory() const override = 0;
190 
191  virtual void beginMultipleChanges() override;
192 
193  virtual void endMultipleChanges() override;
194 
195  virtual void endMultipleChanges(const GUM_SCALAR&) override;
196 
198 
199  protected:
200  // =========================================================================
202  // =========================================================================
204 
208  virtual void _commitMultipleChanges();
209 
214  virtual void _commitMultipleChanges(const GUM_SCALAR& value);
215 
220  bool _isInMultipleChangeMethod() const;
221 
226  bool _isCommitNeeded() const;
227 
234  const List< Instantiation* >& _slaves() const;
235 
245  virtual void _replace(const DiscreteVariable* x,
246  const DiscreteVariable* y) override;
247 
257  virtual void _invert(Idx p1, Idx p2);
258 
260 
264  virtual const MultiDimImplementation< GUM_SCALAR >* content() const final;
265 
269  virtual MultiDimImplementation< GUM_SCALAR >* content() final;
270 
271  private:
274 
277 
279  enum class __InternalChangeMethod : char { DIRECT_CHANGE, MULTIPLE_CHANGE };
280 
283 
286 
289 
292 
296  void __setNotCommitedChange();
297  };
298 
303  template < typename GUM_SCALAR >
304  std::ostream& operator<<(std::ostream&,
306 
307 } /* namespace gum */
308 
310 
311 #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:1022
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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Base class for discrete random variable.
Generic doubly linked lists.
Definition: list.h:372
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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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:605
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:83
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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
__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:48
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.