Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::math_opt::SolverInterface Class Referenceabstract

#include <solver_interface.h>

Inheritance diagram for operations_research::math_opt::SolverInterface:
operations_research::math_opt::CpSatSolver operations_research::math_opt::GScipSolver operations_research::math_opt::GlopSolver operations_research::math_opt::GlpkSolver operations_research::math_opt::GurobiSolver operations_research::math_opt::HighsSolver operations_research::math_opt::PdlpSolver

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
 
SolverInterfaceoperator= (const SolverInterface &)=delete
 
virtual ~SolverInterface ()=default
 
virtual absl::StatusOr< SolveResultProto > Solve (const SolveParametersProto &parameters, 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 &parameters, MessageCallback message_cb, const SolveInterrupter *interrupter)=0
 

Detailed Description

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.

Member Typedef Documentation

◆ Callback

Initial value:
std::function<absl::StatusOr<CallbackResultProto>(
const CallbackDataProto&)>

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.

◆ Factory

Initial value:
std::function<absl::StatusOr<std::unique_ptr<SolverInterface>>(
const ModelProto& model, const InitArgs& init_args)>
GRBmodel * model

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.

◆ MessageCallback

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.

Constructor & Destructor Documentation

◆ SolverInterface() [1/2]

operations_research::math_opt::SolverInterface::SolverInterface ( )
default

◆ SolverInterface() [2/2]

operations_research::math_opt::SolverInterface::SolverInterface ( const SolverInterface & )
delete

◆ ~SolverInterface()

virtual operations_research::math_opt::SolverInterface::~SolverInterface ( )
virtualdefault

Member Function Documentation

◆ ComputeInfeasibleSubsystem()

virtual absl::StatusOr< ComputeInfeasibleSubsystemResultProto > operations_research::math_opt::SolverInterface::ComputeInfeasibleSubsystem ( const SolveParametersProto & parameters,
MessageCallback message_cb,
const SolveInterrupter * interrupter )
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.

◆ operator=()

SolverInterface & operations_research::math_opt::SolverInterface::operator= ( const SolverInterface & )
delete

◆ Solve()

virtual absl::StatusOr< SolveResultProto > operations_research::math_opt::SolverInterface::Solve ( const SolveParametersProto & parameters,
const ModelSolveParametersProto & model_parameters,
MessageCallback message_cb,
const CallbackRegistrationProto & callback_registration,
Callback cb,
const SolveInterrupter * interrupter )
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.

◆ Update()

virtual absl::StatusOr< bool > operations_research::math_opt::SolverInterface::Update ( const ModelUpdateProto & model_update)
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.


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