Page 1 of 1

Refer to Special element of a set

Posted: Wed Jun 09, 2021 12:44 pm
by Bahar_Mdi
Hi,
Consider I have defined set i as /5,7,8,3,2,9/ in Gams and I want to define sub(i) such that contains the first element of i and define sub2(i) such that includes the last element of i. How shoud I do that?
It is notable that the set i is imported to Gams and I don't know its element in advance.

Re: Refer to Special element of a set

Posted: Thu Jun 10, 2021 8:28 pm
by bussieck
First make sure you get the order of i you expect by "display i"; Then you can get the first and last element like this

Code: Select all

set iFirst(i), iLast(i);
iFirst(i) = i.first;
iLast(i) = i.last;
display i,iFirst,iLast;
-Michael

Re: Refer to Special element of a set

Posted: Thu Jun 10, 2021 11:01 pm
by Bahar_Mdi
Thanks for your help.