Indicator constraint for multiplying two binary variables
AnsweredDear community,
I have a constraint of the form:
if x(i, j, k) == 1: sum (over t) {p(i, j, k, t) * u(i, j, t)} == 1
Could you please advise me on how to model it using Gurobi? Here x, u, and t are binary variables. Below is how I tried and then I get the error "TypeError: must be real number, not gurobipy.QuadExpr".
for i in I:
for j in J:
for k in K:
model.addConstr((x[i, j, k] == 1) >> (quicksum(p[i, j, k, t] * u[i, j, t] for t in T) == 1))
Regards
Buddi
-
Hi Charitha,
Indicator constraints only allow linear constraints. What you could do is to introduce additional variables that model the binary products and use those new variables in your indicator constraint, i.e.:
f(i, j, k, t) = p(i, j, k, t) * u(i, j, t)
if x(i, j, k) = 1: sum (over t) f(i, j, k, t) = 1Apart from that, would it work to immediately reformulate the indicator constraint to the following?
sum (over t) f(i, j, k, t) = x(i, j, k)
Best regards,
Mario0 -
Thank you. I think this works for me.
I also have another question, but since it is not directly a follow-up to this thread, I posted it here.
Appreciate if you could have a look at it as well.
Best,
Charitha
0
Please sign in to leave a comment.
Comments
2 comments