User:Jarle Pahr/Gurobi
Notes on Gurobi optimizer:
https://groups.google.com/forum/#!forum/gurobi
Gurobi in Python: http://www.youtube.com/watch?v=aKsfqB-ONfk
Gurobi optimizer reference manual: http://www.gurobi.com/documentation/5.5/reference-manual/refman
Gurobi optimizer quick start: http://www.gurobi.com/documentation/5.5/quick-start-guide/quickstart
Quick start guide Python Interface: http://www.gurobi.com/documentation/5.5/quick-start-guide/node93
The Gurobi Python Interface for Python Users: http://www.gurobi.com/documentation/5.5/quick-start-guide/node39
Python reference manual: http://www.gurobi.com/documentation/5.5/reference-manual/node541
Python commands and examples:
import gurobipy as gurobi
m = gurobi.Model("mip1")
x = m.addVar(vtype=gurobi.GRB.BINARY, name = "x") y = m.addVar(vtype=gurobi.GRB.BINARY, name = "y") z = m.addVar(vtype=gurobi.GRB.BINARY, name = "z") m.update() m.setObjective(x + y + 2 * z, gurobi.GRB.MAXIMIZE) m.addConstr(x + 2 * y + 3 * z <=4, "c0") m.addConstr(x + y >= 1,"c1") m.update() m.optimize() for v in m.getVars():
print v.varName, v.x
print 'Obj:', m.objVal
Using Gurobi to solve an FBA problem:
Python functions and methods
Model methods: http://www.gurobi.com/documentation/5.5/reference-manual/node554
Model.addVar: http://www.gurobi.com/documentation/5.5/reference-manual/node560#pythonmethod:Model.addVar
Model.setObjective: http://www.gurobi.com/documentation/5.5/reference-manual/node600#pythonmethod:Model.setObjective
Model.getVars: http://www.gurobi.com/documentation/5.5/reference-manual/node582
Model.getVarByName() : http://www.gurobi.com/documentation/5.5/reference-manual/node581
Model.update: http://www.gurobi.com/documentation/5.5/quick-start-guide/node99
- Used to manually update the model after changes.
- The model is automatically updated before optimization.
Model.addConstr(): http://www.gurobi.com/documentation/5.5/reference-manual/node556
Model.optimize(): http://www.gurobi.com/documentation/5.5/reference-manual/node584
Objects:
Linear expression:
http://www.gurobi.com/documentation/5.5/reference-manual/node619#pythonclass:LinExpr
- LinExpr(): http://www.gurobi.com/documentation/5.5/reference-manual/node620
- Linear expressions can be created using the LinExpr() constructor or using overloaded operators on one or several variable objects.
LinExpr.add(): http://www.gurobi.com/documentation/5.5/reference-manual/node621
- Add one linear expression into another.
Quadratic expression: http://www.gurobi.com/documentation/5.5/reference-manual/node635#pythonclass:QuadExpr
QuadExpr.addterm(): http://www.gurobi.com/documentation/5.5/reference-manual/node639#pythonmethod:QuadExpr.addTerms
Attributes
A Gurobi model consists of decision variables (objects of class Var), an objective function
Gurobi model attributes: http://www.gurobi.com/documentation/5.5/reference-manual/node680
model.status: http://www.gurobi.com/documentation/5.5/reference-manual/node896#sec:StatusCodes
File formats
File formats: http://www.gurobi.com/documentation/5.5/reference-manual/node899
MPS format: http://www.gurobi.com/documentation/5.5/reference-manual/node900
- Oldest
LP format: http://www.gurobi.com/documentation/5.5/reference-manual/node902
- Example: http://www.gurobi.com/documentation/5.5/quick-start-guide/node25
- Human-readable text-file.