BEAst
BEAst

Reputation: 219

how to define a if statement in the constraint - GAMS optimization

I trying to find optimum behavior in order to achieve greatest reward of this following formula. The program is running, but the output is the same as the input which means something is wrong with the code.

im trying to define price elasticity, where I need to find optimium price tariffs during peak and low peak hours, which are defined specific hours of the day. High peak is 16-23 oclock and low peak is the rest of hours. My question is it possible to define an if statement in the constraint?

Con4(hpd)$(if(ord(hpd)>15)and(ord(hpd)<23)).. P_H(hpd) =E= PHP;

Con5(hpd)$((ord(hpd)<16)and(ord(hpd)>22)).. P_H(hpd) =E= PLP;

All best,

Upvotes: 2

Views: 1370

Answers (1)

Martin Bonde
Martin Bonde

Reputation: 556

You are almost there. You don't need to write if (the dollar sign is basically an if), just the conditional itself, as in the second equation. The second equation should be an or instead of and.

A small pet peeve, I try to use .val instead of ord(), as ord gets messy when the set does not start at 1. Val gives you the numerical value of a set element, assuming the set elements are numbers.

Con4(hpd)$(hpd.val>=16 and hpd.val<=22).. P_H(hpd) =E= PHP;
Con5(hpd)$(hpd.val<16 or hpd.val>22).. P_H(hpd) =E= PLP;

Upvotes: 1

Related Questions