23 #ifndef DOXYGEN_SHOULD_SKIP_THIS 29 template <
typename T_TICKS >
31 const DiscretizedVariable< T_TICKS >& aDRV) {
35 for (
Idx i = 0; i < aDRV.__ticks_size; ++i) {
36 addTick((T_TICKS)aDRV.__ticks[i]);
40 template <
typename T_TICKS >
50 mid = (max + min) / 2;
51 T_TICKS val = __ticks[mid];
55 else if (target < val)
56 res = _dichotomy(target, min, mid);
57 else if (target > val)
58 res = _dichotomy(target, mid, max);
66 template <
typename T_TICKS >
68 if (__ticks_size < 2) {
GUM_ERROR(OutOfBounds,
"not enough ticks"); }
70 if (target < __ticks[0]) {
71 GUM_ERROR(OutOfLowerBound,
"less than first range");
74 if (target > __ticks[__ticks_size - 1]) {
75 GUM_ERROR(OutOfUpperBound,
"more than last range");
78 if (target == __ticks[__ticks_size - 1])
80 return __ticks_size - 2;
82 return _dichotomy(target, 0, __ticks_size - 1);
85 template <
typename T_TICKS >
87 const std::string& aName,
const std::string& aDesc) :
88 IDiscretizedVariable(aName, aDesc),
89 __ticks_size((
Size)0) {
94 template <
typename T_TICKS >
96 const std::string& aName,
97 const std::string& aDesc,
98 const std::vector< T_TICKS >&
ticks) :
103 for (
const auto t : ticks)
107 template <
typename T_TICKS >
109 const DiscretizedVariable< T_TICKS >& aDRV) :
116 template <
typename T_TICKS >
121 template <
typename T_TICKS >
123 return new DiscretizedVariable< T_TICKS >(*this);
126 template <
typename T_TICKS >
128 operator=(
const DiscretizedVariable< T_TICKS >& aDRV) {
133 template <
typename T_TICKS >
143 return (
__ticks[zeIdx] == aTick);
145 return ((
__ticks[zeIdx] == aTick) || (
__ticks[zeIdx + 1] == aTick));
146 }
catch (OutOfBounds&) {
return false; }
149 template <
typename T_TICKS >
150 DiscretizedVariable< T_TICKS >&
154 "Tick '" << aTick <<
"' already used for variable " <<
name());
180 }
catch (OutOfUpperBound&) {
182 }
catch (OutOfLowerBound&) {
196 template <
typename T_TICKS >
201 template <
typename T_TICKS >
203 std::stringstream ss;
206 GUM_ERROR(OutOfBounds,
"inexisting label index");
217 template <
typename T_TICKS >
220 GUM_ERROR(OutOfBounds,
"inexisting label index");
226 template <
typename T_TICKS >
231 std::istringstream i(label);
234 if (!(i >> target)) {
235 GUM_ERROR(NotFound,
"Bad label : " << label <<
" for " << *
this);
245 template <
typename T_TICKS >
250 template <
typename T_TICKS >
255 template <
typename T_TICKS >
262 template <
typename T_TICKS >
281 template <
typename T_TICKS >
282 INLINE
const std::vector< T_TICKS >&
287 template <
typename T_TICKS >
288 INLINE std::vector< double >
290 const std::size_t size =
__ticks.size();
291 std::vector< double >
ticks(size);
292 for (std::size_t i = std::size_t(0); i < size; ++i)
virtual std::vector< double > ticksAsDoubles() const
return the list of ticks as a vector of doubles
std::vector< T_TICKS > __ticks
void _copy(const Variable &aRV)
protected copy
virtual Idx index(const std::string &label) const
from the label to its index in var.
virtual Size domainSize() const
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual ~DiscretizedVariable()
Destructor.
virtual std::string label(Idx i) const
const std::vector< T_TICKS > & ticks() const
Return the list of ticks.
bool isTick(const T_TICKS &aTick) const
DiscretizedVariable & addTick(const T_TICKS &aTick)
add a tick.
virtual double numerical(Idx indice) const
get a numerical representation of he indice-the value.
DiscretizedVariable(const std::string &aName, const std::string &aDesc)
Constructor.
Idx _pos(const T_TICKS &target) const
seach the class of target (internally use _dichotomy)
DiscretizedVariable< T_TICKS > & operator=(const DiscretizedVariable< T_TICKS > &aDRV)
operator =
const T_TICKS & tick(Idx i) const
from the index to the tick.
void eraseTicks()
erase all the Ticks
IDiscretizedVariable(const std::string &aName, const std::string &aDesc)
Default constructor.
virtual DiscretizedVariable< T_TICKS > * clone() const
a virtual clone
const std::string toString() const
string version of *this
virtual const std::string domain() const
string represent the domain of the variable
virtual VarType varType() const
returns the type of variable
std::size_t Size
In aGrUM, hashed values are unsigned long int.
const std::string & name() const
returns the name of the variable
void _copy(const DiscretizedVariable< T_TICKS > &aDRV)
make a copy TODO since we removed T_OtherData maybe some changes are needed in this method...
Idx _dichotomy(const T_TICKS &target, Idx min, Idx max) const
perform a dichotomy on ticks
#define GUM_ERROR(type, msg)