Indicator Constraints with Integers
AnsweredHello community,
I am new in Gurobi so maybe my problem is simple but I just don't have the experience yet. I have been trying to solve the following indicator constraint, where the the two objects to be compared are integers. at(j) is an integer variable which saves the completion time of a task j. T is the time horizon and it is discrete. In my model T is a range. I have tried dozens of variants but none seem to work. The constraint is the following:
The following is one of the codes that I have tried. dummy 311 is integer and dummy312 is binary.
for j in VN:
for k in K:
for t in T:
m.addConstr(dummy311[j,t] == (T[t] - at[j]))
m.addConstr(dummy311[j,t]<= Tmax*dummy312[j,t])
m.addConstr((dummy312[j,t] == 0) >> ((quicksum(x[i,j,k] for i in Vk)) <= (z[g[f[j]],k,t])))
It would be great if you could help me out.
Regards,
Gabriel
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Hi Gabriel,
Indicator constraints must use binary variables and values to set a condition. In your case they are integer, hence the error
0 -
Hi Daniel,
Thank you for the quick response. I am aware of this binary restriction. This is why I added the dummy variables but it still doesn't work. Do you know any other way around this issue?
0 -
I would guess that this does not work:
m.addConstr(dummy311[j,t] == (T[t] - at[j]))
as the difference should be a general integer.... probably you want to to say something like
T[t]-at[j] <= Max(T[t]-at[j]:t,j)*(1-dummy311[j,t])
at[j]-T[t] <= Max(T[t]-at[j]:t,j)*(1-dummy311[j,t])
the maximum you should compute. Those constraint force that T[t] == at[j] whenever dummy311[j,t]=1
0 -
Hi Daniel,
thank you again for your input. It was very helpful. I managed to create an alternative and my model runs perfectly now. Just in case you are interested the code that I implemented is the following:
# Constraint 31
for j in VN:
for t in T:
for k in K:
m.addConstr((dummy312[j,t] == 1) >> (at[j] == T[t]),
"constraint31a[%s,%s]" % (j,t))
m.addConstr((dummy312[j,t] == 1) >> ((quicksum(x[i,j,k] for i in Vk)) <= z[g[f[j]],k,t]),
"constraint31b[%s,%s,%s]" % (j,t,k))
for j in VN:
m.addConstr(quicksum(dummy312[j,t] for t in T) == 1,
"constraint31c[%s,%s]" % (j,t))0
Post is closed for comments.
Comments
5 comments