Refer to Special element of a set

Problems with syntax of GAMS
Post Reply
Bahar_Mdi
User
User
Posts: 21
Joined: 1 year ago

Refer to Special element of a set

Post by Bahar_Mdi » 1 month ago

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.
Last edited by Bahar_Mdi 1 month ago, edited 1 time in total.

User avatar
bussieck
Moderator
Moderator
Posts: 614
Joined: 4 years ago

Re: Refer to Special element of a set

Post by bussieck » 1 month ago

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

Bahar_Mdi
User
User
Posts: 21
Joined: 1 year ago

Re: Refer to Special element of a set

Post by Bahar_Mdi » 1 month ago

Thanks for your help.

Post Reply