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

#include <glpk_solver.h>

Inheritance diagram for operations_research::math_opt::GlpkSolver:
operations_research::math_opt::SolverInterface

Public Member Functions

 ~GlpkSolver () override
 
absl::StatusOr< SolveResultProto > Solve (const SolveParametersProto &parameters, const ModelSolveParametersProto &model_parameters, MessageCallback message_cb, const CallbackRegistrationProto &callback_registration, Callback cb, SolveInterrupter *interrupter) override
 
absl::StatusOr< bool > Update (const ModelUpdateProto &model_update) override
 
absl::StatusOr< ComputeInfeasibleSubsystemResultProto > ComputeInfeasibleSubsystem (const SolveParametersProto &parameters, MessageCallback message_cb, SolveInterrupter *interrupter) override
 
- Public Member Functions inherited from operations_research::math_opt::SolverInterface
 SolverInterface ()=default
 
 SolverInterface (const SolverInterface &)=delete
 
SolverInterfaceoperator= (const SolverInterface &)=delete
 
virtual ~SolverInterface ()=default
 

Static Public Member Functions

static absl::StatusOr< std::unique_ptr< SolverInterface > > New (const ModelProto &model, const InitArgs &init_args)
 

Additional Inherited Members

- Public Types inherited from operations_research::math_opt::SolverInterface
using MessageCallback = std::function<void(const std::vector<std::string>&)>
 
using Callback
 
using Factory
 

Detailed Description

Definition at line 46 of file glpk_solver.h.

Constructor & Destructor Documentation

◆ ~GlpkSolver()

operations_research::math_opt::GlpkSolver::~GlpkSolver ( )
override

Here we simply log an error but glp_delete_prob() should crash with an error like: glp_free: memory allocation error.

Definition at line 925 of file glpk_solver.cc.

Member Function Documentation

◆ ComputeInfeasibleSubsystem()

absl::StatusOr< ComputeInfeasibleSubsystemResultProto > operations_research::math_opt::GlpkSolver::ComputeInfeasibleSubsystem ( const SolveParametersProto & parameters,
MessageCallback message_cb,
SolveInterrupter * interrupter )
overridevirtual

Computes a infeasible subsystem of the model (including all updates).

All input arguments are ensured (by solver.cc) to be valid. Furthermore, since all parameters are references or functions (which could be a lambda expression), the implementation should not keep a reference or copy of them, as they may become invalid reference after the invocation if this function.

The parameters message_cb and interrupter are optional. They are nullptr when not set.

When parameter message_cb is not null the value of parameters.enable_output should be ignored the solver should behave as it is was false (i.e. not print anything).

When parameter message_cb is not null and the underlying solver does not supports message callbacks, it should ignore it.

Implements operations_research::math_opt::SolverInterface.

Definition at line 1807 of file glpk_solver.cc.

◆ New()

absl::StatusOr< std::unique_ptr< SolverInterface > > operations_research::math_opt::GlpkSolver::New ( const ModelProto & model,
const InitArgs & init_args )
static

Definition at line 889 of file glpk_solver.cc.

◆ Solve()

absl::StatusOr< SolveResultProto > operations_research::math_opt::GlpkSolver::Solve ( const SolveParametersProto & parameters,
const ModelSolveParametersProto & model_parameters,
MessageCallback message_cb,
const CallbackRegistrationProto & callback_registration,
Callback cb,
SolveInterrupter * interrupter )
overridevirtual

Solves the current model (included all updates).

All input arguments are ensured (by solver.cc) to be valid. Furthermore, since all parameters are references or functions (which could be a lambda expression), the implementation should not keep a reference or copy of them, as they may become invalid reference after the invocation if this function.

Parameters message_cb, cb and interrupter are optional. They are nullptr when not set.

When parameter message_cb is not null the value of parameters.enable_output should be ignored the solver should behave as it is was false (i.e. not print anything).

When parameter message_cb is not null and the underlying solver does not supports message callbacks, it should ignore it.

Solvers should return a InvalidArgumentError when called with events on callback_registration that are not supported by the solver for the type of model being solved (for example MIP events if the model is an LP, or events that are not emitted by the solver). Solvers should use CheckRegisteredCallbackEvents() to implement that.

Deal with empty integer bounds that result in inverted bounds due to bounds rounding.

Note
glp_term_hook() uses get_env_ptr() that relies on thread local storage to have a different environment per thread. Thus using glp_term_hook() is thread-safe.

We must reset the term hook when before exiting or before flushing the last unfinished line.

We need to use different functions depending on the solve function we used (or placeholders if no solve function was called in case of empty models).

Here we use different solve algorithms depending on the type of problem:

  • For MIPs: glp_intopt()
  • For LPs:

These solve algorithms have dedicated data segments in glp_prob which use different access functions to get the solution; hence each branch will set the corresponding function pointers accordingly. They also use a custom struct for parameters that will be initialized and passed to the algorithm.

Todo
(b/187027049): glp_intopt with presolve off requires an optional solution of the relaxed problem. Here we simply always enable pre-solve but we should support disabling the presolve and call glp_simplex() in that case.

glp_interior() does not support being called with an empty model and returns GLP_EFAIL. Thus we use placeholders in that case.

Todo
(b/259557110): the emptiness is tested by glp_interior() after some pre-processing (including removing fixed variables). The current IsEmpty() is thus not good enough to deal with all cases.
Todo
(b/187027049): add solver specific parameters for glp_iptcp.ord_alg.
Todo
(b/187027049): add option to use glp_exact().

If the primal is proven infeasible and the dual is feasible, the dual is unbounded. Thus we can compute a better dual bound rather than the default value.

Unregister the callback and flush the potential last unfinished line.

Here we can't use obj_val(problem_) as it would be a finite value of the feasible solution found.

Todo
(b/187027049): compute the dual value when the dual is feasible (or problem optimal for interior point) based on the bounds and the dual values for LPs.

Implements operations_research::math_opt::SolverInterface.

Definition at line 1057 of file glpk_solver.cc.

◆ Update()

absl::StatusOr< bool > operations_research::math_opt::GlpkSolver::Update ( const ModelUpdateProto & model_update)
overridevirtual

Updates the model to solve and returns true, or returns false if this update is not supported.

The implementation should assume the input ModelUpdate is valid and is free to assert if this is not the case.

We must do that after testing current thread since the Solver class won't destroy this instance from another thread when the update is not supported (the Solver class destroy the SolverInterface only when an Update() returns false).

See comment in AddVariables() to see why we don't use GLP_BV here.

Either restore the fractional bounds if the variable was integer and is now integer, or rounds the existing bounds if the variable was fractional and is now integer. Here we use the old bounds; they will get updated below by the call to UpdateBounds() if they are also changed by this update.

Glpk uses index 0 for the "shift" of the objective.

Implements operations_research::math_opt::SolverInterface.

Definition at line 1683 of file glpk_solver.cc.


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