Hi,
I would like to do something like this, with t_max as a scalar:
set t /0*t_max/ ;
The problem is that this doesn`t work in GAMS. Is there a syntax which I could use?
Thanks in advance!
Hi,
I would like to do something like this, with t_max as a scalar:
set t /0*t_max/ ;
The problem is that this doesn`t work in GAMS. Is there a syntax which I could use?
Thanks in advance!
You need to understand the difference between compile- and runtime in GAMS (https://www.gams.com/latest/docs/UG_GamsCall.html#UG_GamsCall_TwoPass). All potential set elements need to be known at compile time. Therefore you can use a scalar to declare labels. You can though use the value of the scalar at compile time to define the set elements, or use a compile time constant to both declare the value of the scalar and the set elements. Compile time variables can be fed in to GAMS via command line double-dash parameters (https://www.gams.com/latest/docs/UG_GamsCall.html#UG_GamsCall_DoubleDashParametersEtc):
scalar t_max / 100 /;
$eval T_MAX t_max
set t / 0*%T_MAX% /;
or
$if not set T_MAX $set T_MAX 100
scalar t_max / %T_MAX% /;
set t / 0*%T_MAX% /;
-Michael
Thanks for your reply.
So do I understand correctly that if t_max has to be calculated, it´s not possible to use it for the defintion of the set t?
That´s my current (not working) code:
Dmax=sum(i,d(i));
scalar t_max;
t_max= Dmax+10 ;
set t / 0*t_max / ;
Correct. What one usually does it to overestimate t_max to declare a superset tt (don’t make BIG too large, GAMS needs to store all these labels) and then work with a dynamic set t:
Dmax=sum(i,d(i));
scalar t_max;
t_max= Dmax+10 ;
$if not set BIG $set BIG 1000
set tt / 0*%BIG% /;
set t(tt) ;
t(tt) = ord(tt)<=tmax;
-Michael