Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
solve.cc
Go to the documentation of this file.
1// Copyright 2010-2024 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
15
16#include <memory>
17#include <utility>
18
19#include "absl/status/statusor.h"
20#include "ortools/math_opt/callback.pb.h"
32#include "ortools/math_opt/infeasible_subsystem.pb.h"
33
34namespace operations_research {
35namespace math_opt {
36
37namespace {
38
39Solver::InitArgs ToSolverInitArgs(const SolverInitArguments& arguments) {
40 return {
41 .streamable = arguments.streamable.Proto(),
42 .non_streamable = arguments.non_streamable.get(),
43 };
44}
45
46internal::BaseSolverFactory FactoryFromInitArguments(
47 const SolverInitArguments& arguments) {
48 return [arguments](const SolverTypeProto solver_type, ModelProto model,
49 SolveInterrupter* const local_canceller)
50 -> absl::StatusOr<std::unique_ptr<BaseSolver>> {
51 // We don't use the local_canceller as in-process solve can't be
52 // cancelled. If an error happens in the callback, the solve_impl code will
53 // use CallbackResultProto::set_terminate() to trigger a cooperative
54 // interruption.
55 return Solver::New(solver_type, std::move(model),
56 ToSolverInitArgs(arguments));
57 };
58}
59
60} // namespace
61
62absl::StatusOr<SolveResult> Solve(const Model& model,
63 const SolverType solver_type,
64 const SolveArguments& solve_args,
65 const SolverInitArguments& init_args) {
66 return internal::SolveImpl(FactoryFromInitArguments(init_args), model,
67 solver_type, solve_args,
68 /*user_canceller=*/nullptr,
69 /*remove_names=*/init_args.remove_names);
70}
71
72absl::StatusOr<ComputeInfeasibleSubsystemResult> ComputeInfeasibleSubsystem(
73 const Model& model, const SolverType solver_type,
74 const ComputeInfeasibleSubsystemArguments& compute_args,
75 const SolverInitArguments& init_args) {
77 FactoryFromInitArguments(init_args), model, solver_type, compute_args,
78 /*user_canceller=*/nullptr,
79 /*remove_names=*/init_args.remove_names);
80}
81
82absl::StatusOr<std::unique_ptr<IncrementalSolver>> NewIncrementalSolver(
83 Model* model, SolverType solver_type, SolverInitArguments arguments) {
85 FactoryFromInitArguments(arguments), model, solver_type,
86 /*user_canceller=*/nullptr,
87 /*remove_names=*/arguments.remove_names);
88}
89
90} // namespace math_opt
91} // namespace operations_research
SolverInterface::InitArgs InitArgs
Definition solver.h:68
static absl::StatusOr< std::unique_ptr< Solver > > New(SolverTypeProto solver_type, const ModelProto &model, const InitArgs &arguments)
Definition solver.cc:88
static absl::StatusOr< std::unique_ptr< IncrementalSolverImpl > > New(BaseSolverFactory solver_factory, Model *model, SolverType solver_type, const SolveInterrupter *user_canceller, bool remove_names)
GRBmodel * model
absl::StatusOr< ComputeInfeasibleSubsystemResult > ComputeInfeasibleSubsystemImpl(const BaseSolverFactory solver_factory, const Model &model, const SolverType solver_type, const ComputeInfeasibleSubsystemArguments &compute_args, const SolveInterrupter *const user_canceller, const bool remove_names)
absl::AnyInvocable< absl::StatusOr< std::unique_ptr< BaseSolver > >( SolverTypeProto solver_type, ModelProto model, SolveInterrupter *local_canceller) const > BaseSolverFactory
Definition solve_impl.h:50
absl::StatusOr< SolveResult > SolveImpl(const BaseSolverFactory solver_factory, const Model &model, const SolverType solver_type, const SolveArguments &solve_args, const SolveInterrupter *const user_canceller, const bool remove_names)
SolverType
The solvers supported by MathOpt.
Definition parameters.h:42
absl::StatusOr< SolveResult > Solve(const Model &model, const SolverType solver_type, const SolveArguments &solve_args, const SolverInitArguments &init_args)
Definition solve.cc:62
absl::StatusOr< std::unique_ptr< IncrementalSolver > > NewIncrementalSolver(Model *model, SolverType solver_type, SolverInitArguments arguments)
Definition solve.cc:82
absl::StatusOr< ComputeInfeasibleSubsystemResult > ComputeInfeasibleSubsystem(const Model &model, const SolverType solver_type, const ComputeInfeasibleSubsystemArguments &compute_args, const SolverInitArguments &init_args)
Definition solve.cc:72
In SWIG mode, we don't want anything besides these top-level includes.
Arguments passed to ComputeInfeasibleSubsystem() to control the solver.