Advertisement
Dmitrey15

Untitled

Feb 17th, 2012
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. # GuRoBi Python example from
  2. # http://www.gurobi.com/doc/45/quickstart/node11.html
  3. from gurobipy import *
  4.  
  5. try:
  6.  
  7.   # Create a new model
  8.   m = Model("mip1")
  9.  
  10.   # Create variables
  11.   x = m.addVar(0.0, 1.0, -1.0, GRB.BINARY, "x")
  12.   y = m.addVar(0.0, 1.0, -1.0, GRB.BINARY, "y")
  13.   z = m.addVar(0.0, 1.0, -2.0, GRB.BINARY, "z")
  14.  
  15.   # Integrate new variables
  16.   m.update()
  17.  
  18.  
  19.   # Add constraint: x + 2 y + 3 z <= 4
  20.   m.addConstr(LinExpr([1.0, 2.0, 3.0], [x, y, z]), GRB.LESS_EQUAL, 4.0, "c0")
  21.  
  22.   # Add constraint: x + y >= 1
  23.   m.addConstr(LinExpr([1.0, 1.0], [x, y]), GRB.GREATER_EQUAL, 1.0, "c1")
  24.  
  25.   m.optimize()
  26.  
  27.   for v in m.getVars():
  28.     print v.VarName, v.X
  29.  
  30.   print 'Obj:', m.ObjVal
  31.  
  32. except:
  33.   print 'Error reported'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement