Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
init_arguments.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# Copyright 2010-2025 Google LLC
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""Configures the instantiation of the underlying solver."""
16
17import dataclasses
18from typing import Optional
19
20from ortools.math_opt import parameters_pb2
21from ortools.math_opt.solvers import gurobi_pb2
22
23
24@dataclasses.dataclass
26 """Streamable GScip specific parameters for solver instantiation."""
27
28
29@dataclasses.dataclass(frozen=True)
31 """The Gurobi ISV key, an alternative to license files.
32
33 Contact Gurobi for details.
34
35 Attributes:
36 name: A string, typically a company/organization.
37 application_name: A string, typically a project.
38 expiration: An int, a value of 0 indicates no expiration.
39 key: A string, the secret.
40 """
41
42 name: str = ""
43 application_name: str = ""
44 expiration: int = 0
45 key: str = ""
46
47 def to_proto(self) -> gurobi_pb2.GurobiInitializerProto.ISVKey:
48 """Returns a protocol buffer equivalent of this."""
49 return gurobi_pb2.GurobiInitializerProto.ISVKey(
50 name=self.name,
51 application_name=self.application_name,
52 expiration=self.expiration,
53 key=self.key,
54 )
55
56
58 proto: gurobi_pb2.GurobiInitializerProto.ISVKey,
59) -> GurobiISVKey:
60 """Returns an equivalent GurobiISVKey to the input proto."""
61 return GurobiISVKey(
62 name=proto.name,
63 application_name=proto.application_name,
64 expiration=proto.expiration,
65 key=proto.key,
66 )
67
68
69@dataclasses.dataclass
71 """Streamable Gurobi specific parameters for solver instantiation."""
72
73 isv_key: Optional[GurobiISVKey] = None
74
75 def to_proto(self) -> gurobi_pb2.GurobiInitializerProto:
76 """Returns a protocol buffer equivalent of this."""
77 return gurobi_pb2.GurobiInitializerProto(
78 isv_key=self.isv_key.to_proto() if self.isv_key else None
79 )
80
81
83 proto: gurobi_pb2.GurobiInitializerProto,
84) -> StreamableGurobiInitArguments:
85 """Returns an equivalent StreamableGurobiInitArguments to the input proto."""
87 if proto.HasField("isv_key"):
88 result.isv_key = gurobi_isv_key_from_proto(proto.isv_key)
89 return result
90
91
92@dataclasses.dataclass
94 """Streamable Glop specific parameters for solver instantiation."""
95
96
97@dataclasses.dataclass
99 """Streamable CP-SAT specific parameters for solver instantiation."""
100
101
102@dataclasses.dataclass
104 """Streamable Pdlp specific parameters for solver instantiation."""
105
106
107@dataclasses.dataclass
109 """Streamable GLPK specific parameters for solver instantiation."""
110
111
112@dataclasses.dataclass
114 """Streamable OSQP specific parameters for solver instantiation."""
115
116
117@dataclasses.dataclass
119 """Streamable Ecos specific parameters for solver instantiation."""
120
121
122@dataclasses.dataclass
124 """Streamable Scs specific parameters for solver instantiation."""
125
126
127@dataclasses.dataclass
129 """Streamable Highs specific parameters for solver instantiation."""
130
131
132@dataclasses.dataclass
134 """Streamable Santorini specific parameters for solver instantiation."""
135
136
137@dataclasses.dataclass
139 """Solver initialization parameters that can be sent to another process.
140
141 Attributes:
142 gscip: Initialization parameters specific to GScip.
143 gurobi: Initialization parameters specific to Gurobi.
144 glop: Initialization parameters specific to GLOP.
145 cp_sat: Initialization parameters specific to CP-SAT.
146 pdlp: Initialization parameters specific to PDLP.
147 glpk: Initialization parameters specific to GLPK.
148 osqp: Initialization parameters specific to OSQP.
149 ecos: Initialization parameters specific to ECOS.
150 scs: Initialization parameters specific to SCS.
151 highs: Initialization parameters specific to HiGHS.
152 santorini: Initialization parameters specific to Santorini.
153 """
154
155 gscip: Optional[StreamableGScipInitArguments] = None
156 gurobi: Optional[StreamableGurobiInitArguments] = None
157 glop: Optional[StreamableGlopInitArguments] = None
158 cp_sat: Optional[StreamableCpSatInitArguments] = None
159 pdlp: Optional[StreamablePdlpInitArguments] = None
160 glpk: Optional[StreamableGlpkInitArguments] = None
161 osqp: Optional[StreamableOsqpInitArguments] = None
162 ecos: Optional[StreamableEcosInitArguments] = None
163 scs: Optional[StreamableScsInitArguments] = None
164 highs: Optional[StreamableHighsInitArguments] = None
165 santorini: Optional[StreamableSantoriniInitArguments] = None
166
167 def to_proto(self) -> parameters_pb2.SolverInitializerProto:
168 """Returns a protocol buffer equivalent of this."""
169 return parameters_pb2.SolverInitializerProto(
170 gurobi=self.gurobi.to_proto() if self.gurobi else None
171 )
172
173
175 proto: parameters_pb2.SolverInitializerProto,
176) -> StreamableSolverInitArguments:
177 """Returns an equivalent StreamableSolverInitArguments to the input proto."""
179 if proto.HasField("gurobi"):
180 result.gurobi = streamable_gurobi_init_arguments_from_proto(proto.gurobi)
181 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)