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