Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::SCIPInterface Class Reference
Inheritance diagram for operations_research::SCIPInterface:
operations_research::MPSolverInterface

Public Member Functions

 SCIPInterface (MPSolver *solver)
 
 ~SCIPInterface () override
 
void SetOptimizationDirection (bool maximize) override
 Not cached.
 
MPSolver::ResultStatus Solve (const MPSolverParameters &param) override
 
bool SupportsDirectlySolveProto (std::atomic< bool > *interrupt) const override
 
MPSolutionResponse DirectlySolveProto (LazyMutableCopy< MPModelRequest > request, std::atomic< bool > *interrupt) override
 
void Reset () override
 
double infinity () override
 
void SetVariableBounds (int var_index, double lb, double ub) override
 Modifies bounds of an extracted variable.
 
void SetVariableInteger (int var_index, bool integer) override
 Modifies integrality of an extracted variable.
 
void SetConstraintBounds (int row_index, double lb, double ub) override
 Modify bounds of an extracted variable.
 
void AddRowConstraint (MPConstraint *ct) override
 Adds a linear constraint.
 
bool AddIndicatorConstraint (MPConstraint *ct) override
 
void AddVariable (MPVariable *var) override
 Add a variable.
 
void SetCoefficient (MPConstraint *constraint, const MPVariable *variable, double new_value, double old_value) override
 Changes a coefficient in a constraint.
 
void ClearConstraint (MPConstraint *constraint) override
 Not cached.
 
void SetObjectiveCoefficient (const MPVariable *variable, double coefficient) override
 Cached.
 
void SetObjectiveOffset (double value) override
 Cached.
 
void ClearObjective () override
 Clear objective of all its terms.
 
void BranchingPriorityChangedForVariable (int var_index) override
 
int64_t iterations () const override
 
int64_t nodes () const override
 
MPSolver::BasisStatus row_status (int constraint_index) const override
 Returns the basis status of a row.
 
MPSolver::BasisStatus column_status (int variable_index) const override
 Returns the basis status of a constraint.
 
bool IsContinuous () const override
 
bool IsLP () const override
 Returns true if the problem is continuous and linear.
 
bool IsMIP () const override
 Returns true if the problem is discrete and linear.
 
void ExtractNewVariables () override
 Extracts the variables that have not been extracted yet.
 
void ExtractNewConstraints () override
 Extracts the constraints that have not been extracted yet.
 
void ExtractObjective () override
 Extracts the objective.
 
std::string SolverVersion () const override
 Returns a string describing the underlying solver and its version.
 
bool InterruptSolve () override
 
void * underlying_solver () override
 Returns the underlying solver.
 
bool NextSolution () override
 
void SetCallback (MPCallback *mp_callback) override
 MPCallback API.
 
bool SupportsCallbacks () const override
 
- Public Member Functions inherited from operations_research::MPSolverInterface
 MPSolverInterface (MPSolver *solver)
 
virtual ~MPSolverInterface ()
 
virtual void Write (const std::string &filename)
 
double best_objective_bound () const
 
double objective_value () const
 Returns the objective value of the best solution found so far.
 
bool CheckSolutionIsSynchronized () const
 
virtual bool CheckSolutionExists () const
 
bool CheckSolutionIsSynchronizedAndExists () const
 Handy shortcut to do both checks above (it is often used).
 
int last_variable_index () const
 Returns the index of the last variable extracted.
 
bool variable_is_extracted (int var_index) const
 
void set_variable_as_extracted (int var_index, bool extracted)
 
bool constraint_is_extracted (int ct_index) const
 
void set_constraint_as_extracted (int ct_index, bool extracted)
 
bool quiet () const
 Returns the boolean indicating the verbosity of the solver output.
 
void set_quiet (bool quiet_value)
 Sets the boolean indicating the verbosity of the solver output.
 
MPSolver::ResultStatus result_status () const
 Returns the result status of the last solve.
 
virtual double ComputeExactConditionNumber () const
 
virtual void SetStartingLpBasis (const std::vector< MPSolver::BasisStatus > &, const std::vector< MPSolver::BasisStatus > &)
 See MPSolver::SetStartingLpBasis().
 

Additional Inherited Members

