Defining an if condition in a constraint

You need to set up a binary variable (integer variable constrained by 0 <= Z[I,t] <= 1) that takes a different value depending on the sign of Pb[I,t]. (C.f. Big M method - Wikipedia )

Then you can simply write your constraint as

e[i,t] - e[i,t.-1] + (0.85 + (-1.11-0.85)*Z[i,t]) * Pb[i,t.-1] == 0.0

Edit: I just realised it is a bit trickier still. The product between the binary and the continuous variable needs to be re-written using another artificial variable and a few constraints if you want a mixed-integer linear formulation.

4 Likes