aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
rangeVariable.h
Go to the documentation of this file.
1
/**
2
*
3
* Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4
* info_at_agrum_dot_org
5
*
6
* This library is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
10
*
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Lesser General Public License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with this library. If not, see <http://www.gnu.org/licenses/>.
18
*
19
*/
20
21
22
/**
23
* @file
24
* @brief Header of gumRangeVariable.
25
*
26
* @author Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
27
*/
28
29
#
ifndef
GUM_RANGE_VARIABLE_H
30
#
define
GUM_RANGE_VARIABLE_H
31
32
#
include
<
ostream
>
33
#
include
<
sstream
>
34
#
include
<
string
>
35
36
#
include
<
agrum
/
agrum
.
h
>
37
38
#
include
<
agrum
/
tools
/
core
/
hashFunc
.
h
>
39
#
include
<
agrum
/
tools
/
variables
/
discreteVariable
.
h
>
40
41
namespace
gum {
42
43
/**
44
* @class RangeVariable
45
* @brief Defines a discrete random variable over an integer interval.
46
*
47
* It is technically possible to create RangeVariable with minVal > maxVal
48
* (or modify in that way an already created RangeVariable). The result is
49
* an empty variable (i.e. empty() returns true).
50
* If maxVal - minVal < 0, then domainsize() = 0.
51
*/
52
53
class
RangeVariable:
public
DiscreteVariable {
54
public
:
55
/// @name Constructors / Destructors
56
57
/// @{
58
/// constructors
59
RangeVariable(
const
std::string& aName,
const
std::string& aDesc,
long
minVal,
long
maxVal);
60
61
/// by de default min=0, max=1
62
RangeVariable(
const
std::string& aName,
const
std::string& aDesc);
63
64
/** Copy Constructor.
65
*
66
* If aDRV haves any listener, it will not be copied.
67
*
68
* @param aDRV the variable we copy
69
*/
70
RangeVariable(
const
RangeVariable& aDRV);
71
72
/// destructor
73
virtual
~RangeVariable();
74
75
/// Copy Factory.
76
/// @return Returns a pointer on a new copy of this.
77
virtual
RangeVariable* clone()
const
;
78
79
/// @}
80
81
/// @name Accessors / Modifiers
82
83
/// @{
84
/// returns the size of the random discrete variable domain
85
/// @warning : It is technically possible to create RangeVariable with minVal
86
/// > maxVal
87
/// (or modify in that way an already created RangeVariable). The result is
88
/// an empty variable (i.e. empty() returns true).
89
/// If maxVal - minVal < 0, then domainsize() = 0.
90
virtual
Size domainSize()
const
;
91
92
/// returns the type of variable
93
94
virtual
VarType varType()
const
;
95
96
///
97
/**
98
* Get the indice-th label.
99
* @param indice the index of the label we wish to return
100
* @throw OutOfBound
101
*/
102
virtual
std::string label(Idx indice)
const
;
103
104
/// get a numerical representation of he indice-the value.
105
virtual
double
numerical(Idx indice)
const
;
106
107
/**
108
* Returns the lower bound.
109
*/
110
long
minVal()
const
;
111
112
/**
113
* Set a new value for the lower bound.
114
*/
115
void
setMinVal(
long
minVal);
116
117
/**
118
* Returns the upper bound.
119
*/
120
long
maxVal()
const
;
121
122
/**
123
* Set a new value of the upper bound.
124
*/
125
void
setMaxVal(
long
maxVal);
126
127
/**
128
* Returns true if the param belongs to the variable's interval.
129
*/
130
bool
belongs(
long
val)
const
;
131
132
/**
133
* @return the modality index from the label
134
* @throw NotFound
135
*/
136
virtual
Idx index(
const
std::string&)
const
;
137
138
/// @}
139
140
/// @name Operators
141
/// @{
142
/**
143
* Copy operator
144
* @param aRV to be copied
145
* @return a ref to *this */
146
RangeVariable& operator=(
const
RangeVariable& aRV);
147
148
/// @}
149
150
virtual
const
std::string domain()
const
;
151
152
private
:
153
/// @name Private Members.
154
155
/// @{
156
/// The lower bound.
157
long
_minBound_;
158
159
/// The upper bound.
160
long
_maxBound_;
161
162
/// @}
163
};
164
165
}
/* namespace gum */
166
167
#
ifndef
GUM_NO_INLINE
168
#
include
<
agrum
/
tools
/
variables
/
rangeVariable_inl
.
h
>
169
#
endif
/* GUM_NO_INLINE */
170
171
#
endif
/* GUM_RANGE_VARIABLE_H */