- Public Types inherited from operations_research::MPSolverInterface
enum  SynchronizationStatus { MUST_RELOAD , MODEL_SYNCHRONIZED , SOLUTION_SYNCHRONIZED }
 
- Static Public Attributes inherited from operations_research::MPSolverInterface
static constexpr int64_t kUnknownNumberOfIterations = -1
 
static constexpr int64_t kUnknownNumberOfNodes = -1
 
- Protected Member Functions inherited from operations_research::MPSolverInterface
void ExtractModel ()
 Extracts model stored in MPSolver.
 
void ResetExtractionInformation ()
 Resets the extraction information.
 
void InvalidateSolutionSynchronization ()
 
void SetCommonParameters (const MPSolverParameters &param)
 Sets parameters common to LP and MIP in the underlying solver.
 
void SetMIPParameters (const MPSolverParameters &param)
 Sets MIP specific parameters in the underlying solver.
 
void SetUnsupportedDoubleParam (MPSolverParameters::DoubleParam param)
 Sets an unsupported double parameter.
 
void SetDoubleParamToUnsupportedValue (MPSolverParameters::DoubleParam param, double value)
 Sets a supported double parameter to an unsupported value.
 
- Protected Attributes inherited from operations_research::MPSolverInterface
MPSolver *const solver_
 
SynchronizationStatus sync_status_
 Indicates whether the model and the solution are synchronized.
 
MPSolver::ResultStatus result_status_
 
bool maximize_
 Optimization direction.
 
int last_constraint_index_
 Index in MPSolver::variables_ of last constraint extracted.
 
int last_variable_index_
 Index in MPSolver::constraints_ of last variable extracted.
 
double objective_value_
 The value of the objective function.
 
double best_objective_bound_
 The value of the best objective bound. Used only for MIP solvers.
 
bool quiet_
 Boolean indicator for the verbosity of the solver output.
 
- Static Protected Attributes inherited from operations_research::MPSolverInterface
static const int kDummyVariableIndex = 0
 -------— MPSolverInterface -------—
 

Detailed Description

Definition at line 67 of file scip_interface.cc.

Constructor & Destructor Documentation

◆ SCIPInterface()

operations_research::SCIPInterface::SCIPInterface ( MPSolver * solver)
explicit

Definition at line 258 of file scip_interface.cc.

◆ ~SCIPInterface()

operations_research::SCIPInterface::~SCIPInterface ( )
override

Definition at line 263 of file scip_interface.cc.

Member Function Documentation

◆ AddIndicatorConstraint()

bool operations_research::SCIPInterface::AddIndicatorConstraint ( MPConstraint * )
overridevirtual

Adds an indicator constraint. Returns true if the feature is supported by the underlying solver.

Reimplemented from operations_research::MPSolverInterface.

Definition at line 499 of file scip_interface.cc.

◆ AddRowConstraint()

void operations_research::SCIPInterface::AddRowConstraint ( MPConstraint * ct)
overridevirtual

Adds a linear constraint.

Implements operations_research::MPSolverInterface.

Definition at line 495 of file scip_interface.cc.

◆ AddVariable()

void operations_research::SCIPInterface::AddVariable ( MPVariable * var)
overridevirtual

Add a variable.

Implements operations_research::MPSolverInterface.

Definition at line 504 of file scip_interface.cc.

◆ BranchingPriorityChangedForVariable()

void operations_research::SCIPInterface::BranchingPriorityChangedForVariable ( int var_index)
overridevirtual

As of 2019-05, SCIP does not support setting branching priority for variables in models that have already been solved. Therefore, we force reset the model when setting the priority on an already extracted variable.

Note
this is a more drastic step than merely changing the sync_status. This may be slightly conservative, as it is technically possible that the extraction has occurred without a call to Solve().

Reimplemented from operations_research::MPSolverInterface.

Definition at line 483 of file scip_interface.cc.

◆ ClearConstraint()

void operations_research::SCIPInterface::ClearConstraint ( MPConstraint * constraint)
overridevirtual

Not cached.

Constraint may not have been extracted yet.

Set coefficient to zero by subtracting the old coefficient value.

Implements operations_research::MPSolverInterface.

Definition at line 429 of file scip_interface.cc.

◆ ClearObjective()

void operations_research::SCIPInterface::ClearObjective ( )
overridevirtual

