Dear staff,
I would like to receive some help writing the following constraint for a mathematical model.
Within a graph, I define arcs (i-j) where “i” and “j” are nodes. For each arc and node, I also have the following variables and parameters:
p(i) binary variable
p(j) binary variable
a(i,j) continuous variable
C(i,j) parameter
H(i) parameter
H(j) parameter
I would like to write a constraint expressing the following conditions:
if p(i) = 1 and p(j) = 0, then a(i,j) <= C(i,j)*H(j)
if p(i) = 0 and p(j) = 1, then a(i,j) <= C(i,j)*H(i)
if p(i) = 0 and p(j) = 0, then a(i,j) <= C(i,j) * (H(i) + H(j))/2
if p(i) = 1 and p(j) = 1, then a(i,j) <= C(i,j)
If you have any suggestions on how to write the above conditions within a constraint, I will be glad.
Thank you,
Best answer by Marcel Hunting
This is getting somewhat ugly. I would use indicator constraints; see section 14.2.4 in the Language Reference for more information.
p(i) = 1 → a(i,j) <= C(i,j)*H(j)*(1-p(j)) + C(i,j)*p(j)
p(j) = 1 → a(i,j) <= C(i,j)*H(i)*(1-p(i)) + C(i,j)*p(i)
p(i) = 0 → a(i,j) <= C(i,j) * (H(i) + H(j))/2 * (1-p(j)) + M*p(j)
Here M is a big number (“big M”). The left part of each of these three constraints represents the activating condition.
Please note that indicator constraints are only supported by CPLEX and Gurobi.