Set Operations Topic is solved

Problems with syntax of GAMS
Post Reply
Janisch
User
User
Posts: 26
Joined: 2 months ago

Set Operations

Post by Janisch » 2 weeks ago

Hello all,

I want to define a new set from two sets. In my example:

s,m,i,j are sets
alias(i,j)
Of i and j there is a subset: dummy_TS(i) and dummy_TS(j) respectively

defined sets: f(s,m,i,j) and h(dummy_TS)

Now I want to define a new set: t(s,dummy_TS)
s shall always be assigned to dummy_TS if at f(s,m,i,j) s is assigned to the subset dummy_TS over i or j.

I have already tried to work by means of intersection, but I have encountered a bunch of syntax errors.

I hope someone can help me :)

Many greetings
Janisch

abhosekar
Moderator
Moderator
Posts: 97
Joined: 4 months ago

Re: Set Operations

Post by abhosekar » 2 weeks ago

Many things need to be clarified in the question before looking for the right answer.

1. "s shall always be assigned to dummy_TS" but dummy_TS is a subset of i. you cannot assign s to it.
2. "if at f(s,m,i,j) s is assigned to the subset dummy_TS": at any value of m, i, j/all values of m, i, j? is f a function? if yes, how can f(s, m, i, j) be a set? You don't need alias to define s, m ,i, j you could say s, m ,i, i
3. "over i or j" both are aliases.

Best to give a small example.

- Atharv

Janisch
User
User
Posts: 26
Joined: 2 months ago

Re: Set Operations

Post by Janisch » 2 weeks ago

Hey Atharv,

f(s,m,i,j) is not a function. It is a set.

here a short example:
set i respectively j:
i/j
i/j
set h(dummy_TS):
h_dummy_TS
h_dummy_TS
h_dummy_TS.JPG (10.04 KiB) Viewed 285 times
set f(s,m,i,j):
f
f
f.JPG (34.12 KiB) Viewed 285 times
The solution should be: t(s, dummy_TS) = /Bet.TransferB, Middlegate.terminalC_d, Alliance_Europe.terminalE_d, Top.TransferB, Top.TransferA)

I hope this has made it more understandable.

abhosekar
Moderator
Moderator
Posts: 97
Joined: 4 months ago

Re: Set Operations

Post by abhosekar » 1 week ago

If an element in i or j columns of set f exist in set h (which is a subset of dummy_ts, not sure if this is needed or makes sense) then you want to include that element in set t. This can be done as follows.

Code: Select all

set f(s, m ,i, i);

f(s, m, i, i)$(dummy_ts(i))=yes;
It is not clear why you would want h(dummy_ts) which is a subset of a subset. You can simply have h(i) and populate it as needed.

Code: Select all

h(i)$(dummy_ts(i)) =yes;
- Atharv

Janisch
User
User
Posts: 26
Joined: 2 months ago

Re: Set Operations

Post by Janisch » 1 week ago

I want to achieve that I automatically know which c is assigned to a dummy_TS and only the combinations I want to have in this set t(s,dummy_TS).

abhosekar
Moderator
Moderator
Posts: 97
Joined: 4 months ago

Re: Set Operations

Post by abhosekar » 1 week ago

Let me reframe your question:
You need t(s, i) only when i is in dummy_ts and i is in 'any' two of the last two columns of f.

It is much clearer now that you need to create another set to tell you whether a given i exists in the last two columns of set f.

Let's say that set is fprojected(i) that contains all i elements in set f.

It is then easy to populate set t(s, i) as follows:

Code: Select all

t(s, i)$(dummy_ts(i) and fprojected(i)) =yes;
The only question now is to get the set fprojected. There are many ways but one the elegant ways is to use projections.

Code: Select all

*To get i in fourth column
set f1(i);
f1 < f; 

* To get i from third column
set f2(i) <= f;

*Union of two sets
fprojected(i)$(f1(i) and f2(i)) = yes;
Hope this answers your question.

- Atharv

Janisch
User
User
Posts: 26
Joined: 2 months ago

Re: Set Operations

Post by Janisch » 1 week ago

Yes, exactly. But unfortunately my code example does not work when I try to implement your solution. Something is wrong with the syntax.
Here is my example:

Code: Select all

SET f_c_r(s,m,i,j);
SET dummy_TS(i);
SET fprojected(i)
SET t(s,i);

set f1(i);
*To get i in fourth column
f1(i) <= f_c_r;                          
set f2(i);
*To get i from third column
f2 <= f;
*Union of two sets
fprojected(i)$(f1(i) and f2(i)) = yes;
t(s, i)$(dummy_ts(i) and fprojected(i)) =yes;

abhosekar
Moderator
Moderator
Posts: 97
Joined: 4 months ago

Re: Set Operations

Post by abhosekar » 1 week ago

There are a couple of typos in my previous comment. Following code works.

Code: Select all

set
s /s1*s5/
m /m1*m4/
i /i1*i8/
dummy_ts(i) /i2, i6, i7/
h(dummy_ts) /i2, i6, i7/
;
display
dummy_ts
h;

alias(i, j);

set
f(s, m, i, i);
f(s, m, 'i2', 'i6') = yes;

sets
fprojected1(i)
fprojected2(i)
fprojected(i);

*fprojected1 = sum((ii, s, m), f(s, m, ii,i )
option fprojected1 < f;
option fprojected2 <= f;
fprojected(i)$(fprojected1(i) or fprojected2(i))= yes;

display fprojected;
f(s, m ,i, i)$(dummy_ts(i))=yes;

set t(s, i);
t(s, i)$(dummy_ts(i) and fprojected(i))= yes;
*f(s, m ,i, i)$(h(dummy_ts))=yes;

display t;
- Atharv

Janisch
User
User
Posts: 26
Joined: 2 months ago

Re: Set Operations

Post by Janisch » 1 week ago

Now it works perfectly! Thank you :)

Post Reply