Urgent HELP! , GDX output in a loop uses old variable values Topic is solved

Problems with syntax of GAMS
Post Reply
sam_Hab
User
User
Posts: 10
Joined: 5 years ago

Urgent HELP! , GDX output in a loop uses old variable values

Post by sam_Hab »

Hello everyone,
I am trying to solve several problems in a loop and for each, I am generating the corresponding .gdx and .xlsx file

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 test /all/;
Scalar num /0/;
for ( product = 5 to 15 by 5,
    for( supplier = 5 to 10 by 5,
       for ( time = 5 to 10 by 5,

           sub_i(i) = ord(i) <= product;
           sub_j(j) = ord(j) <= supplier;
           sub_t(t) = ord(t) <= time;
           num = num+1     ;
           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);
           display num;
           Solve test minimizing cost using mip ;
           Put_utility 'log'    / 'Create GDX File F:\Sameh\test_'product:0:0'_'supplier:0:0'_'time:0:0'_p'num:0:0'.gdx';
           Put_utility 'gdxout' / 'F:\Sameh\test_'product:0:0'_'supplier:0:0'_'time:0:0'_p'num:0:0'.gdx' ;
           Execute_unload;
           Put_utility 'exec' / 'gdx2xls  F:\Sameh\test_'product:0:0'_'supplier:0:0'_'time:0:0'_p'num:0:0'.gdx';

       );
    );
);
Everything works fine until problem number 3:
The problem size is i= 5, j= 10 and t = 5
However, in the gdx file the x and y variables are messed up with previous x and y from the previous problem which is problem 2 having i= 5, j= 5 and t = 10
It looks like when the size of the variable becomes smaller for example t here from 10 becomes 5 in the loop it uses the old variable values
Do you have any suggestions, please?
any help would be appreciated
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Urgent HELP! , GDX output in a loop uses old variable values

Post by Renger »

Hi
You defined the variables over i, j and t, so if you solve the model for a smaller subset, the variables that are not part of the subset aren't changed and keep the values of the previous solve.
If you add some lines where you initialize all the variable with EPS

Code: Select all

loop(...
  loop(...
     loop(..
		x.L ( i , j , t ) = EPS;
		y.L( j , t ) = EPS;
		R.L( i , t ) = EPS;
		Z.L( i , j , t ) = EPS;
                solve...
);););
they will be easily recognized in your output.

Hope this helps
CHeers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Jarenka
User
User
Posts: 64
Joined: 5 years ago

Re: Urgent HELP! , GDX output in a loop uses old variable values

Post by Jarenka »

Dear,
I have a question concerning gdx-output changing path. I am writing a code in a normal *.gms file named LINE2.gms. I press F10 and automatically comes LINE2.gdx file in the same directory.
I would like to have this LINE2.gdx file placed in a different directory, for example: ""gdx"".
I tried option:

Code: Select all

$gdxOut \gdx\LINE2.gdx
but it does not work.

Irena
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Urgent HELP! , GDX output in a loop uses old variable values

Post by bussieck »

With F10 in GAMS Studio this adds the command line parameter GDX=default to the list of GAMS command line parameters. If you want the GDX file somewhere else, add GDX=gdx\myfile.gdx to the list of command line parameter and hit F9 or F10. You can use "default" which becomes the name of the main input file anymore:
Capture.JPG
-Michael
Jarenka
User
User
Posts: 64
Joined: 5 years ago

Re: Urgent HELP! , GDX output in a loop uses old variable values

Post by Jarenka »

Thank you!

It seems it works on my 64bit computer, but I couldn't make it work on 32bit. There is no commend line in GAMS Studio installed on 32bit computer.
Anyway, in case when you want to call/include this mymodel.gdx file from that folder, like this:

Code: Select all

$gdxin mymodel.gdx
$load ...
you just press F10 and GAMS searches the mymodel.gdx file both in default directory and in my newly created gdx-directory?

Irena

NB. The picture presents GAMS Studio on my computer 32bit - there is no commend line there:
Attachments
GAMS Studio.JPG
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Urgent HELP! , GDX output in a loop uses old variable values

Post by bussieck »

  • You can make the option window visible by selecting it in the menu View->Option.
  • The creation of the GDX file via F10 (or via the command line and F9) has absolutely nothing to do with how you read it in a subsequent run. $gdxIn requires an absolute or relative path to the GDX file
-Michael
Jarenka
User
User
Posts: 64
Joined: 5 years ago

Re: Urgent HELP! , GDX output in a loop uses old variable values

Post by Jarenka »

I have *.gdx files (created externally from R program) that are placed in a different directory "gdx", which is a sub-directory to my working directory. I want to read them in to GAMS.
I tried the options above, but they do not work.
How can I include them into GAMS from the "gdx" directory. I tried this:

Code: Select all

$gdxin gdx/Income_2011.gdx
$load ypat qpe
$gdxin 
It does not recognize the sub-directory.
Jarenka
User
User
Posts: 64
Joined: 5 years ago

Re: Urgent HELP! , GDX output in a loop uses old variable values

Post by Jarenka »

Now it works. It should be "\" and not "/". :D
Post Reply