0 Python-Gurobi Interface
0 Python-Gurobi Interface
Python-Gurobi Interface
Summer 2024
Solvers
• A solver is a piece of mathematical software, possibly in the form of a
stand-alone computer program or as a software library, that 'solves' a
mathematical problem.
• A solver takes problem descriptions in some sort of generic form and
calculates their solution.
• Popular solvers:
• CPLEX (LP, MILP, QP)
• GUROBI (LP, MILP, QP)
• MOSEK (LP, MILP, QP)
• BARON (LP, NLP, MINLP)
• CONOPT (Large scale NLP)
• …
IE311 2
Gurobi-Python Interface
• Gurobi Optimizer is a prescriptive analytics platform and a decision-
making technology developed by Gurobi Optimization, LLC.
• The Gurobi Optimizer (often referred to as simply, “Gurobi”) is a
solver, since it uses mathematical optimization to calculate the
answer to a problem.
• Gurobi comes with a Python extension module called “gurobipy” that
offers convenient object-oriented modeling constructs and an API to
all Gurobi features.
IE311 3
A small example
IE311 4
Import functions and classes
,Model,quicksum
IE311 5
Creating a model
IE311 6
Adding variables to the model
IE311 7
Setting the objective
• The next step in the example is to set the optimization objective:
IE311 8
Adding constraints to the model
• The next step in the example is to add the linear constraints.
IE311 9
Optimize the model
• Now that the model has been built, the next step is to optimize it.
IE311 10
Function Model.addVar()
IE311 11
Function Model.addConstr()
IE311 12
Function Model.setObjective()
IE311 13
Function quicksum()
𝑎𝑗 𝑥𝑗 ≤ 𝑏
𝑗=1
IE311 14