Google OR-Tools v9.11
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-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
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 RemoteSolve() and RemoteComputeInfeasibleSubsystem(), these hints
34// are mostly optional as some defaults will be computed based on the other
35// parameters.
36//
37// When using RemoteStreamingSolve() these hints are used to dimension the
38// resources available during the execution of every action; thus it is
39// recommended to set them.
40//
42 // The number of solver threads that are expected to actually execute in
43 // parallel. Must be finite and >0.0.
44 //
45 // For example a value of 3.0 means that if the solver has 5 threads that can
46 // execute we expect at least 3 of these threads to be scheduled in parallel
47 // for any given time slice of the operating system scheduler.
48 //
49 // A fractional value indicates that we don't expect the operating system to
50 // constantly schedule the solver's work. For example with 0.5 we would expect
51 // the solver's threads to be scheduled half the time.
52 //
53 // This parameter is usually used in conjunction with
54 // SolveParameters.threads. For some solvers like Gurobi it makes sense to use
55 // SolverResources.cpu = SolveParameters.threads. For other solvers like
56 // CP-SAT, it may makes sense to use a value lower than the number of threads
57 // as not all threads may be ready to be scheduled at the same time. It is
58 // better to consult each solver documentation to set this parameter.
59 //
60 // Note that if the SolveParameters.threads is not set then this parameter
61 // should also be left unset.
62 std::optional<double> cpu;
63
64 // The limit of RAM for the solve in bytes. Must be finite and >=1.0 (even
65 // though it should in practice be much larger).
66 std::optional<double> ram;
67
68 SolverResourcesProto Proto() const;
69 static absl::StatusOr<SolverResources> FromProto(
70 const SolverResourcesProto& proto);
71};
72
73bool AbslParseFlag(absl::string_view text, SolverResources* solver_resources,
74 std::string* error);
75
76std::string AbslUnparseFlag(const SolverResources& solver_resources);
77
78} // namespace operations_research::math_opt
79
80#endif // OR_TOOLS_MATH_OPT_CPP_SOLVER_RESOURCES_H_
CpModelProto proto
The output proto.
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)