defining a subset in GAMS Topic is solved

Problems with syntax of GAMS
Post Reply
Bahar_Mdi
User
User
Posts: 21
Joined: 4 years ago

defining a subset in GAMS

Post by Bahar_Mdi »

Dear all,

I want to determine a subset based on the indices of elements.

for example, I have a set i /0,4,3,1,5,2,6/ and the order of elements in this set is important to me. I want to define a subset that contains the third element of i to the sixth element. In more details, I want the subset to be as subi(i) /3,1,5,2/ but i do not want to type each element manually.
How should I define the mentioned subset based on the order of elements?

I appreciate it if someone can help me.
Thanks and regards,
Bahar
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: defining a subset in GAMS

Post by abhosekar »

Code: Select all

set subi(i);
subi(i) $(ord(i) ge 3 and ord(i) le 6) = yes; 
If you want it till the last or second from the last element you can use card(i) for comparison instead of 3 and 6.

Hope this helps.

- Atharv
Bahar_Mdi
User
User
Posts: 21
Joined: 4 years ago

Re: defining a subset in GAMS

Post by Bahar_Mdi »

Thanks a lot for your help.
Post Reply