aGrUM  0.16.0
multiDimBucket.h
Go to the documentation of this file.
1 
31 #ifndef GUM_MULTIDIM_BUCKET_H
32 #define GUM_MULTIDIM_BUCKET_H
33 
34 #include <climits>
35 #include <sstream>
36 
37 #include <agrum/core/bijection.h>
38 #include <agrum/core/hashTable.h>
39 #include <agrum/core/sequence.h>
40 #include <agrum/core/set.h>
41 
44 
45 namespace gum {
46 
74  template < typename GUM_SCALAR >
75  class MultiDimBucket : public MultiDimReadOnly< GUM_SCALAR > {
76  public:
77  // ========================================================================
79  // ========================================================================
81 
90  explicit MultiDimBucket(Size bufferSize = INT_MAX);
91 
97 
101  virtual ~MultiDimBucket();
102 
104  // ========================================================================
106  // ========================================================================
108 
114  void add(const MultiDimContainer< GUM_SCALAR >& impl);
115 
121  void add(const MultiDimContainer< GUM_SCALAR >* impl);
122 
127  void erase(const MultiDimContainer< GUM_SCALAR >& impl);
128 
133  void erase(const MultiDimContainer< GUM_SCALAR >* impl);
134 
140  bool contains(const MultiDimContainer< GUM_SCALAR >& impl) const;
141 
149 
154  Size bucketSize() const;
155 
160  bool isBucketEmpty() const;
161 
168  bool bucketChanged() const;
169 
175  const MultiDimArray< GUM_SCALAR >& bucket() const;
176 
181  Size bufferSize() const;
182 
192  void setBufferSize(Size amount);
193 
213  void compute(bool force = false) const;
214 
216  // ========================================================================
218  // ========================================================================
220 
221  virtual MultiDimContainer< GUM_SCALAR >* newFactory() const override;
222 
223  const std::string& name() const override;
224 
225  virtual void add(const DiscreteVariable& v) override;
226 
227  virtual void erase(const DiscreteVariable& v) override;
228 
229  virtual Size realSize() const override;
230 
231  bool contains(const DiscreteVariable& v) const override;
232 
233  virtual GUM_SCALAR get(const Instantiation& i) const override;
234 
235  virtual void changeNotification(const Instantiation& i,
236  const DiscreteVariable* const var,
237  Idx oldval,
238  Idx newval) override;
239 
240  virtual void setFirstNotification(const Instantiation& i) override;
241 
242  virtual void setLastNotification(const Instantiation& i) override;
243 
244  virtual void setIncNotification(const Instantiation& i) override;
245 
246  virtual void setDecNotification(const Instantiation& i) override;
247 
248  virtual void setChangeNotification(const Instantiation& i) override;
249 
250  virtual bool registerSlave(Instantiation& i) override;
251 
252  virtual bool unregisterSlave(Instantiation& i) override;
253 
254  virtual MultiDimAdressable& getMasterRef() override;
255 
256  virtual const MultiDimAdressable& getMasterRef() const override;
257 
258  virtual const std::string toString(const Instantiation* i) const override;
259 
261 
267  multidims() const;
268 
269  protected:
270  virtual void _commitMultipleChanges() override;
271 
276  virtual GUM_SCALAR& _get(const Instantiation& i) const override;
277 
278  virtual void _replace(const DiscreteVariable* x,
279  const DiscreteVariable* y) override;
280 
281  private:
284 
288 
291 
295 
298 
301 
308  void __addVariable(const DiscreteVariable* var);
309 
316  void __eraseVariable(const DiscreteVariable* var);
317 
323  void __initializeBuffer();
324 
328  void __eraseBuffer();
329 
339  GUM_SCALAR __computeValue(const Instantiation& value) const;
340 
343  mutable bool __changed;
344 
348 
350  std::string __name;
351  };
352 
353 
354 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
355  extern template class MultiDimBucket< double >;
356 #endif
357 
358 
359 } /* namespace gum */
360 
362 
363 #endif /* GUM_MULTIDIM_BUCKET_H */
virtual bool unregisterSlave(Instantiation &i) override
Unregister i as a slave of this MultiDimAdressable.
virtual void setDecNotification(const Instantiation &i) override
Listen to increment in each recorded Instantiation.
Size __bufferSize
The number of element allowed in __bucket.
Instantiation __allVarsInst
Instantiation over all variable in this.
MultiDimArray< GUM_SCALAR > * __bucket
The result table of this bucket.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
HashTable< const MultiDimContainer< GUM_SCALAR > *, Instantiation *> __multiDims
The set of MultiDimContainer in this bucket.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual void setChangeNotification(const Instantiation &i) override
Listen to an assignment of a value in a Instantiation.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
std::string __name
The class name.
virtual Size realSize() const override
Returns the real number of parameters used for this table.
bool isBucketEmpty() const
Returns true if this bucket is empty.
virtual const std::string toString() const
Returns a representation of this MultiDimContainer.
A multidim implementation for buckets.
HashTable< const Instantiation *, GUM_SCALAR > __slavesValue
This table is used to keep the last value computed for an instantiation when the value are computed o...
GUM_SCALAR __computeValue(const Instantiation &value) const
Compute the value of the final table of this bucket given i.
Base class for discrete random variable.
bool contains(const MultiDimContainer< GUM_SCALAR > &impl) const
Returns true if the MultiDimContainer is in this bucket.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
Abstract base class for all multi dimensionnal containers.
virtual MultiDimContainer< GUM_SCALAR > * newFactory() const override
Default constructor.
Abstract base class for all multi dimensionnal read only structure.
The class for generic Hash Tables.
Definition: hashTable.h:679
virtual ~MultiDimBucket()
Destructor.
void __addVariable(const DiscreteVariable *var)
Add a variable to __allVariables, and do nothing if var is already in the set.
Representation of a setA Set is a structure that contains arbitrary elements.
Definition: set.h:165
void __initializeBuffer()
Initialize the internal buffer.
void __eraseBuffer()
Clean the buffer and switch it&#39;s instantiation to this bucket.
void erase(const MultiDimContainer< GUM_SCALAR > &impl)
Remove a MultiDimContainer from this bucket.
virtual void changeNotification(const Instantiation &i, const DiscreteVariable *const var, Idx oldval, Idx newval) override
Listen to changes in a given Instantiation.
virtual void setLastNotification(const Instantiation &i) override
Listen to setLast in a given Instantiation.
const MultiDimArray< GUM_SCALAR > & bucket() const
Returns the MultiDimArray used by this MultiDimBucket.
void __eraseVariable(const DiscreteVariable *var)
Erase a variable from __allVariables if no other multidimensional table uses it in this bucket...
Size bucketSize() const
Returns the number of MultiDimContainer in in this bukcet.
MultiDimBucket(Size bufferSize=INT_MAX)
Default constructor.
virtual GUM_SCALAR & _get(const Instantiation &i) const override
void compute(bool force=false) const
This method computes the final table of this bucket.
virtual void setIncNotification(const Instantiation &i) override
Listen to increment in a given Instantiation.
Multidimensional matrix stored as an array in memory.
Definition: multiDimArray.h:54
Set of pairs of elements with fast search for both elements.
Definition: bijection.h:1805
Bijection< Instantiation *, Instantiation *> __instantiations
Bijection between instantiations registered on this and their equivalent on __bucket.
bool bucketChanged() const
Returns true if the bucket need re-computation since the last computation.
bool __changed
Flag used to know if changes has occurred in the bucket since last computation.
virtual void setFirstNotification(const Instantiation &i) override
Listen to setFirst in a given Instantiation.
Abstract base class for all multi dimensionnal addressable.
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:83
virtual void _commitMultipleChanges() override
Synchronize content after MultipleChanges.
Set< const DiscreteVariable *> __allVariables
The set of all variables of the multidims in this bucket.
Size bufferSize() const
Returns the amount of memory allowed for this bucket.
virtual bool registerSlave(Instantiation &i) override
Register i as a slave of this MultiDimAdressable.
Size Idx
Type for indexes.
Definition: types.h:53
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void setBufferSize(Size amount)
Changes the amount of memory allowed for this bucket.
const Set< const DiscreteVariable *> & allVariables() const
Returns the sequence of all the variables contained in the bucket.
const HashTable< const MultiDimContainer< GUM_SCALAR > *, Instantiation *> & multidims() const
Returns the MultiDimContainer and their respective Instantiation.
const std::string & name() const override
Returns the real name of the multiDim implementation.
virtual MultiDimAdressable & getMasterRef() override
In order to insure the dereference for decorators, we need to virtualize the access to master pointer...
void add(const MultiDimContainer< GUM_SCALAR > &impl)
Add a MultiDimContainer in the bucket.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual void _replace(const DiscreteVariable *x, const DiscreteVariable *y) override
Replace variable x by y.