« Return to Thread: [AMPL 2631] Arbitrary Cartesian Products

[AMPL 2639] Re: Arbitrary Cartesian Products

by Robert Fourer-2 :: Rate this Message:

Reply to Author | View in Thread



The dimension (or arity) of a set cannot depend on a data value.  Hence you
can make this work, as Paul suggests, when L is a fixed number, but not when
L is an integer parameter whose value is given in the data.  Indeed the
latter would require a substantial extension to AMPL's indexing expressions;
for example the number of "subscripts" in an expression like X[i1,i2,i3]
would not be known when the expression was parsed but would instead depend
on the data.

To enumerate all possible tuples (r_1, ..., r_L) having some property like
this, I have taken the following approach.  I let the tuples be numbered
arbitrarily from 1 to N, and define "param tuple_list {1..L,1..N};" where
tuple_list[i,j] is the value of r_i in the jth tuple.  I set N to some upper
limit (depending on L) on the number of tuples that will be generated, and
then write some for loops to compute all the possible tuples.  It does take
some thought to figure out how to do the for loops efficiently, though;
writing L nested for loops will not work, since L depends on the data.

Also possibly if L does not get very large then you could just write a
different model or script for each different value of L.

Bob Fourer
4er@...


> -----Original Message-----
> From: ampl@... [mailto:ampl@...]
> On Behalf Of Guilherme Freitas [guilherme@...]
> Sent: Thursday, July 09, 2009 3:21 AM
> To: AMPL Modeling Language
> Subject: [AMPL 2631] Arbitrary Cartesian Products
>
>
> 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.
>
> Thanks in advance,
>
> --Guilherme Freitas
>



--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

 « Return to Thread: [AMPL 2631] Arbitrary Cartesian Products