Aggregate Parameter Indices

Problems with modeling
GabrielYin
User
Posts: 57
Joined: 1 year ago
Location: Dallas, TX, USA

Aggregate Parameter Indices

Hi all,

I have to use one parameter to store the following information: n variables, each variable can take Sn values. I have a toy example, 3 variables and each of them can take 1 or 2. The desired outcome should be like this:

Code: Select all

``````1	1	1
1	1	2
1	2	1
1	2	2
2	1	1
2	1	2
2	2	1
2	2	2
``````
It can be easily achieved in the following way:

Code: Select all

``````Set
s       /1*8/
s1      /1*2/
s2      /1*2/
s3      /1*2/
j       /1*3/

Parameter        a(j,s1,s2,s3)

loop(s1,
a('1',s1,s2,s3) = ord(s1);
);

loop(s2,
a('2',s1,s2,s3) = ord(s2);
);

loop(s3,
a('3',s1,s2,s3) = ord(s3);
);

display a;
``````
Note that here I used three indices s1 s2 s3 to express. Then I wonder if there is a way to only use one index, say s /1*8/, to achieve this. Then the desired outcome would be like the following (here I express it like a table for convenience, but I actually want a parameter)

Code: Select all

``````
Parameter		a(j, s)
j1	j2	j3
s1	1	1	1
s2	1	1	2
s3	1	2	1
s4	1	2	2
s5	2	1	1
s6	2	1	2
s7	2	2	1
s8	2	2	2
``````
It is a toy example though but I can use the idea to express more complicated instance like 21 variables and each of them can have 10 or more possible values. Anyone can give a comment on this is highly appreciated!

Best,
Gabriel

bussieck
Moderator
Posts: 371
Joined: 3 years ago

Re: Aggregate Parameter Indices

Hi,

GAMS has an obscure syntax to do exactly this. For details see https://www.gams.com/latest/docs/UG_Sys ... s_PowerSet.

Code: Select all

``````\$set digits 3
set s / s1*s%digits% /, b / 1,2,3 /;
\$eval nMax power(card(b),card(s))
set n        / n1*n%nMax% /
x(n,s,b) / system.powerSetRight /;
parameter xp(n,s); loop(x(n,s,b), xp(n,s) = b.val;)
option xp:0:1:1; display xp;
``````
Be aware of the data you generate! 21 "variables" with 10 different values gives you 10^21 elements. I hope you know how large this number is. No way to store these explicitly on a computer.

-Michael

GabrielYin
User
Posts: 57
Joined: 1 year ago
Location: Dallas, TX, USA

Re: Aggregate Parameter Indices

bussieck wrote:
1 year ago
Hi,

GAMS has an obscure syntax to do exactly this. For details see https://www.gams.com/latest/docs/UG_Sys ... s_PowerSet.

Code: Select all

``````\$set digits 3
set s / s1*s%digits% /, b / 1,2,3 /;
\$eval nMax power(card(b),card(s))
set n        / n1*n%nMax% /
x(n,s,b) / system.powerSetRight /;
parameter xp(n,s); loop(x(n,s,b), xp(n,s) = b.val;)
option xp:0:1:1; display xp;
``````
Be aware of the data you generate! 21 "variables" with 10 different values gives you 10^21 elements. I hope you know how large this number is. No way to store these explicitly on a computer.

-Michael
Thank you Michael! I know the scenario number is very large if I want to do that way. I had the honor to read one of your paper about GUSS:
At the bottom of the paper, you illustrated the performance of GUSS with an SDDP problem, which solved 60,000+ LP problems. I have checked the codes you shared in the GAMS library about that part. However, water.gdx seemed not readable in my computer. So, I am wondering how you store your scenarios in that problem. I guess the way you did was totally different with mine in this post.

I have another idea about how to store the scenarios. That is firstly to find out all discrete distribution of each random parameter then pick them up one by one in the loop. The sample code is shown below.

Code: Select all

``````Set ff /ff1*ff50/
tmp1 /1*2/;
option decimals=6;

\$set inputdir "C:\Users\Gabriel\Desktop"

Table c15RHS(ff, tmp1)      RHS Data

\$include "%inputdir%\C15RHS.txt";

Table c16RHS(ff, tmp1)      RHS Data

\$include "%inputdir%\C16RHS.txt";

Table c17RHS(ff, tmp1)      RHS Data

\$include "%inputdir%\C17RHS.txt";

Table c18RHS(ff, tmp1)      RHS Data

\$include "%inputdir%\C18RHS.txt";

Table c19RHS(ff, tmp1)      RHS Data

\$include "%inputdir%\C19RHS.txt";

Table c20RHS(ff, tmp1)      RHS Data

\$include "%inputdir%\C20RHS.txt";

Table c21RHS(ff, tmp1)      RHS Data

\$include "%inputdir%\C21RHS.txt";
``````
Then we have 7 tables storing 50 discrete distributions of each random parameter, thus the total scenario number is 50^7.

I wonder if there is any other efficient way to store the scenarios in GAMS, then I can use GUSS to do stochastic programming thing.

Best,
Gabriel

GabrielYin
User
Posts: 57
Joined: 1 year ago
Location: Dallas, TX, USA

Re: Aggregate Parameter Indices

By the way,

I think GUSS needs exactly a single scenario index 's' to run right? But likely if I have a scenario set which is controlled by multiple indices like I posted previously, is it possible to use GUSS? The relevant site and my another post about GUSS are listed below.
https://www.gams.com/latest/docs/S_GUSS.html
viewtopic.php?f=2&t=10432
I guess the following pseudocode is invalid

Code: Select all

``````Set dict / s1.  scenario. ''
s2.  scenario. ''
s3.  scenario. ''
A1.  param.    A_s(s1)
A2.  param.    A_s(s2)
A3.  param.    A_s(s3)
x.   lower.    xlo_s(s1, s2, s3)
x.   level.    xl_s(s1, s2, s3)
e.   marginal. em_s(s1, s2, s3)   /;
solve mymodel min z using lp scenario dict;
``````
That is the motivation of this post, I want to aggregate the parameter indices to one index then GUSS is applicable. I appreciate any suggestion or comment!

Best,
Gabriel