## Question about replacing two sets Topic is solved

Problems with syntax of GAMS
TsungHaoHu
User Posts: 10
Joined: 9 months ago

### Question about replacing two sets

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;

execute_unload "Out.gdx"
``````
Thanks.

Manassaldi
User Posts: 83
Joined: 2 years ago
Location: Rosario - Argentina

### Re: Question about replacing two sets

I do not know if I understood correctly.
Your goal is to express Data_2 in a simpler or more compact way?
I hope this can help you

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;
``````

TsungHaoHu
User Posts: 10
Joined: 9 months ago

### Re: Question about replacing two sets

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.

bussieck
Moderator Posts: 340
Joined: 2 years ago

### Re: Question about replacing two sets

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

TsungHaoHu
User Posts: 10
Joined: 9 months ago

### Re: Question about replacing two sets

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.

bussieck
Moderator Posts: 340
Joined: 2 years ago

### Re: Question about replacing two sets

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

TsungHaoHu
User Posts: 10
Joined: 9 months ago

### Re: Question about replacing two sets

Thank you for help.
It successfully solved my problem.