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

Public Member Functions

 CBCInterface (MPSolver *solver)
 Constructor that takes a name for the underlying glpk solver.
 
 ~CBCInterface () override
 
void Reset () override
 --— Reset --—
 
void SetOptimizationDirection (bool maximize) override
 Sets the optimization direction (min/max).
 
absl::Status SetNumThreads (int num_threads) override
 --— Parameters --—
 
MPSolver::ResultStatus Solve (const MPSolverParameters &param) override
 
virtual void ExtractModel ()
 
bool IsContinuous () const override
 Query problem type.
 
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 SetVariableBounds (int var_index, double lb, double ub) override
 Modify bounds.
 
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
 Add constraint incrementally.
 
void AddVariable (MPVariable *var) override
 Add variable incrementally.
 
void SetCoefficient (MPConstraint *const constraint, const MPVariable *const variable, double new_value, double old_value) override
 Change a coefficient in a constraint.
 
void ClearConstraint (MPConstraint *const constraint) override
 Clear a constraint from all its terms.
 
void SetObjectiveCoefficient (const MPVariable *const variable, double coefficient) override
 Change a coefficient in the linear objective.
 
void SetObjectiveOffset (double value) override
 Change the constant term in the linear objective.
 
void ClearObjective () override
 Clear the objective from all its terms.
 
int64_t iterations () const override
 Number of simplex iterations.
 
int64_t nodes () const override
 Number of branch-and-bound nodes. Only available for discrete problems.
 
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 column.
 
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.
 
void * underlying_solver () override
 
- Public Member Functions inherited from operations_research::MPSolverInterface
 MPSolverInterface (MPSolver *solver)
 
virtual ~MPSolverInterface ()
 
virtual bool SupportsDirectlySolveProto (std::atomic< bool > *) const
 
virtual MPSolutionResponse DirectlySolveProto (LazyMutableCopy< MPModelRequest >, std::atomic< bool > *)
 
virtual void Write (const std::string &filename)
 
virtual bool AddIndicatorConstraint (MPConstraint *const)
 
virtual void BranchingPriorityChangedForVariable (int)
 
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().
 
virtual double infinity ()
 
virtual bool InterruptSolve ()
 
virtual bool NextSolution ()
 See MPSolver::NextSolution() for contract.
 
virtual void SetCallback (MPCallback *)
 See MPSolver::SetCallback() for details.
 
virtual bool SupportsCallbacks () const
 

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.
 
virtual void SetUnsupportedIntegerParam (MPSolverParameters::IntegerParam param)
 Sets an unsupported integer parameter.
 
void SetDoubleParamToUnsupportedValue (MPSolverParameters::DoubleParam param, double value)
 Sets a supported double parameter to an unsupported value.
 
virtual void SetIntegerParamToUnsupportedValue (MPSolverParameters::IntegerParam param, int value)
 Sets a supported integer parameter to an unsupported value.
 
virtual bool SetSolverSpecificParametersAsString (const std::string &parameters)
 
- 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 45 of file cbc_interface.cc.

Constructor & Destructor Documentation

◆ CBCInterface()

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

Constructor that takes a name for the underlying glpk solver.

--— Solver --—

Creates a LP/MIP instance with the specified name and minimization objective.

Definition at line 161 of file cbc_interface.cc.

◆ ~CBCInterface()

operations_research::CBCInterface::~CBCInterface ( )
override

Definition at line 170 of file cbc_interface.cc.

Member Function Documentation

◆ AddRowConstraint()

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

Add constraint incrementally.

Implements operations_research::MPSolverInterface.

Definition at line 234 of file cbc_interface.cc.

◆ AddVariable()

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

Add variable incrementally.

Implements operations_research::MPSolverInterface.

Definition at line 238 of file cbc_interface.cc.

◆ ClearConstraint()

void operations_research::CBCInterface::ClearConstraint ( MPConstraint *const constraint)
inlineoverridevirtual

Clear a constraint from all its terms.

Implements operations_research::MPSolverInterface.

Definition at line 93 of file cbc_interface.cc.

◆ ClearObjective()

void operations_research::CBCInterface::ClearObjective ( )
inlineoverridevirtual

Clear the objective from all its terms.

Implements operations_research::MPSolverInterface.

Definition at line 105 of file cbc_interface.cc.

◆ column_status()

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

Returns the basis status of a column.

Implements operations_research::MPSolverInterface.

Definition at line 118 of file cbc_interface.cc.

◆ ExtractModel()

virtual void operations_research::CBCInterface::ExtractModel ( )
inlinevirtual
Todo
(user): separate the solve from the model extraction.

Definition at line 70 of file cbc_interface.cc.

◆ ExtractNewConstraints()

void operations_research::CBCInterface::ExtractNewConstraints ( )
inlineoverridevirtual

Extracts the constraints that have not been extracted yet.

Implements operations_research::MPSolverInterface.

Definition at line 124 of file cbc_interface.cc.

◆ ExtractNewVariables()

void operations_research::CBCInterface::ExtractNewVariables ( )
inlineoverridevirtual

Extracts the variables that have not been extracted yet.

Implements operations_research::MPSolverInterface.

Definition at line 123 of file cbc_interface.cc.

◆ ExtractObjective()

