Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # GuRoBi Python example from
- # http://www.gurobi.com/doc/45/quickstart/node11.html
- from gurobipy import *
- try:
- # Create a new model
- m = Model("mip1")
- # Create variables
- x = m.addVar(0.0, 1.0, -1.0, GRB.BINARY, "x")
- y = m.addVar(0.0, 1.0, -1.0, GRB.BINARY, "y")
- z = m.addVar(0.0, 1.0, -2.0, GRB.BINARY, "z")
- # Integrate new variables
- m.update()
- # Add constraint: x + 2 y + 3 z <= 4
- m.addConstr(LinExpr([1.0, 2.0, 3.0], [x, y, z]), GRB.LESS_EQUAL, 4.0, "c0")
- # Add constraint: x + y >= 1
- m.addConstr(LinExpr([1.0, 1.0], [x, y]), GRB.GREATER_EQUAL, 1.0, "c1")
- m.optimize()
- for v in m.getVars():
- print v.VarName, v.X
- print 'Obj:', m.ObjVal
- except:
- print 'Error reported'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement