Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
remote_streaming_mode.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#ifndef ORTOOLS_MATH_OPT_CPP_REMOTE_STREAMING_MODE_H_
15#define ORTOOLS_MATH_OPT_CPP_REMOTE_STREAMING_MODE_H_
16
17#include <ostream>
18#include <string>
19
20#include "absl/strings/string_view.h"
21
23
24// Operation mode of remote streaming solver.
25//
26// Default mode is to make an RPC call. Other modes enables using local solving
27// (either in a subprocess or in the same process).
28//
29// Most users should use a non-default mode in unit tests or as a debug tool. It
30// is recommended to use subprocess solving as a replacement for an RPC call as
31// this behaves similarly to RPC, especially regarding cancellation.
33 // Default mode which uses a regular streaming RPC call.
35
36 // Use a local sub-process instead of making a remote call. When this mode is
37 // used the stub parameter is ignored.
38 //
39 // The application must be linked with the target corresponding to the solver
40 // type, i.e. something like:
41 // //ortools/math_opt/subprocess/solvers:xxx_subprocess_solver
42 //
43 // The bonus of using this mode is that as with an RPC, the call can be
44 // cancelled immediately. And crashes in the solver can't crash the main
45 // application. There may be a slight overhead when using this mode as it has
46 // to spawn a subprocess for each solve.
48
49 // Make a direct call to the solver in the same process. When this mode is
50 // used the stub parameter is ignored.
51 //
52 // The application must be linked with the target corresponding to the solver
53 // type, i.e. something like:
54 // //ortools/math_opt/solvers:xxx_solver
55 //
56 // The call to the solver is done in a background thread making sure it is
57 // still compatible with fibers (and their cancellation) in this mode. See
58 // ThreadSolve() documentation for details.
59 //
60 // The cancellation is handled using cooperative interruption, that is as if a
61 // SolveInterrupter was used with Solve().
62 //
63 // The bonus of using this mode is that crashes are easier to debug. The
64 // downside is that cancellation is delayed until the solver decides to stop.
66};
67
68// Parses a flag of type RemoteStreamingSolveMode.
69bool AbslParseFlag(absl::string_view text, RemoteStreamingSolveMode* value,
70 std::string* error);
71
72// Unparses a flag of type RemoteStreamingSolveMode.
74
75// Prints the enum using AbslUnparseFlag().
76std::ostream& operator<<(std::ostream& out, RemoteStreamingSolveMode mode);
77
78// Prints the enum using AbslUnparseFlag().
79template <typename Sink>
80void AbslStringify(Sink& sink, const RemoteStreamingSolveMode mode) {
81 sink.Append(AbslUnparseFlag(mode));
82}
83
84} // namespace operations_research::math_opt
85
86#endif // ORTOOLS_MATH_OPT_CPP_REMOTE_STREAMING_MODE_H_
bool AbslParseFlag(const absl::string_view text, SolverType *const value, std::string *const error)
void AbslStringify(Sink &sink, const RemoteStreamingSolveMode mode)
std::ostream & operator<<(std::ostream &ostr, const SecondOrderConeConstraint &constraint)
std::string AbslUnparseFlag(const SolverType value)