aGrUM 3.1.1
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-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
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(std::string_view aName, std::string_view aDesc = "");
74
80 IntegerVariable(std::string_view aName,
81 std::string_view aDesc,
82 const std::vector< int >& domain);
83
91 IntegerVariable(std::string_view aName, std::string_view aDesc, int first, int last, Size nb);
92
94
98
101
103 [[nodiscard]] IntegerVariable* clone() const override;
104
107
109
110
111 // ############################################################################
113 // ############################################################################
115
117
119
121
123
124
126
127
128 // ############################################################################
130 // ############################################################################
131
134 Size domainSize() const override;
135
137 VarType varType() const override;
138
139 // returns the variable in fast syntax
140 std::string toFast() const override;
141
143
146 Idx index(std::string_view label) const override;
147
149 Idx closestIndex(double val) const override;
150
152 std::string label(Idx index) const override;
153
155 double numerical(Idx index) const override;
156
158 std::string domain() const override;
159
161 std::string stype() const override;
162
164 const std::vector< int >& integerDomain() const;
165
167
169 void addValue(int value);
170
172 bool isValue(int value) const;
173
175 void changeValue(int old_value, int new_value);
176
178 void eraseValue(int value);
179
182
189 std::string closestLabel(double val) const override;
190
192
193 private:
195
198 bool _checkSameDomain_(const Variable& aRV) const override;
199
201 std::vector< int > _domain_;
202 };
203
204} /* namespace gum */
205
206
207#ifndef GUM_NO_INLINE
209#endif /* GUM_NO_INLINE */
210
211#endif /* GUM_INTEGER_DISCRETE_VARIABLE_H */
DiscreteVariable(std::string_view aName, std::string_view aDesc)
Default constructor.
bool _checkSameDomain_(const Variable &aRV) const override
check the domain
IntegerVariable(IntegerVariable &&from) noexcept
move constructor
IntegerVariable & operator=(const IntegerVariable &from)
copy operator
std::vector< int > _domain_
the domain of the variable
Size domainSize() const override
returns the domain size of the discrete random variable
Idx index(std::string_view label) const override
returns the index of a given label
std::string closestLabel(double val) const override
gives the value closets to val
void addValue(int value)
add a new value to the domain size
double numerical(Idx index) const override
get an integer representation of the value at a given index
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
IntegerVariable & operator=(IntegerVariable &&from)
move operator
void eraseValues()
clear the domain of the variable
std::string stype() const override
string represent the type of the variable
IntegerVariable(std::string_view aName, std::string_view aDesc="")
constructor
IntegerVariable * clone() const override
virtual copy constructor
Idx closestIndex(double val) const override
returns the closest index of the value
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 label(Idx index) const override
returns a string corresponding to the ith value of the domain
VarType varType() const override
returns the type of variable
~IntegerVariable() override
destructor
std::string domain() const override
Returns the domain as a string.
std::string toFast() const override
returns the domain size of the discrete random variable
Base class for every random variable.
Definition variable.h:81
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:62