## Produce .lst, .gdx and .xls for each solve statement

Problems with syntax of GAMS
sam_Hab
User Posts: 10
Joined: 8 months ago

### Produce .lst, .gdx and .xls for each solve statement

Hello everyone,

I am trying to generate random problems using gams, solve them and then save the solutions into different Excel files, .lst files and .gdx files.

I am trying to figure out how to change the file name and produce a .lst, .xls and .gdx files for each solve statement

The code I have below only uses the same file and I only have one Excel file of the last run

Code: Select all

``````Scalar product ;
Scalar supplier ;
Scalar time ;

Sets i products / i0*i50 /
j suppliers / j0*j50  /
t time periods / t0*t50 /
sub_j(j)   dynamic subset for j
sub_t(t)   dynamic subset for t
sub_i(i)   dynamic subset for i ;

Alias ( k , t ) ;
Parameter D( i , t )  ;
Parameter P( i , j ) ;
Parameter H( i )  ;
Parameter O( j )  ;

Variables x ( i , j , t )
y ( j , t )
R( i , t )
Z( i , j , t )
cost ;
Positive Variables x ,R, Z;
Binary Variable y ;
Equations obj objective function
con1 ( i , t ) ;

obj ..
cost =E= sum ( ( sub_i(i) , sub_j(j) , sub_t(t) ) ,P( i , j )* x ( i , j , t ))+sum ( ( sub_j(j) , sub_t(t) ) ,O( j )* y ( j , t ) )
+ sum ( ( sub_i(i) , sub_t(t) ) ,H( i ) * ( sum ( k\$ ( ord ( t ) GE ord ( k ) ) , sum ( sub_j(j) , x ( i , j , k))-D( i , k ) ) ) ) ;

con1 ( sub_i(i) , sub_t(t) ) ..
R( i , t ) =E= sum ( k\$ ( ord ( t ) GE ord ( k ) ) , sum ( sub_j(j) , x ( i , j , k))-D( i , k ) ) ;

display "---------------------formulation ----------------------";

option optcr =0;
option limrow =0;
option limcol =0;

Model Regular /all/;

for ( product = 1 to 3 by 1,
for( supplier = 1 to 3 by 1,
for ( time = 1 to 3 by 1,

sub_i(i) = ord(i) <= product;
sub_j(j) = ord(j) <= supplier;
sub_t(t) = ord(t) <= time;

D(sub_i,sub_t) = uniformint(10,20);
P(sub_i,sub_j) = uniformint(10,20);
H(sub_i) = uniformint(1,4);
O(sub_j) = uniformint(10,20);

Solve Regular minimizing cost using mip ;
execute_unload "output.gdx" sub_i, sub_j, sub_t, P, O, D ;
execute 'gdxxrw.exe output.gdx o=output.xls set=sub_i rng=A1 set=sub_j rng=A5 set=sub_t rng=A10 par=P rng=A15 par=O rng=A20 par=D rng=A25';
);
);
);

``````
Any help would be appreciated!
Thanks

Renger
Posts: 263
Joined: 2 years ago

### Re: Produce .lst, .gdx and .xls for each solve statement

Hi
Take a look at this https://support.gams.com/gams:loop_over_file_names. You probably also want to have a look in the documentation on setlocal or setglobal.
Cheers
Renger

sam_Hab
User Posts: 10
Joined: 8 months ago

### Re: Produce .lst, .gdx and .xls for each solve statement

Hello,

Thanks for your answer, I was able to create a .gdx file and the corresponding .xls file for each solve statement but I am not able to produce a new .lst file for each solve statement. Do you have any suggestions?

Thanks

Renger
Posts: 263
Joined: 2 years ago

### Re: Produce .lst, .gdx and .xls for each solve statement

Hi

You could use setglobal to define your scenarios and then write a batch "myrun.bat" file with the following lines (I usually do stuff like this writing a small gams program with the put utility and the loops I use in the model):

call gams --scenario=myscenario1_1_1 --myparam1=1 myparam2=1 myparam3=1 o=myscenario1_1_1.lst
call gams --scenario=myscenario1_1_2 --myparam1=1 myparam2=1 myparam3=2 o=myscenario1_1_2.lst
call gams --scenario=myscenario1_1_3 --myparam1=1 myparam2=1 myparam3=2 o=myscenario1_1_3.lst
....

In your model file you remove the loops and define the parameters using %myparam1%, %myparam2%, %myparam3% to define each run.
(something like
if %myparam1% = 1, ....)

and use %scenario% for renaming the gdx file. Instead of using myout.gdx you use %scenario%.gdx.

You now can run the batch file that starts gams for each scenario separately.
Hope this helps

Cheers
Renger