Skip to content

Instantly share code, notes, and snippets.

@odow
Last active September 19, 2016 05:13
Show Gist options
  • Save odow/5255c34daef85a752da76b3836f20be3 to your computer and use it in GitHub Desktop.
Save odow/5255c34daef85a752da76b3836f20be3 to your computer and use it in GitHub Desktop.
Gurobi Bug
Maximize
C4
Subject To
R0: C2 = 0.5
R1: - 4.1 C0 + C1 = 0
R2: 5.1 C0 - C2 + C3 >= -0.1
R3: - 5.1 C0 + C2 + C3 >= 0.1
R4: - 0.230438 C0 + C2 + C4 <= 3.9695627
Bounds
-infinity <= C0 <= 1
-10 <= C1 <= 10
C2 free
C3 free
-infinity <= C4 <= 2e+06
End
Maximize
C4
Subject To
R0: C2 = 0.5
R1: - 4.1 C0 + C1 = 0
R2: 5.1 C0 - C2 + C3 >= -0.1
R3: - 5.1 C0 + C2 + C3 >= 0.1
R4: - 0.230438 C0 + C2 + C4 <= 3.9695627
Bounds
-infinity <= C0 <= 1
-10 <= C1 <= 10
C2 free
C3 free
-infinity <= C4 <= 2e+006
End
Maximize
C4
Subject To
R0: C2 = 0.5
R1: - 4.1 C0 + C1 = 0
R2: 5.1 C0 - C2 + C3 >= -0.1
R3: - 5.1 C0 + C2 + C3 >= 0.1
R4: - 0.230438 C0 + C2 + C4 <= 3.9695627
Bounds
-infinity <= C0 <= 1
-10 <= C1 <= 10
C2 free
C3 free
-infinity <= C4 <= 2e+06
End
Maximize
C4
Subject To
R0: C2 = 0.5
R1: - 4.1 C0 + C1 = 0
R2: 5.1 C0 - C2 + C3 >= -0.1
R3: - 5.1 C0 + C2 + C3 >= 0.1
R4: - 0.230438 C0 + C2 + C4 <= 3.9695627
Bounds
-infinity <= C0 <= 1
-10 <= C1 <= 10
C2 free
C3 free
-infinity <= C4 <= 2e+06
End
Maximize
C4
Subject To
R0: C2 = 0.5
R1: - 4.1 C0 + C1 = 0
R2: 5.1 C0 - C2 + C3 >= -0.1
R3: - 5.1 C0 + C2 + C3 >= 0.1
R4: - 0.230438 C0 + C2 + C4 <= 3.9695627
R5: 3.892116 C0 - C1 + C2 + C4 <= 3.9921156
Bounds
-infinity <= C0 <= 1
-10 <= C1 <= 10
C2 free
C3 free
-infinity <= C4 <= 2e+06
End
Maximize
C4
Subject To
R0: C2 = 0.5
R1: - 4.1 C0 + C1 = 0
R2: 5.1 C0 - C2 + C3 >= -0.1
R3: - 5.1 C0 + C2 + C3 >= 0.1
R4: - 0.230438 C0 + C2 + C4 <= 3.9695627
R5: 3.892116 C0 - C1 + C2 + C4 <= 3.9921156
Bounds
-infinity <= C0 <= 1
-10 <= C1 <= 10
C2 free
C3 free
-infinity <= C4 <= 2e+06
End
Maximize
- C4
Subject To
R0: C2 = 0.5
R1: 4.1 C0 + C1 = 0
R2: - 5.1 C0 - C2 + C3 >= -0.1
R3: 5.1 C0 + C2 + C3 >= 0.1
R4: 0.230438 C0 + C2 - C4 <= 3.9695627
R5: - 3.892116 C0 - C1 + C2 - C4 <= 3.9921156
Bounds
C0 >= -1
-10 <= C1 <= 10
C2 free
C3 free
C4 >= -2e+06
End
Maximize
- C4
Subject To
R0: C2 = 0.5
R1: 4.1 C0 + C1 = 0
R2: - 5.1 C0 - C2 + C3 >= -0.1
R3: 5.1 C0 + C2 + C3 >= 0.1
R4: 0.230438 C0 + C2 - C4 <= 3.9695627
R5: - 3.892116 C0 - C1 + C2 - C4 <= 3.9921156
Bounds
C0 >= -1
-10 <= C1 <= 10
C2 free
C3 free
C4 >= -2e+06
End
Maximize
C4
Subject To
R0: C2 = 0.5
R1: 4.1 C0 + C1 = 0
R2: - 5.1 C0 - C2 + C3 >= -0.1
R3: 5.1 C0 + C2 + C3 >= 0.1
R4: 0.230438 C0 + C2 - C4 <= 3.9695627
R5: - 3.892116 C0 - C1 + C2 - C4 <= 3.9921156
Bounds
C0 >= -1
-10 <= C1 <= 10
C2 free
C3 free
C4 >= -2e+06
End
Maximize
Maximize
C4
Subject To
R0: C2 = 0.5
R1: 4.1 C0 + C1 = 0
R2: - 5.1 C0 - C2 + C3 >= -0.1
R3: 5.1 C0 + C2 + C3 >= 0.1
R4: 0.230438 C0 + C2 - C4 <= 3.9695627
R5: - 3.892116 C0 - C1 + C2 - C4 <= 3.9921156
Bounds
C0 >= -1
-10 <= C1 <= 10
C2 free
C3 free
C4 >= -2e+06
End
Maximize
- C4
Subject To
R0: C2 = 0.5
R1: - 4.1 C0 + C1 = 0
R2: 5.1 C0 - C2 + C3 >= -0.1
R3: - 5.1 C0 + C2 + C3 >= 0.1
R4: - 0.230438 C0 + C2 + C4 <= 3.9695627
R5: 3.892116 C0 - C1 + C2 + C4 <= 3.9921156
Bounds
-infinity <= C0 <= 1
-10 <= C1 <= 10
C2 free
C3 free
-infinity <= C4 <= 2e+06
End
Maximize
- C4
Subject To
R0: C2 = 0.5
R1: - 4.1 C0 + C1 = 0
R2: 5.1 C0 - C2 + C3 >= -0.1
R3: - 5.1 C0 + C2 + C3 >= 0.1
R4: - 0.230438 C0 + C2 + C4 <= 3.9695627
R5: 3.892116 C0 - C1 + C2 + C4 <= 3.9921156
Bounds
-infinity <= C0 <= 1
-10 <= C1 <= 10
C2 free
C3 free
-infinity <= C4 <= 2e+06
End
Gurobi 6.5.2 (win64) logging started 09/19/16 14:08:06
Optimize a model with 5 rows, 5 columns and 12 nonzeros
Coefficient statistics:
Matrix range [2e-01, 5e+00]
Objective range [1e+00, 1e+00]
Bounds range [1e+00, 2e+06]
RHS range [1e-01, 4e+00]
Presolve removed 5 rows and 5 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration Objective Primal Inf. Dual Inf. Time
0 3.7000007e+00 0.000000e+00 0.000000e+00 0s
Solved in 0 iterations and 0.00 seconds
Optimal objective 3.700000700e+00
Optimize a model with 6 rows, 5 columns and 16 nonzeros
Coefficient statistics:
Matrix range [2e-01, 5e+00]
Objective range [1e+00, 1e+00]
Bounds range [1e+00, 2e+06]
RHS range [1e-01, 4e+00]
Iteration Objective Primal Inf. Dual Inf. Time
0 3.7000007e+00 0.000000e+00 0.000000e+00 0s
1 3.6999996e+00 0.000000e+00 0.000000e+00 0s
Solved in 1 iterations and 0.00 seconds
Optimal objective 3.699999600e+00
Optimize a model with 6 rows, 5 columns and 16 nonzeros
Coefficient statistics:
Matrix range [2e-01, 5e+00]
Objective range [1e+00, 1e+00]
Bounds range [1e+00, 2e+06]
RHS range [1e-01, 4e+00]
Iteration Objective Primal Inf. Dual Inf. Time
0 4.2078840e+30 2.300000e+30 4.207884e+00 0s
Solved in 3 iterations and 0.00 seconds
Unbounded model
using Gurobi
env = Gurobi.Env()
model = Gurobi.Model(env, "Bug Example", :maximize)
setparam!(model, "LogFile", "gurobi.log")
Gurobi.add_var!(model, GRB_CONTINUOUS, 0., -Inf, 1.)
Gurobi.add_var!(model, GRB_CONTINUOUS, 0., -10., 10.)
Gurobi.add_var!(model, GRB_CONTINUOUS, 0., -Inf, Inf)
Gurobi.add_var!(model, GRB_CONTINUOUS, 0., -Inf, Inf)
Gurobi.add_var!(model, GRB_CONTINUOUS, 1., -Inf, 2e6)
Gurobi.update_model!(model)
Gurobi.add_constr!(model, [3], [1.], '=', 0.5)
Gurobi.add_constr!(model, [1, 2], [-4.1, 1.], '=', 0.)
Gurobi.add_constr!(model, [1, 3, 4], [5.1, -1., 1.], '>', -0.1)
Gurobi.add_constr!(model, [1, 3, 4], [-5.1, 1., 1.], '>', 0.1)
Gurobi.add_constr!(model, [1, 3, 5], [-0.230438, 1., 1.], '<', 3.9695627)
Gurobi.update_model!(model)
Gurobi.write_model(model, "0_julia.lp")
Gurobi.optimize(model)
Gurobi.write_model(model, "1_julia.lp")
Gurobi.add_constr!(model, [1, 2, 3, 5], [3.892116, -1., 1., 1.], '<', 3.9921156)
Gurobi.update_model!(model)
Gurobi.write_model(model, "2_julia.lp")
Gurobi.optimize(model)
Gurobi.write_model(model, "3_julia.lp")
obj = Gurobi.get_dblattrarray(model, "Obj", 1, num_vars(model))
Gurobi.set_dblattrarray!(model, "Obj", 1, num_vars(model), obj)
Gurobi.update_model!(model)
Gurobi.write_model(model, "4_julia.lp")
Gurobi.optimize(model)
Gurobi.write_model(model, "5_julia.lp")
Gurobi.free_model(model)
Gurobi.free_env(env)
from gurobipy import *
m = Model("Gurobi Bug")
C1 = m.addVar(lb=-GRB.INFINITY, ub=1)
C2 = m.addVar(lb=-10, ub=10)
C3 = m.addVar(lb=-GRB.INFINITY, ub=GRB.INFINITY)
C4 = m.addVar(lb=-GRB.INFINITY, ub=GRB.INFINITY)
C5 = m.addVar(lb=-GRB.INFINITY, ub=2e6, obj=1)
m.modelSense = GRB.MAXIMIZE
m.update()
R1 = m.addConstr(C3 == 0.5)
m.addConstr(-4.1*C1 + C2 == 0)
m.addConstr(5.1*C1 - C3 + C4 >= -0.1)
m.addConstr(-5.1*C1 + C3 + C4 >= 0.1)
m.addConstr(-0.230438*C1 + C3 + C5 <= 3.9695627)
m.update()
m.write("0_python.lp")
m.optimize()
m.write("1_python.lp")
m.addConstr(3.892116*C1 - C2 + C3 + C5 <= 3.9921156)
m.update()
m.write("2_python.lp")
m.optimize()
m.write("3_python.lp")
obj = m.getAttr("Obj", m.getVars())
m.setAttr("Obj", m.getVars(), obj)
m.update()
m.write("4_python.lp")
m.optimize()
m.write("5_python.lp")
Optimize a model with 5 rows, 5 columns and 12 nonzeros
Coefficient statistics:
Matrix range [2e-01, 5e+00]
Objective range [1e+00, 1e+00]
Bounds range [1e+00, 2e+06]
RHS range [1e-01, 4e+00]
Presolve removed 5 rows and 5 columns
Presolve time: 0.10s
Presolve: All rows and columns removed
Iteration Objective Primal Inf. Dual Inf. Time
0 3.7000007e+00 0.000000e+00 0.000000e+00 0s
Solved in 0 iterations and 0.11 seconds
Optimal objective 3.700000700e+00
Optimize a model with 6 rows, 5 columns and 16 nonzeros
Coefficient statistics:
Matrix range [2e-01, 5e+00]
Objective range [1e+00, 1e+00]
Bounds range [1e+00, 2e+06]
RHS range [1e-01, 4e+00]
Iteration Objective Primal Inf. Dual Inf. Time
0 3.7000007e+00 0.000000e+00 0.000000e+00 0s
1 3.6999996e+00 0.000000e+00 0.000000e+00 0s
Solved in 1 iterations and 0.02 seconds
Optimal objective 3.699999600e+00
Optimize a model with 6 rows, 5 columns and 16 nonzeros
Coefficient statistics:
Matrix range [2e-01, 5e+00]
Objective range [1e+00, 1e+00]
Bounds range [1e+00, 2e+06]
RHS range [1e-01, 4e+00]
Iteration Objective Primal Inf. Dual Inf. Time
0 4.2078840e+30 2.300000e+30 4.207884e+00 0s
Solved in 3 iterations and 0.01 seconds
Unbounded model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment