ortools.math_opt.python.init_arguments

Configures the instantiation of the underlying solver.

  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
 25class StreamableGScipInitArguments:
 26    """Streamable GScip specific parameters for solver instantiation."""
 27
 28
 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        )
 55
 56
 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    )
 67
 68
 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        )
 80
 81
 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
 90
 91
 92@dataclasses.dataclass
 93class StreamableGlopInitArguments:
 94    """Streamable Glop specific parameters for solver instantiation."""
 95
 96
 97@dataclasses.dataclass
 98class StreamableCpSatInitArguments:
 99    """Streamable CP-SAT specific parameters for solver instantiation."""
100
101
102@dataclasses.dataclass
103class StreamablePdlpInitArguments:
104    """Streamable Pdlp specific parameters for solver instantiation."""
105
106
107@dataclasses.dataclass
108class StreamableGlpkInitArguments:
109    """Streamable GLPK specific parameters for solver instantiation."""
110
111
112@dataclasses.dataclass
113class StreamableOsqpInitArguments:
114    """Streamable OSQP specific parameters for solver instantiation."""
115
116
117@dataclasses.dataclass
118class StreamableEcosInitArguments:
119    """Streamable Ecos specific parameters for solver instantiation."""
120
121
122@dataclasses.dataclass
123class StreamableScsInitArguments:
124    """Streamable Scs specific parameters for solver instantiation."""
125
126
127@dataclasses.dataclass
128class StreamableHighsInitArguments:
129    """Streamable Highs specific parameters for solver instantiation."""
130
131
132@dataclasses.dataclass
133class StreamableSantoriniInitArguments:
134    """Streamable Santorini specific parameters for solver instantiation."""
135
136
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        )
172
173
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
@dataclasses.dataclass
class StreamableGScipInitArguments:
25@dataclasses.dataclass
26class StreamableGScipInitArguments:
27    """Streamable GScip specific parameters for solver instantiation."""

Streamable GScip specific parameters for solver instantiation.

@dataclasses.dataclass(frozen=True)
class GurobiISVKey:
30@dataclasses.dataclass(frozen=True)
31class GurobiISVKey:
32    """The Gurobi ISV key, an alternative to license files.
33
34    Contact Gurobi for details.
35
36    Attributes:
37      name: A string, typically a company/organization.
38      application_name: A string, typically a project.
39      expiration: An int, a value of 0 indicates no expiration.
40      key: A string, the secret.
41    """
42
43    name: str = ""
44    application_name: str = ""
45    expiration: int = 0
46    key: str = ""
47
48    def to_proto(self) -> gurobi_pb2.GurobiInitializerProto.ISVKey:
49        """Returns a protocol buffer equivalent of this."""
50        return gurobi_pb2.GurobiInitializerProto.ISVKey(
51            name=self.name,
52            application_name=self.application_name,
53            expiration=self.expiration,
54            key=self.key,
55        )

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.
GurobiISVKey( name: str = '', application_name: str = '', expiration: int = 0, key: str = '')
name: str = ''
application_name: str = ''
expiration: int = 0
key: str = ''
48    def to_proto(self) -> gurobi_pb2.GurobiInitializerProto.ISVKey:
49        """Returns a protocol buffer equivalent of this."""
50        return gurobi_pb2.GurobiInitializerProto.ISVKey(
51            name=self.name,
52            application_name=self.application_name,
53            expiration=self.expiration,
54            key=self.key,
55        )

Returns a protocol buffer equivalent of this.

def gurobi_isv_key_from_proto( proto: ortools.math_opt.solvers.gurobi_pb2.GurobiInitializerProto.ISVKey) -> GurobiISVKey:
58def gurobi_isv_key_from_proto(
59    proto: gurobi_pb2.GurobiInitializerProto.ISVKey,
60) -> GurobiISVKey:
61    """Returns an equivalent GurobiISVKey to the input proto."""
62    return GurobiISVKey(
63        name=proto.name,
64        application_name=proto.application_name,
65        expiration=proto.expiration,
66        key=proto.key,
67    )

Returns an equivalent GurobiISVKey to the input proto.