void operations_research::CBCInterface::ExtractObjective ( )
inlineoverridevirtual

Extracts the objective.

Implements operations_research::MPSolverInterface.

Definition at line 125 of file cbc_interface.cc.

◆ IsContinuous()

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

Query problem type.

Implements operations_research::MPSolverInterface.

Definition at line 73 of file cbc_interface.cc.

◆ IsLP()

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

Returns true if the problem is continuous and linear.

Implements operations_research::MPSolverInterface.

Definition at line 74 of file cbc_interface.cc.

◆ IsMIP()

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

Returns true if the problem is discrete and linear.

Implements operations_research::MPSolverInterface.

Definition at line 75 of file cbc_interface.cc.

◆ iterations()

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

Number of simplex iterations.

---— Query statistics on the solution and the solve ---—

Implements operations_research::MPSolverInterface.

Definition at line 470 of file cbc_interface.cc.

◆ nodes()

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

Number of branch-and-bound nodes. Only available for discrete problems.

Implements operations_research::MPSolverInterface.

Definition at line 475 of file cbc_interface.cc.

◆ Reset()

void operations_research::CBCInterface::Reset ( )
overridevirtual

--— Reset --—

Reset the solver.

Implements operations_research::MPSolverInterface.

Definition at line 173 of file cbc_interface.cc.

◆ row_status()

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

Returns the basis status of a row.

Implements operations_research::MPSolverInterface.

Definition at line 113 of file cbc_interface.cc.

◆ SetCoefficient()

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

Change a coefficient in a constraint.

Implements operations_research::MPSolverInterface.

Definition at line 87 of file cbc_interface.cc.

◆ SetConstraintBounds()

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

Modify bounds of an extracted variable.

Implements operations_research::MPSolverInterface.

Definition at line 225 of file cbc_interface.cc.

◆ SetNumThreads()

absl::Status operations_research::CBCInterface::SetNumThreads ( int num_threads)
inlineoverridevirtual

--— Parameters --—

Reimplemented from operations_research::MPSolverInterface.

Definition at line 59 of file cbc_interface.cc.

◆ SetObjectiveCoefficient()

void operations_research::CBCInterface::SetObjectiveCoefficient ( const MPVariable *const variable,
double coefficient )
inlineoverridevirtual

Change a coefficient in the linear objective.

Implements operations_research::MPSolverInterface.

Definition at line 98 of file cbc_interface.cc.

◆ SetObjectiveOffset()

void operations_research::CBCInterface::SetObjectiveOffset ( double value)
inlineoverridevirtual

Change the constant term in the linear objective.

Implements operations_research::MPSolverInterface.

Definition at line 103 of file cbc_interface.cc.

◆ SetOptimizationDirection()

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

Sets the optimization direction (min/max).

Implements operations_research::MPSolverInterface.

Definition at line 188 of file cbc_interface.cc.

◆ SetVariableBounds()

void operations_research::CBCInterface::SetVariableBounds ( int var_index,
double lb,
double ub )
overridevirtual

Modify bounds.

Implements operations_research::MPSolverInterface.

Definition at line 202 of file cbc_interface.cc.

◆ SetVariableInteger()

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

Modifies integrality of an extracted variable.

Todo
(user) : Check if this is actually a change.

Implements operations_research::MPSolverInterface.

Definition at line 211 of file cbc_interface.cc.

◆ Solve()

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

--— Solve --— Solve the problem using the parameter values specified.

Solve the LP/MIP. Returns true only if the optimal solution was revealed. Returns the status of the search.

CBC requires unique variable and constraint names. By using Lookup*, we generate variable and constraint indices and ensure the duplicate name crash will happen here with a readable error message.

Note
CBC does not provide any incrementality.

Special case if the model is empty since CBC is not able to handle this special case by itself.

Finish preparing the problem. Define variables.

Create dummy variable for objective offset.

Define constraints.

Changing optimization direction through OSI so that the model file (written through OSI) has the correct optimization duration.

Solve

Set log level.

Time limit.

And solve.

Here we use the default function from the command-line CBC solver. This enables to activate all the features and get the same performance as the CBC stand-alone executable. The syntax is ugly, however.

Always turn presolve on (it's the CBC default and it consistently improves performance).

Special way to set the relative MIP gap parameter as it cannot be set through callCbc.

Note
Trailing space is required to avoid buffer overflow in cbc.

to the CBC source

Check the status: optimal, infeasible, etc.

Order of tests counts; if model.isContinuousUnbounded() returns true, then so does model.isProvenInfeasible()!

Get the results

if optimal or feasible solution is found.

Implements operations_research::MPSolverInterface.

Definition at line 244 of file cbc_interface.cc.

◆ SolverVersion()

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

Returns a string describing the underlying solver and its version.

Implements operations_research::MPSolverInterface.

Definition at line 127 of file cbc_interface.cc.

◆ underlying_solver()

void * operations_research::CBCInterface::underlying_solver ( )
inlineoverridevirtual
Todo
(user): Maybe we should expose the CbcModel build from osi_ instead, but a new CbcModel is built every time Solve is called, so it is not possible right now.

Implements operations_research::MPSolverInterface.

Definition at line 132 of file cbc_interface.cc.


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