GHOST
|
#include <variable.hpp>
Public Member Functions | |
Variable ()=default | |
Default constructor. More... | |
Variable (const std::vector< int > &domain, int index=0, const std::string &name=std::string()) | |
Variable (int starting_value, std::size_t size, int index=0, const std::string &name=std::string()) | |
Variable (const std::vector< int > &domain, const std::string &name) | |
Variable (int starting_value, std::size_t size, const std::string &name) | |
std::vector< int > | get_full_domain () const |
std::vector< int > | get_partial_domain (int range) const |
int | get_value () const |
void | set_value (int value) |
std::size_t | get_domain_size () const |
int | get_domain_min_value () const |
int | get_domain_max_value () const |
std::string | get_name () const |
Inline accessor to get the variable name. More... | |
int | get_id () const |
Inline method to get the unique id of the Variable object. More... | |
This class encodes variables of the model. Users cannot write classes inheriting from ghost::Variable.
In GHOST, all variables are discrete variables with a domain containing integers only (positive, negative or both). Since no classes can inherits from ghost::Variable, if constraints or the objective function need specific details about variables (for instance, each variable models an agent with 2D coordinates), users need to either store these data into data structures in their own Constraints and/or their own Objective classes, or to place these data into their derived AuxiliaryData class, depending on their needs.
|
default |
Default constructor.
ghost::Variable::Variable | ( | const std::vector< int > & | domain, |
int | index = 0 , |
||
const std::string & | name = std::string() |
||
) |
Constructor with the domain as input.
This is the only constructor able to give a non-contiguous domain to a variable, i.e., a domain with "holes" like [1, 2, 5, 7, 8], where 3, 4 and 6 are missing.
domain | a const reference to the vector of integers composing the domain to create. |
index | the position in the domain corresponding to the variable initial value. For instance with the domain [1, 2, 5, 7, 8], if index equals to 3 then the variable initial value is 7. By default, the index is zero. |
name | a const reference of a string to give a name to the variable. If no names are given, GHOST will automatically rename variables by "vx", with x the variable ID. |
ghost::Variable::Variable | ( | int | starting_value, |
std::size_t | size, | ||
int | index = 0 , |
||
const std::string & | name = std::string() |
||
) |
Constructor building a contiguous domain with all intergers from starting_value to starting_value + size-1.
starting_value | an integer representing the first value of the domain. The creating domain will then be the interval [starting_value, starting_value + size - 1]. |
size | a size_t corresponding to the size of the domain to create. |
index | the position in the domain corresponding to the variable initial value. For instance with the domain [1, 2, 5, 7, 8], if index equals to 3 then the variable initial value is 7. By default, the index is zero. |
name | a const reference of a string to give a name to the variable. If no names are given, GHOST will automatically rename variables by "vx", with x the variable ID. |
ghost::Variable::Variable | ( | const std::vector< int > & | domain, |
const std::string & | name | ||
) |
Equivalent to the constructor Variable(domain, index, name).
It simply calls Variable(domain, 0, name).
domain | a const reference to the vector of integers composing the domain to create. |
name | a const reference of a string to give a name to the variable. |
ghost::Variable::Variable | ( | int | starting_value, |
std::size_t | size, | ||
const std::string & | name | ||
) |
Equivalent to the constructor Variable(starting_value, size, index, name).
It simply calls Variable(starting_value, size, 0, name).
starting_value | an integer representing the first value of the domain. The creating domain will then be the interval [starting_value, starting_value + size - 1]. |
size | a size_t corresponding to the size of the domain to create. |
name | a const reference of a string to give a name to the variable. |
|
inline |
Inline method returning the maximal value in the variable's domain.
|
inline |
Inline method returning the minimal value in the variable's domain.
|
inline |
Inline method returning the size of the domain of the variable.
|
inline |
Inline method returning the domain.
|
inline |
Inline method to get the unique id of the Variable object.
|
inline |
Inline accessor to get the variable name.
std::vector<int> ghost::Variable::get_partial_domain | ( | int | range | ) | const |
Method returning the range of values [current_value - range/2 [mod domain_size], current_value + range/2 [mod domain_size]] from the domain.
|
inline |
Inline method to get the current value of the variable.
|
inline |
Set the value of the variable.
value | an integer that must be a value in the domain to assign to the variable. |
If | the given value is not in the domain, raises a valueException. |