Problem with IF between 2 variables

Hi all,

Problem with if between two variables
I have a variable (positive) discharge(i) and I want that a second variable DS(i) to be:
200 if discharge(i) >0 and 0 if discharge(i)=0

I’ve tried:
Eq15(i)…200=e=DS(i)(discharge(i)>0) Eq16(i)..0=e=DS(i)(discharge(i)=0)

Thanks
Regards

You cannot have ‘if’ condition on variables in an optimization formulation
define a binary variable y(i) which is 0 if discharge(i) is 0 and 1 otherwise.
DS(i) =e= 200*y(i);

You can establish the relationship between y(i) an discharge(i) as follows:
discharge(i) =l= M*y(i);
where M is a large constant (you can set it to the upper bound of discharge(i).

This condition ensures that, if discharge is positive then y(i) is 1.
If your objective naturally favors minimizing DS(i), the above equations should be enough.

  • Atharv

Thanks
I’ll try it