aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
integerVariable.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
47#ifndef GUM_INTEGER_DISCRETE_VARIABLE_H
48#define GUM_INTEGER_DISCRETE_VARIABLE_H
49
50#include <agrum/agrum.h>
51
53
54namespace gum {
55
60 /* =========================================================================*/
61
62 class IntegerVariable final: public DiscreteVariable {
63 public:
64 // ############################################################################
66 // ############################################################################
68
73 IntegerVariable(const std::string& aName, const std::string& aDesc = "");
74
80 IntegerVariable(const std::string& aName,
81 const std::string& aDesc,
82 const std::vector< int >& domain);
83
91 IntegerVariable(const std::string& aName,
92 const std::string& aDesc,
93 int first,
94 int last,
95 Size nb);
96
98
102
105
107 IntegerVariable* clone() const final;
108
111
113
114
115 // ############################################################################
117 // ############################################################################
119
121
122 IntegerVariable& operator=(const IntegerVariable& from);
123
125
127
128
130
131
132 // ############################################################################
134 // ############################################################################
135
138 Size domainSize() const final;
139
141 VarType varType() const final;
142
143 // returns the variable in fast syntax
144 std::string toFast() const final;
145
147
150 Idx index(const std::string& label) const final;
151
153 Idx closestIndex(double val) const final;
154
156 std::string label(Idx index) const final;
157
159 double numerical(Idx index) const final;
160
162 std::string domain() const final;
163
165 std::string stype() const final { return "Integer"; };
166
168 const std::vector< int >& integerDomain() const;
169
171
173 void addValue(int value);
174
176 bool isValue(int value) const;
177
179 void changeValue(int old_value, int new_value);
180
182 void eraseValue(int value);
183
186
193 std::string closestLabel(double val) const;
194
196
197 private:
199
202 bool _checkSameDomain_(const Variable& aRV) const final;
203
205 std::vector< int > _domain_;
206 };
207
208} /* namespace gum */
209
210
211#ifndef GUM_NO_INLINE
213#endif /* GUM_NO_INLINE */
214
215#endif /* GUM_INTEGER_DISCRETE_VARIABLE_H */
DiscreteVariable(const std::string &aName, const std::string &aDesc)
Default constructor.
Idx closestIndex(double val) const final
returns the closest index of the value
IntegerVariable(IntegerVariable &&from) noexcept
move constructor
std::string domain() const final
Returns the domain as a string.
Size domainSize() const final
returns the domain size of the discrete random variable
std::vector< int > _domain_
the domain of the variable
Idx index(const std::string &label) const final
returns the index of a given label
bool _checkSameDomain_(const Variable &aRV) const final
check the domain
void addValue(int value)
add a new value to the domain size
std::string closestLabel(double val) const
gives the value closets to val
std::string stype() const final
string represent the type of the variable
IntegerVariable(const std::string &aName, const std::string &aDesc="")
constructor
bool isValue(int value) const
does this value exist in the domain ?
void eraseValue(int value)
erase a value from the domain of the variable
void eraseValues()
clear the domain of the variable
std::string label(Idx index) const final
returns a string corresponding to the ith value of the domain
VarType varType() const final
returns the type of variable
IntegerVariable(const IntegerVariable &from)
Copy constructor.
const std::vector< int > & integerDomain() const
returns the domain as a sequence of values
void changeValue(int old_value, int new_value)
substitute a value by another one
std::string toFast() const final
returns the domain size of the discrete random variable
double numerical(Idx index) const final
get a integer representation of the value at a given index
IntegerVariable * clone() const final
virtual copy constructor
Base class for every random variable.
Definition variable.h:79
Base class for discrete random variable.
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
Base class for Integer discrete random variables.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
VarType
Definition variable.h:60
STL namespace.