@dataclasses.dataclass
class StreamableGurobiInitArguments:
70@dataclasses.dataclass
71class StreamableGurobiInitArguments:
72    """Streamable Gurobi specific parameters for solver instantiation."""
73
74    isv_key: Optional[GurobiISVKey] = None
75
76    def to_proto(self) -> gurobi_pb2.GurobiInitializerProto:
77        """Returns a protocol buffer equivalent of this."""
78        return gurobi_pb2.GurobiInitializerProto(
79            isv_key=self.isv_key.to_proto() if self.isv_key else None
80        )

Streamable Gurobi specific parameters for solver instantiation.

StreamableGurobiInitArguments( isv_key: GurobiISVKey | None = None)
isv_key: GurobiISVKey | None = None
76    def to_proto(self) -> gurobi_pb2.GurobiInitializerProto:
77        """Returns a protocol buffer equivalent of this."""
78        return gurobi_pb2.GurobiInitializerProto(
79            isv_key=self.isv_key.to_proto() if self.isv_key else None
80        )

Returns a protocol buffer equivalent of this.

def streamable_gurobi_init_arguments_from_proto( proto: ortools.math_opt.solvers.gurobi_pb2.GurobiInitializerProto) -> StreamableGurobiInitArguments:
83def streamable_gurobi_init_arguments_from_proto(
84    proto: gurobi_pb2.GurobiInitializerProto,
85) -> StreamableGurobiInitArguments:
86    """Returns an equivalent StreamableGurobiInitArguments to the input proto."""
87    result = StreamableGurobiInitArguments()
88    if proto.HasField("isv_key"):
89        result.isv_key = gurobi_isv_key_from_proto(proto.isv_key)
90    return result

Returns an equivalent StreamableGurobiInitArguments to the input proto.

@dataclasses.dataclass
class StreamableGlopInitArguments:
93@dataclasses.dataclass
94class StreamableGlopInitArguments:
95    """Streamable Glop specific parameters for solver instantiation."""

Streamable Glop specific parameters for solver instantiation.

@dataclasses.dataclass
class StreamableCpSatInitArguments:
 98@dataclasses.dataclass
 99class StreamableCpSatInitArguments:
100    """Streamable CP-SAT specific parameters for solver instantiation."""

Streamable CP-SAT specific parameters for solver instantiation.

@dataclasses.dataclass
class StreamablePdlpInitArguments:
103@dataclasses.dataclass
104class StreamablePdlpInitArguments:
105    """Streamable Pdlp specific parameters for solver instantiation."""

Streamable Pdlp specific parameters for solver instantiation.

@dataclasses.dataclass
class StreamableGlpkInitArguments:
108@dataclasses.dataclass
109class StreamableGlpkInitArguments:
110    """Streamable GLPK specific parameters for solver instantiation."""

Streamable GLPK specific parameters for solver instantiation.

@dataclasses.dataclass
class StreamableOsqpInitArguments:
113@dataclasses.dataclass
114class StreamableOsqpInitArguments:
115    """Streamable OSQP specific parameters for solver instantiation."""

Streamable OSQP specific parameters for solver instantiation.

@dataclasses.dataclass
class StreamableEcosInitArguments:
118@dataclasses.dataclass
119class StreamableEcosInitArguments:
120    """Streamable Ecos specific parameters for solver instantiation."""

Streamable Ecos specific parameters for solver instantiation.

@dataclasses.dataclass
class StreamableScsInitArguments:
123@dataclasses.dataclass
124class StreamableScsInitArguments:
125    """Streamable Scs specific parameters for solver instantiation."""

Streamable Scs specific parameters for solver instantiation.

@dataclasses.dataclass
class StreamableHighsInitArguments:
128@dataclasses.dataclass
129class StreamableHighsInitArguments:
130    """Streamable Highs specific parameters for solver instantiation."""

Streamable Highs specific parameters for solver instantiation.

@dataclasses.dataclass
class StreamableSantoriniInitArguments:
133@dataclasses.dataclass
134class StreamableSantoriniInitArguments:
135    """Streamable Santorini specific parameters for solver instantiation."""

Streamable Santorini specific parameters for solver instantiation.

