Page 1 of 1

### Question about replacing two sets

Posted: Mon Mar 04, 2019 4:23 am
Hi all,
I have a question I would like to ask.
How to have a simplified conversion of DATA in two different Sets?

For example, the GAMS codes as following:

Code: Select all

``````set
i  /i1 * i12/
j  /j1 * j3/
;

parameter
Data_1(i)
/
i1 5
i2 3
i3 0
i4 6
i5 7
i6 9
i7 0
i8 12
i9 0
i10 2
i11 8
i12 1
/
Data_2(j)
;

Data_2("j1") = Data_1("i1");
Data_2("j2") = Data_1("i5");
Data_2("j3") = Data_1("i9");
Data_2(j) = Data_2(j) + eps;

display Data_1,Data_2;

``````
Thanks.

### Re: Question about replacing two sets

Posted: Fri Mar 08, 2019 2:36 pm
I do not know if I understood correctly.
Your goal is to express Data_2 in a simpler or more compact way?

Code: Select all

``````set
i  /i1 * i12/
j  /j1 * j3/
DATA(j,i) /j1.i1,j2.i5,j3.i9/
;

parameter
Data_1(i)
/
i1 5
i2 3
i3 0
i4 6
i5 7
i6 9
i7 0
i8 12
i9 0
i10 2
i11 8
i12 1
/
Data_2(j)
;

Data_2(j) = sum(i\$DATA(j,i),Data_1(i));

Data_2(j) = Data_2(j) + eps;

display Data_1,Data_2;
``````

### Re: Question about replacing two sets

Posted: Mon Mar 11, 2019 2:25 am
Sorry, I didn't describe the problem very well. My goal is to express Data_2 in a simpler way. The code "Data_2(j) = sum(i\$DATA(j,i),Data_1(i))" is more simplified than "Data_2("j1") = Data_1("i1"),...etc".
But the set DATA(j,i) need to set one by one. Is there a more simplified way to express it if ?

Thanks.

### Re: Question about replacing two sets

Posted: Mon Mar 11, 2019 8:39 am
What's the "algorithm" behind setting DATA? I just see the result: map j1.i1,j2.i5,j3.i9. Do you want to map jk to il with l = (k-1)*4+1? You need to be more explicit in your questions.

-Michael

### Re: Question about replacing two sets

Posted: Tue Mar 12, 2019 4:34 pm
Yes, I need to map Data1(i) to Data2(j). The relationship between i and j are j=(i-1)*4-1.
In fact, if the Data1 will sample 15 minutes in a day (it will have 96 points).
The Data2 will take hourly data from Data1 (it will have 24 points).
So, if I don't have the simple way to write code, It will become Ex1 or Ex2 as following:

Code: Select all

``````Ex1:
Data_2("j1") = Data_1("i1");
Data_2("j2") = Data_1("i5");
Data_2("j3") = Data_1("i9");
Data_2("j4") = Data_1("i13");
Data_2("j5") = Data_1("i17");
...
Data_2("j24") = Data_1("i91");
``````

Code: Select all

``````Ex2:
[code]i  /i1 * i96/
j  /j1 * j24/
DATA(j,i) /j1.i1,j2.i5,j3.i9,...,j24.i91/
...
Data_2(j) = sum(i\$DATA(j,i),Data_1(i));``````
[/code]

Is there a more simplified way to write the code ?

Thanks.

### Re: Question about replacing two sets

Posted: Tue Mar 12, 2019 5:38 pm
Okay, I get it. This is actually not so difficult:

Code: Select all

``````set q /i1 * i96/, h  /j1 * j24/, hq(h,q);
hq(h,q) = (h.pos-1)*4+1 = q.pos;
option hq:0:0:1; display hq;
``````
-Michael

### Re: Question about replacing two sets

Posted: Wed Mar 13, 2019 2:19 am
Thank you for help.
It successfully solved my problem.