Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <solver_interface.h>
Classes | |
struct | InitArgs |
Initialization arguments. More... | |
Public Types | |
using | MessageCallback = std::function<void(const std::vector<std::string>&)> |
using | Callback |
using | Factory |
Public Member Functions | |
SolverInterface ()=default | |
SolverInterface (const SolverInterface &)=delete | |
SolverInterface & | operator= (const SolverInterface &)=delete |
virtual | ~SolverInterface ()=default |
virtual absl::StatusOr< SolveResultProto > | Solve (const SolveParametersProto ¶meters, const ModelSolveParametersProto &model_parameters, MessageCallback message_cb, const CallbackRegistrationProto &callback_registration, Callback cb, const SolveInterrupter *interrupter)=0 |
virtual absl::StatusOr< bool > | Update (const ModelUpdateProto &model_update)=0 |
virtual absl::StatusOr< ComputeInfeasibleSubsystemResultProto > | ComputeInfeasibleSubsystem (const SolveParametersProto ¶meters, MessageCallback message_cb, const SolveInterrupter *interrupter)=0 |
Interface implemented by actual solvers.
This interface is not meant to be used directly. The actual API is the one of the Solver class. The Solver class validates the models before calling this interface. It makes sure no concurrent calls happen on Solve(), CanUpdate() and Update(). It makes sure no other function is called after Solve(), Update() or a callback have failed.
Implementations of this interface should not have public constructors but instead have a static New
function with the signature of Factory function as defined below. They should register this factory using the macro MATH_OPT_REGISTER_SOLVER().
Definition at line 52 of file solver_interface.h.
A callback function (if non null) is a function that validates its input and its output, and if fails, return a status. The invariant is that the solver implementation can rely on receiving valid data. The implementation of this interface must provide valid input (which will be validated) and in error, it will return a status (without actually calling the callback function). This is enforced in the solver.cc layer.
Definition at line 76 of file solver_interface.h.
A factory builds a solver based on the input model and parameters.
Implementation should have a static New()
function with this signature and no public constructors.
The implementation should assume the input ModelProto is valid and is free to CHECK-fail if this is not the case. It should also assume that the input init_args.streamable and init_args.non_streamable are also either not set of set to the arguments of the correct solver.
Definition at line 88 of file solver_interface.h.
using operations_research::math_opt::SolverInterface::MessageCallback = std::function<void(const std::vector<std::string>&)> |
A callback function (if non null) for messages emitted by the solver.
See Solver::MessageCallback documentation for details.
Definition at line 68 of file solver_interface.h.
|
default |
|
delete |
|
virtualdefault |
|
pure virtual |
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.
Implemented in operations_research::math_opt::CpSatSolver, operations_research::math_opt::GlopSolver, operations_research::math_opt::GlpkSolver, operations_research::math_opt::GScipSolver, operations_research::math_opt::GurobiSolver, operations_research::math_opt::HighsSolver, and operations_research::math_opt::PdlpSolver.
|
delete |
|
pure virtual |
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.
Implemented in operations_research::math_opt::CpSatSolver, operations_research::math_opt::GlopSolver, operations_research::math_opt::GlpkSolver, operations_research::math_opt::GScipSolver, operations_research::math_opt::GurobiSolver, operations_research::math_opt::HighsSolver, and operations_research::math_opt::PdlpSolver.
|
pure virtual |
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.
Implemented in operations_research::math_opt::CpSatSolver, operations_research::math_opt::GlopSolver, operations_research::math_opt::GlpkSolver, operations_research::math_opt::GScipSolver, operations_research::math_opt::GurobiSolver, operations_research::math_opt::HighsSolver, and operations_research::math_opt::PdlpSolver.