Thank Michael, as always a very useful reply
On Wednesday, May 29, 2013 6:53:43 PM UTC+12, Michael Bussieck wrote:
Andrew,
-
You could dump the set.emission to your spreadsheet to have all known labels in the tables where you need them prior to a merge/clear call of gdxxrw
-
In GAMS there is a single list of labels. The order of this list is the entry order of the label seen by the compiler. GAMS maintains this order in every symbol. So in your example
set report1_headings / capacity, generation, emissions /;
set report2_headings / unitname, region, capacity, emissions /;
the internal label order is capacity, generation, emissions, unitname, region. So all displays, loops, exports etc of symbols will follow this order. If you want a different order in your reports etc, you either need to prefix the labels (as you have done before) or introduce a sort index in the first position:
set seq /11000/, seq3(seq) /31000/;
set emissions / nox, so2, co2 /;
set report1_headings / 1.capacity, 2.generation, 3.emissions /;
set report2_headings / 1.unitname, 2.region, 3.capacity, 4.emissions /;
set report3_headings / 1.capacity, 2.generation, set.seq3:set.emissions /;
Now when you create reports with put you can loop over
alias (*,hdr); file f;
put f ‘report1’; loop(report1_headings(seq,hdr), put / hdr.tl);
put / ‘report2’; loop(report2_headings(seq,hdr), put / hdr.tl);
put / ‘report3’; loop(report3_headings(seq,hdr), put / hdr.tl);
Just make sure that the labels of seq are always in correct order e.g. by making sure they do not show up as labels in other symbols. So 1,2,3 is probably no a good choice. mysort1,mysort2,… would be a better choice. If you are exporting to Excel, you will have an additional row/column for this sort index, but Excel allows you nicely to hide rows and columns, so that shouldn’t be too bad.
Just to be complete, there is a predefined symbol in GAMS that allows you to loop through a symbol in the alphabetical order of its elements labels (also knows as UEL = unique element in GAMS lingo): SortedUels:
set report1_headings / capacity, generation, emissions /;
set report2_headings / unitname, region, capacity, emissions /;
alias (*,u); file f; put f ‘report2 sorted’;
loop(SortedUels(u,report2_headings), put / report2_headings.tl);
gives you:
report2 sorted
capacity
emissions
region
unitname
Sorting in GAMS can be awkward/impossible if different sets share the same labels.
Hope this helps anyway.
Michael Bussieck - GAMSWorld Coordinator
On Tuesday, May 28, 2013 6:39:02 PM UTC-4, AC wrote:
Hi Renger
We do use gdxxrw for some reports, and your comment lead me to a feature I simply didn’t know about until now: the MERGE option in the gdxxrw.
That will definitely help with some reports and give us exactly what we need - a big thanks!
We are still interested in general however for a couple of reasons.
(1) unfortunately some of our reports have some unknown set elements so we cannot set them up beforehand. For example
set report1_headings / capacity, generation, set.emissions /
The emissions set is not know before hand, it is data driven, the user can set up as many or as few emission types as they like in their dataset. So we cannot set up the report template headings a priori.
(2) some of our reports have very specific formatting requirements and cannot just be dumped in as a table into Excel easily. We make these as .csv via the PUT command and use loops over our report heading sets in various places. We want the ordering to be in the order we defined the elements.
Any further ideas on the ordering problem?
Cheers
Andrew
On Tuesday, May 28, 2013 7:02:14 PM UTC+12, Renger van Nieuwkoop wrote:
Hi Andrew
Why do you use the dump and not prepare your tables with the headings in the proper order and use gdxxrw?
Gdxxrw will then write the results accordingly.
Cheers
Renger
From: gams...@googlegroups.com [mailto:gams...@googlegroups.com] On Behalf Of AC
Sent: Dienstag, 28. Mai 2013 01:04
To: gams...@googlegroups.com
Cc: sup...@gams.com
Subject: Controling set ordering where element names are not unique
Hi
In the past we have not found a solution to this problem, but are wondering if something has changed since last time we looked.
We have a couple of sets that share some element identifiers. For example
set report1_headings / capacity, generation, emissions /;
set report2_headings / unitname, region, capacity, emissions /;
What we really want is for the elements in these sets to be ordered in the same order as we declare them. Unfortunately they are not, the elements are ordered in the order that they first appear in the code. For example
display report1_headings
display report2_headings;
produces
---- 3 SET report1_headings
capacity , generation, emissions
---- 4 SET report2_headings
capacity , emissions, unitname , region
As you can guess from the set names these are report headings, and we want them to appear in the order we declare them. We dump the results out to Excel using gdxxrw, and they appear in the set order as demonstrated above.
In the past we have dummied up new names to produce unique set elements to get around this problem. For example
set report3_headings / r3_unitname, r3_region, r3_capacity, r3_emissions /;
But this is not possible for our current work.
Is there a solution to this problem?
Thanks
Andrew
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
\