aGrUM 3.1.1
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-2026 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-2026 *
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_ELEMENT >
85 class MultiDimImplementation: public MultiDimContainer< GUM_ELEMENT > {
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
175 virtual const GUM_ELEMENT* data() const noexcept;
176
184 virtual GUM_ELEMENT* data() noexcept;
185
187 // ========================================================================
189 // ========================================================================
191 Idx nbrDim() const override;
192
193 Size domainSize() const override;
194
195 void add(const DiscreteVariable& v) override;
196
197 void erase(const DiscreteVariable& v) override;
198
199 const Sequence< const DiscreteVariable* >& variablesSequence() const override;
200
201 const DiscreteVariable& variable(Idx i) const override;
202 const DiscreteVariable& variable(std::string_view name) const override;
203
204 Idx pos(const DiscreteVariable& v) const override;
205
206 bool contains(const DiscreteVariable& v) const override;
207
208 bool empty() const override;
209
211 // =========================================================================
213 // =========================================================================
215
216 bool registerSlave(Instantiation& slave) override;
217
218 bool unregisterSlave(Instantiation& slave) override;
219
221 // =========================================================================
223 // =========================================================================
225
226 using MultiDimContainer< GUM_ELEMENT >::get;
227
228 [[nodiscard]] MultiDimContainer< GUM_ELEMENT >* newFactory() const override = 0;
229
230 void beginMultipleChanges() override;
231
232 void endMultipleChanges() override;
233
234 void endMultipleChanges(const GUM_ELEMENT&) override;
235
237
238 protected:
239 // =========================================================================
241 // =========================================================================
243
248
253 virtual void commitMultipleChanges_(const GUM_ELEMENT& value);
254
260
265 bool isCommitNeeded_() const;
266
273 const List< Instantiation* >& slaves_() const;
274
284 void replace_(const DiscreteVariable* x, const DiscreteVariable* y) override;
285
295 virtual void invert_(Idx p1, Idx p2);
296
298
302 const MultiDimImplementation< GUM_ELEMENT >* content() const final;
303
307 MultiDimImplementation< GUM_ELEMENT >* content() final;
308
309 private:
312
315
318
321
324
327
330
335 };
336
341 template < typename GUM_ELEMENT >
342 std::ostream& operator<<(std::ostream&, const MultiDimImplementation< GUM_ELEMENT >&);
343
344} /* namespace gum */
345
347
348#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:378
MultiDimContainer()
Default constructor.
<agrum/base/multidim/multiDimImplementation.h>
float compressionRate() const
The compression ratio of the table (depending on the type of implementation).
MultiDimImplementation()
Default constructor.
_InternalChangeMethod_
Used to represent in which change method this MultiDimImplementation is.
const std::string & basename() const
Returns the base class name of this MultiDimImplementation.
void _setNotCommitedChange_()
Change the internalChangeState to NOT_COMMITTED_CHANGE.
MultiDimImplementation(const MultiDimImplementation< GUM_ELEMENT > &from)
Copy constructor.
_InternalChangeState_
Used to represent in which change state this MultiDimImplementation is.
virtual const GUM_ELEMENT * data() const noexcept
Returns a pointer to the contiguous data buffer, or nullptr if the implementation does not store data...
~MultiDimImplementation() override
Class destructor.
virtual Size realSize() const =0
Returns the real number of parameters used for this table.
virtual const std::string & name() const =0
Returns the real name of the multiDim implementation.
The generic class for storing (ordered) sequences of objects.
Definition sequence.h:994
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
STL namespace.