Clear objective of all its terms.

Clear linear terms

Variable may have not been extracted yet.

Note
we don't clear the objective offset here because it's not necessary (it's always reset anyway in ExtractObjective) and we sometimes run into crashes when clearing the whole model (see http://test/OCL:253365573:BASE:253566457:1560777456754:e181f4ab). It's not worth to spend time investigating this issue.

Implements operations_research::MPSolverInterface.

Definition at line 459 of file scip_interface.cc.

◆ column_status()

MPSolver::BasisStatus operations_research::SCIPInterface::column_status ( int variable_index) const
inlineoverridevirtual

Returns the basis status of a constraint.

Implements operations_research::MPSolverInterface.

Definition at line 105 of file scip_interface.cc.

◆ DirectlySolveProto()

MPSolutionResponse operations_research::SCIPInterface::DirectlySolveProto ( LazyMutableCopy< MPModelRequest > request,
std::atomic< bool > * interrupt )
overridevirtual

Reimplemented from operations_research::MPSolverInterface.

Definition at line 884 of file scip_interface.cc.

◆ ExtractNewConstraints()

void operations_research::SCIPInterface::ExtractNewConstraints ( )
overridevirtual

Extracts the constraints that have not been extracted yet.

Find the length of the longest row.

Add each new constraint.

See http://scip.zib.de/doc/html/cons__linear_8h.php#aa7aed137a4130b35b168812414413481 for an explanation of the parameters.

Implements operations_research::MPSolverInterface.

Definition at line 551 of file scip_interface.cc.

◆ ExtractNewVariables()

void operations_research::SCIPInterface::ExtractNewVariables ( )
overridevirtual

Extracts the variables that have not been extracted yet.

Define new variables

The true objective coefficient will be set later in ExtractObjective.

Add new variables to existing constraints.

The variable is new, so we know the previous coefficient value was 0 and we can directly add the coefficient.

Implements operations_research::MPSolverInterface.

Definition at line 506 of file scip_interface.cc.

◆ ExtractObjective()

void operations_research::SCIPInterface::ExtractObjective ( )
overridevirtual

Extracts the objective.

Linear objective: set objective coefficients for all variables (some might have been modified).

Constant term: change objective offset.

Implements operations_research::MPSolverInterface.

Definition at line 651 of file scip_interface.cc.

◆ infinity()

double operations_research::SCIPInterface::infinity ( )
overridevirtual

Reimplemented from operations_research::MPSolverInterface.

Definition at line 317 of file scip_interface.cc.

◆ InterruptSolve()

bool operations_research::SCIPInterface::InterruptSolve ( )
inlineoverridevirtual

Reimplemented from operations_research::MPSolverInterface.

Definition at line 124 of file scip_interface.cc.

◆ IsContinuous()

bool operations_research::SCIPInterface::IsContinuous ( ) const
inlineoverridevirtual

--— Misc --— Queries problem type. For simplicity, the distinction between continuous and discrete is based on the declaration of the user when the solver is created (example: GLPK_LINEAR_PROGRAMMING vs. GLPK_MIXED_INTEGER_PROGRAMMING), not on the actual content of the model. Returns true if the problem is continuous.

Implements operations_research::MPSolverInterface.

Definition at line 110 of file scip_interface.cc.

◆ IsLP()

bool operations_research::SCIPInterface::IsLP ( ) const
inlineoverridevirtual

Returns true if the problem is continuous and linear.

Implements operations_research::MPSolverInterface.

Definition at line 111 of file scip_interface.cc.

◆ IsMIP()

bool operations_research::SCIPInterface::IsMIP ( ) const
inlineoverridevirtual

Returns true if the problem is discrete and linear.

Implements operations_research::MPSolverInterface.

Definition at line 112 of file scip_interface.cc.

◆ iterations()

int64_t operations_research::SCIPInterface::iterations ( ) const
overridevirtual

---— Query statistics on the solution and the solve ---— Returns the number of simplex iterations. The problem must be discrete, otherwise it crashes, or returns kUnknownNumberOfIterations in NDEBUG mode.

NOTE(user): As of 2018-12 it doesn't run in the stubby server, and is a specialized call, so it's ok to crash if the status is broken.

Implements operations_research::MPSolverInterface.

Definition at line 907 of file scip_interface.cc.

◆ NextSolution()

bool operations_research::SCIPInterface::NextSolution ( )
overridevirtual

MULTIPLE SOLUTIONS SUPPORT The default behavior of scip is to store the top incidentally generated integer solutions in the solution pool. The default maximum size is 100. This can be adjusted by setting the param limits/maxsol. There is no way to ensure that the pool will actually be full.

You can also ask SCIP to enumerate all feasible solutions. Combined with an equality or inequality constraint on the objective (after solving once to find the optimal solution), you can use this to find all high quality solutions. See https://scip.zib.de/doc/html/COUNTER.php. This behavior is not supported directly through MPSolver, but in theory can be controlled entirely through scip parameters.

Make sure we have successfully solved the problem and not modified it.

Reimplemented from operations_research::MPSolverInterface.

Definition at line 893 of file scip_interface.cc.

◆ nodes()

int64_t operations_research::SCIPInterface::nodes ( ) const
overridevirtual

Returns the number of branch-and-bound nodes. The problem must be discrete, otherwise it crashes, or returns kUnknownNumberOfNodes in NDEBUG mode.

NOTE(user): Same story as iterations(): it's OK to crash here.

This is the total number of nodes used in the solve, potentially across multiple branch-and-bound trees. Use limits/totalnodes (rather than limits/nodes) to control this value.

Implements operations_research::MPSolverInterface.

Definition at line 914 of file scip_interface.cc.

◆ Reset()

void operations_research::SCIPInterface::Reset ( )
overridevirtual

--— Model modifications and extraction --— Resets extracted model.

We hold calls to SCIPinterruptSolve() until the new scip_ is fully built.

Remove existing one but keep it alive to copy parameters from it.

Install the new one.

Copy all existing parameters from the previous SCIP to the new one. This ensures that if a user calls multiple times SetSolverSpecificParametersAsString() and then Reset() is called, we still take into account all parameters. Note though that at the end of Solve(), parameters are reset so after Solve() has been called, only the last set parameters are kept.

Implements operations_research::MPSolverInterface.

Definition at line 265 of file scip_interface.cc.

◆ row_status()

MPSolver::BasisStatus operations_research::SCIPInterface::row_status ( int constraint_index) const
inlineoverridevirtual

Returns the basis status of a row.

Implements operations_research::MPSolverInterface.

Definition at line 101 of file scip_interface.cc.

◆ SetCallback()

void operations_research::SCIPInterface::SetCallback ( MPCallback * mp_callback)
overridevirtual

MPCallback API.

CALLBACK SUPPORT:

  • We support MPSolver's callback API via MPCallback. See ./linear_solver_callback.h.
  • We also support SCIP's more general callback interface, built on 'constraint handlers'. See ./scip_callback.h and test, these are added directly to the underlying SCIP object, bypassing SCIPInterface. The former works by calling the latter.

Reimplemented from operations_research::MPSolverInterface.

Definition at line 1148 of file scip_interface.cc.

◆ SetCoefficient()

void operations_research::SCIPInterface::SetCoefficient ( MPConstraint * constraint,
const MPVariable * variable,
double new_value,
double old_value )
overridevirtual

Changes a coefficient in a constraint.

The modification of the coefficient for an extracted row and variable is not cached.

SCIP does not allow to set a coefficient directly, so we add the difference between the new and the old value instead.

The modification of an unextracted row or variable is cached and handled in ExtractModel.

Implements operations_research::MPSolverInterface.

Definition at line 404 of file scip_interface.cc.

◆ SetConstraintBounds()

void operations_research::SCIPInterface::SetConstraintBounds ( int index,
double lb,
double ub )
overridevirtual

Modify bounds of an extracted variable.

Not cached if the row has been extracted.

Implements operations_research::MPSolverInterface.

Definition at line 388 of file scip_interface.cc.

◆ SetObjectiveCoefficient()

void operations_research::SCIPInterface::SetObjectiveCoefficient ( const MPVariable * variable,
double coefficient )
overridevirtual

Cached.

Implements operations_research::MPSolverInterface.

Definition at line 448 of file scip_interface.cc.

◆ SetObjectiveOffset()

void operations_research::SCIPInterface::SetObjectiveOffset ( double value)
overridevirtual

Cached.

Implements operations_research::MPSolverInterface.

Definition at line 454 of file scip_interface.cc.

◆ SetOptimizationDirection()

void operations_research::SCIPInterface::SetOptimizationDirection ( bool maximize)
overridevirtual

Not cached.

Implements operations_research::MPSolverInterface.

Definition at line 343 of file scip_interface.cc.

◆ SetVariableBounds()

void operations_research::SCIPInterface::SetVariableBounds ( int index,
double lb,
double ub )
overridevirtual

Modifies bounds of an extracted variable.

Not cached if the variable has been extracted.

Implements operations_research::MPSolverInterface.

Definition at line 351 of file scip_interface.cc.

◆ SetVariableInteger()

void operations_research::SCIPInterface::SetVariableInteger ( int index,
bool integer )
overridevirtual

Modifies integrality of an extracted variable.

Not cached if the variable has been extracted.

Implements operations_research::MPSolverInterface.

Definition at line 367 of file scip_interface.cc.

◆ Solve()

MPSolver::ResultStatus operations_research::SCIPInterface::Solve ( const MPSolverParameters & param)
overridevirtual

--— Solve --— Solves problem with specified parameter values. Returns true if the solution is optimal.

"status_" may encode a variety of failure scenarios, many of which would correspond to another MPResultStatus than ABNORMAL, but since SCIP is a moving target, we use the most likely error code here (abnormalities, often numeric), and rely on the user enabling output to see more details.

Note
SCIP does not provide any incrementality.
Todo
(user): Is that still true now (2018) ?

Set log level.

Special case if the model is empty since SCIP expects a non-empty model.

When the value of callback_ is changed, callback_reset_ is set and code above you call Reset() that should have cleared scip_constraint_handler_. Here we assert that if this has not happened then callback_ value has not changed.

Time limit.

We first set our internal MPSolverParameters from param and then set any user specified internal solver, ie. SCIP, parameters via solver_specific_parameter_string_. Default MPSolverParameters can override custom parameters (for example for presolving) and therefore we apply MPSolverParameters first.

Use the solution hint if any.

We start by creating an empty partial solution.

We start by creating the all-zero solution.

Fill the other variables from the given solution hint.

Todo
(user): I more or less copied this from the SCIPreadSol() code that reads a solution from a file. I am not sure what SCIPisTransformed() is or what is the difference between the try and add version. In any case this seems to always call SCIPaddSolFree() for now and it works.

Solve.

Get the results.

If optimal or feasible solution is found.

Check the status: optimal, infeasible, etc.

To be consistent with the other solvers.

Todo
(user): We could introduce our own "infeasible or unbounded" status.

Implements operations_research::MPSolverInterface.

Definition at line 684 of file scip_interface.cc.

◆ SolverVersion()

std::string operations_research::SCIPInterface::SolverVersion ( ) const
inlineoverridevirtual

Returns a string describing the underlying solver and its version.

Implements operations_research::MPSolverInterface.

Definition at line 118 of file scip_interface.cc.

◆ SupportsCallbacks()

bool operations_research::SCIPInterface::SupportsCallbacks ( ) const
inlineoverridevirtual

Reimplemented from operations_research::MPSolverInterface.

Definition at line 160 of file scip_interface.cc.

◆ SupportsDirectlySolveProto()

bool operations_research::SCIPInterface::SupportsDirectlySolveProto ( std::atomic< bool > * ) const
overridevirtual

DirectlySolveProto() shall only be used if SupportsDirectlySolveProto() is true.

DirectlySolveProto() solves a MPModelRequest, bypassing the MPSolver data structures entirely. Like MPSolver::SolveWithProto(), optionally takes in an 'interrupt' boolean.

ScipSolveProto doesn't solve concurrently.

Interruption via atomic<bool> is not directly supported by SCIP.

Reimplemented from operations_research::MPSolverInterface.

Definition at line 873 of file scip_interface.cc.

◆ underlying_solver()

void * operations_research::SCIPInterface::underlying_solver ( )
inlineoverridevirtual

Returns the underlying solver.

Implements operations_research::MPSolverInterface.

Definition at line 134 of file scip_interface.cc.


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