GAMS indexing query

91 views Asked by At

Hi I am trying to optimize a function involving the components of a variable s(L) indexing by the set L /1*10/;

I created a subset Leven of the set L involving the even numbers (Leven /2,4,6,8,10/)

I want to write down an equation which sets the even components of s(L) as double the value of the odd components..

How should I write such an equation pls?

I was going to write it as

equation(Leven).. s(Leven) =E= s(Leven-1)*2;

However the above is wrong as for example for Leven = 4, s(Leven-1) is interpreted as s(2) and not as s(3) ..

Many thanks

1

There are 1 answers

0
Martin Bonde On

You can use a dollar condition to limit the equation to your subset like so:

set Leven(L);
Leven(L) = yes$(mod(ord(L),2) eq 0);

equation(L)$Leven(L).. s(L) =E= s(L-1)*2;

(I'm not a 100% sure on the syntax used to define the subset above, as I'm on vacation and don't have GAMS with me, but you should get the idea.)