C++ Reference

C++ Reference: Linear solver

MPConstraint

Detailed Description

The class for constraints of a Mathematical Programming (MP) model.

A constraint is represented as a linear equation or inequality.

Definition at line 1140 of file linear_solver.h.

Public Member Functions

const std::string & name () const
 Returns the name of the constraint. More...
 
void Clear ()
 Clears all variables and coefficients. Does not clear the bounds. More...
 
void SetCoefficient (const MPVariable *const var, double coeff)
 Sets the coefficient of the variable on the constraint. More...
 
double GetCoefficient (const MPVariable *const var) const
 Gets the coefficient of a given variable on the constraint (which is 0 if the variable does not appear in the constraint). More...
 
const absl::flat_hash_map< const MPVariable *, double > & terms () const
 Returns a map from variables to their coefficients in the constraint. More...
 
double lb () const
 Returns the lower bound. More...
 
double ub () const
 Returns the upper bound. More...
 
void SetLB (double lb)
 Sets the lower bound. More...
 
void SetUB (double ub)
 Sets the upper bound. More...
 
void SetBounds (double lb, double ub)
 Sets both the lower and upper bounds. More...
 
bool is_lazy () const
 Advanced usage: returns true if the constraint is "lazy" (see below). More...
 
void set_is_lazy (bool laziness)
 Advanced usage: sets the constraint "laziness". More...
 
const MPVariableindicator_variable () const
 
bool indicator_value () const
 
int index () const
 Returns the index of the constraint in the MPSolver::constraints_. More...
 
double dual_value () const
 Advanced usage: returns the dual value of the constraint in the current solution (only available for continuous problems). More...
 
MPSolver::BasisStatus basis_status () const
 Advanced usage: returns the basis status of the constraint. More...
 

Protected Member Functions

 MPConstraint (int index, double lb, double ub, const std::string &name, MPSolverInterface *const interface_in)
 
void set_dual_value (double dual_value)
 

Constructor & Destructor Documentation

◆ MPConstraint()

MPConstraint ( int  index,
double  lb,
double  ub,
const std::string &  name,
MPSolverInterface *const  interface_in 
)
inlineprotected

Definition at line 1247 of file linear_solver.h.

Member Function Documentation

◆ basis_status()

MPSolver::BasisStatus basis_status ( ) const

Advanced usage: returns the basis status of the constraint.

It is only available for continuous problems).

Note that if a constraint "linear_expression in [lb, ub]" is transformed into "linear_expression + slack = 0" with slack in [-ub, -lb], then this status is the same as the status of the slack variable with AT_UPPER_BOUND and AT_LOWER_BOUND swapped.

◆ Clear()

void Clear ( )

Clears all variables and coefficients. Does not clear the bounds.

◆ dual_value()

double dual_value ( ) const

Advanced usage: returns the dual value of the constraint in the current solution (only available for continuous problems).

◆ GetCoefficient()

double GetCoefficient ( const MPVariable *const  var) const

Gets the coefficient of a given variable on the constraint (which is 0 if the variable does not appear in the constraint).

◆ index()

int index ( ) const
inline

Returns the index of the constraint in the MPSolver::constraints_.

Definition at line 1208 of file linear_solver.h.

◆ indicator_value()

bool indicator_value ( ) const
inline

Definition at line 1205 of file linear_solver.h.

◆ indicator_variable()

const MPVariable* indicator_variable ( ) const
inline

Definition at line 1204 of file linear_solver.h.

◆ is_lazy()

bool is_lazy ( ) const
inline

Advanced usage: returns true if the constraint is "lazy" (see below).

Definition at line 1187 of file linear_solver.h.

◆ lb()

double lb ( ) const
inline

Returns the lower bound.

Definition at line 1172 of file linear_solver.h.

◆ name()

const std::string& name ( ) const
inline

Returns the name of the constraint.

Definition at line 1143 of file linear_solver.h.

◆ set_dual_value()

void set_dual_value ( double  dual_value)
inlineprotected

Definition at line 1259 of file linear_solver.h.

◆ set_is_lazy()

void set_is_lazy ( bool  laziness)
inline

Advanced usage: sets the constraint "laziness".

This is only supported for SCIP and has no effect on other solvers.

When laziness is true, the constraint is only considered by the Linear Programming solver if its current solution violates the constraint. In this case, the constraint is definitively added to the problem. This may be useful in some MIP problems, and may have a dramatic impact on performance.

For more info see: http://tinyurl.com/lazy-constraints.

Definition at line 1202 of file linear_solver.h.

◆ SetBounds()

void SetBounds ( double  lb,
double  ub 
)

Sets both the lower and upper bounds.

◆ SetCoefficient()

void SetCoefficient ( const MPVariable *const  var,
double  coeff 
)

Sets the coefficient of the variable on the constraint.

If the variable does not belong to the solver, the function just returns, or crashes in non-opt mode.

◆ SetLB()

void SetLB ( double  lb)
inline

Sets the lower bound.

Definition at line 1178 of file linear_solver.h.

◆ SetUB()

void SetUB ( double  ub)
inline

Sets the upper bound.

Definition at line 1181 of file linear_solver.h.

◆ terms()

const absl::flat_hash_map<const MPVariable*, double>& terms ( ) const
inline

Returns a map from variables to their coefficients in the constraint.

If a variable is not present in the map, then its coefficient is zero.

Definition at line 1167 of file linear_solver.h.

◆ ub()

double ub ( ) const
inline

Returns the upper bound.

Definition at line 1175 of file linear_solver.h.


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