User:Jarle Pahr/Gurobi: Difference between revisions
Jarle Pahr (talk | contribs) |
Jarle Pahr (talk | contribs) |
||
Line 51: | Line 51: | ||
Model.update: http://www.gurobi.com/documentation/5.5/quick-start-guide/node99 | 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. | |||
Objects: | Objects: |
Revision as of 02:49, 4 October 2013
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.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.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.
Objects:
Linear expression:
http://www.gurobi.com/documentation/5.5/reference-manual/node619#pythonclass:LinExpr
Quadratic expression: http://www.gurobi.com/documentation/5.5/reference-manual/node635#pythonclass:QuadExpr
Attributes
A Gurobi model consists of decision variables (objects of class Var), an objective function
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.