aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
multiDimImplementation.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
48#ifndef GUM_MULTI_DIM_IMPLEMENTATION_H
49#define GUM_MULTI_DIM_IMPLEMENTATION_H
50
51#include <vector>
52
53#include <agrum/agrum.h>
54
56
57namespace gum {
58
59 // ===========================================================================
60 // === GUM_MULTI_DIM_IMPLEMENTATION ===
61 // ===========================================================================
84 template < typename GUM_SCALAR >
85 class MultiDimImplementation: public MultiDimContainer< GUM_SCALAR > {
86 public:
87 // =========================================================================
89 // =========================================================================
91
96
102
107
109 // =========================================================================
111 // =========================================================================
113
127 virtual const std::string& name() const = 0;
128
135 const std::string& basename() const;
136
147 virtual Size realSize() const = 0;
148
162 float compressionRate() const;
163
165 // ========================================================================
167 // ========================================================================
169 virtual Idx nbrDim() const override;
170
171 virtual Size domainSize() const override;
172
173 virtual void add(const DiscreteVariable& v) override;
174
175 virtual void erase(const DiscreteVariable& v) override;
176
178
179 const DiscreteVariable& variable(Idx i) const override;
180 const DiscreteVariable& variable(const std::string& name) const override;
181
182 virtual Idx pos(const DiscreteVariable& v) const override;
183
184 virtual bool contains(const DiscreteVariable& v) const override;
185
186 virtual bool empty() const override;
187
189 // =========================================================================
191 // =========================================================================
193
194 virtual bool registerSlave(Instantiation& slave) override;
195
196 virtual bool unregisterSlave(Instantiation& slave) override;
197
199 // =========================================================================
201 // =========================================================================
203
204 using MultiDimContainer< GUM_SCALAR >::get;
205
206 virtual MultiDimContainer< GUM_SCALAR >* newFactory() const override = 0;
207
208 void beginMultipleChanges() override;
209
210 void endMultipleChanges() override;
211
212 void endMultipleChanges(const GUM_SCALAR&) override;
213
215
216 protected:
217 // =========================================================================
219 // =========================================================================
221
226
231 virtual void commitMultipleChanges_(const GUM_SCALAR& value);
232
238
243 bool isCommitNeeded_() const;
244
252
262 virtual void replace_(const DiscreteVariable* x, const DiscreteVariable* y) override;
263
273 virtual void invert_(Idx p1, Idx p2);
274
276
280 virtual const MultiDimImplementation< GUM_SCALAR >* content() const final;
281
285 virtual MultiDimImplementation< GUM_SCALAR >* content() final;
286
287 private:
290
293
296
299
302
305
308
313 };
314
319 template < typename GUM_SCALAR >
320 std::ostream& operator<<(std::ostream&, const MultiDimImplementation< GUM_SCALAR >&);
321
322} /* namespace gum */
323
325
326#endif /* GUM_MULTI_DIM_IMPLEMENTATION_H */
Base class for discrete random variable.
Class for assigning/browsing values to tuples of discrete variables.
Generic doubly linked lists.
Definition list.h:379
MultiDimContainer()
Default constructor.
<agrum/base/multidim/multiDimImplementation.h>
virtual bool empty() const override
Returns true if no var is in *this.
virtual const std::string & name() const =0
Returns the real name of the multiDim implementation.
void _setNotCommitedChange_()
Change the internalChangeState to NOT_COMMITTED_CHANGE.
virtual void invert_(Idx p1, Idx p2)
Inverts variables at position p1 and p2.
virtual ~MultiDimImplementation()
Class destructor.
const std::string & basename() const
Returns the base class name of this MultiDimImplementation.
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
virtual MultiDimContainer< GUM_SCALAR > * newFactory() const override=0
Creates an empty clone of this MultiDimContainer.
const DiscreteVariable & variable(const std::string &name) const override
Returns the variable with the name.
virtual Size realSize() const =0
Returns the real number of parameters used for this table.
MultiDimImplementation()
Default constructor.
virtual Idx nbrDim() const override
Returns the number of vars in the multidimensional container.
virtual void add(const DiscreteVariable &v) override
Adds a new var to the variables of the multidimensional matrix.
virtual void commitMultipleChanges_()
Synchronize content after MultipleChanges.
float compressionRate() const
The compression ratio of the table (depending on the type of implementation).
const List< Instantiation * > & slaves_() const
Returns a constant reference over the list of slaved instantiations.
bool isCommitNeeded_() const
Get the actual state of *this.
virtual Size domainSize() const override
Returns the product of the variables domain size.
virtual void replace_(const DiscreteVariable *x, const DiscreteVariable *y) override
Replace variable x by y.
_InternalChangeMethod_
Used to represent in which change method this MultiDimImplementation is.
virtual const Sequence< const DiscreteVariable * > & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.
virtual void erase(const DiscreteVariable &v) override
Removes a var from the variables of the multidimensional matrix.
virtual bool contains(const DiscreteVariable &v) const override
Returns true if var is in *this.
virtual bool registerSlave(Instantiation &slave) override
Register i as a slave of this MultiDimAdressable.
void endMultipleChanges() override
Call this method after doing important changes in this MultiDimContainer.
void endMultipleChanges(const GUM_SCALAR &) override
Call this method after doing important changes in this MultiDimContainer.
_InternalChangeState_
Used to represent in which change state this MultiDimImplementation is.
MultiDimImplementation(const MultiDimImplementation< GUM_SCALAR > &from)
Copy constructor.
const DiscreteVariable & variable(Idx i) const override
Returns a const ref to the ith var.
virtual bool unregisterSlave(Instantiation &slave) override
Unregister i as a slave of this MultiDimAdressable.
virtual Idx pos(const DiscreteVariable &v) const override
Returns the index of a variable.
void beginMultipleChanges() override
Call this method before doing important changes in this MultiDimContainer.
virtual void commitMultipleChanges_(const GUM_SCALAR &value)
Synchronize content after MultipleChanges.
bool isInMultipleChangeMethod_() const
Get the actual change method of this MultiDimImplementation.
The generic class for storing (ordered) sequences of objects.
Definition sequence.h:972
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size Idx
Type for indexes.
Definition types.h:79
Headers of the MultiDimContainer class.
Implementation of gum::MultiDimImplementation.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
Definition AVLTree.h:913