Which constraints are active at Optimization Termination
AnsweredI have a MILP model which is solved to optimality by Gurobi. I would now like to know which constraints are active at optimization termination i.e. constraints that are limiting.
I found on the forum a possible answer which mentions about looking at constraint Slack (image below). It appears reasonable to me, however I have a simple question: Can someone explain the condition below i.e. Slack >1e6 to me incase I am lacking to grasp it. If the slack is 100, is the constraint still active then? In my simple understanding, there should be a range for it.
Also, I have equality constraints in the model, in that case do I also need to exclude the equality constraints but filtering them based on the Sense?

Hi Nitin,
Any constraint that is active at the solution will theoretically have slack value of 0 ("there is no slack in the constraint"). In practice we compare against a number close to 0, such as 1e6, due to the consequences of floating point arithmetic.
There looks to be a typo in the post from the screenshot and the condition should be
if c.Slack < 1e6:
Equality constraints will always have a theoretical slack of 0 so you can filter them out via the "Sense" attribute as you suggest.
You may wish to play around with the following toy model, where the optimal solution and active constraints at the solution should be apparent.
m = gp.Model()
x = m.addVar()
y = m.addVar()
c1=m.addConstr(x + y <= 1)
c2=m.addConstr(2*x + y <= 2)
c3=m.addConstr(x + 2*y == 2)
m.setObjective(y, gp.GRB.MAXIMIZE)
m.optimize()
print(x.X, y.X) # should be (0,1)
print(c1.Slack, c2.Slack, c3.Slack) # should be (0,1,0)
# note for c2 slack:
# what is the value of 2  y  2*x at the optimal solution? Riley
1
Please sign in to leave a comment.
Comments
1 comment