Page 1 of 1

defining a subset in GAMS

Posted: Mon Dec 28, 2020 9:57 am
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

Re: defining a subset in GAMS

Posted: Mon Dec 28, 2020 2:36 pm
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

Re: defining a subset in GAMS

Posted: Mon Dec 28, 2020 2:42 pm
by Bahar_Mdi
Thanks a lot for your help.