Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
solve_arguments.h
Go to the documentation of this file.
1// Copyright 2010-2025 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
14// IWYU pragma: private, include "ortools/math_opt/cpp/math_opt.h"
15// IWYU pragma: friend "ortools/math_opt/cpp/.*"
16
17#ifndef ORTOOLS_MATH_OPT_CPP_SOLVE_ARGUMENTS_H_
18#define ORTOOLS_MATH_OPT_CPP_SOLVE_ARGUMENTS_H_
19
20#include "absl/base/nullability.h"
21#include "absl/status/status.h"
22#include "ortools/math_opt/cpp/callback.h" // IWYU pragma: export
23#include "ortools/math_opt/cpp/message_callback.h" // IWYU pragma: export
24#include "ortools/math_opt/cpp/model_solve_parameters.h" // IWYU pragma: export
25#include "ortools/math_opt/cpp/parameters.h" // IWYU pragma: export
27#include "ortools/util/solve_interrupter.h" // IWYU pragma: export
28
30
31// Arguments passed to Solve() and IncrementalSolver::Solve() to control the
32// solve.
34 // Model independent parameters, e.g. time limit.
36
37 // Model dependent parameters, e.g. solution hint.
39
40 // An optional callback for messages emitted by the solver.
41 //
42 // When set it enables the solver messages and ignores the `enable_output` in
43 // solve parameters; messages are redirected to the callback and not printed
44 // on stdout/stderr/logs anymore.
45 //
46 // See PrinterMessageCallback() for logging to stdout/stderr.
47 //
48 // Usage:
49 //
50 // // To print messages to stdout with a prefix.
51 // ASSIGN_OR_RETURN(
52 // const SolveResult result,
53 // Solve(model, SolverType::kGlop,
54 // { .message_callback = PrinterMessageCallback(std::cout,
55 // "logs| "); });
57
58 // Callback registration parameters. Usually `callback` should also be set
59 // when these parameters are modified.
61
62 // The optional callback for LP/MIP events.
63 //
64 // The `callback_registration` parameters have to be set, in particular
65 // `callback_registration.events`.
66 //
67 // See callback.h file comment for documentation on callbacks.
68 Callback callback = nullptr;
69
70 // An optional interrupter that the solver can use to interrupt the solve
71 // early.
72 //
73 // Usage:
74 // auto interrupter = std::make_shared<SolveInterrupter>();
75 //
76 // // Use another thread to trigger the interrupter.
77 // RunInOtherThread([interrupter](){
78 // ... wait for something that should interrupt the solve ...
79 // interrupter->Interrupt();
80 // });
81 //
82 // ASSIGN_OR_RETURN(const SolveResult result,
83 // Solve(model, SolverType::kGlop,
84 // { .interrupter = interrupter.get() });
85 //
86 const SolveInterrupter* absl_nullable interrupter = nullptr;
87
88 // Returns a failure if the referenced variables and constraints don't belong
89 // to the input expected_storage (which must not be nullptr).
90 absl::Status CheckModelStorage(ModelStorageCPtr expected_storage) const;
91};
92
93} // namespace operations_research::math_opt
94
95#endif // ORTOOLS_MATH_OPT_CPP_SOLVE_ARGUMENTS_H_
const ModelStorage *absl_nonnull ModelStorageCPtr
std::function< CallbackResult(const CallbackData &)> Callback
Definition callback.h:94
std::function< void(const std::vector< std::string > &)> MessageCallback
const SolveInterrupter *absl_nullable interrupter
absl::Status CheckModelStorage(ModelStorageCPtr expected_storage) const