Page 1 of 1

Sum limits

Posted: Wed Jun 20, 2018 8:48 pm
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?

Re: Sum limits

Posted: Thu Jun 21, 2018 8:03 am
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