Loop through Compile Time Variables using $set

Problems with syntax of GAMS
Post Reply
Translucent
User
User
Posts: 1
Joined: 3 years ago

Loop through Compile Time Variables using $set

Post by Translucent »

I would like to loop through a set of Compile Time Variables without repeatedly redefining their content using the $set option.

For example, i have the following code.

$set A 123
Execute 'gams %GAMS_Model% --DataPath=%A%';

$set A 456
Execute 'gams %GAMS_Model% --DataPath=%A%';

$set A 789
Execute 'gams %GAMS_Model% --DataPath=%A%';

I have nearly 1000 such Datapaths. Is there a way to loop through all 1,000 values, without typing 2,000 lines of code?

Any suggestions are appreciated.
User avatar
bussieck
Moderator
Moderator
Posts: 1042
Joined: 7 years ago

Re: Loop through Compile Time Variables using $set

Post by bussieck »

It seems that you use the CTV for writing different file names. The varying file name part seems to be relatively simple (in your example a number). I would do this with a driving set and the put_utility 'exec' all at run-time:

Code: Select all

set run / 123, 465, 789 /;
loop(run,
  put_utility 'exec' / 'gams %GAMS_Model% --DataPath=' run.tl:0;
);
Search the forum for put_utility and you will find many similar topics.

-Michael
Post Reply