User:Jarle Pahr/Gurobi: Difference between revisions

From OpenWetWare
Jump to navigationJump to search
Line 49: Line 49:


Model.getVars: http://www.gurobi.com/documentation/5.5/reference-manual/node582
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
Model.update: http://www.gurobi.com/documentation/5.5/quick-start-guide/node99

Revision as of 04:27, 4 October 2013

Notes on Gurobi optimizer:

http://www.gurobi.com/

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.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


Objects:


Linear expression: http://www.gurobi.com/documentation/5.5/reference-manual/node619#pythonclass:LinExpr

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

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