aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
rangeVariable.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_RANGE_VARIABLE_H
50#define GUM_RANGE_VARIABLE_H
51
52#include <ostream>
53#include <sstream>
54#include <string>
55
56#include <agrum/agrum.h>
57
59
60namespace gum {
61
71
72 class RangeVariable final: public DiscreteVariable {
73 public:
75
78 RangeVariable(const std::string& aName, const std::string& aDesc, long minVal, long maxVal);
79
81 RangeVariable(const std::string& aName, const std::string& aDesc);
82
89 RangeVariable(const RangeVariable& aDRV);
90
92 ~RangeVariable() final;
93
96 RangeVariable* clone() const final;
97
99
101
109 Size domainSize() const final;
110
112
113 VarType varType() const final;
114
115 // returns the variable in fast syntax
116 std::string toFast() const final;
118
123 std::string label(Idx index) const final;
124
126 double numerical(Idx index) const final;
127
131 long minVal() const;
132
136 void setMinVal(long minVal);
137
141 long maxVal() const;
142
146 void setMaxVal(long maxVal);
147
151 bool belongs(long val) const;
152
157 Idx index(const std::string&) const final;
158
160 Idx closestIndex(double val) const final;
161
163
166
171
173
174 std::string domain() const final;
175
177 std::string stype() const final { return "Range"; };
178
179 private:
181
184 bool _checkSameDomain_(const Variable& aRV) const final;
185
190
193
195 };
196
197} /* namespace gum */
198
199#ifndef GUM_NO_INLINE
201#endif /* GUM_NO_INLINE */
202
203#endif /* GUM_RANGE_VARIABLE_H */
DiscreteVariable(const std::string &aName, const std::string &aDesc)
Default constructor.
void setMaxVal(long maxVal)
Set a new value of the upper bound.
RangeVariable * clone() const final
Copy Factory.
Idx index(const std::string &) const final
Idx closestIndex(double val) const final
returns the closest index of the value
std::string label(Idx index) const final
Get the index-th label.
long maxVal() const
Returns the upper bound.
long _minBound_
The upper bound.
bool belongs(long val) const
Returns true if the param belongs to the variable's interval.
bool _checkSameDomain_(const Variable &aRV) const final
check the domain
void setMinVal(long minVal)
Set a new value for the lower bound.
Size domainSize() const final
returns the size of the random discrete variable domain
VarType varType() const final
returns the type of variable
std::string toFast() const final
returns the size of the random discrete variable domain
RangeVariable & operator=(const RangeVariable &aRV)
Copy operator.
std::string stype() const final
string represent the type of the variable
double numerical(Idx index) const final
get a numerical representation of the index-the value.
std::string domain() const final
string represent the domain of the variable
RangeVariable(const std::string &aName, const std::string &aDesc, long minVal, long maxVal)
constructors
long minVal() const
Returns the lower bound.
~RangeVariable() final
destructor
long _maxBound_
The upper bound.
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
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
VarType
Definition variable.h:60
Inline implementation of gumRangeVariable.