I have a GAMS code where I want an if statement. I've read about dollar condition and I thought it could help me. Reading GAMS user guide, it says:
The Dollar Condition
This section introduces the dollar operator , which is one of the most powerful features of GAMS. The dollar operator operates with a logical condition. The term $(condition) can be read as 'such that condition is valid' where condition is a logical condition.
Attention: The dollar logical conditions cannot contain variables. Variable attributes (like .l and .m) are permitted however.
The dollar operator is used to model conditional assignments, expressions, and equations. The following subsection provides an example that will clarify its use. The next section will deal individually with the topic of using dollar conditions to model conditional assignments, expressions, and equations respectively.
I have tryed it in my code, but still I found always the same error:
*** Error 53 in C:\route\Filename.gms
Endogenous $ operation not allowed
This is my actual code:
ACUMULADO_FIN_GRUPOS(k,l,t)..
GA(k,l,t)$(GA(k,l,t) GE GT(k,l)) =E= 0 ;
(I want to change value of a variable to 0 if it is greater or equal to another variable). I have also tryed with .l attribute:
ACUMULADO_FIN_GRUPOS(k,l,t)..
GA(k,l,t)$(GA(k,l,t).l GE GT(k,l).l) =E= 0 ;
but then next error appears (just in the .l definition)
*** Error 8 in C:\route\Filename.gms
')' expected
Please, could anyone help?
Thanks in advance!!
I have seen that my previous code was not correct, the correct way is:
ACUMULADO_FIN_GRUPOS(k,l,t)..
GA(k,l,t)$(GA.l(k,l,t) GE GT.l(k,l)) =E= 0 ;
with the .l
previous to set definition.
来源:https://stackoverflow.com/questions/37861471/use-variable-in-gams-dollar