Google OR-Tools
v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
solver_resources.py
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
"""Configures solver resources."""
15
16
import
dataclasses
17
from
typing
import
Optional
18
19
from
ortools.math_opt
import
rpc_pb2
20
21
22
@dataclasses.dataclass
23
class
SolverResources
:
24
"""The hints on the resources a remote solve is expected to use.
25
26
These parameters are hints and may be ignored by the remote server (in
27
particular in case of solve in a local subprocess, for example).
28
29
When using remote_solve() and remote_compute_infeasible_subsystem(), these
30
hints are mostly optional as some defaults will be computed based on the other
31
parameters.
32
33
When using remote_streaming_solve() these hints are used to dimension the
34
resources available during the execution of every action; thus it is
35
recommended to set them.
36
37
MOE:begin_intracomment_strip
38
39
The go/uoss server will use these parameters to do a bin-packing of all
40
requests. Parameter cpu is a soft-limit, the solve may still be able to use
41
more CPUs. The ram parameter is an hard-limit, an out-of-memory error will
42
occur if the solve attempts to use more memory.
43
44
MOE:end_intracomment_strip
45
46
Attributes:
47
cpu: The number of solver threads that are expected to actually execute in
48
parallel. Must be finite and >0.0. For example a value of 3.0 means that
49
if the solver has 5 threads that can execute we expect at least 3 of these
50
threads to be scheduled in parallel for any given time slice of the
51
operating system scheduler. A fractional value indicates that we don't
52
expect the operating system to constantly schedule the solver's work. For
53
example with 0.5 we would expect the solver's threads to be scheduled half
54
the time. This parameter is usually used in conjunction with
55
SolveParameters.threads. For some solvers like Gurobi it makes sense to
56
use SolverResources.cpu = SolveParameters.threads. For other solvers like
57
CP-SAT, it may makes sense to use a value lower than the number of threads
58
as not all threads may be ready to be scheduled at the same time. It is
59
better to consult each solver documentation to set this parameter. Note
60
that if the SolveParameters.threads is not set then this parameter should
61
also be left unset.
62
ram: The limit of RAM for the solve in bytes. Must be finite and >=1.0 (even
63
though it should in practice be much larger).
64
"""
65
66
cpu: Optional[float] =
None
67
ram: Optional[float] =
None
68
69
def
to_proto
(self) -> rpc_pb2.SolverResourcesProto:
70
return
rpc_pb2.SolverResourcesProto(cpu=self.
cpu
, ram=self.
ram
)
ortools.math_opt.python.solver_resources.SolverResources
Definition
solver_resources.py:23
ortools.math_opt.python.solver_resources.SolverResources.cpu
Optional cpu
Definition
solver_resources.py:66
ortools.math_opt.python.solver_resources.SolverResources.ram
Optional ram
Definition
solver_resources.py:67
ortools.math_opt.python.solver_resources.SolverResources.to_proto
rpc_pb2.SolverResourcesProto to_proto(self)
Definition
solver_resources.py:69
ortools.math_opt
Definition
__init__.py:1
build
python
ortools
math_opt
python
solver_resources.py
Generated by
1.12.0