Nested summation on same set

Hello, I need help for my GAMS program.
I want to do a nested summation on the same set, as follows:

sum(i in 1…n, sum(j in i…n, x_j))

I hope you understand the summation. It is a double summation where the first index (i) goes from 1 to n, and the second index goes from i to n.
In gams I defined the set 1…n as T (it is a temporal set), and I don’t know how to write the second summation.

I hope you can help me.

Thank you very much


To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/hyIfVVZyiysJ.
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.

Hi Lucy

Try this

Set i /i1*i3/;
alias(i,j);

parameter x(j), tot;

  • Give x(j) some values:
    x(j) = 1;

tot = Sum(i, sum(j$(ord(j) LE ord(i)), x(j)));

display tot;

Cheers
Renger


Modelworks
Gewerbestrasse 15
3600 Thun - Switzerland
+41 79 818 53 73
Info@modelworks.ch
blog.modelworks.ch

From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of Lucy N
Sent: Dienstag, 8. Januar 2013 14:56
To: gamsworld@googlegroups.com
Subject: Nested summation on same set

Hello, I need help for my GAMS program.
I want to do a nested summation on the same set, as follows:

sum(i in 1…n, sum(j in i…n, x_j))

I hope you understand the summation. It is a double summation where the first index (i) goes from 1 to n, and the second index goes from i to n.
In gams I defined the set 1…n as T (it is a temporal set), and I don’t know how to write the second summation.

I hope you can help me.

Thank you very much

Hello Lucy,

I’m sorry if this sounds mean, but have you tried reading the user guide? In chapter 2 is a nice example, which shows that you haven’t even bothered looking at the guide.

thanks,

On Tuesday, January 8, 2013 3:57:40 PM UTC+1, Lucy N wrote:

Hello,

I am sorry if this post appears more than once. I have post it 3 times but it doesn’t appear in the posts page.

I want to do a double summation, where the first index i goes from 1 to n (which I called set T in GAMS) and the second index goes from i to n (this is from the value or position of the first index to n).
Something like this:
sum( (i = 1…n), sum ( (j = i…n), a( j ) ) )

I don’t know how to do the second part of the summation.

I would appreciate very much your help!

Thank you


To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/m-M3fmrLUcAJ.
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.

Thank you very much!
I now understand what “alias” is used for.
Thanks!

On Tuesday, January 8, 2013 11:56:10 AM UTC-3, Renger van Nieuwkoop wrote:

Hi Lucy

Try this

Set i /i1*i3/;
alias(i,j);

parameter x(j), tot;

  • Give x(j) some values:
    x(j) = 1;

tot = Sum(i, sum(j$(ord(j) LE ord(i)), x(j)));

display tot;

Cheers
Renger


Modelworks
Gewerbestrasse 15
3600 Thun - Switzerland
+41 79 818 53 73
In…@modelworks.ch
blog.modelworks.ch

From: gams...@googlegroups.com [mailto:gams...@googlegroups.com] On Behalf Of Lucy N
Sent: Dienstag, 8. Januar 2013 14:56
To: gams...@googlegroups.com
Subject: Nested summation on same set

Hello, I need help for my GAMS program.
I want to do a nested summation on the same set, as follows:

sum(i in 1…n, sum(j in i…n, x_j))

I hope you understand the summation. It is a double summation where the first index (i) goes from 1 to n, and the second index goes from i to n.
In gams I defined the set 1…n as T (it is a temporal set), and I don’t know how to write the second summation.

I hope you can help me.

Thank you very much

To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/hyIfVVZyiysJ.
To post to this group, send email to gams...@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.


To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/yjGJ10n2tpEJ.
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.