defining a subset in GAMS

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

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

Thanks a lot for your help.