Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
solver_resources.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_SOLVER_RESOURCES_H_
18#define ORTOOLS_MATH_OPT_CPP_SOLVER_RESOURCES_H_
19
20#include <optional>
21#include <ostream>
22#include <string>
23
24#include "absl/status/statusor.h"
25#include "absl/strings/string_view.h"
27
29
30// The hints on the resources a remote solve is expected to use. These
31// parameters are hints and may be ignored by the remote server (in particular
32// in case of solve in a local subprocess, for example).
33//
34// When using:
35// - RemoteSolve(),
36// - RemoteComputeInfeasibleSubsystem(),
37// - XxxRemoteStreamingSolve(),
38// - XxxRemoteStreamingComputeInfeasibleSubsystem(),
39// these hints are recommended but optional. When they are not provided,
40// resource usage will be estimated based on other parameters.
41//
42// When using NewXxxRemoteStreamingIncrementalSolver() these hints are used to
43// dimension the resources available during the execution of every action; thus
44// it is recommended to set them.
45//
47 // The number of solver threads that are expected to actually execute in
48 // parallel. Must be finite and >0.0.
49 //
50 // For example a value of 3.0 means that if the solver has 5 threads that can
51 // execute we expect at least 3 of these threads to be scheduled in parallel
52 // for any given time slice of the operating system scheduler.
53 //
54 // A fractional value indicates that we don't expect the operating system to
55 // constantly schedule the solver's work. For example with 0.5 we would expect
56 // the solver's threads to be scheduled half the time.
57 //
58 // This parameter is usually used in conjunction with
59 // SolveParameters.threads. For some solvers like Gurobi it makes sense to use
60 // SolverResources.cpu = SolveParameters.threads. For other solvers like
61 // CP-SAT, it may makes sense to use a value lower than the number of threads
62 // as not all threads may be ready to be scheduled at the same time. It is
63 // better to consult each solver documentation to set this parameter.
64 //
65 // Note that if the SolveParameters.threads is not set then this parameter
66 // should also be left unset.
67 std::optional<double> cpu;
68
69 // The limit of RAM for the solve in bytes. Must be finite and >=1.0 (even
70 // though it should in practice be much larger).
71 std::optional<double> ram;
72
74 static absl::StatusOr<SolverResources> FromProto(
75 const SolverResourcesProto& proto);
76};
77
78std::ostream& operator<<(std::ostream& out, const SolverResources& resources);
79
80bool AbslParseFlag(absl::string_view text, SolverResources* solver_resources,
81 std::string* error);
82
83std::string AbslUnparseFlag(const SolverResources& solver_resources);
84
85} // namespace operations_research::math_opt
86
87#endif // ORTOOLS_MATH_OPT_CPP_SOLVER_RESOURCES_H_
bool AbslParseFlag(const absl::string_view text, SolverType *const value, std::string *const error)
std::ostream & operator<<(std::ostream &ostr, const SecondOrderConeConstraint &constraint)
std::string AbslUnparseFlag(const SolverType value)
static absl::StatusOr< SolverResources > FromProto(const SolverResourcesProto &proto)