put command

Hello!

My program in GAMS is working, but some results are not what I was expecting. I need to check some of my equations line by line, to see what value each variable has in every iteration. So I need a report in excel, which I know will be done with the put command. What I want to see for example is this :

Net9(i,f,t)$(Ainc(i,f)=1) .. K(i,t) =e= sum(j$(Ainc(j,f)=-1),K(j,t)) + 2*((R(f)/Zbase)*(P_line(f,t)/Sbase) +
                                 	    				  (X(f)/Zbase)*(Q_line(f,t)/Sbase));



  • -------k(i) - k(j) – P() —Q()
    iter1: 5 ----4 -----202 —150
    iter2: 7 ----2 -----420 —340 …

Would appreciate some help with this.

Hi

Why use the put command to write to Excel. The best tool for doing this is gdxxrw:

Net9(i,f,t)$(Ainc(i,f)=1) .. K(i,t) =e= sum(j$(Ainc(j,f)=-1),K(j,t)) + 2*((R(f)/Zbase)*(P_line(f,t)/Sbase) +
                                 	    				  (X(f)/Zbase)*(Q_line(f,t)/Sbase));


parameter eq_net9(*,i,f,t);
loop(f,
    eq_net9("K", i,f,t) = K.L(i,t);
    eq_net9("Ksum", i,f,t) = sum(j$(Ainc(j,f)=-1),K.L(j,t));
    etc...
);
Execute_Unload "results.gdx", eq_net9;
execute 'gdxxrw results.gdx par=eq_net9 rng=eq_net9!a1

Cheers
Renger

Thank you very much! It works that way, however it’s not very easy to read, since all the values of K are printed first, then sumK, Pline etc… Thus can’t check each equation. Ideally what I want to see is :

---------------------K()-------sumK()---------P_line()-------- Q_line()
eq_net9(1,1,1)–k(1,1)----sumK(1,1)—P_line(1,1)----Q_line(1,1)
eq_net9(2,1,1)–k(2,1)----sumK(2,1)—P_line(2,1)----Q_line(2,1)

just redefine the parameter as

eq_net9(i,f,t, *)

and adjust the export command as follows:

execute 'gdxxrw results.gdx par=eq_net9 rng=eq_net9!a1 Rdim=3 Cdim=1

This will correct the order and you will have the output according to equations.
CHeers
Renger

Thank you again. It’s getting better and better every time :smiley:
How come it works correctly since you used only the f argument inside the loop? Also how can you put labels for the sets as well?

Hi
I only use the f loop because you use K(i,t) in an equation with the additional index f. i and t are on both sides of the assignment but f is missing on the right:

loop(f, 
	eq_net9("K", i,f,t) = K.L(i,t);

);
If K was also defined over f, you don’t have to use a loop to assign values and this would do the job:

eq_net9("K", i,f,t) = K.L(i,f,t);

You can’t easily export the labels, however, you can define your sets more explicitly. For example:

i /Sector1*Sector12/, j /Iter1*Iter24/

instead of

i /1*12/, j /1*24/

.

You will than have “Sector1” , “Iter1”, etc. instead of 1, 1 in your excel table.

CHeers
Renger