GHOST
Protected Member Functions | Protected Attributes | List of all members
ghost::global_constraints::LinearEquation Class Referenceabstract

#include <linear_equation.hpp>

Inheritance diagram for ghost::global_constraints::LinearEquation:
Inheritance graph
Collaboration diagram for ghost::global_constraints::LinearEquation:
Collaboration graph

Protected Member Functions

 LinearEquation (const std::vector< int > &variables_index, double rhs, const std::vector< double > &coefficients)
 
 LinearEquation (const std::vector< Variable > &variables, double rhs, const std::vector< double > &coefficients)
 
virtual double compute_error (double sum) const =0
 
double required_error (const std::vector< Variable * > &variables) const override
 
double optional_delta_error (const std::vector< Variable * > &variables, const std::vector< int > &variable_indexes, const std::vector< int > &candidate_values) const override
 
void conditional_update_data_structures (const std::vector< Variable * > &variables, int variable_id, int new_value) override
 
- Protected Member Functions inherited from ghost::Constraint
double get_current_error () const
 
int get_id () const
 Inline method to get the unique id of the Constraint object. More...
 

Protected Attributes

double rhs
 

Additional Inherited Members

- Public Member Functions inherited from ghost::Constraint
 Constraint (const std::vector< int > &variables_index)
 
 Constraint (const std::vector< Variable > &variables)
 
 Constraint (const Constraint &other)=default
 Default copy contructor. More...
 
 Constraint (Constraint &&other)=default
 Default move contructor. More...
 
Constraintoperator= (const Constraint &other)=delete
 Copy assignment operator disabled. More...
 
Constraintoperator= (Constraint &&other)=delete
 Move assignment operator disabled. More...
 
virtual ~Constraint ()=default
 Default virtual destructor. More...
 
bool has_variable (int var_id) const
 

Constructor & Destructor Documentation

◆ LinearEquation() [1/2]

ghost::global_constraints::LinearEquation::LinearEquation ( const std::vector< int > &  variables_index,
double  rhs,
const std::vector< double > &  coefficients 
)
protected

◆ LinearEquation() [2/2]

ghost::global_constraints::LinearEquation::LinearEquation ( const std::vector< Variable > &  variables,
double  rhs,
const std::vector< double > &  coefficients 
)
protected

Member Function Documentation

◆ compute_error()

virtual double ghost::global_constraints::LinearEquation::compute_error ( double  sum) const
protectedpure virtual

◆ conditional_update_data_structures()

void ghost::global_constraints::LinearEquation::conditional_update_data_structures ( const std::vector< Variable * > &  variables,
int  index,
int  new_value 
)
overrideprotectedvirtual

Update user-defined data structures in the constraint.

Like any methods prefixed by 'conditional_', this method must be overriden under some conditions: if some inner data structures are defined in derived constraint 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 constraint.
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]'.

Reimplemented from ghost::Constraint.

◆ optional_delta_error()

double ghost::global_constraints::LinearEquation::optional_delta_error ( const std::vector< Variable * > &  variables,
const std::vector< int > &  indexes,
const std::vector< int > &  candidate_values 
) const
overrideprotectedvirtual

Virtual method to compute the difference, or delta, between the current error and the error of a candidate assignment.

The current assignment, as well as its error, are automatically stored in the class Constraint. Giving a vector of variable indexes and their respective candidate value, this methods ouputs the difference between the error of the current assignment in 'variables' given as input and the error we would get if we assign new candidate values.

The ouput can be negative, positive, or equals to 0. If the candidate error is strictly lower (then better) than the current error, the ouput is negative. If errors are the same, the ouputs equals to 0. Finally, if the candidate error is strictly higher (then worst) than the current error, the ouput is positive.

For EF-CSP/EF-COP models, this method can be VERY important to have faster computation. Although optional (the solver still works without it), we strongly advise users to define it properly, unless the overridden required_error method is trivial to compute. Having this method may make a big difference for the solver to quickly find better solutions. However, if the problem is modeled as an CSP/COP, users can just skip the implementation of this method.

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

Warning
DO NOT implement any side effect in this method. It is called by the solver to compute the constraint delta error but also for some inner mechanisms (such as error simulations).
Parameters
variablesa const reference of the vector of raw pointers of 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.
indexesthe vector of indexes of variables that are reassigned.
candidate_valuesthe vector of their respective candidate values.
Returns
A double corresponding to the difference between the current error of the constraint and the error one would get if the solver assigns candidate values to given variables.
Exceptions
Throwsan exception if the computed value is NaN.

Reimplemented from ghost::Constraint.

◆ required_error()

double ghost::global_constraints::LinearEquation::required_error ( const std::vector< Variable * > &  variables) const
overrideprotectedvirtual

Pure virtual method to compute the error of the constraint regarding the values of variables given as input.

This method is fundamental: as a predicate, it evalutes if the given values of variables violate this contraint, and as an error function, it evaluates how much.
Let's consider the following example to understand error functions: consider the contraint (x = y).
If x = 42 and y = 42, then these values satify the contraint. The error is then 0.
If x = 42 and y = 40, the constraint is not satified, but intuitively, we are closer to have a solution than with x = 42 and y = 10,000. Thus the error when y = 40 must be strictly lower than the error when y = 10,000.
Thus, a required_error candidate for the contraint (x = y) could be the function |x-y|.

This method MUST returns a value greater than or equals to 0.

Users have the choice: while modeling CSP or COP problems, required_error must implement the logic of a predicate and should outputs 0 if current values of variables satisfy the user-defined constraint, and something strictly higher than 0 otherwise, like 1 for instance.

While modeling EF-CSP/EF-COP problems, required_error needs to express an error function. It still must outputs 0 for satisfying values of variables, but must outputs a value strictly higher than 0 otherwise, such that the higher this value, the further current values of variables are from satisfying the user-defined constraint.

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

Warning
DO NOT implement any side effect in this method. It is called by the solver to compute the constraint error but also for some inner mechanisms (such as error simulations).
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 positive double corresponding to the error of the constraint. Outputing 0 means that given variable values satisfy the constraint.
Exceptions
Throwsan exception if the computed value is negative or is NaN.

Implements ghost::Constraint.

Member Data Documentation

◆ rhs

double ghost::global_constraints::LinearEquation::rhs
protected

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