Concatenate in GAMS Topic is solved

Problems with syntax of GAMS
Post Reply
anaaza
User
User
Posts: 8
Joined: 1 year ago

Concatenate in GAMS

Post by anaaza » 1 month ago

Hi,

I am importing two different tables into GAMS:

RotStandOut(SiteIndexS,SiteIndexP,SiteINdexB,Rot_Perc,Ages,Items)
PixTable(Stands,Pixels,SiteIndexS,SiteIndexP,SiteIndexB,Rot_Perc,Items)

Both tables have common sets (SiteIndexS,SiteIndexP,SiteINdexB,Rot_Perc). I need to group those sets together creating sort of an "Index/key", so I can identity such index on table RotStandOut and bring its outcome/value to table PixTable.
What I want to do is kinda of concatenating such sets in both tables and then performing a vlookup.

Any ideas on how I can do that on GAMS?

User avatar
bussieck
Moderator
Moderator
Posts: 614
Joined: 4 years ago

Re: Concatenate in GAMS

Post by bussieck » 1 month ago

Rather than looking at spreadsheet logic (vlookup) relational algebra like SQL from databases will give you a better understanding of how GAMS looks at data:

Code: Select all

* Declaration with artificial data
set SiteIndexS /s1*s10/,SiteIndexP /p1*p10/, SiteINdexB /b1*b10/,
    Rot_Perc /r1*r10/, Ages /a1*a10/, Items /i1*i10/,
    Stands /t1*t10/,Pixels /p1*p10/;
parameters
    RotStandOut(SiteIndexS,SiteIndexP,SiteINdexB,Rot_Perc,Ages,Items)
    PixTable(Stands,Pixels,SiteIndexS,SiteIndexP,SiteIndexB,Rot_Perc,Items);

* Fill with sparsely with ranom data
RotStandOut(SiteIndexS,SiteIndexP,SiteINdexB,Rot_Perc,Ages,Items)$(uniform(0,1)<0.005) = uniFormInt(1,10);
PixTable(Stands,Pixels,SiteIndexS,SiteIndexP,SiteIndexB,Rot_Perc,Items)$(uniform(0,1)<0.005) = uniFormInt(1,10);

* Declare indiviual index sets
set idx_RotStandOut(SiteIndexS,SiteIndexP,SiteINdexB,Rot_Perc)
    idx_PixTable(SiteIndexS,SiteIndexP,SiteINdexB,Rot_Perc);

* Project relevant indexes out of the parameters    
option idx_RotStandOut<idx_RotStandOut,
       idx_PixTable<PixTable;
       
set idx(SiteIndexS,SiteIndexP,SiteINdexB,Rot_Perc);
* Build the union of the two index spaces
idx(SiteIndexS,SiteIndexP,SiteINdexB,Rot_Perc) =
      idx_RotStandOut(SiteIndexS,SiteIndexP,SiteINdexB,Rot_Perc)
   or idx_PixTable(SiteIndexS,SiteIndexP,SiteINdexB,Rot_Perc);

* Use the new sparse index in some calculation
Parameter maxAges(SiteIndexS,SiteIndexP,SiteINdexB,Rot_Perc,Items);
maxAges(idx,Items) = smax(Ages, RotStandOut(idx,Ages,Items))
-Michael

anaaza
User
User
Posts: 8
Joined: 1 year ago

Re: Concatenate in GAMS

Post by anaaza » 1 month ago

Hi Michael,

Thank you for the didactic explanation. I learned new concepts that I had never heard before.
I tried it on my model and it works perfectly.

Cheers,

Ana

Post Reply