sets in gams

Problems with syntax of GAMS
Post Reply
Nikou
User
User
Posts: 33
Joined: 4 years ago

sets in gams

Post by Nikou »

I declare the set k as follows:
SET k /1 * 3/ ;

Later in my model I am using the expression

X(i,j,'3') = ....

In this expression '3' denotes the last element of the set k.

My question is: Is it possible to write X(i,j,last element of k) instead of X(i,j,'3') ? How can I do this?

The reason for asking is, that I would like to be able to change the cardinality of k without having to go through the rest of the model.
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: sets in gams

Post by Renger »

Hi
You can either use card in the equation

Code: Select all

X(i,j,k)$(ord(k) = card(k)) = ...

or use a dynamic set:

Code: Select all

SET k /1 * 3/,
       klast(k) ;

klast(k)$(ord(k) = card(k))= YES;

X(i,j,klast) = ....
In both cases, you can change the cardinality of the set and this will be reflected in your assignment of X.

Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Post Reply