Skip to content

Instantly share code, notes, and snippets.

@odow
Last active September 29, 2016 22:38
Show Gist options
  • Save odow/61a1cb2824a670b4e635843b004f1dcc to your computer and use it in GitHub Desktop.
Save odow/61a1cb2824a670b4e635843b004f1dcc to your computer and use it in GitHub Desktop.
Bug in Gurobi v6.5.2 and earlier
Minimize
- C2
Subject To
R0: C0 + C1 >= 0
R1: 2 C0 - C1 >= 0
R2: C2 >= -2
R3: C0 - C2 >= 0
R4: - 1.000001 C0 + C1 - C2 >= 0
Bounds
C0 <= 1
-infinity <= C2 <= 1
End
Minimize
- C2
Subject To
R0: C0 + C1 >= 0
R1: 2 C0 - C1 >= 0
R2: - C2 >= -2
R3: C0 + C2 >= 0
R4: - 1.000001 C0 + C1 + C2 >= 0
Bounds
C0 <= 1
C2 >= -1
End
from gurobipy import *
m = Model("Gurobi Bug")
m.modelSense = GRB.MINIMIZE
x = m.addVar(lb=0, ub=1)
y = m.addVar(lb=0, ub=GRB.INFINITY)
z = m.addVar(lb=-GRB.INFINITY, ub=1, obj=-1)
m.update()
m.addConstr( x + y >= 0)
m.addConstr(2*x - y >= 0)
m.addConstr( z >= -2)
m.addConstr( x - z >= 0)
m.update()
m.optimize()
print "The solution vector is:", m.getAttr("x",m.getVars())
m.addConstr(-1.000001*x + y - z >= 0)
m.update()
m.write("correct_model.lp")
m.optimize()
m.write("reformulated_model.lp")
print "The solution vector is:", m.getAttr("x",m.getVars())
c = m.getAttr("Obj", m.getVars())
m.setAttr("Obj", m.getVars(), c)
m.update()
m.write("incorrect_model.lp")
m.optimize()
print "The solution vector is:", m.getAttr("x",m.getVars())
Minimize
C2
Subject To
R0: C0 + C1 >= 0
R1: 2 C0 - C1 >= 0
R2: - C2 >= -2
R3: C0 + C2 >= 0
R4: - 1.000001 C0 + C1 + C2 >= 0
Bounds
C0 <= 1
C2 >= -1
End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment