32 #include <agrum/agrum.h> 34 #include <agrum/tools/core/hashTable.h> 35 #include <agrum/tools/variables/discreteVariable.h> 38 #include <agrum/tools/variables/integerVariable.h> 40 #ifndef DOXYGEN_SHOULD_SKIP_THIS 45 INLINE IntegerVariable::IntegerVariable(
const std::string& aName,
46 const std::string& aDesc) :
47 DiscreteVariable(aName, aDesc) {
49 GUM_CONSTRUCTOR(IntegerVariable);
54 INLINE IntegerVariable::IntegerVariable(
const IntegerVariable& from) :
55 DiscreteVariable(from), _domain_(from._domain_) {
57 GUM_CONS_CPY(IntegerVariable);
62 INLINE IntegerVariable::IntegerVariable(IntegerVariable&& from) :
63 DiscreteVariable(std::move(from)), _domain_(std::move(from._domain_)) {
64 from._domain_.clear();
66 GUM_CONSTRUCTOR(IntegerVariable);
71 INLINE IntegerVariable* IntegerVariable::clone()
const {
72 return new IntegerVariable(*
this);
77 INLINE IntegerVariable::~IntegerVariable() {
78 GUM_DESTRUCTOR(IntegerVariable);
83 INLINE IntegerVariable& IntegerVariable::operator=(
const IntegerVariable& from) {
86 DiscreteVariable::operator=(from);
87 _domain_ = from._domain_;
95 INLINE IntegerVariable& IntegerVariable::operator=(IntegerVariable&& from) {
98 DiscreteVariable::operator=(std::move(from));
99 _domain_ = std::move(from._domain_);
100 from._domain_.clear();
108 INLINE
bool IntegerVariable::operator!=(
const Variable& var)
const {
109 return !operator==(var);
114 INLINE Size IntegerVariable::domainSize()
const {
115 return _domain_.size();
120 INLINE VarType IntegerVariable::varType()
const {
121 return VarType::Integer;
126 INLINE Idx IntegerVariable::index(
const std::string& aLabel)
const {
128 return _domain_.pos(std::stoi(aLabel));
130 GUM_ERROR(NotFound,
"label '" << aLabel <<
"' is unknown in " <<
this->toString());
136 INLINE std::string IntegerVariable::label(Idx i)
const {
139 return std::to_string(_domain_[i]);
144 INLINE
double IntegerVariable::numerical(Idx i)
const {
145 return double(_domain_[i]);
150 INLINE
const Sequence<
int >& IntegerVariable::integerDomain()
const {
156 INLINE
void IntegerVariable::changeValue(
int old_value,
int new_value) {
157 if (! _domain_.exists(old_value))
return;
158 if (_domain_.exists(new_value)) {
159 GUM_ERROR(DuplicateElement,
160 "Value" << new_value <<
" already belongs to the domain of the variable");
163 eraseValue(old_value);
169 INLINE
void IntegerVariable::eraseValue(
int value) {
170 _domain_.erase(value);
175 INLINE
void IntegerVariable::eraseValues() {