60#ifndef DOXYGEN_SHOULD_SKIP_THIS
86 if (
isLabel(aLabel))
GUM_ERROR(DuplicateElement,
"Label '" << aLabel <<
"' already exists")
94 const std::
string& aDesc,
95 const
Size nbrLabel) :
100 for (
Idx i = 0; i < nbrLabel; ++i) {
101 std::ostringstream oss;
109 const std::string& aDesc,
110 const std::vector< std::string >&
labels) :
113 GUM_CONSTRUCTOR(LabelizedVariable);
115 for (Idx i = 0; i < labels.size(); ++i)
116 _labels_.insert(labels[i]);
119 INLINE Idx LabelizedVariable::posLabel(
const std::string& label)
const {
120 return _labels_.pos(label);
126 LabelizedVariable::LabelizedVariable(
const LabelizedVariable& aLDRV) :
127 DiscreteVariable(aLDRV), _labels_(aLDRV._labels_) {
128 GUM_CONSTRUCTOR(LabelizedVariable);
133 INLINE LabelizedVariable::~LabelizedVariable() {
135 GUM_DESTRUCTOR(LabelizedVariable);
139 LabelizedVariable* LabelizedVariable::clone()
const {
return new LabelizedVariable(*
this); }
142 INLINE LabelizedVariable& LabelizedVariable::operator=(
const LabelizedVariable& aLDRV) {
144 if (&aLDRV !=
this) { copy_(aLDRV); }
150 INLINE
bool LabelizedVariable::isLabel(
const std::string& aLabel)
const {
151 return _labels_.exists(aLabel);
155 INLINE std::string LabelizedVariable::label(Idx i)
const {
return _labels_.atPos(i); }
158 INLINE
double LabelizedVariable::numerical(Idx indice)
const {
return double(indice); }
161 INLINE Idx LabelizedVariable::closestIndex(
double val)
const {
164 INLINE Idx LabelizedVariable::index(
const std::string& aLabel)
const {
166 return _labels_.pos(aLabel);
173 INLINE Size LabelizedVariable::domainSize()
const {
return _labels_.size(); }
175 INLINE
VarType LabelizedVariable::varType()
const {
return VarType::LABELIZED; }
177 INLINE std::string LabelizedVariable::toFast()
const {
179 s << name() << domain();
183 INLINE
bool LabelizedVariable::_checkSameDomain_(
const gum::Variable& aRV)
const {
186 const auto& cv =
static_cast< const LabelizedVariable&
>(aRV);
187 if (domainSize() != cv.domainSize())
return false;
188 for (Idx i = 0; i < domainSize(); ++i)
189 if (label(i) != cv.label(i))
return false;
DiscreteVariable(const std::string &aName, const std::string &aDesc)
Default constructor.
std::vector< std::string > labels() const
vector of labels
void eraseLabels()
erase all the labels
bool isLabel(const std::string &aLabel) const
indicates whether the variable already has the label passed in argument
LabelizedVariable(const std::string &aName, const std::string &aDesc="", const Size nbrLabel=2)
constructor
void copy_(const LabelizedVariable &aLDRV)
copies the content of aLDRV
LabelizedVariable & addLabel(const std::string &aLabel)
add a label with a new index (we assume that we will NEVER remove a label)
LabelizedVariable()
(protected) Default constructor
void changeLabel(Idx pos, const std::string &aLabel) const
change a label for this index
Sequence< std::string > _labels_
the set of labels contained in the variable
Exception : there is something wrong with an implementation.
Exception : out of bound.
Base class for every random variable.
void copy_(const Variable &aRV)
protected copy
Base class for discrete random variable.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
Class hash tables iterators.
Base class for labelized discrete random variables.
gum is the global namespace for all aGrUM entities