Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::MPConstraint Class Reference

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 1285 of file linear_solver.h.

#include <linear_solver.h>

Public Member Functions

 MPConstraint (const MPConstraint &)=delete
 This type is neither copyable nor movable.
MPConstraintoperator= (const MPConstraint &)=delete
const std::string & name () const
 Returns the name of the constraint.
void Clear ()
 Clears all variables and coefficients. Does not clear the bounds.
void SetCoefficient (const MPVariable *var, double coeff)
double GetCoefficient (const MPVariable *var) const
const absl::flat_hash_map< const MPVariable *, double > & terms () const
double lb () const
 Returns the lower bound.
double ub () const
 Returns the upper bound.
void SetLB (double lb)
 Sets the lower bound.
void SetUB (double ub)
 Sets the upper bound.
void SetBounds (double lb, double ub)
 Sets both the lower and upper bounds.
bool is_lazy () const
 Advanced usage: returns true if the constraint is "lazy" (see below).
void set_is_lazy (bool laziness)
const MPVariableindicator_variable () const
bool indicator_value () const
int index () const
 Returns the index of the constraint in the MPSolver::constraints_.
double dual_value () const
MPSolver::BasisStatus basis_status () const

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)

Friends

class MPSolver
class MPSolverInterface
class CBCInterface
class CLPInterface
class GLPKInterface
class SCIPInterface
class SLMInterface
class GurobiInterface
class CplexInterface
class XpressInterface
class GLOPInterface
class BopInterface
class SatInterface
class PdlpInterface
class HighsInterface
class KnapsackInterface

Constructor & Destructor Documentation

◆ MPConstraint() [1/2]

operations_research::MPConstraint::MPConstraint ( const MPConstraint & )
delete

This type is neither copyable nor movable.

◆ MPConstraint() [2/2]

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

Constructor. A constraint points to a single MPSolverInterface that is specified in the constructor. A constraint cannot belong to several models.

Definition at line 1402 of file linear_solver.h.

Member Function Documentation

◆ basis_status()

MPSolver::BasisStatus operations_research::MPConstraint::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.

See also
MPSolver::BasisStatus.

This is done lazily as this method is expected to be rarely used.

Definition at line 168 of file linear_solver.cc.

◆ Clear()

void operations_research::MPConstraint::Clear ( )

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

Definition at line 145 of file linear_solver.cc.

◆ dual_value()

double operations_research::MPConstraint::dual_value ( ) const

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

Definition at line 159 of file linear_solver.cc.

◆ GetCoefficient()

double operations_research::MPConstraint::GetCoefficient ( const MPVariable * var) const

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

Definition at line 113 of file linear_solver.cc.

◆ index()

int operations_research::MPConstraint::index ( ) const
inline

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

Definition at line 1359 of file linear_solver.h.

◆ indicator_value()

bool operations_research::MPConstraint::indicator_value ( ) const
inline

Definition at line 1356 of file linear_solver.h.

◆ indicator_variable()

const MPVariable * operations_research::MPConstraint::indicator_variable ( ) const
inline

Definition at line 1355 of file linear_solver.h.

◆ is_lazy()

bool operations_research::MPConstraint::is_lazy ( ) const
inline

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

Definition at line 1338 of file linear_solver.h.

◆ lb()

double operations_research::MPConstraint::lb ( ) const
inline

Returns the lower bound.

Definition at line 1323 of file linear_solver.h.

◆ name()

const std::string & operations_research::MPConstraint::name ( ) const
inline

Returns the name of the constraint.

Definition at line 1294 of file linear_solver.h.

◆ operator=()

MPConstraint & operations_research::MPConstraint::operator= ( const MPConstraint & )
delete

◆ set_dual_value()

void operations_research::MPConstraint::set_dual_value ( double dual_value)
inlineprotected

Definition at line 1414 of file linear_solver.h.

◆ set_is_lazy()

void operations_research::MPConstraint::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 1353 of file linear_solver.h.

◆ SetBounds()

void operations_research::MPConstraint::SetBounds ( double lb,
double ub )

Sets both the lower and upper bounds.

Definition at line 150 of file linear_solver.cc.

◆ SetCoefficient()

void operations_research::MPConstraint::SetCoefficient ( const MPVariable * 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.

If setting a coefficient to 0 when this coefficient did not exist or was already 0, do nothing: skip interface_->SetCoefficient() and do not store a coefficient in the map. Note that if the coefficient being set to 0 did exist and was not 0, we do have to keep a 0 in the coefficients_ map, because the extraction of the constraint might rely on it, depending on the underlying solver.

Definition at line 119 of file linear_solver.cc.

◆ SetLB()

void operations_research::MPConstraint::SetLB ( double lb)
inline

Sets the lower bound.

Definition at line 1329 of file linear_solver.h.

◆ SetUB()

void operations_research::MPConstraint::SetUB ( double ub)
inline

Sets the upper bound.

Definition at line 1332 of file linear_solver.h.

◆ terms()

const absl::flat_hash_map< const MPVariable *, double > & operations_research::MPConstraint::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 1318 of file linear_solver.h.

◆ ub()

double operations_research::MPConstraint::ub ( ) const
inline

Returns the upper bound.

Definition at line 1326 of file linear_solver.h.

◆ BopInterface

friend class BopInterface
friend

Definition at line 1393 of file linear_solver.h.

◆ CBCInterface

friend class CBCInterface
friend

Definition at line 1384 of file linear_solver.h.

◆ CLPInterface

friend class CLPInterface
friend

Definition at line 1385 of file linear_solver.h.

◆ CplexInterface

friend class CplexInterface
friend

Definition at line 1390 of file linear_solver.h.

◆ GLOPInterface

friend class GLOPInterface
friend

Definition at line 1392 of file linear_solver.h.

◆ GLPKInterface

friend class GLPKInterface
friend

Definition at line 1386 of file linear_solver.h.

◆ GurobiInterface

friend class GurobiInterface
friend

Definition at line 1389 of file linear_solver.h.

◆ HighsInterface

friend class HighsInterface
friend

Definition at line 1396 of file linear_solver.h.

◆ KnapsackInterface

friend class KnapsackInterface
friend

Definition at line 1397 of file linear_solver.h.

◆ MPSolver

friend class MPSolver
friend

Definition at line 1382 of file linear_solver.h.

◆ MPSolverInterface

friend class MPSolverInterface
friend

Definition at line 1383 of file linear_solver.h.

◆ PdlpInterface

friend class PdlpInterface
friend

Definition at line 1395 of file linear_solver.h.

◆ SatInterface

friend class SatInterface
friend

Definition at line 1394 of file linear_solver.h.

◆ SCIPInterface

friend class SCIPInterface
friend

Definition at line 1387 of file linear_solver.h.

◆ SLMInterface

friend class SLMInterface
friend

Definition at line 1388 of file linear_solver.h.

◆ XpressInterface

friend class XpressInterface
friend

Definition at line 1391 of file linear_solver.h.


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