Error with if and elseif in GAMS software: Uncontrolled set entered as constant

Hello, I wrote the following code in GAMS, but it shows the following error for WindSpeed after running. All symbols are scalars, and WindSpeed is data dependent on i and j. Could you please guide me?

CODE:

If (WindSpeed(i, j) < Vin_W or WindSpeed(i, j) > Vout_W,
         Pwind(i, j) =e= 0;
Elseif Vin_W <= WindSpeed(i, j) and WindSpeed(i, j) < Vrat_W,
         Pwind(i, j) =e= Prat_W*(WindSpeed(i, j)-Vin_W)/(Vrat_W-Vin_W);
Elseif Vrat_W <= WindSpeed(i, j) and WindSpeed(i, j) <= Vout_W,
         Pwind(i, j) =e= Prat_W);

ERROR:

Uncontrolled set entered as constant

This does just not work. If and ElseIf can’t be used to define different constraints. Assuming the symbols in the condition, i.e. WindSpeed, Vin_W, Vout_W, … are all exogenous (i.e. parameters, not variables) then you can just do

eq1(i,j)$(WindSpeed(i, j) < Vin_W or WindSpeed(i, j) > Vout_W)..  Pwind(i, j) =e= 0;
eq2(i,j)$(Vin_W <= WindSpeed(i, j) and WindSpeed(i, j) < Vrat_W).. Pwind(i, j) =e= Prat_W*(WindSpeed(i, j)-Vin_W)/(Vrat_W-Vin_W);
eq3(i,j)$(Vrat_W <= WindSpeed(i, j) and WindSpeed(i, j) <= Vout_W).. Pwind(i, j) =e= Prat_W;

but my fear is that some of these symbols are variables. This is much more complicated and you need to look into ways how to linearize these logical constraints. Questions like this have been asked often in this forum and I suggest that you search for logical constraint and for the recommended book to study and linearize logical constraints by HP Williams.

Good luck.
-Michael

1 Like

thank you Now it is fixed and working.

1 Like