Accessing the last element of a variable in GAMS

612 views Asked by At

I have a set:

Set t /t1*t6/;

Let us consider there is a variable called var. I have a constraint that the last element of var is less than 20.

Variable var(t);

Equation const;

const..

var('t6') < 20;

I would like to replace 't6' in the last line by something like card(t), so that if the size of t changes then I do not have to change it manually.

2

There are 2 answers

3
Martin Bonde On BEST ANSWER

You can use a dollar condition to limit the equation to the last period:

const(t)$(ord(t) = card(t)).. var(t) < 20;

Or you could define a singleton subset for your end condition like so:

singleton set tEnd(t) /t6/;

const.. var(tEnd) < 20;
0
Lutz On

You could also define an upper bound with the help of the "last" attribute of the set t:

Set t /t1*t6/;

Variable var(t);

var.up(t)$(t.last) = 20;

Best, Lutz