@dataclasses.dataclass
class StreamableSolverInitArguments:
138@dataclasses.dataclass
139class StreamableSolverInitArguments:
140    """Solver initialization parameters that can be sent to another process.
141
142    Attributes:
143      gscip: Initialization parameters specific to GScip.
144      gurobi: Initialization parameters specific to Gurobi.
145      glop: Initialization parameters specific to GLOP.
146      cp_sat: Initialization parameters specific to CP-SAT.
147      pdlp: Initialization parameters specific to PDLP.
148      glpk: Initialization parameters specific to GLPK.
149      osqp: Initialization parameters specific to OSQP.
150      ecos: Initialization parameters specific to ECOS.
151      scs: Initialization parameters specific to SCS.
152      highs: Initialization parameters specific to HiGHS.
153      santorini: Initialization parameters specific to Santorini.
154    """
155
156    gscip: Optional[StreamableGScipInitArguments] = None
157    gurobi: Optional[StreamableGurobiInitArguments] = None
158    glop: Optional[StreamableGlopInitArguments] = None
159    cp_sat: Optional[StreamableCpSatInitArguments] = None
160    pdlp: Optional[StreamablePdlpInitArguments] = None
161    glpk: Optional[StreamableGlpkInitArguments] = None
162    osqp: Optional[StreamableOsqpInitArguments] = None
163    ecos: Optional[StreamableEcosInitArguments] = None
164    scs: Optional[StreamableScsInitArguments] = None
165    highs: Optional[StreamableHighsInitArguments] = None
166    santorini: Optional[StreamableSantoriniInitArguments] = None
167
168    def to_proto(self) -> parameters_pb2.SolverInitializerProto:
169        """Returns a protocol buffer equivalent of this."""
170        return parameters_pb2.SolverInitializerProto(
171            gurobi=self.gurobi.to_proto() if self.gurobi else None
172        )

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.
StreamableSolverInitArguments( gscip: StreamableGScipInitArguments | None = None, gurobi: StreamableGurobiInitArguments | None = None, glop: StreamableGlopInitArguments | None = None, cp_sat: StreamableCpSatInitArguments | None = None, pdlp: StreamablePdlpInitArguments | None = None, glpk: StreamableGlpkInitArguments | None = None, osqp: StreamableOsqpInitArguments | None = None, ecos: StreamableEcosInitArguments | None = None, scs: StreamableScsInitArguments | None = None, highs: StreamableHighsInitArguments | None = None, santorini: StreamableSantoriniInitArguments | None = None)
gscip: StreamableGScipInitArguments | None = None
gurobi: StreamableGurobiInitArguments | None = None
glop: StreamableGlopInitArguments | None = None
cp_sat: StreamableCpSatInitArguments | None = None
pdlp: StreamablePdlpInitArguments | None = None
glpk: StreamableGlpkInitArguments | None = None
osqp: StreamableOsqpInitArguments | None = None
ecos: StreamableEcosInitArguments | None = None
scs: StreamableScsInitArguments | None = None
highs: StreamableHighsInitArguments | None = None
santorini: StreamableSantoriniInitArguments | None = None
def to_proto(self) -> ortools.math_opt.parameters_pb2.SolverInitializerProto:
168    def to_proto(self) -> parameters_pb2.SolverInitializerProto:
169        """Returns a protocol buffer equivalent of this."""
170        return parameters_pb2.SolverInitializerProto(
171            gurobi=self.gurobi.to_proto() if self.gurobi else None
172        )

Returns a protocol buffer equivalent of this.

def streamable_solver_init_arguments_from_proto( proto: ortools.math_opt.parameters_pb2.SolverInitializerProto) -> StreamableSolverInitArguments:
175def streamable_solver_init_arguments_from_proto(
176    proto: parameters_pb2.SolverInitializerProto,
177) -> StreamableSolverInitArguments:
178    """Returns an equivalent StreamableSolverInitArguments to the input proto."""
179    result = StreamableSolverInitArguments()
180    if proto.HasField("gurobi"):
181        result.gurobi = streamable_gurobi_init_arguments_from_proto(proto.gurobi)
182    return result

Returns an equivalent StreamableSolverInitArguments to the input proto.