GHOST
|
#include <model_builder.hpp>
Public Member Functions | |
ModelBuilder (bool permutation_problem=false) | |
virtual | ~ModelBuilder ()=default |
Default virtual destructor. More... | |
virtual void | declare_variables ()=0 |
virtual void | declare_constraints () |
virtual void | declare_objective () |
virtual void | declare_auxiliary_data () |
void | create_n_variables (int number, const std::vector< int > &domain, int index=0) |
void | create_n_variables (int number, int starting_value, std::size_t size, int index=0) |
int | get_number_variables () |
int | get_number_constraints () |
Protected Attributes | |
std::vector< Variable > | variables |
The global vector containing all variables of the problem instance. More... | |
std::vector< std::shared_ptr< Constraint > > | constraints |
The vector of shared pointers of each constraint composing the problem instance. More... | |
std::shared_ptr< Objective > | objective |
The shared pointer of the objective function of the problem instance. Is set to nullptr is declare_objective() is not overriden. More... | |
std::shared_ptr< AuxiliaryData > | auxiliary_data |
The shared pointer of the auxiliary data of the problem instance. Is set to nullptr is declare_auxiliary_data() is not overriden. More... | |
bool | permutation_problem |
This is the base class from which users need to derive their ModelBuilder class.
ghost::ModelBuilder cannot be directly used to encode user-defined model builder, since this is an abstract class. Users need to make their own derived model builder.
Once users have written their own Constraint class(es), and eventually an Objective class and an AuxiliaryData class, they need to declare what their combinatorial problem is by:
A user-defined ModelBuilder class is here to declare all elements above composing a problem instance.
ghost::ModelBuilder::ModelBuilder | ( | bool | permutation_problem = false | ) |
Unique constructor.
permutation_problem | a Boolean to declare if the problem is a permutation problem. False by default. |
|
virtualdefault |
Default virtual destructor.
void ghost::ModelBuilder::create_n_variables | ( | int | number, |
const std::vector< int > & | domain, | ||
int | index = 0 |
||
) |
Method to create 'number' identical variables, all with a domain given as input.
number | the number of variables to create. |
domain | the domain to copy and give to each variable. |
index | an optional parameter to make variables starting with the index-th value of the domain. Set to 0 by default. |
void ghost::ModelBuilder::create_n_variables | ( | int | number, |
int | starting_value, | ||
std::size_t | size, | ||
int | index = 0 |
||
) |
Method to create 'number' identical variables, all with a domain containing all integers in [starting_value, starting_value + size - 1].
number | the number of variables to create. |
starting_value | the first value of each domain. |
size | the size of each domain. |
index | an optional parameter to make variables starting with the index-th value of the domain. Set to 0 by default. |
|
virtual |
Method to declare the auxiliary data of the problem instance.
No need to override this method if the problem don't need auxiliary data. Otherwise, the implementation should be like
void UserBuilder::declare_auxiliary_data()
{
auxiliary_data = std::make_shared<UserData>(parameters_of_UserData_constructor);
}
|
virtual |
Method to declare the constraints of the problem instance. If not declared, the problem is considered to be a pure optimization problem.
The implementation should be like
void UserBuilder::declare_constraints()
{
constraints.emplace_back( std::make_shared<UserConstraint-1>(parameters_of_Constraint-1_constructor ) );
constraints.emplace_back( std::make_shared<UserConstraint-1>(parameters_of_Constraint-1_constructor ) ); // the model may need several constraints of the same type UserConstraint-1
...
constraints.emplace_back( std::make_shared<UserConstraint-k>(parameters_of_Constraint-k_constructor ) );
}
|
virtual |
If working with an optimization problem, mandatory method to declare the objective function of the problem instance.
No need to override this method for decision problems (CSP and EFSP models). For optimization problems (COP and EFOP models), the implementation should be like
void UserBuilder::declare_objective()
{
objective = std::make_shared<UserObjective>(parameters_of_UserObjective_constructor);
}
|
pure virtual |
Mandatory method to declare the variables of the problem instance.
The implementation should be like
void UserBuilder::declare_variables()
{
variables.emplace_back(parameters_of_Variable_constructor);
variables.emplace_back(parameters_of_Variable_constructor);
...
variables.emplace_back(parameters_of_Variable_constructor);
}
Alternatively, if the problem has many variables with similar domains with all integers in [first_value_domain, domain_size - 1], users can declare several variables at once:
void UserBuilder::declare_variables()
{
create_n_variables( number_of_variables, first_value_domain, domain_size);
}
|
inline |
|
inline |
Inline method returning the number of declared variables. This may be helpful in some specific cases to know how many variables are composing the problem instance.
|
protected |
The shared pointer of the auxiliary data of the problem instance. Is set to nullptr is declare_auxiliary_data() is not overriden.
|
protected |
The vector of shared pointers of each constraint composing the problem instance.
|
protected |
The shared pointer of the objective function of the problem instance. Is set to nullptr is declare_objective() is not overriden.
|
protected |
|
protected |
The global vector containing all variables of the problem instance.