aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
multiDimWithOffset.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
49#ifndef GUM_MULTI_DIM_WITH_OFFSET_H
50#define GUM_MULTI_DIM_WITH_OFFSET_H
51
52#include <vector>
53
54#include <agrum/agrum.h>
55
57
58namespace gum {
59 // ==========================================================================
60 // === GUM_MULTI_DIM_WITH_OFFSET === */
61 // ==========================================================================
72 template < typename GUM_SCALAR >
73 class MultiDimWithOffset: public MultiDimImplementation< GUM_SCALAR > {
74 public:
75 // =========================================================================
77 // =========================================================================
79
84
94
98 virtual ~MultiDimWithOffset();
99
106
108
110 // =========================================================================
112 // =========================================================================
114
115 virtual void add(const DiscreteVariable& v);
116
117 virtual void erase(const DiscreteVariable& v);
118
119 virtual void fill(const GUM_SCALAR& d) const = 0;
120
121 virtual std::string toString(const Instantiation* i) const;
122
123 virtual void changeNotification(const Instantiation& i,
124 const DiscreteVariable* const var,
125 Idx oldval,
126 Idx newval);
127
128 virtual void setChangeNotification(const Instantiation& i);
129
130 virtual void setFirstNotification(const Instantiation& i);
131
132 virtual void setLastNotification(const Instantiation& i);
133
134 void setIncNotification(const Instantiation& i);
135
136 void setDecNotification(const Instantiation& i);
137
138 virtual bool registerSlave(Instantiation& i);
139
140 virtual bool unregisterSlave(Instantiation& i);
141
143 // =========================================================================
145 // =========================================================================
147
149
158 Size toOffset(const Instantiation& i) const;
159
172 Instantiation& fromOffset(Instantiation& i, Size offset) const;
173
175
176 protected:
190 Size getOffs_(const Instantiation& i) const;
191
201
204
215 void computeInstantiationValue_(Instantiation& result, Size indice) const;
216
217 virtual GUM_SCALAR& get_(const Instantiation& i) const = 0;
218 };
219} /* namespace gum */
220
222
223#endif /* GUM_MULTI_DIM_WITH_OFFSET_H */
Base class for discrete random variable.
The class for generic Hash Tables.
Definition hashTable.h:637
Class for assigning/browsing values to tuples of discrete variables.
Abstract base class for all multi dimensionnal containers.
virtual std::string toString() const
Returns a representation of this MultiDimContainer.
MultiDimImplementation()
Default constructor.
HashTable< const Instantiation *, Size > offsets_
The position in the array of each slave Instantiation.
virtual void erase(const DiscreteVariable &v)
Removes a var from the variables of the multidimensional matrix.
HashTable< const DiscreteVariable *, Size > gaps_
The gaps between consecutive values of a given variable.
MultiDimWithOffset< GUM_SCALAR > & operator=(const MultiDimWithOffset< GUM_SCALAR > &from)
Copy operator.
void setIncNotification(const Instantiation &i)
Listen to increment in a given Instantiation.
virtual void setChangeNotification(const Instantiation &i)
Listen to an assignment of a value in a Instantiation.
virtual MultiDimContainer< GUM_SCALAR > * newFactory() const =0
Class constructor.
void setDecNotification(const Instantiation &i)
Listen to increment in each recorded Instantiation.
virtual void setLastNotification(const Instantiation &i)
Listen to setLast in a given Instantiation.
virtual bool unregisterSlave(Instantiation &i)
Unregister i as a slave of this MultiDimAdressable.
virtual void changeNotification(const Instantiation &i, const DiscreteVariable *const var, Idx oldval, Idx newval)
Listen to changes in a given Instantiation.
MultiDimWithOffset()
Class constructor.
Size getOffs_(const Instantiation &i) const
Compute the offset of a Instantiation.
void computeInstantiationValue_(Instantiation &result, Size indice) const
For a given index of a value in the vector values, this method computes the corresponding instantiati...
virtual void add(const DiscreteVariable &v)
Adds a new var to the variables of the multidimensional matrix.
virtual GUM_SCALAR & get_(const Instantiation &i) const =0
Return a data, given a Instantiation.
virtual void setFirstNotification(const Instantiation &i)
Listen to setFirst in a given Instantiation.
virtual bool registerSlave(Instantiation &i)
Register i as a slave of this MultiDimAdressable.
virtual void fill(const GUM_SCALAR &d) const =0
Fill the table with d.
Instantiation & fromOffset(Instantiation &i, Size offset) const
Set the Instantiation to the values corresponding to the offset (in this array).
Size toOffset(const Instantiation &i) const
Compute offset from an Instantiation (in this array).
virtual ~MultiDimWithOffset()
Class destrucor.
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 gum::MultiDimImplementation.
Headers of the MultiDimWithOffset class.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46