Is there something like varible in other languages in GAMS for softcoding? Topic is solved

Problems with syntax of GAMS
Post Reply
GAMS_practitioner
User
User
Posts: 9
Joined: 1 year ago

Is there something like varible in other languages in GAMS for softcoding?

Post by GAMS_practitioner »

Hi friends,

I'd like to write a model in GAMS and run it for a number of different data. So, for example, in one run I might have a set j /1*30/ and in other run I might want to change it to set j/1*50/. And many other similar cases.
So, when this is the case, in other languages you go with softcoding like: total_nodes = 30 and then set j /1* total_nodes/

However, it seems as if there's no such thing as variable (with that definition) in GAMS. One thing is to use parameters. But it there any direct thing available?
User avatar
bussieck
Moderator
Moderator
Posts: 1038
Joined: 7 years ago

Re: Is there something like varible in other languages in GAMS for softcoding?

Post by bussieck »

The size of a static set needs to be known at compile time. So you have two ways:

1) use a compile time variable (https://www.gams.com/latest/docs/UG_Gam ... 1_variable) and use that to set the size of set j:

Code: Select all

$if not set jsize $set jsize 30
set j /1*%jsize% /;
When you run GAMS you can pass jsize as --jsize=50 as a command line parameter.

2) if jsize is calculated with some complex logic in your model and not easily known at compile time, you can use a super set jj with a size that is an overestimation of jsize and use a dynamic set with the calculated size:

Code: Select all

set jj /1*1000 /, j(jj);
scalar jsize; jsize = uniformInt(10,1000);
j(jj) = ord(jj)<=jsize;
display jsize, j;
-Michael
Post Reply