GHOST
Classes | Public Member Functions | Protected Member Functions | List of all members
ghost::Objective Class Referenceabstract

#include <objective.hpp>

Inheritance diagram for ghost::Objective:
Inheritance graph
Collaboration diagram for ghost::Objective:
Collaboration graph

Public Member Functions

 Objective (const Objective &other)=default
 Default copy contructor. More...
 
 Objective (Objective &&other)=default
 Default move contructor. More...
 
Objectiveoperator= (const Objective &other)=delete
 Copy assignment operator disabled. More...
 
Objectiveoperator= (Objective &&other)=delete
 Move assignment operator disabled. More...
 
virtual ~Objective ()=default
 Default virtual destructor. More...
 
std::string get_name () const
 Inline accessor to get the name of the objective object. More...
 
bool is_optimization () const
 Inline method returning if a user-defined objective function has been declared. More...
 
bool is_maximization () const
 

Protected Member Functions

virtual double required_cost (const std::vector< Variable * > &variables) const =0
 
virtual void conditional_update_data_structures (const std::vector< Variable * > &variables, int index, int new_value)
 
virtual int expert_heuristic_value (const std::vector< Variable * > &variables, int variable_index, const std::vector< int > &possible_values, randutils::mt19937_rng &rng) const
 
virtual int expert_heuristic_value_permutation (const std::vector< Variable * > &variables, int variable_index, const std::vector< int > &bad_variables, randutils::mt19937_rng &rng) const
 
virtual double expert_postprocess (const std::vector< Variable * > &variables, double best_cost) const
 
void is_not_optimization ()
 

Detailed Description

This is the base class containing the logic of objective functions. However, users would not derive their own Objective class directly from ghost::Objective, but from one of the two derived class ghost::Minimize and ghost::Maximize.

This class contains some methods prefixed by 'expert_'. It is highly recommended that users override such methods only if they know what they are doing.

See also
Variable

Constructor & Destructor Documentation

◆ Objective() [1/2]

ghost::Objective::Objective ( const Objective other)
default

Default copy contructor.

◆ Objective() [2/2]

ghost::Objective::Objective ( Objective &&  other)
default

Default move contructor.

◆ ~Objective()

virtual ghost::Objective::~Objective ( )
virtualdefault

Default virtual destructor.

Member Function Documentation

◆ conditional_update_data_structures()

virtual void ghost::Objective::conditional_update_data_structures ( const std::vector< Variable * > &  variables,
int  index,
int  new_value 
)
protectedvirtual

Update user-defined data structures in the objective function.

Like any methods prefixed by 'conditional_', this method must be overriden under some conditions: if some inner data structures are defined in derived objective classes and need to be updated while variable values change (i.e., when the solver asssign 'new_value' to variables[index]), this method must be implemented to define how data structures must be updated.

Parameters
variablesa const reference of the vector of raw pointers to variables of the objective function.
indexan integer to get the variable 'variables[index]' that has been updated by the solver.
new_valuean integer to know what is the new value of 'variables[index]'.

◆ expert_heuristic_value()

virtual int ghost::Objective::expert_heuristic_value ( const std::vector< Variable * > &  variables,
int  variable_index,
const std::vector< int > &  possible_values,
randutils::mt19937_rng &  rng 
) const
protectedvirtual

Virtual method to apply the value heuristic used by the solver for non permutation problems.

While dealing with non permutation problems, the solver calls this method to apply an eventual user-defined heuristic to choose a new domain value for a variable selected by the solver.

The default implementation outputs the value leading to the lowest objective cost. If two or more values lead to configurations with the same lowest cost, one of them is randomly returned.

Like any methods prefixed by 'expert_', users should override this method only if they know what they are doing.

Parameters
variablesa const reference of the vector of raw pointers of variables in the scope of the objective function. The solver is calling this method with the vector of variables that has been given to the constructor.
variable_indexthe index of the variable to change in the vector Objective::_variables.
possible_valuesa const reference to the vector of possible values of the variable to change.
rnga neat random generator implemented in thirdparty/randutils.hpp, see https://www.pcg-random.org/posts/ease-of-use-without-loss-of-power.html
Returns
The selected value according to the heuristic.

