How to deal with the restriction of not being able to use strictly greater/smaller constraints?
AnsweredHi,
I tried to use BigM for conditional constraints.
The length of Part 1,2,3,4, can be denoted as Q1,Q2,Q3,Q4.
The accumulated length after part 1,2,3,4 join can be denoted as AQ1, AQ2, AQ3, AQ4 respectively.
The order for these parts is also part of the optimized variable.
I have a threshold TH, I want to know which part starts to be longer than the threshold. The part that meets: AQQ < TH < AQ is the part I am looking for. (Binary4=1)
(Q1,Q2,Q3,Q4 are all variables)
Four binary variables Binary1, Binary2, Binary3, and Binary4 are used to formulate this.
However, when AQ= TH, it would lead to the problem of having two parts that meet the constraints.
Assume the order of the part is 1>2>3>4
AQ2=AQ1+AQ2
AQ3=AQ1+AQ2+AQ3
If AQ2=TH, then AQ3Q3 would also equal TH.
In this case, Binary4[2] and Binary4[3] all equal 1.
How do I modify the equation to let Binbary4[2]=0?
I tried to add another Binary5 to identify the situation when AQ=TH, however, in my case, the two values are not exactly the same (i.e., AQ2=10.818181818181806, TH=10.81818181818)
For i in range(1,5):
m.addConstr((AQ[i]Q[i])>=(TH+eps(1Binary1[i])*M))
m.addConstr((AQ[i]Q[i])<=(TH+eps+(Binary1[i]*M)))
m.addConstr((AQ[i]+eps(1Binary2[i])*M)<=TH)
m.addConstr((AQ[i]+eps+(Binary2[i]*M))>=TH)
m.addConstr(Binary3[i]==Binary1[i]+Binary2[i])
m.addConstr((Binary3[i]==1)>>(Binary4[i]==0))
m.addConstr((Binary3[i]==0)>>(Binary4[i]==1))

I am not sure if I understand your setting. But isn't it enough to change the sign of eps, i.e.,
m.addConstr((AQ[i]Q[i])>=(THeps(1Binary1[i])*M)) m.addConstr((AQ[i]Q[i])<=(THeps+(Binary1[i]*M)))
0 
Hi Marika,
I tried to change the sign of eps, but it would lead to both Binary4[2] and Binary4[3] =0.
I want to have Binary4[2]=0 but Binary4[3]=1Is there any other way that might be able to solve this issue?
Thanks for helping0 
I assume there is only one part for which AQQ <= TH < AQ holds. You need to have B1=1 if AQQ <= TH and B2=1 if TH < AQ. Then with Model.addGenConstrAnd() you can get B4=1 if both B1 and B2 are one. This should then only hold for 3 in your example. For 2 TH < AQ is not fulfilled.
For i in range(1,5): m.addConstr((AQ[i]Q[i])<=(TH + tol + (1Binary1[i])*M)) m.addConstr((AQ[i]Q[i])>=(TH + tol  (Binary1[i]*M))) m.addConstr(TH +eps <= (AQ[i] + (1Binary2[i])*M)) m.addConstr(TH +eps >= (AQ[i]  (Binary2[i]*M))) m.addGenConstrAnd(Binary4[i], [Binary1[i],Binary2[i]])
tol is a small tolerance, e.g. FeasibilityTol. But for the < check, eps needs to be a bigger value.
0 
Hi Marika,
Thanks for the reply. I'll check out how to use Model.addGenConstrAnd().
Thanks again for your help.
0
Please sign in to leave a comment.
Comments
4 comments