views:

26

answers:

1

Hello,

i want to store some kind of distance-matrix (2D), where each entry has some alternatives (different coordinates). So i want to access the distance for example x=1 with x_alt=3 and y=3 with y_alt=1, looking in a 4-dim multi-array with array[1][3][3][1].

The important thing to notice is the following: the 2 most inner arrays/vectors don't have the same size for different values of the outer ones.

After a first init step, where i calculate the values, no more modifying is needed!

This should be easily possible with the use of stl-vectors:

vector<vector<vector<vector<double> > > >`extended_distance_matrix;

where i can dynamically iterate over the outer 2 dimensions and fill only as much alternatives to the inner 2 dimensions as i need (e.g. with push_back()).

Questions:

  • Is this kind of data-structure definition possible with Boost.MultiArray? How?
  • Is it a good idea to use Boost.MultiArray instead of the nested vectors? Performance (especially lookups! (Memory-layout))? Easy of use?

Thanks for any input!

sascha

PS: The boost documentation didn't help me. Maybe one can use multi_array_ref to get already sized arrays into the whole 4D-structure?

Edit: At the moment i'm thinking of another approach: flattening the alternatives -> one bigger matrix with all the distances between the alternatives. Then i only need to calc the number of alternatives per node, build up the prefix sum (which is describing the matrix position/shift) and can then access the information in a 2-step-way.

But my questions are still open.

+1  A: 

it sounds like you need:

multi_array<ublas::matrix<type>,2>
aaa
A 2-dim array of 2-dim matrices? Could you please explain that in more detail? Where would you save the dynamic part (alternatives). How will this be indexed? The outer array is indexed by [x][y]. Maybe the id's of the object -> distance from x to y. But how should the alternative-chose be encoded? Now i have 4 more indexes (2 for each array part) for encoding an 2-index-information (one alternative-decision per id)? You see, i'm having problems understanding your proposal.
sascha