38 #include "thirdparty/randutils.hpp"
61 std::vector<int> _domain;
69 struct valueException : std::exception
74 valueException(
int value,
int min,
int max ) : value( value ), min( min ), max( max ) {}
75 std::string message =
"Wrong value " + std::to_string( value ) +
" passed to Variable::set_value. The given value does not belong to the domain and/or is not be between "
76 + std::to_string( min ) +
" (included) and "
77 + std::to_string( max ) +
" (included).\n";
78 const char* what() const noexcept {
return message.c_str(); }
82 inline void pick_random_value( randutils::mt19937_rng& rng ) { _current_value = rng.pick( _domain ); }
104 const std::string& name = std::string() );
122 const std::string& name = std::string() );
134 const std::string& name );
148 const std::string& name );
181 if( std::find( _domain.cbegin(), _domain.cend(), value ) == _domain.cend() )
184 _current_value = value;
209 inline std::string
get_name()
const {
return _name; }
212 inline int get_id()
const {
return _id; }
217 std::string domain =
"";
219 domain += std::to_string( value ) + std::string(
", " );
222 <<
"Variable name: " << v._name
224 <<
"\nValue: " << v._current_value
225 <<
"\nDomain: " << domain
Definition: model_builder.hpp:63
Definition: variable.hpp:57
void set_value(int value)
Definition: variable.hpp:179
Variable(int starting_value, std::size_t size, int index=0, const std::string &name=std::string())
friend class SearchUnit
Definition: variable.hpp:58
std::vector< int > get_partial_domain(int range) const
Variable(int starting_value, std::size_t size, const std::string &name)
int get_id() const
Inline method to get the unique id of the Variable object.
Definition: variable.hpp:212
int get_value() const
Definition: variable.hpp:171
std::string get_name() const
Inline accessor to get the variable name.
Definition: variable.hpp:209
std::vector< int > get_full_domain() const
Definition: variable.hpp:155
Variable(const std::vector< int > &domain, int index=0, const std::string &name=std::string())
friend std::ostream & operator<<(std::ostream &os, const Variable &v)
To have a nicer stream of Variable.
Definition: variable.hpp:215
Variable(const std::vector< int > &domain, const std::string &name)
int get_domain_min_value() const
Definition: variable.hpp:199
int get_domain_max_value() const
Definition: variable.hpp:206
std::size_t get_domain_size() const
Definition: variable.hpp:192
Variable()=default
Default constructor.
Definition: auxiliary_data.hpp:38