Google OR-Tools v9.12
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
init_arguments.py
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"""Configures the instantiation of the underlying solver."""
15
16import dataclasses
17from typing import Optional
18
19from ortools.math_opt import parameters_pb2
20from ortools.math_opt.solvers import gurobi_pb2
21
22
23@dataclasses.dataclass
25 """Streamable GScip specific parameters for solver instantiation."""
26
27
28@dataclasses.dataclass(frozen=True)
30 """The Gurobi ISV key, an alternative to license files.
31
32 Contact Gurobi for details.
33
34 Attributes:
35 name: A string, typically a company/organization.
36 application_name: A string, typically a project.
37 expiration: An int, a value of 0 indicates no expiration.
38 key: A string, the secret.
39 """
40
41 name: str = ""
42 application_name: str = ""
43 expiration: int = 0
44 key: str = ""
45
46 def to_proto(self) -> gurobi_pb2.GurobiInitializerProto.ISVKey:
47 """Returns a protocol buffer equivalent of this."""
48 return gurobi_pb2.GurobiInitializerProto.ISVKey(
49 name=self.name,
50 application_name=self.application_name,
51 expiration=self.expiration,
52 key=self.key,
53 )
54
55
57 proto: gurobi_pb2.GurobiInitializerProto.ISVKey,
58) -> GurobiISVKey:
59 """Returns an equivalent GurobiISVKey to the input proto."""
60 return GurobiISVKey(
61 name=proto.name,
62 application_name=proto.application_name,
63 expiration=proto.expiration,
64 key=proto.key,
65 )
66
67
68@dataclasses.dataclass
70 """Streamable Gurobi specific parameters for solver instantiation."""
71
72 isv_key: Optional[GurobiISVKey] = None
73
74 def to_proto(self) -> gurobi_pb2.GurobiInitializerProto:
75 """Returns a protocol buffer equivalent of this."""
76 return gurobi_pb2.GurobiInitializerProto(
77 isv_key=self.isv_key.to_proto() if self.isv_key else None
78 )
79
80
82 proto: gurobi_pb2.GurobiInitializerProto,
83) -> StreamableGurobiInitArguments:
84 """Returns an equivalent StreamableGurobiInitArguments to the input proto."""
86 if proto.HasField("isv_key"):
87 result.isv_key = gurobi_isv_key_from_proto(proto.isv_key)
88 return result
89
90
91@dataclasses.dataclass
93 """Streamable Glop specific parameters for solver instantiation."""
94
95
96@dataclasses.dataclass
98 """Streamable CP-SAT specific parameters for solver instantiation."""
99
100
101@dataclasses.dataclass
103 """Streamable Pdlp specific parameters for solver instantiation."""
104
105
106@dataclasses.dataclass
108 """Streamable GLPK specific parameters for solver instantiation."""
109
110
111@dataclasses.dataclass
113 """Streamable OSQP specific parameters for solver instantiation."""
114
115
116@dataclasses.dataclass
118 """Streamable Ecos specific parameters for solver instantiation."""
119
120
121@dataclasses.dataclass
123 """Streamable Scs specific parameters for solver instantiation."""
124
125
126@dataclasses.dataclass
128 """Streamable Highs specific parameters for solver instantiation."""
129
130
131@dataclasses.dataclass
133 """Streamable Santorini specific parameters for solver instantiation."""
134
135
136@dataclasses.dataclass
138 """Solver initialization parameters that can be sent to another process.
139
140 Attributes:
141 gscip: Initialization parameters specific to GScip.
142 gurobi: Initialization parameters specific to Gurobi.
143 glop: Initialization parameters specific to GLOP.
144 cp_sat: Initialization parameters specific to CP-SAT.
145 pdlp: Initialization parameters specific to PDLP.
146 glpk: Initialization parameters specific to GLPK.
147 osqp: Initialization parameters specific to OSQP.
148 ecos: Initialization parameters specific to ECOS.
149 scs: Initialization parameters specific to SCS.
150 highs: Initialization parameters specific to HiGHS.
151 santorini: Initialization parameters specific to Santorini.
152 """
153
154 gscip: Optional[StreamableGScipInitArguments] = None
155 gurobi: Optional[StreamableGurobiInitArguments] = None
156 glop: Optional[StreamableGlopInitArguments] = None
157 cp_sat: Optional[StreamableCpSatInitArguments] = None
158 pdlp: Optional[StreamablePdlpInitArguments] = None
159 glpk: Optional[StreamableGlpkInitArguments] = None
160 osqp: Optional[StreamableOsqpInitArguments] = None
161 ecos: Optional[StreamableEcosInitArguments] = None
162 scs: Optional[StreamableScsInitArguments] = None
163 highs: Optional[StreamableHighsInitArguments] = None
164 santorini: Optional[StreamableSantoriniInitArguments] = None
165
166 def to_proto(self) -> parameters_pb2.SolverInitializerProto:
167 """Returns a protocol buffer equivalent of this."""
168 return parameters_pb2.SolverInitializerProto(
169 gurobi=self.gurobi.to_proto() if self.gurobi else None
170 )
171
172
174 proto: parameters_pb2.SolverInitializerProto,
175) -> StreamableSolverInitArguments:
176 """Returns an equivalent StreamableSolverInitArguments to the input proto."""
178 if proto.HasField("gurobi"):
179 result.gurobi = streamable_gurobi_init_arguments_from_proto(proto.gurobi)
180 return result
gurobi_pb2.GurobiInitializerProto.ISVKey to_proto(self)
StreamableSolverInitArguments streamable_solver_init_arguments_from_proto(parameters_pb2.SolverInitializerProto proto)
GurobiISVKey gurobi_isv_key_from_proto(gurobi_pb2.GurobiInitializerProto.ISVKey proto)
StreamableGurobiInitArguments streamable_gurobi_init_arguments_from_proto(gurobi_pb2.GurobiInitializerProto proto)