GHOST
Classes | Public Member Functions | List of all members
ghost::Variable Class Referencefinal

#include <variable.hpp>

Collaboration diagram for ghost::Variable:
Collaboration graph

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...
 

Detailed Description

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.

See also
AuxiliaryData

Constructor & Destructor Documentation

◆ Variable() [1/5]

ghost::Variable::Variable ( )
default

Default constructor.

◆ Variable() [2/5]

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.

Parameters
domaina const reference to the vector of integers composing the domain to create.
indexthe 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.
namea 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.

◆ Variable() [3/5]

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.

Parameters
starting_valuean integer representing the first value of the domain. The creating domain will then be the interval [starting_value, starting_value + size - 1].
sizea size_t corresponding to the size of the domain to create.
indexthe 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.
namea 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.

◆ Variable() [4/5]

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).

Parameters
domaina const reference to the vector of integers composing the domain to create.
namea const reference of a string to give a name to the variable.

◆ Variable() [5/5]

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).

Parameters
starting_valuean integer representing the first value of the domain. The creating domain will then be the interval [starting_value, starting_value + size - 1].
sizea size_t corresponding to the size of the domain to create.
namea const reference of a string to give a name to the variable.

Member Function Documentation

◆ get_domain_max_value()

int ghost::Variable::get_domain_max_value ( ) const
inline

Inline method returning the maximal value in the variable's domain.

Returns
The maximal value in the domain, in constant time.

◆ get_domain_min_value()

int ghost::Variable::get_domain_min_value ( ) const
inline

Inline method returning the minimal value in the variable's domain.

Returns
The minimal value in the domain, in constant time.

◆ get_domain_size()

std::size_t ghost::Variable::get_domain_size ( ) const
inline

Inline method returning the size of the domain of the variable.

Returns
A size_t equals to size of the domain of the variable.

◆ get_full_domain()

std::vector<int> ghost::Variable::get_full_domain ( ) const
inline

Inline method returning the domain.

Returns
The vector of integers composing the domain.

◆ get_id()

int ghost::Variable::get_id ( ) const
inline

Inline method to get the unique id of the Variable object.

◆ get_name()

std::string ghost::Variable::get_name ( ) const
inline

Inline accessor to get the variable name.

◆ get_partial_domain()

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.

Returns
A vector containing these integers.

◆ get_value()

int ghost::Variable::get_value ( ) const
inline

Inline method to get the current value of the variable.

Returns
An integer corresponding to the variable value.

◆ set_value()

void ghost::Variable::set_value ( int  value)
inline

Set the value of the variable.

Parameters
valuean integer that must be a value in the domain to assign to the variable.
Exceptions
Ifthe given value is not in the domain, raises a valueException.

The documentation for this class was generated from the following file: