I need to formulate a constraint involving a `cumsum` calculation:
sum_{k=1}^j (x_k - p_k) <= d for all j in 1..n
The following expression in AMPL does not work as it returns an error message
"k is not defined":
subject to some_rule {j in 1..n}: sum {k in 1..j} x[k] - p[k] <= d
How can I write such a constraint in AMPL correctly?
Many thanks in advance.