Skip to main content

Gurobi

Gurobi is an industry-leading solver for mathematical optimization.

Solvers

ModelBackend
BinaryQuadraticModelgurobi.qubo
MPSFilegurobi.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"

optimizer = StrangeworksOptimizer(model=model, solver=solver, options=options)
sw_job = optimizer.run()

print(f"Job slug: {sw_job.slug}")
print(f"Job status: {optimizer.status(sw_job.slug)}")

results = optimizer.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"

optimizer = StrangeworksOptimizer(model=model, solver=solver, options=options)
sw_job = optimizer.run()

print(optimizer.status(sw_job.slug))

results = optimizer.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.

NameDescriptionTypeDefaultValues (Range)
BarIterLimitLimits the number of iterations the barrier algorithm will perform.int1000[0, MAXINT]
BestBdStopStops optimization once the best objective bound is at least this good.doubleInfinity[-Infinity, Infinity]
BestObjStopStops optimization once a solution with an objective value this good is found.double-Infinity[-Infinity, Infinity]
CutoffSets a threshold objective value; optimization stops if no better value is possible.doubleInfinity for minimization, -Infinity for maximization[-Infinity, Infinity]
IterationLimitRestricts the number of simplex iterations to prevent excessive computation.intInfinity[0, Infinity]
MemLimitSets the maximum amount of memory the solver may use, in GB.doubleNone[0, Infinity]
NodeLimitImposes a limit on the number of MIP nodes explored in the search tree.intNone[0, Infinity]
SoftMemLimitSets a soft limit on the memory usage, allowing for minimal overages.doubleNone[0, Infinity]
SolutionLimitStops optimization after finding a specified number of feasible solutions.intNone[1, MAXINT]
TimeLimitSpecifies the maximum time (in seconds) the solver should run.doubleNone[0, Infinity]
WorkLimitLimits the amount of "work" (an abstract measure of effort) the solver can perform.intNone[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.

NameDescriptionTypeDefaultValues (Range)
BarConvTolTolerance used by the barrier algorithm to determine convergence.float1e-8[0.0, 1.0]
BarQCPConvTolTolerance for convergence when solving Quadratically Constrained Programs using the barrier method.float1e-6[0.0, 1.0]
FeasibilityTolTolerance for primal feasibility in the optimization.float1e-6[1e-9, 1e-2]
IntFeasTolTolerance to determine if an integer variable is at its bound.float1e-5[1e-9, 1e-1]
MarkowitzTolControls the threshold for numerical pivoting in the simplex algorithms.float0.0078125[1e-4, 0.999]
MIPGapRelative gap between the lower and upper bounds for terminating MIP optimization.float1e-4[0.0, Infinity]
MIPGapAbsAbsolute gap between the lower and upper bounds for terminating MIP optimization.float1e-10[0.0, Infinity]
OptimalityTolTolerance for dual feasibility in the optimization.float1e-6[1e-9, 1e-2]
PSDTolTolerance used to check the positive semi-definiteness in optimization.float1e-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.

NameDescriptionTypeDefaultValues (Range)
AggFillSpecifies the level of fill allowed during presolve aggregation.int-1[-1, MAXINT]
AggregateControls the aggregation level in presolve: off, moderate, or aggressive.bool1[0, 2]
DualReductionsEnables or disables dual reductions during presolve.bool1[0, 1]
PreCrushAllows translation of user constraints into equivalent presolved model constraints.bool0[0, 1]
PreDepRowEnables or disables dependent row reduction in presolve.bool1[0, 1]
PreDualDetermines whether to dualize the problem during presolve.bool0[0, 1]
PreMIQCPFormSpecifies the form of the presolved Mixed Integer Quadratically Constrained Program (MIQCP).int0[0, 1]
PrePassesSets the maximum number of presolve passes.int-1[-1, MAXINT]
PreQLinearizeDetermines whether to linearize the quadratic terms in objective and constraints during presolve.bool0[0, 1]
PresolveSets the presolve level to control the aggressiveness of the presolve process.int-1[-1, 2]
PreSOS1BigMSpecifies the largest coefficient allowed in SOS1 (Special Ordered Sets type 1) reformulations.float1e6[0, Infinity]
PreSOS1EncodingControls the encoding method used for SOS1 reformulations.int-1[-1, 2]
PreSOS2BigMSpecifies the largest coefficient allowed in SOS2 (Special Ordered Sets type 2) reformulations.float1e6[0, Infinity]
PreSOS2EncodingControls the encoding method used for SOS2 reformulations.int-1[-1, 2]
PreSparsifyEnables or disables the sparsification of the problem during presolve to reduce size without altering the optimal solution significantly.bool0[0, 1]