◆ expert_heuristic_value_permutation()

virtual int ghost::Objective::expert_heuristic_value_permutation ( const std::vector< Variable * > &  variables,
int  variable_index,
const std::vector< int > &  bad_variables,
randutils::mt19937_rng &  rng 
) const
protectedvirtual

Virtual method to apply the value heuristic used by the solver for permutation problems.

While dealing with permutation problems, the solver calls this method to apply an eventual user-defined heuristic to choose a variable to swap the value with.

By default, it returns a random variable from the bad_variables vector given as input.

Like any methods prefixed by 'expert_', users should override this method only if they know what they are doing.

Parameters
variablesa const reference of the vector of raw pointers of variables in the scope of the objective function. The solver is calling this method with the vector of variables that has been given to the constructor.
variable_indexthe index of the variable to change in the vector Objective::_variables.
bad_variablesa const reference to the vector of candidate variables the solver may swap the value with.
rnga neat random generator implemented in thirdparty/randutils.hpp, see https://www.pcg-random.org/posts/ease-of-use-without-loss-of-power.html
Returns
The index of the selected variable to swap with, according to the heuristic.

◆ expert_postprocess()

virtual double ghost::Objective::expert_postprocess ( const std::vector< Variable * > &  variables,
double  best_cost 
) const
protectedvirtual

Virtual method to perform post-processing optimization.

This method is called by the solver once it has found a solution. Its purpose is to apply human-knowledge optimization.

By default, it simply returns best_cost given as input, without modifying the variables. Users need to override it to have their own post-processing optimization.

Like any methods prefixed by 'expert_', users should override this method only if they know what they are doing.

Warning
The computation spantime of this method is not taken into account by timeouts given to the solver. If users override this method, they must ensure its computation time is neglictable compare to the timeout giving as input to Solver::solve.
Parameters
variablesa const reference of the vector of raw pointers of variables in the scope of the objective function. The solver is calling this method with the vector of variables that has been given to the constructor. If users must change some variables values, they must do it on variables from this vector, otherwise the modified solution won't be taken into account by the solver.
best_costa double representing the best optimization cost found by the solver so far. This helps users be sure that their post-processing leads to actual improvements.
Returns
The new error after post-processing.

◆ get_name()

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

Inline accessor to get the name of the objective object.

◆ is_maximization()

bool ghost::Objective::is_maximization ( ) const
inline

Inline method if the user-defined objective function has to be maximized (true) or minimize (false).

◆ is_not_optimization()

void ghost::Objective::is_not_optimization ( )
inlineprotected

◆ is_optimization()

bool ghost::Objective::is_optimization ( ) const
inline

Inline method returning if a user-defined objective function has been declared.

◆ operator=() [1/2]

Objective& ghost::Objective::operator= ( const Objective other)
delete

Copy assignment operator disabled.

◆ operator=() [2/2]

Objective& ghost::Objective::operator= ( Objective &&  other)
delete

Move assignment operator disabled.

◆ required_cost()

virtual double ghost::Objective::required_cost ( const std::vector< Variable * > &  variables) const
protectedpure virtual

Pure virtual method to compute the value of the objective function regarding the values of variables given as input.

Like Constraint::required_error, this method is fundamental: it evalutes the performance of the current values of the variables. GHOST will search for variable values that will minimize or maximize the output of this method.

Like any methods prefixed by 'required_', overriding this method is mandatory.

Parameters
variablesa const reference of the vector of raw pointers to variables in the scope of the constraint. The solver is actually calling this method with the vector of variables that has been given to the constructor.
Returns
A double corresponding to the value of the objective function on the current configuration. Unlike Constraint::required_error, this output may be negative.
Exceptions
Throwsan exception if the computed value is NaN.

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