nested summation

310 views
Skip to first unread message

rch...@gmail.com

unread,
Dec 5, 2005, 11:55:46 PM12/5/05
to AMPL Modeling Language
Hi All,

Any ideas on how to nest summations.
What I am trying to do is the following
for each element 't' of 1 ... (T-60). I want a constraint like this
(dp[t+1]+dp[t+2]+dp[t+3]...+dp[t+60]) - Ip[t]) >=0

I'm currently modeling this constraint in AMPL as
subject to IB {t in 1..(T-60)}: sum{(t+1)..(t+60)} (dp[t]) - Ip[t] >=0;

but this doesn't appear to constraining as I expected it to.
Anyone, see a problem with my formulation. Thanks in advance for your
help.

-Richard

Hans Mittelmann

unread,
Dec 6, 2005, 9:30:41 AM12/6/05
to AMPL Modeling Language
Hi,
this is a very simple programming mistake. In the past one would simply
think a bit harder and correct it. Nowadays one simply asks in a
newsgroup. This way one does not improve one's problem solving skills
much.
You definitely cannot use the same summation variable at both levels of
a nested expression and in the inner loop you do not even define the
summation variable.
Hans Mittelmann

Marqoos

unread,
Dec 6, 2005, 3:20:15 PM12/6/05
to AMPL Modeling Language
Hmmm? I don't get it really. I don't see any mistake. However it's very
simple. This model (properly bounded of course) should be working
properly:
I assumed value of T and that Ip is a parameter and dp i a variable to
make a tests and I made one stupid obcetive. It was really simple and I
don't know why you ask. Maybe I did something wrong. Let me know if
there will be some problems.

param T=40;
param Ip{1..(T-60)};
let {i in 1..(T-60)} Ip[i] := 40;

var dp{1..T};

subject to hej {s in 1..(T-60)}:
(sum {i in (s+1)..(s+60)} dp[i]) - Ip[s] >= 0;

maximize rum:
sum {p in 1..kert} dp[p];

solve;

display rum;

Markus

Marqoos

unread,
Dec 6, 2005, 3:26:44 PM12/6/05
to AMPL Modeling Language
Sorry. There of course should be

maximize rum:
sum {p in 1..T} dp[p];

But it doesn't matter because it's not your objective after all.

Hans Mittelmann

unread,
Dec 6, 2005, 10:23:10 PM12/6/05
to AMPL Modeling Language
Hi,
while you claim to not see a mistake you make an important correction
in the lines:

subject to hej {s in 1..(T-60)}:
(sum {i in (s+1)..(s+60)} dp[i]) - Ip[s] >= 0;
Hans Mittelmann
P.S. the parentheses around te sum are not needed

Marqoos

unread,
Dec 7, 2005, 10:08:18 AM12/7/05
to AMPL Modeling Language
Sorry. Of course it's a mistake. I don't know why i read only first
part of first messeage. And that was resonable. I mean there was just
that what author want to make. But I really don't know why I didn't
read the rest. I didn't ralize that there is some rest. I don't know.
Sorry. I realized after writting this replay and then i felt really
stupid. First: You were right - there is a series mistake. Second:
After reading the rest of message I realize, that it's really not the
best topic for newsgroup. Sorry Hans.

Regards

Markus

P.S. I often use as many round brackets as possible. But thank you.

Reply all
Reply to author
Forward
0 new messages