How to write this particular sum of sums? from j=0 to J and then from jj=j-k to j

438 views
Skip to first unread message

robf...@gmail.com

unread,
Oct 6, 2015, 8:31:19 PM10/6/15
to AMPL Modeling Language
I have a continuous parameter a that is indexed by j, and a continuous variable x also indexed by j. j is the set of integers from 0 to J. Also, k is a positive integer constant that is specified by the user.

My objective function is to maximise something like this:


I know how to how to write up the first part (without the second summation).
My question is how do I write this with the second summation?

A secondary question which may follow on from my first is whether this summation works or what happens when j-k<0? There is only data over the set 0 to J. And I would like for cases where j<k that the second summation to go from 0 to j.

I am new to AMPL, so forgive me if I have overlooked something simple. Thank you for your help in advance.
Auto Generated Inline Image 1

Robert Fourer

unread,
Oct 7, 2015, 12:25:38 PM10/7/15
to am...@googlegroups.com

This expression may be written in AMPL in the same way as shown in your question:

   sum {j in 0..J} (a[j] * x[j] * sum {jj in j-k..j} x[jj])

To prevent jj from taking negative values, you can replace "j-k" in the above expression by "max(0,j-k)" or by "j less k".  (The little-known AMPL operation "a less b" gives a-b if a is greater than b, or 0 otherwise; so it's just a shorthand for max(0,a-b).)

Bob Fourer
4...@ampl.com


image001.png
Reply all
Reply to author
Forward
0 new messages