56 template <
typename GUM_SCALAR >
63 template <
typename GUM_SCALAR >
65 MultiDimReadOnly< GUM_SCALAR >(source), _bufferSize_(source._bufferSize_), _bucket_(0),
66 _multiDims_(source._multiDims_), _allVariables_(source._allVariables_),
67 _allVarsInst_(source._allVarsInst_), _changed_(source._changed_), _name_(
"MultiDimBucket") {
71 template <
typename GUM_SCALAR >
90 template <
typename GUM_SCALAR >
95 template <
typename GUM_SCALAR >
97 _multiDims_.insert(impl,
new Instantiation(*impl));
99 if (!MultiDimImplementation< GUM_SCALAR >::isInMultipleChangeMethod_()) {
100 for (
const auto var: impl->variablesSequence()) {
108 template <
typename GUM_SCALAR >
113 template <
typename GUM_SCALAR >
115 if (
auto p = _multiDims_.tryGet(impl)) {
117 _multiDims_.erase(impl);
120 for (
auto var: impl->variablesSequence()) {
121 _eraseVariable_(var);
129 template <
typename GUM_SCALAR >
131 return _multiDims_.exists(&impl);
134 template <
typename GUM_SCALAR >
139 template <
typename GUM_SCALAR >
144 template <
typename GUM_SCALAR >
149 template <
typename GUM_SCALAR >
154 template <
typename GUM_SCALAR >
159 template <
typename GUM_SCALAR >
170 template <
typename GUM_SCALAR >
186 template <
typename GUM_SCALAR >
191 template <
typename GUM_SCALAR >
205 template <
typename GUM_SCALAR >
219 template <
typename GUM_SCALAR >
224 template <
typename GUM_SCALAR >
229 template <
typename GUM_SCALAR >
248 template <
typename GUM_SCALAR >
266 template <
typename GUM_SCALAR >
279 template <
typename GUM_SCALAR >
291 template <
typename GUM_SCALAR >
303 template <
typename GUM_SCALAR >
315 template <
typename GUM_SCALAR >
328 template <
typename GUM_SCALAR >
339 template <
typename GUM_SCALAR >
361 template <
typename GUM_SCALAR >
370 template <
typename GUM_SCALAR >
379 template <
typename GUM_SCALAR >
381 std::stringstream sBuff;
382 sBuff << (*i) <<
" = " <<
get(*i);
386 template <
typename GUM_SCALAR >
405 for (
auto var: iter.key()->variablesSequence()) {
413 template <
typename GUM_SCALAR >
418 template <
typename GUM_SCALAR >
428 template <
typename GUM_SCALAR >
436 if (iter.key()->contains(*var)) {
449 template <
typename GUM_SCALAR >
453 delete iter.second();
470 iter != this->
slaves_().cendSafe();
479 template <
typename GUM_SCALAR >
483 delete iter.second();
492 template <
typename GUM_SCALAR >
496 GUM_SCALAR sum = (GUM_SCALAR)0;
501 current = (GUM_SCALAR)1;
508 current *= iter.key()->get(*(iter.val()));
517 template <
typename GUM_SCALAR >
522 template <
typename GUM_SCALAR >
531 template <
typename GUM_SCALAR >
536 iter.first()->replace(*x, *y);
537 iter.second()->replace(*x, *y);
547 template <
typename GUM_SCALAR >
Safe Iterators for hashtables.
BijectionIteratorSafe< T1, T2 > iterator_safe
types for STL compliance
Base class for discrete random variable.
Exception : a similar element already exists.
The class for generic Hash Tables.
Class for assigning/browsing values to tuples of discrete variables.
bool end() const
Returns true if the Instantiation reached the end.
void inc()
Operator increment.
bool isMaster(const MultiDimAdressable *m) const
Indicates whether m is the master of this instantiation.
void setFirst()
Assign the first values to the tuple of the Instantiation.
ListConstIteratorSafe< Val > const_iterator_safe
Types for STL compliance.
Abstract base class for all multi dimensionnal addressable.
virtual bool unregisterSlave(Instantiation &i)=0
Unregister i as a slave of this MultiDimAdressable.
Multidimensional matrix stored as an array in memory.
A multidim implementation for buckets.
Bijection< Instantiation *, Instantiation * > _instantiations_
Bijection between instantiations registered on this and their equivalent on bucket.
GUM_ELEMENT get(const Instantiation &i) const override
Returns the value pointed by i.
bool isBucketEmpty() const
Returns true if this bucket is empty.
void replace_(const DiscreteVariable *x, const DiscreteVariable *y) override
This is called by MultiDimContainer::replace() to proceed with the replacing between x and y.
void setFirstNotification(const Instantiation &i) override
Listen to setFirst in a given Instantiation.
void setLastNotification(const Instantiation &i) override
Listen to setLast in a given Instantiation.
const gum::VariableSet & allVariables() const
Returns the sequence of all the variables contained in the bucket.
void erase(const MultiDimContainer< GUM_ELEMENT > &impl)
Remove a MultiDimContainer from this bucket.
void commitMultipleChanges_() override
Synchronize content after MultipleChanges.
gum::VariableSet _allVariables_
The set of all variables of the multidims in this bucket.
void changeNotification(const Instantiation &i, const DiscreteVariable *const var, Idx oldval, Idx newval) override
Listen to changes in a given Instantiation.
Size bufferSize() const
Returns the amount of memory allowed for this bucket.
void _initializeBuffer_()
Initialize the internal buffer.
Instantiation _allVarsInst_
Instantiation over all variable in this.
void setChangeNotification(const Instantiation &i) override
Listen to an assignment of a value in a Instantiation.
void _eraseVariable_(const DiscreteVariable *var)
Erase a variable from allVariables if no other multidimensional table uses it in this bucket.
GUM_ELEMENT _computeValue_(const Instantiation &value) const
Compute the value of the final table of this bucket given i.
~MultiDimBucket() override
Destructor.
void setIncNotification(const Instantiation &i) override
Listen to increment in a given Instantiation.
const HashTable< const MultiDimContainer< GUM_ELEMENT > *, Instantiation * > & multidims() const
Returns the MultiDimContainer and their respective Instantiation.
void _eraseBuffer_()
Clean the buffer and switch it's instantiation to this bucket.
void setBufferSize(Size amount)
Changes the amount of memory allowed for this bucket.
MultiDimArray< GUM_ELEMENT > * _bucket_
The result table of this bucket.
const MultiDimArray< GUM_ELEMENT > & bucket() const
Returns the MultiDimArray used by this MultiDimBucket.
Size _bufferSize_
The number of element allowed in bucket.
MultiDimContainer< GUM_ELEMENT > * newFactory() const override
Default constructor.
const std::string & name() const override
Returns the real name of the multiDim implementation.
bool bucketChanged() const
Returns true if the bucket need re-computation since the last computation.
HashTable< const MultiDimContainer< GUM_ELEMENT > *, Instantiation * > _multiDims_
The set of MultiDimContainer in this bucket.
void add(const MultiDimContainer< GUM_ELEMENT > &impl)
Add a MultiDimContainer in the bucket.
MultiDimAdressable & getMasterRef() override
In order to insure the dereference for decorators, we need to virtualize the access to master pointer...
bool _changed_
Flag used to know if changes has occurred in the bucket since last computation.
GUM_ELEMENT & get_(const Instantiation &i) const override
Size bucketSize() const
Returns the number of MultiDimContainer in this bucket.
bool registerSlave(Instantiation &i) override
Register i as a slave of this MultiDimAdressable.
void _addVariable_(const DiscreteVariable *var)
Add a variable to allVariables, and do nothing if var is already in the set.
bool unregisterSlave(Instantiation &i) override
Unregister i as a slave of this MultiDimAdressable.
void setDecNotification(const Instantiation &i) override
Listen to increment in each recorded Instantiation.
void compute(bool force=false) const
This method computes the final table of this bucket.
Size realSize() const override
Returns the real number of parameters used for this table.
MultiDimBucket(Size bufferSize=INT_MAX)
Default constructor.
std::string _name_
The class name.
bool contains(const MultiDimContainer< GUM_ELEMENT > &impl) const
Returns true if the MultiDimContainer is in this bucket.
HashTable< const Instantiation *, GUM_ELEMENT > _slavesValue_
This table is used to keep the last value computed for an instantiation when the value are computed o...
virtual std::string toString() const
Returns a representation of this MultiDimContainer.
<agrum/base/multidim/multiDimImplementation.h>
void erase(const DiscreteVariable &v) override
Removes a var from the variables of the multidimensional matrix.
Size domainSize() const override
Returns the product of the variables domain size.
bool isInMultipleChangeMethod_() const
Get the actual change method of this MultiDimImplementation.
const Sequence< const DiscreteVariable * > & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.
void add(const DiscreteVariable &v) override
Adds a new var to the variables of the multidimensional matrix.
bool registerSlave(Instantiation &slave) override
Register i as a slave of this MultiDimAdressable.
const List< Instantiation * > & slaves_() const
Returns a constant reference over the list of slaved instantiations.
bool empty() const override
Returns true if no var is in *this.
void replace_(const DiscreteVariable *x, const DiscreteVariable *y) override
Replace variable x by y.
virtual void commitMultipleChanges_()
Synchronize content after MultipleChanges.
bool contains(const DiscreteVariable &v) const override
Returns true if var is in *this.
Abstract base class for all multi dimensionnal read only structure.
MultiDimReadOnly()
Default constructor.
Exception : operation not allowed.
Exception : problem with size.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
Headers of the MultiDimBucket class.
gum is the global namespace for all aGrUM entities
Set< const DiscreteVariable * > VariableSet