variable as a condition for a equation

Problems with modeling
Post Reply
akram
User
User
Posts: 2
Joined: 3 years ago

variable as a condition for a equation

Post by akram »

Hi All!

I have problem related to conditional statement using variables. I know that its not possible to use variable with a dollar condition for an equation so what can be an alternative?
For example:
I want to model this logic
there are two variables x and y and a parameter z
If x<z then use
eq1.. deltaT=x-y
If x>z then use
eq2.. deltaT=y-x

variable x has no upper and lower bounds as it has to be modelled that way.
I think that binary variables might be a solution for this but i am not sure how. I hope anyone with similar experience can help.

Cheers
Nouman
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: variable as a condition for a equation

Post by abhosekar »

Akram,

This is an incorrect way to think when it comes to optimization models. Constraints in optimization are not sequentially executed as a normal code and therefore, such conditions that you are mentioning do not make sense. You say if x < z, but at the time when the model is generated or when the solver is reading it there is no value for x or for z which makes it unclear on what your model actually is.

For your case, you have to use big-M constraint. Use a binary variable b which is 1 if x > z and 0 otherwise.

x =g= z - M(1- b);
x =l= z - Mb;

Now coming to deltaT

deltaT =g= x - y - Mb;
deltaT =l= x - y + Mb;

deltaT =g= y - x - M(1-b);
deltaT =l= y - x + M(1-b);

M is a big number (not too big). To understand the logic behind these constraints, first put b = 0 and read everything. Then repeat the procedure by putting b=1

- Atharv
Post Reply