Sum limits

Problems with syntax of GAMS
Post Reply
Nijobi
User
User
Posts: 1
Joined: 5 years ago

Sum limits

Post by Nijobi »

Hello,

I have a question regarding sum limits.
I can find how to sum over an entire set, which is not that difficult.
When trying to find how to sum up to some limit, i cannot find anything on how to do this in GAMS.
This is (one of the) function(s) i'd like to model:

∑_(t=1)^(f_j-g_j+e_j) X_ajt ≥1,
(the sum of X_ajt from t=1 to (f_j-g_j+e_j))

How do you model this is GAMS?
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Sum limits

Post by Renger »

Hi

If you have a sets that uses numbers instead of strings, you can sum as follows:

Code: Select all

set i /1*10/;
sum(i$(i.val > 5), x(i));
.val gives you the numerical value of the set element (which is treated as a string, even when it is a number, so you can't use $(i >5)).

If you have strings as set elements, you can use ord(), which gives you the place in the set (e.g. first element has order 1).

Code: Select all

set i /i1*i10/;
sum(i$(ord(i) > 5, x(i));
Be aware that ord() not always gives you the number in the set itself (especially if you use subsets). To be 100% sure, I usually write some code to see the ord() of the set elements:

Code: Select all

parameter ordset(i);
ordset(i) = ord(i);
display ordset;
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Post Reply