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

Public Member Functions

 GLPKInterface (MPSolver *solver, bool mip)
 Constructor that takes a name for the underlying glpk solver.
 
 ~GLPKInterface () override
 Frees the LP memory allocations.
 
void SetOptimizationDirection (bool maximize) override
 Sets the optimization direction (min/max).
 
MPSolver::ResultStatus Solve (const MPSolverParameters &param) override
 Solve the problem using the parameter values specified.
 
void Reset () override
 
void SetVariableBounds (int mpsolver_var_index, double lb, double ub) override
 Modify bounds.
 
void SetVariableInteger (int mpsolver_var_index, bool integer) override
 Modifies integrality of an extracted variable.
 
void SetConstraintBounds (int mpsolver_constraint_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 *constraint, const MPVariable *variable, double new_value, double old_value) override
 Change a coefficient in a constraint.
 
void ClearConstraint (MPConstraint *constraint) override
 Clear a constraint from all its terms.
 
void SetObjectiveCoefficient (const MPVariable *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
 ---— Query statistics on the solution and the solve ---—
 
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.
 
bool CheckSolutionExists () const override
 Checks whether a feasible solution exists.
 
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
 Define new variables and add them to existing constraints.
 
void ExtractNewConstraints () override
 Define new constraints on old and new variables.
 
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
 Returns the underlying solver.
 
double ComputeExactConditionNumber () const 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
 
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 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 absl::Status SetNumThreads (int num_threads)
 Sets the number of threads to be used by the solver.
 
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 94 of file glpk_interface.cc.

Constructor & Destructor Documentation

◆ GLPKInterface()

operations_research::GLPKInterface::GLPKInterface ( MPSolver * solver,
bool mip )

Constructor that takes a name for the underlying glpk solver.

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

Make sure glp_free_env() is called at the exit of the current thread.

Definition at line 211 of file glpk_interface.cc.

◆ ~GLPKInterface()

operations_research::GLPKInterface::~GLPKInterface ( )
override

Frees the LP memory allocations.

Definition at line 223 of file glpk_interface.cc.

Member Function Documentation

◆ AddRowConstraint()

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

Add Constraint incrementally.

Implements operations_research::MPSolverInterface.

Definition at line 371 of file glpk_interface.cc.

◆ AddVariable()

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

Add variable incrementally.

Implements operations_research::MPSolverInterface.

Definition at line 375 of file glpk_interface.cc.

◆ CheckSolutionExists()

bool operations_research::GLPKInterface::CheckSolutionExists ( ) const
overridevirtual

Checks whether a feasible solution exists.

Call default implementation

Reimplemented from operations_research::MPSolverInterface.

Definition at line 714 of file glpk_interface.cc.

◆ ClearConstraint()

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

Clear a constraint from all its terms.

Not cached.

Constraint may have not been extracted yet.

Implements operations_research::MPSolverInterface.

Definition at line 335 of file glpk_interface.cc.

◆ ClearObjective()

void operations_research::GLPKInterface::ClearObjective ( )
overridevirtual

Clear the objective from all its terms.

Clear objective of all its terms (linear)

Variable may have not been extracted yet.

Constant term.

Implements operations_research::MPSolverInterface.

Definition at line 356 of file glpk_interface.cc.

◆ column_status()

MPSolver::BasisStatus operations_research::GLPKInterface::column_status ( int variable_index) const
overridevirtual

Returns the basis status of a column.

Implements operations_research::MPSolverInterface.

Definition at line 706 of file glpk_interface.cc.

◆ ComputeExactConditionNumber()

double operations_research::GLPKInterface::ComputeExactConditionNumber ( ) const
overridevirtual

Computes exact condition number. Only available for continuous problems and only implemented in GLPK.

Todo
(user): support MIP.

Simplex is the only LP algorithm supported in the wrapper for GLPK, so when a solution exists, a basis exists.

GLPK indexes everything starting from 1 instead of 0.

Override this method in interfaces that actually support it.

Reimplemented from operations_research::MPSolverInterface.

Definition at line 725 of file glpk_interface.cc.

◆ ExtractNewConstraints()

void operations_research::GLPKInterface::ExtractNewConstraints ( )
overridevirtual

Define new constraints on old and new variables.

Define new constraints

All constraints are set to be of the type <= limit_ .

Fill new constraints with coefficients

Faster extraction when nothing has been extracted yet: build and load whole matrix at once instead of constructing rows separately.

The first entry in the following arrays is dummy, to be consistent with glpk API.

Build each new row separately.

The first entry in the following arrays is dummy, to be consistent with glpk API.

Implements operations_research::MPSolverInterface.

Definition at line 444 of file glpk_interface.cc.

◆ ExtractNewVariables()

void operations_research::GLPKInterface::ExtractNewVariables ( )
overridevirtual

Define new variables and add them to existing constraints.

The true objective coefficient will be set later in ExtractObjective.

Add new variables to the existing constraints.

Implements operations_research::MPSolverInterface.

Definition at line 380 of file glpk_interface.cc.

◆ ExtractObjective()

void operations_research::GLPKInterface::ExtractObjective ( )
overridevirtual

Extracts the objective.

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

Constant term.

Implements operations_research::MPSolverInterface.

Definition at line 505 of file glpk_interface.cc.

◆ IsContinuous()

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

--— Misc --— Query problem type.

Implements operations_research::MPSolverInterface.

Definition at line 150 of file glpk_interface.cc.

◆ IsLP()

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

Returns true if the problem is continuous and linear.

Implements operations_research::MPSolverInterface.

Definition at line 151 of file glpk_interface.cc.

◆ IsMIP()

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

Returns true if the problem is discrete and linear.

Implements operations_research::MPSolverInterface.

Definition at line 152 of file glpk_interface.cc.

◆ iterations()

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

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

---— Query statistics on the solution and the solve ---— Number of simplex iterations

Implements operations_research::MPSolverInterface.

Definition at line 673 of file glpk_interface.cc.

◆ nodes()

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

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

Implements operations_research::MPSolverInterface.

Definition at line 688 of file glpk_interface.cc.

◆ Reset()

void operations_research::GLPKInterface::Reset ( )
overridevirtual

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

Implements operations_research::MPSolverInterface.

Definition at line 229 of file glpk_interface.cc.

◆ row_status()

MPSolver::BasisStatus operations_research::GLPKInterface::row_status ( int constraint_index) const
overridevirtual

Returns the basis status of a row.

Implements operations_research::MPSolverInterface.

Definition at line 698 of file glpk_interface.cc.

◆ SetCoefficient()

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

Change a coefficient in a constraint.

GLPK does not allow to modify one coefficient at a time, so we extract the whole constraint again, if it has been extracted already and if it does not contain new variables. Otherwise, we cache the modification.

Implements operations_research::MPSolverInterface.

Definition at line 316 of file glpk_interface.cc.

◆ SetConstraintBounds()

void operations_research::GLPKInterface::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 287 of file glpk_interface.cc.

◆ SetObjectiveCoefficient()

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

Change a coefficient in the linear objective.

Cached.

Implements operations_research::MPSolverInterface.

Definition at line 345 of file glpk_interface.cc.

◆ SetObjectiveOffset()

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

Change the constant term in the linear objective.

Cached.

Implements operations_research::MPSolverInterface.

Definition at line 351 of file glpk_interface.cc.

◆ SetOptimizationDirection()

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

Sets the optimization direction (min/max).

---— Model modifications and extraction --—

Not cached

Implements operations_research::MPSolverInterface.

Definition at line 241 of file glpk_interface.cc.

◆ SetVariableBounds()

void operations_research::GLPKInterface::SetVariableBounds ( int mpsolver_var_index,
double lb,
double ub )
overridevirtual

Modify bounds.

Not cached if the variable has been extracted.

Implements operations_research::MPSolverInterface.

Definition at line 246 of file glpk_interface.cc.

◆ SetVariableInteger()

void operations_research::GLPKInterface::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 274 of file glpk_interface.cc.

◆ Solve()

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

Solve the problem using the parameter values specified.

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

Note
GLPK provides incrementality for LP but not for MIP.

Set log level.

Configure parameters at every solve, even when the model has not been changed, in case some of the parameters such as the time limit have been changed since the last solve.

Solve

glp_intopt requires to solve the root LP separately. If the root LP was solved successfully, solve the MIP.

Something abnormal occurred during the root LP solve. It is highly unlikely that an integer feasible solution is available at this point, so we don't put any effort in trying to recover it.

Get the results.

Check the status: optimal, infeasible, etc.

For infeasible problems, GLPK actually seems to return GLP_UNDEF. So this is never (?) reached. Return infeasible in case GLPK returns a correct status in future versions.

GLPK does not have a status code for unbounded MIP models, so we return an abnormal status instead.

For infeasible problems, GLPK actually seems to return GLP_UNDEF. So this is never (?) reached. Return infeasible in case GLPK returns a correct status in future versions.

For unbounded problems, GLPK actually seems to return GLP_UNDEF. So this is never (?) reached. Return unbounded in case GLPK returns a correct status in future versions.

Implements operations_research::MPSolverInterface.

Definition at line 517 of file glpk_interface.cc.

◆ SolverVersion()

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

Returns a string describing the underlying solver and its version.

Implements operations_research::MPSolverInterface.

Definition at line 158 of file glpk_interface.cc.

◆ underlying_solver()

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

Returns the underlying solver.

Implements operations_research::MPSolverInterface.

Definition at line 162 of file glpk_interface.cc.


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