Gurobi says the model is infeasible, yet I can come up with a solution by hand (Python)
AnsweredI optimized the model below, but guroby says the model is infeasible.
from gurobipy import *
m = Model('test')
a = m.addVar(name="a", vtype=GRB.INTEGER)
b = m.addVar(name="b", vtype=GRB.INTEGER)
c = m.addVar(name="c", vtype=GRB.INTEGER)
m.addConstr(a >= 0)
m.addConstr(a <= 0)
m.addConstr(a <= 3)
m.addConstr(a-b <= 1)
m.addConstr(a+b <= 5)
m.addConstr(b >= -1)
m.addConstr(b <= 1)
m.addConstr(a-c <= 0)
m.addConstr(a+c <= 0)
m.addConstr(c >= -1)
m.addConstr(c <= 1)
m.addConstr(b+c == -1)
objective = LinExpr(-b)
m.setObjective(objective, GRB.MINIMIZE)
m.setParam(GRB.Param.PoolSearchMode, 2)
m.setParam(GRB.Param.PoolSolutions, 10000)
m.setParam(GRB.Param.PoolGap, 1e-4)
m.optimize()
if m.status != GRB.Status.OPTIMAL:
print('No Solution')
m.write("file.lp")
else:
m.setParam(GRB.Param.SolutionNumber, 0)
print(m.getVarByName("a").Xn)
print(m.getVarByName("b").Xn)
print(m.getVarByName("c").Xn)
I think that the model is feasible if a=0, b=-1, c=0. Why is the model infeasible? Any help is appreciated.
0
-
Thank you for reaching us.
The default lower bound of a variable is zero (please refer to our manual about Model.addVar()).
If you add variables like as follows, you will get the optimal solution you want.a = m.addVar(lb=-GRB.INFINITY, name="a", vtype=GRB.INTEGER)
b = m.addVar(lb=-GRB.INFINITY, name="b", vtype=GRB.INTEGER)
c = m.addVar(lb=-GRB.INFINITY, name="c", vtype=GRB.INTEGER)Whenever you have any questions, feel free to contact us.
Best regards,
Chung-Kyun Han0 -
Thank you very much!
0 -
Hi Yechan,
You should also take a look at our article How do I determine why my model is infeasible?
With this knowledge, you will runm.computeIIS()
m.write("model.ilp")and inspect the file that is written.
- Riley0
Please sign in to leave a comment.
Comments
3 comments