GHOST
Public Member Functions | Protected Attributes | List of all members
ghost::ModelBuilder Class Referenceabstract

#include <model_builder.hpp>

Collaboration diagram for ghost::ModelBuilder:
Collaboration graph

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< Variablevariables
 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< Objectiveobjective
 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< AuxiliaryDataauxiliary_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
 

Detailed Description

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.

See also
Variable Constraint Objective AuxiliaryData

Constructor & Destructor Documentation

◆ ModelBuilder()

ghost::ModelBuilder::ModelBuilder ( bool  permutation_problem = false)

Unique constructor.

Parameters
permutation_problema Boolean to declare if the problem is a permutation problem. False by default.

◆ ~ModelBuilder()

virtual ghost::ModelBuilder::~ModelBuilder ( )
virtualdefault

Default virtual destructor.

Member Function Documentation

◆ create_n_variables() [1/2]

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.

Parameters
numberthe number of variables to create.
domainthe domain to copy and give to each variable.
indexan optional parameter to make variables starting with the index-th value of the domain. Set to 0 by default.

◆ create_n_variables() [2/2]

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

Parameters
numberthe number of variables to create.
starting_valuethe first value of each domain.
sizethe size of each domain.
indexan optional parameter to make variables starting with the index-th value of the domain. Set to 0 by default.

◆ declare_auxiliary_data()

virtual void ghost::ModelBuilder::declare_auxiliary_data ( )
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);
}

◆ declare_constraints()

virtual void ghost::ModelBuilder::declare_constraints ( )
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 ) );
}

◆ declare_objective()

virtual void ghost::ModelBuilder::declare_objective ( )
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);
}

◆ declare_variables()

virtual void ghost::ModelBuilder::declare_variables ( )
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);
}

◆ get_number_constraints()

int ghost::ModelBuilder::get_number_constraints ( )
inline

◆ get_number_variables()

int ghost::ModelBuilder::get_number_variables ( )
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.

Member Data Documentation

◆ auxiliary_data

std::shared_ptr<AuxiliaryData> ghost::ModelBuilder::auxiliary_data
protected

The shared pointer of the auxiliary data of the problem instance. Is set to nullptr is declare_auxiliary_data() is not overriden.

◆ constraints

std::vector<std::shared_ptr<Constraint> > ghost::ModelBuilder::constraints
protected

The vector of shared pointers of each constraint composing the problem instance.

◆ objective

std::shared_ptr<Objective> ghost::ModelBuilder::objective
protected

The shared pointer of the objective function of the problem instance. Is set to nullptr is declare_objective() is not overriden.

◆ permutation_problem

bool ghost::ModelBuilder::permutation_problem
protected

◆ variables

std::vector<Variable> ghost::ModelBuilder::variables
protected

The global vector containing all variables of the problem instance.


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