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?

## Sum limits

### Re: Sum limits

Hi

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

.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).

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:

Cheers

Renger

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));
```

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));
```

Code: Select all

```
parameter ordset(i);
ordset(i) = ord(i);
display ordset;
```

Renger

____________________________________

Enjoy modeling even more: The lazy economist

Enjoy modeling even more: The lazy economist