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

#include <solver.h>

Inheritance diagram for operations_research::math_opt::Solver:
operations_research::math_opt::BaseSolver

Public Types

using InitArgs = SolverInterface::InitArgs
 
- Public Types inherited from operations_research::math_opt::BaseSolver
using MessageCallback = std::function<void(const std::vector<std::string>&)>
 
using Callback = std::function<CallbackResultProto(const CallbackDataProto&)>
 Callback function type for MIP/LP callbacks.
 

Public Member Functions

 ~Solver () override
 
absl::StatusOr< SolveResultProto > Solve (const SolveArgs &arguments) override
 Solves the current model (including all updates).
 
absl::StatusOr< bool > Update (ModelUpdateProto model_update) override
 
absl::StatusOr< ComputeInfeasibleSubsystemResultProto > ComputeInfeasibleSubsystem (const ComputeInfeasibleSubsystemArgs &arguments) override
 Computes an infeasible subsystem of model (including all updates).
 
- Public Member Functions inherited from operations_research::math_opt::BaseSolver
 BaseSolver ()=default
 
 BaseSolver (const BaseSolver &)=delete
 
BaseSolveroperator= (const BaseSolver &)=delete
 
virtual ~BaseSolver ()=default
 

Static Public Member Functions

static absl::StatusOr< SolveResultProto > NonIncrementalSolve (const ModelProto &model, SolverTypeProto solver_type, const InitArgs &init_args, const SolveArgs &solve_args)
 A shortcut for calling Solver::New() and then Solver::Solve().
 
static absl::StatusOr< ComputeInfeasibleSubsystemResultProto > NonIncrementalComputeInfeasibleSubsystem (const ModelProto &model, SolverTypeProto solver_type, const InitArgs &init_args, const ComputeInfeasibleSubsystemArgs &compute_infeasible_subsystem_args)
 
static absl::StatusOr< std::unique_ptr< Solver > > New (SolverTypeProto solver_type, const ModelProto &model, const InitArgs &arguments)
 

Detailed Description

A solver for a given model and solver implementation.

Use the New() function to build a new solver instance; then call Solve() to solve the model. You can then update the model using Update() and resolve.

Thread-safety: methods Solve() and Update() must not be called concurrently; they will immediately return with an error status if this happens. Some solvers may add more restriction regarding threading. Please see SOLVER_TYPE_XXX documentation for details.

Usage: const ModelProto model = ...; const auto solver = Solver::New(SOLVER_TYPE_GSCIP, model, /*arguments=*‍/{}); CHECK_OK(solver.status()); Solver::SolveArgs solve_arguments; ...

///< First solve of the initial Model. const auto first_solution = (*solver)->Solve(solve_arguments); CHECK_OK(first_solution.status()); ///< Use the first_solution here.

///< Update the Model with a ModelUpdate. const ModelUpdate update = ...; CHECK_OK((*solver)->Update(update)); const auto second_solution = (*solver)->Solve(solve_arguments); CHECK_OK(second_solution.status()); ///< Use the second_solution of the updated problem here.

Definition at line 66 of file solver.h.

Member Typedef Documentation

◆ InitArgs

Constructor & Destructor Documentation

◆ ~Solver()

operations_research::math_opt::Solver::~Solver ( )
override

Definition at line 86 of file solver.cc.

Member Function Documentation

◆ ComputeInfeasibleSubsystem()

absl::StatusOr< ComputeInfeasibleSubsystemResultProto > operations_research::math_opt::Solver::ComputeInfeasibleSubsystem ( const ComputeInfeasibleSubsystemArgs & arguments)
overridevirtual

Computes an infeasible subsystem of model (including all updates).

We will reset it in code paths where no error occur.

We consider errors in result to be internal errors, but ValidateInfeasibleSubsystemResult() will return an InvalidArgumentError. So here we convert the error.

Implements operations_research::math_opt::BaseSolver.

Definition at line 188 of file solver.cc.

◆ New()

absl::StatusOr< std::unique_ptr< Solver > > operations_research::math_opt::Solver::New ( SolverTypeProto solver_type,
const ModelProto & model,
const InitArgs & arguments )
static

Builds a solver of the given type with the provided model and initialization parameters.

Definition at line 88 of file solver.cc.

◆ NonIncrementalComputeInfeasibleSubsystem()

absl::StatusOr< ComputeInfeasibleSubsystemResultProto > operations_research::math_opt::Solver::NonIncrementalComputeInfeasibleSubsystem ( const ModelProto & model,
SolverTypeProto solver_type,
const InitArgs & init_args,
const ComputeInfeasibleSubsystemArgs & compute_infeasible_subsystem_args )
static

A shortcut for calling Solver::New() and then Solver()ComputeInfeasibleSubsystem()

Definition at line 220 of file solver.cc.

◆ NonIncrementalSolve()

absl::StatusOr< SolveResultProto > operations_research::math_opt::Solver::NonIncrementalSolve ( const ModelProto & model,
SolverTypeProto solver_type,
const InitArgs & init_args,
const SolveArgs & solve_args )
static

A shortcut for calling Solver::New() and then Solver::Solve().

Definition at line 70 of file solver.cc.

◆ Solve()

absl::StatusOr< SolveResultProto > operations_research::math_opt::Solver::Solve ( const SolveArgs & arguments)
overridevirtual

Solves the current model (including all updates).

We will reset it in code paths where no error occur.

Todo
(b/168037341): we should validate the result maths. Since the result can be filtered, this should be included in the solver_interface implementations.
Todo
(b/290091715): Remove once language specific structs can use new messages.

We consider errors in result to be internal errors, but ValidateResult() will return an InvalidArgumentError. So here we convert the error.

Implements operations_research::math_opt::BaseSolver.

Definition at line 101 of file solver.cc.

◆ Update()

absl::StatusOr< bool > operations_research::math_opt::Solver::Update ( ModelUpdateProto model_update)
overridevirtual

See BaseSolver::Update.

When this function returns false, the Solver object is in a failed state. In that case the underlying SolverInterface implementation has been destroyed (this enables the caller to instantiate a new Solver without destroying the previous one first even if they use Gurobi with a single-use license).

We will reset it in code paths where no error occur.

We only destroy underlying_solver_ in this specific case as it would be incorrect to destroy if the solver is GLPK and the error is that we are trying to use it in a different thread. Here we know this is not the case as Update() would have returned an error.

Implements operations_research::math_opt::BaseSolver.

Definition at line 158 of file solver.cc.


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