ortools.math_opt.python.init_arguments
Configures the instantiation of the underlying solver.
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 24class StreamableGScipInitArguments: 25 """Streamable GScip specific parameters for solver instantiation.""" 26 27 28@dataclasses.dataclass(frozen=True) 29class GurobiISVKey: 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 56def gurobi_isv_key_from_proto( 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 69class StreamableGurobiInitArguments: 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 81def streamable_gurobi_init_arguments_from_proto( 82 proto: gurobi_pb2.GurobiInitializerProto, 83) -> StreamableGurobiInitArguments: 84 """Returns an equivalent StreamableGurobiInitArguments to the input proto.""" 85 result = StreamableGurobiInitArguments() 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 92class StreamableGlopInitArguments: 93 """Streamable Glop specific parameters for solver instantiation.""" 94 95 96@dataclasses.dataclass 97class StreamableCpSatInitArguments: 98 """Streamable CP-SAT specific parameters for solver instantiation.""" 99 100 101@dataclasses.dataclass 102class StreamablePdlpInitArguments: 103 """Streamable Pdlp specific parameters for solver instantiation.""" 104 105 106@dataclasses.dataclass 107class StreamableGlpkInitArguments: 108 """Streamable GLPK specific parameters for solver instantiation.""" 109 110 111@dataclasses.dataclass 112class StreamableOsqpInitArguments: 113 """Streamable OSQP specific parameters for solver instantiation.""" 114 115 116@dataclasses.dataclass 117class StreamableEcosInitArguments: 118 """Streamable Ecos specific parameters for solver instantiation.""" 119 120 121@dataclasses.dataclass 122class StreamableScsInitArguments: 123 """Streamable Scs specific parameters for solver instantiation.""" 124 125 126@dataclasses.dataclass 127class StreamableHighsInitArguments: 128 """Streamable Highs specific parameters for solver instantiation.""" 129 130 131@dataclasses.dataclass 132class StreamableSantoriniInitArguments: 133 """Streamable Santorini specific parameters for solver instantiation.""" 134 135 136@dataclasses.dataclass 137class StreamableSolverInitArguments: 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 173def streamable_solver_init_arguments_from_proto( 174 proto: parameters_pb2.SolverInitializerProto, 175) -> StreamableSolverInitArguments: 176 """Returns an equivalent StreamableSolverInitArguments to the input proto.""" 177 result = StreamableSolverInitArguments() 178 if proto.HasField("gurobi"): 179 result.gurobi = streamable_gurobi_init_arguments_from_proto(proto.gurobi) 180 return result
24@dataclasses.dataclass 25class StreamableGScipInitArguments: 26 """Streamable GScip specific parameters for solver instantiation."""
Streamable GScip specific parameters for solver instantiation.
29@dataclasses.dataclass(frozen=True) 30class GurobiISVKey: 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 )
The Gurobi ISV key, an alternative to license files.
Contact Gurobi for details.
Attributes:
- name: A string, typically a company/organization.
- application_name: A string, typically a project.
- expiration: An int, a value of 0 indicates no expiration.
- key: A string, the secret.
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 )
Returns a protocol buffer equivalent of this.
57def gurobi_isv_key_from_proto( 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 )
Returns an equivalent GurobiISVKey to the input proto.
69@dataclasses.dataclass 70class StreamableGurobiInitArguments: 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 )
Streamable Gurobi specific parameters for solver instantiation.
82def streamable_gurobi_init_arguments_from_proto( 83 proto: gurobi_pb2.GurobiInitializerProto, 84) -> StreamableGurobiInitArguments: 85 """Returns an equivalent StreamableGurobiInitArguments to the input proto.""" 86 result = StreamableGurobiInitArguments() 87 if proto.HasField("isv_key"): 88 result.isv_key = gurobi_isv_key_from_proto(proto.isv_key) 89 return result
Returns an equivalent StreamableGurobiInitArguments to the input proto.
92@dataclasses.dataclass 93class StreamableGlopInitArguments: 94 """Streamable Glop specific parameters for solver instantiation."""
Streamable Glop specific parameters for solver instantiation.
97@dataclasses.dataclass 98class StreamableCpSatInitArguments: 99 """Streamable CP-SAT specific parameters for solver instantiation."""
Streamable CP-SAT specific parameters for solver instantiation.
102@dataclasses.dataclass 103class StreamablePdlpInitArguments: 104 """Streamable Pdlp specific parameters for solver instantiation."""
Streamable Pdlp specific parameters for solver instantiation.
107@dataclasses.dataclass 108class StreamableGlpkInitArguments: 109 """Streamable GLPK specific parameters for solver instantiation."""
Streamable GLPK specific parameters for solver instantiation.
112@dataclasses.dataclass 113class StreamableOsqpInitArguments: 114 """Streamable OSQP specific parameters for solver instantiation."""
Streamable OSQP specific parameters for solver instantiation.
117@dataclasses.dataclass 118class StreamableEcosInitArguments: 119 """Streamable Ecos specific parameters for solver instantiation."""
Streamable Ecos specific parameters for solver instantiation.
122@dataclasses.dataclass 123class StreamableScsInitArguments: 124 """Streamable Scs specific parameters for solver instantiation."""
Streamable Scs specific parameters for solver instantiation.
127@dataclasses.dataclass 128class StreamableHighsInitArguments: 129 """Streamable Highs specific parameters for solver instantiation."""
Streamable Highs specific parameters for solver instantiation.
132@dataclasses.dataclass 133class StreamableSantoriniInitArguments: 134 """Streamable Santorini specific parameters for solver instantiation."""
Streamable Santorini specific parameters for solver instantiation.
137@dataclasses.dataclass 138class StreamableSolverInitArguments: 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 )
Solver initialization parameters that can be sent to another process.
Attributes:
- gscip: Initialization parameters specific to GScip.
- gurobi: Initialization parameters specific to Gurobi.
- glop: Initialization parameters specific to GLOP.
- cp_sat: Initialization parameters specific to CP-SAT.
- pdlp: Initialization parameters specific to PDLP.
- glpk: Initialization parameters specific to GLPK.
- osqp: Initialization parameters specific to OSQP.
- ecos: Initialization parameters specific to ECOS.
- scs: Initialization parameters specific to SCS.
- highs: Initialization parameters specific to HiGHS.
- santorini: Initialization parameters specific to Santorini.
174def streamable_solver_init_arguments_from_proto( 175 proto: parameters_pb2.SolverInitializerProto, 176) -> StreamableSolverInitArguments: 177 """Returns an equivalent StreamableSolverInitArguments to the input proto.""" 178 result = StreamableSolverInitArguments() 179 if proto.HasField("gurobi"): 180 result.gurobi = streamable_gurobi_init_arguments_from_proto(proto.gurobi) 181 return result
Returns an equivalent StreamableSolverInitArguments to the input proto.