aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
rangeVariable.h
Go to the documentation of this file.
1
/**
2
*
3
* Copyright 2005-2020 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,
60
const
std::string& aDesc,
61
long
minVal,
62
long
maxVal);
63
64
/// by de default min=0, max=1
65
RangeVariable(
const
std::string& aName,
const
std::string& aDesc);
66
67
/** Copy Constructor.
68
*
69
* If aDRV haves any listener, it will not be copied.
70
*
71
* @param aDRV the variable we copy
72
*/
73
RangeVariable(
const
RangeVariable& aDRV);
74
75
/// destructor
76
virtual
~RangeVariable();
77
78
/// Copy Factory.
79
/// @return Returns a pointer on a new copy of this.
80
virtual
RangeVariable* clone()
const
;
81
82
/// @}
83
84
/// @name Accessors / Modifiers
85
86
/// @{
87
/// returns the size of the random discrete variable domain
88
/// @warning : It is technically possible to create RangeVariable with minVal
89
/// > maxVal
90
/// (or modify in that way an already created RangeVariable). The result is
91
/// an empty variable (i.e. empty() returns true).
92
/// If maxVal - minVal < 0, then domainsize() = 0.
93
virtual
Size domainSize()
const
;
94
95
/// returns the type of variable
96
97
virtual
VarType varType()
const
;
98
99
///
100
/**
101
* Get the indice-th label.
102
* @param indice the index of the label we wish to return
103
* @throw OutOfBound
104
*/
105
virtual
std::string label(Idx indice)
const
;
106
107
/// get a numerical representation of he indice-the value.
108
virtual
double
numerical(Idx indice)
const
;
109
110
/**
111
* Returns the lower bound.
112
*/
113
long
minVal()
const
;
114
115
/**
116
* Set a new value for the lower bound.
117
*/
118
void
setMinVal(
long
minVal);
119
120
/**
121
* Returns the upper bound.
122
*/
123
long
maxVal()
const
;
124
125
/**
126
* Set a new value of the upper bound.
127
*/
128
void
setMaxVal(
long
maxVal);
129
130
/**
131
* Returns true if the param belongs to the variable's interval.
132
*/
133
bool
belongs(
long
val)
const
;
134
135
/**
136
* @return the modality index from the label
137
* @throw NotFound
138
*/
139
virtual
Idx index(
const
std::string&)
const
;
140
141
/// @}
142
143
/// @name Operators
144
/// @{
145
/**
146
* Copy operator
147
* @param aRV to be copied
148
* @return a ref to *this */
149
RangeVariable& operator=(
const
RangeVariable& aRV);
150
151
/// @}
152
153
virtual
const
std::string domain()
const
;
154
155
private
:
156
/// @name Private Members.
157
158
/// @{
159
/// The lower bound.
160
long
minBound__;
161
162
/// The upper bound.
163
long
maxBound__;
164
165
/// @}
166
};
167
168
}
/* namespace gum */
169
170
#
ifndef
GUM_NO_INLINE
171
#
include
<
agrum
/
tools
/
variables
/
rangeVariable_inl
.
h
>
172
#
endif
/* GUM_NO_INLINE */
173
174
#
endif
/* GUM_RANGE_VARIABLE_H */