Gurobi
Gurobi is an industry-leading solver for mathematical optimization.
Solvers
Model | Backend |
---|---|
BinaryQuadraticModel | gurobi.qubo |
MPSFile | gurobi.mps |
Binary Quadratic Model
import strangeworks as sw
from strangeworks_optimization import StrangeworksOptimizer
from strangeworks_optimization_models.parameter_models import GurobiParameterModel
from dimod import BinaryQuadraticModel
sw.authenticate('your-api-key')
linear = {1: -2, 2: -2, 3: -3, 4: -3, 5: -2}
quadratic = {(1, 2): 2, (1, 3): 2, (2, 4): 2, (3, 4): 2, (3, 5): 2, (4, 5): 2}
model = BinaryQuadraticModel(linear, quadratic, "BINARY")
options = GurobiParameterModel(TimeLimit=60)
solver = "gurobi.qubo"
so = StrangeworksOptimizer(model=model, solver=solver, options=options)
sw_job = so.run()
print(f"Job slug: {sw_job.slug}")
print(f"Job status: {so.status(sw_job.slug)}")
results = so.results(sw_job.slug)
Mathemical Programming System
import strangeworks as sw
from strangeworks_optimization import StrangeworksOptimizer
from strangeworks_optimization_models.problem_models import MPSFile
from strangeworks_optimization_models.parameter_models import GurobiParameterModel
sw.authenticate('your-api-key')
file = "example.mps"
model = MPSFile.read_file(file)
options = GurobiParameterModel(TimeLimit=60)
solver = "gurobi.mps"
so = StrangeworksOptimizer(model=model, solver=solver, options=options)
sw_job = so.run()
print(so.status(sw_job.slug))
results = so.results(sw_job.slug)
GurobiParameterModel
Below are some of the parameter types that can be used to control the behavior of the Gurobi solver. For a full list of parameters, please refer to the Gurobi documentation.
Termination
These parameters control the conditions under which the solver will terminate.
Name | Description | Type | Default | Values (Range) |
---|---|---|---|---|
BarIterLimit | Limits the number of iterations the barrier algorithm will perform. | int | 1000 | [0, MAXINT] |
BestBdStop | Stops optimization once the best objective bound is at least this good. | double | Infinity | [-Infinity, Infinity] |
BestObjStop | Stops optimization once a solution with an objective value this good is found. | double | -Infinity | [-Infinity, Infinity] |
Cutoff | Sets a threshold objective value; optimization stops if no better value is possible. | double | Infinity for minimization, -Infinity for maximization | [-Infinity, Infinity] |
IterationLimit | Restricts the number of simplex iterations to prevent excessive computation. | int | Infinity | [0, Infinity] |
MemLimit | Sets the maximum amount of memory the solver may use, in GB. | double | None | [0, Infinity] |
NodeLimit | Imposes a limit on the number of MIP nodes explored in the search tree. | int | None | [0, Infinity] |
SoftMemLimit | Sets a soft limit on the memory usage, allowing for minimal overages. | double | None | [0, Infinity] |
SolutionLimit | Stops optimization after finding a specified number of feasible solutions. | int | None | [1, MAXINT] |
TimeLimit | Specifies the maximum time (in seconds) the solver should run. | double | None | [0, Infinity] |
WorkLimit | Limits the amount of "work" (an abstract measure of effort) the solver can perform. | int | None | [0, Infinity] |
Tolerances
These parameters control the feasibility and optimality tolerances. The feasibility tolerance is the maximum amount by which a constraint can be violated, and the optimality tolerance is the maximum amount by which the objective function can be improved.
Name | Description | Type | Default | Values (Range) |
---|---|---|---|---|
BarConvTol | Tolerance used by the barrier algorithm to determine convergence. | float | 1e-8 | [0.0, 1.0] |
BarQCPConvTol | Tolerance for convergence when solving Quadratically Constrained Programs using the barrier method. | float | 1e-6 | [0.0, 1.0] |
FeasibilityTol | Tolerance for primal feasibility in the optimization. | float | 1e-6 | [1e-9, 1e-2] |
IntFeasTol | Tolerance to determine if an integer variable is at its bound. | float | 1e-5 | [1e-9, 1e-1] |
MarkowitzTol | Controls the threshold for numerical pivoting in the simplex algorithms. | float | 0.0078125 | [1e-4, 0.999] |
MIPGap | Relative gap between the lower and upper bounds for terminating MIP optimization. | float | 1e-4 | [0.0, Infinity] |
MIPGapAbs | Absolute gap between the lower and upper bounds for terminating MIP optimization. | float | 1e-10 | [0.0, Infinity] |
OptimalityTol | Tolerance for dual feasibility in the optimization. | float | 1e-6 | [1e-9, 1e-2] |
PSDTol | Tolerance used to check the positive semi-definiteness in optimization. | float | 1e-6 | [0, Infinity] |
Presolve
These parameters control the presolve phase of the optimization. Presolve is the process of simplifying the model before it is solved.
Name | Description | Type | Default | Values (Range) |
---|---|---|---|---|
AggFill | Specifies the level of fill allowed during presolve aggregation. | int | -1 | [-1, MAXINT] |
Aggregate | Controls the aggregation level in presolve: off, moderate, or aggressive. | bool | 1 | [0, 2] |
DualReductions | Enables or disables dual reductions during presolve. | bool | 1 | [0, 1] |
PreCrush | Allows translation of user constraints into equivalent presolved model constraints. | bool | 0 | [0, 1] |
PreDepRow | Enables or disables dependent row reduction in presolve. | bool | 1 | [0, 1] |
PreDual | Determines whether to dualize the problem during presolve. | bool | 0 | [0, 1] |
PreMIQCPForm | Specifies the form of the presolved Mixed Integer Quadratically Constrained Program (MIQCP). | int | 0 | [0, 1] |
PrePasses | Sets the maximum number of presolve passes. | int | -1 | [-1, MAXINT] |
PreQLinearize | Determines whether to linearize the quadratic terms in objective and constraints during presolve. | bool | 0 | [0, 1] |
Presolve | Sets the presolve level to control the aggressiveness of the presolve process. | int | -1 | [-1, 2] |
PreSOS1BigM | Specifies the largest coefficient allowed in SOS1 (Special Ordered Sets type 1) reformulations. | float | 1e6 | [0, Infinity] |
PreSOS1Encoding | Controls the encoding method used for SOS1 reformulations. | int | -1 | [-1, 2] |
PreSOS2BigM | Specifies the largest coefficient allowed in SOS2 (Special Ordered Sets type 2) reformulations. | float | 1e6 | [0, Infinity] |
PreSOS2Encoding | Controls the encoding method used for SOS2 reformulations. | int | -1 | [-1, 2] |
PreSparsify | Enables or disables the sparsification of the problem during presolve to reduce size without altering the optimal solution significantly. | bool | 0 | [0, 1] |