COUNT THE ELEMENTS INSIDE A SET

questions about GAMS' tools
Post Reply
lopejor
User
User
Posts: 1
Joined: 1 year ago

COUNT THE ELEMENTS INSIDE A SET

Post by lopejor »

Dear friends,

I have a multidimensional parameter with 4 sets and 1 value into a gdx file.

I would like to know how many rows do I have per each set r1,p1,r2 or p2.

The problem is that the file is too large and I cannot open the gdxviewer, and I don't know the different elements that I have in each set.

So, I'm looking for this kind of information (in the image is the sample):

for r1: a1 2, a2 1
for p1: xa0 2, xa2 1
for r2: a2 2, a1 1
for p2: yt5 1, yt3 1, yt1 1.

Maybe you can help me.

Thank you and all the best,
table with elements
table with elements
image.png (2.7 KiB) Viewed 2982 times
User avatar
bussieck
Moderator
Moderator
Posts: 1042
Joined: 7 years ago

Re: COUNT THE ELEMENTS INSIDE A SET

Post by bussieck »

This is easily achieved by the projection operator accessible via the option statement. See https://www.gams.com/latest/docs/UG_Opt ... ggregation for details. Here is the code for your example:

Code: Select all

set r1,p1,r2,p2;
parameter d(r1<,p1<,r2<,p2<) /
a1.xa0.a2.yt5 6
a1.xa0.a2.yt3 5
a2.xa2.a1.yt1 7
/;

parameter cnt_r1(r1), cnt_p1(p1), cnt_r2(r2), cnt_p2(p2);

option cnt_r1<d, cnt_p1<d, cnt_r2<d, cnt_p2<d;

display cnt_r1, cnt_p1, cnt_r2, cnt_p2;
which results in the following display:

Code: Select all

----     12 PARAMETER cnt_r1  
a1 2.000,    a2 1.000

----     12 PARAMETER cnt_p1  
xa0 2.000,    xa2 1.000

----     12 PARAMETER cnt_r2  
a1 1.000,    a2 2.000

----     12 PARAMETER cnt_p2  
yt5 1.000,    yt3 1.000,    yt1 1.000
-Michael
Post Reply