Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <solver.h>
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 | |
BaseSolver & | operator= (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) |
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.
|
override |
|
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.
|
static |
A shortcut for calling Solver::New() and then Solver()ComputeInfeasibleSubsystem()
|
static |
A shortcut for calling Solver::New() and then Solver::Solve().
|
overridevirtual |
Solves the current 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 ValidateResult()
will return an InvalidArgumentError. So here we convert the error.
Implements operations_research::math_opt::BaseSolver.
|
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.