--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Hm ..., not exactly pp.148, which - sorry - confuse me a little bit, because they focus on the LINK-theme. My view is typically index-oriented, where elements of the 3-dimensional structure (like the 12 elements of an C-array A[2][2][3]) can be directly accessed by numerical triples of indices, which includes for-manipulation. (And yes, I know, both views, in the end, are more or less identical.)
Regarding density. Yes all is dense, but not constantly sized, since the K matrices actually vary in their dimensions I x J (where the perfect C-analogy would be a dynamic pointer-based construction for i=1,...,I and j=1,...,J, while K can be perfectly estimated in advance).
On Tue, Apr 24, 2018 at 8:31 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
If your matrix is a dense matrix, then you could represent it by using 3-dimensional structure. I am assuming that 3-dimensional structure is the param declaration of the matrix as described in https://ampl.com/BOOK/CHAPTERS/12-data.pdf (pp: 148). However, if you have sparse matrix, then you could store non-zero values and corresponding rows and columns. The non-zero representation will substantially reduce the memory requirement.
Thanks
Paras
--
Paras Tiwari
am...@googlegroups.com
Thank you! I believe, I got your message ... essentially. Already noticed, indexing over empty "spaces" won't work, but on the other side I cannot totally see your argument that I[k]-by-J[k] matrices are only useful if they are filled: (1) If I know, where a single value is located within such a, say, 3-by-2 area, and if I don't need more values on that "level" (=k), then I'd saved the storage of 5 numbers. Is this picture wrong? Or is this true: I can directly acces a single value (if I know where it is), but, nevertheless, overall storage still remains that one for 6 numbers!? (probably, this is the correct picture ...) And, (2), another advantage is given by the different dimensions, I can have: 3-by-5 on k=1 and 2-by-2 on k=2, all in all using the storage of 19 numbers ... right?
Are there any means to release storage, e.g. reducing K to K-1, in order to free and forget my I[K]-by-J[K] area?
And - excuses, this is absolutely thrilling - are there any commands to show the memory occupied - or even to manage it?
Finally, thanks for your storage suggestion, which is actually sparse!
On Fri, Apr 27, 2018 at 3:01 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
Writing "param t {k in 1..K, i in 1..I[k], j in 1..J[k]};" is only worthwhile if you are going to fill up all of the I[k]-by-J[k] matrices. If you fill in only some of the values, then you will get errors when you try to index over {k in 1..K, i in 1..I[k], j in 1..J[k]} in your model. Moreover there's no AMPL syntax to index over something like {k in 1..K, i in 1..I[k], j in 1..J[k]: "t[k,i,j] exists"}. Instead you will want to use a "sparse matrix" structure as Paras originally mentioned. For example you could specify
param K;
param I {1..K};
param J {1..K};
set KIJ within {k in 1..K, i in 1..I[k], j in 1..J[k]};
param t {KIJ};
Then KIJ is a set of triples that contains a member (k,i,j) for each position (i,j) within matrix k where there is actually a number. No storage is allocated by "set KIJ within . . ." until you add some triples to it by, say,
let KIJ := {};
let KIJ := KIJ union {(2,6,4)};
let t[2,6,4] := 264;
let KIJ := KIJ union {(3,6,4)};
let t[3,6,4]:= 364;
--
Robert Fourer
am...@googlegroups.com
I noticed your answer a little late, thanks for your detailed explanations! - May I finally draw your attention to one question already sketched: so when I learned that memory-usage can be directly increased by extending ranges of arrays (e.g. by increasing I[k] and J[k]), and subsequently using that extension storage, is there also a way to release memory (e.g. erasing an array I[k] x J[k] for any k)?
On Mon, Apr 30, 2018 at 6:15 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
It's true that if you define "param t {k in 1..K, i in 1..I[k], j in 1..J[k]};" and then assign only a few of the values in some of the I[k]-by-J[k] matrices, then AMPL will allocate space for only the values that you have assigned. However to later make use of those values, you'll need to keep track of where they are, which is basically the function of the set KIJ in my example.
I should note that another way to define your sparse data is to define
param K;
param I {1..K};
param J {1..K};
set IJ {k in 1..K} within {i in 1..I[k], j in 1..J[k]};
param t {k in 1..K, (i,j) in IJ[k]};
Then IJ[k] is a set of pairs that contains a member (i,j) for each position within matrix k where there is actually a number. In this case, no storage is allocated by "set IJ {k in 1..K} within . . ." until you add some pairs to some of the sets IJ[k] by, say,
let {k in 1..K} IJ[k] := {};
let IJ[2] := IJ[2] union {(6,4)};
let t[2,6,4] := 264;
let IJ[3] := IJ[3] union {(5,2)};
let t[3,5,2]:= 352;
Whether you use this or the other setup with a set KIJ of triples is just a matter of your preference and convenience; either way, t ends up having 3 subscripts.
--
Robert Fourer
am...@googlegroups.com