Set declatation with scalar inside

Problems with syntax of GAMS
Post Reply
MES
User
User
Posts: 14
Joined: 4 years ago

Set declatation with scalar inside

Post by MES »

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!
User avatar
bussieck
Moderator
Moderator
Posts: 1038
Joined: 7 years ago

Re: Set declatation with scalar inside

Post by bussieck »

You need to understand the difference between compile- and runtime in GAMS (https://www.gams.com/latest/docs/UG_Gam ... ll_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_Gam ... ametersEtc):

Code: Select all

scalar t_max / 100 /;
$eval T_MAX t_max
set t / 0*%T_MAX% /;
or

Code: Select all

$if not set T_MAX $set T_MAX 100
scalar t_max / %T_MAX% /;
set t / 0*%T_MAX% /;
-Michael
MES
User
User
Posts: 14
Joined: 4 years ago

Re: Set declatation with scalar inside

Post by MES »

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:

Code: Select all

Dmax=sum(i,d(i));

scalar   t_max;

t_max= Dmax+10  ;

set       t    / 0*t_max /  ;
User avatar
bussieck
Moderator
Moderator
Posts: 1038
Joined: 7 years ago

Re: Set declatation with scalar inside

Post by bussieck »

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:

Code: Select all

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
Post Reply