On Jul 9, 4:21 am, Guilherme Freitas <
guilhe...@...> wrote:
> Hi everybody. I need to evaluate a function over a set like this:
>
> { (r_1, ..., r_L) : r_1 <= n_1, ..., r_L <= n_L and sum {i in
> 1, ..., L} r_i = k }
>
> where L, n1, ..., n_L and k are positive integers ('params') defined
> by data. The problem is that I don't know how to write the set above
> in AMPL. I looked in the book for a while, but couldn't find anything
> helpful. I would be very grateful if someone could point out the page
> in the book where this is explained or post the code to write this
> set.
>
You did not specify lower limits for r_1, r_2 etc.; I'm assuming you
want them >= 1 (but >= 0 is an easy adjustment).
I'm not sure you can do this with L as a parameter. With L as a
constant it can be done. Suppose L=3. The following should work:
param n {1..L} integer > 0;
param k integer > 0;
# ...
set S := setof {(r1,r2,r3) in 1..n[1] cross 1..n[2] cross 1..n[3] : r1
+ r2 + r3 == k};
# now index your function over S
Unfortunately, AMPL tends to be rather finicky about set arity (in
particular, I don't think you can declare an array of sets where each
set has a different arity), and at least in the (rather old) version
that I have, the cross operator cannot be indexed.
/Paul
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to
ampl@...
To unsubscribe from this group, send email to
ampl+unsubscribe@...
For more options, visit this group at
http://groups.google.com/group/ampl?hl=en-~----------~----~----~----~------~----~------~--~---