Unique Permutation: with logical Elements OR with vectors which should at the end stand as one dimension (after each other) in a 2-dim-Matrix
1 view (last 30 days)
Show older comments
Hello everybody,
I have a tough problem. I try to explain in a simple way: I need a logical 2-dim-matrix (just ones and zeros) with every possible combination of ones and zeros AND some additional conditions:
- number of "ones" per line is fixed, e.g. two "ones" per line, but it can be more. Variable "N_min" shows the exact number of ones per line
- some columns (always side by side) refer to each other and in these columns, there must be at most one "one" per line. Number of columns, which refer to each other, may change between one and ... well, open end. Also 100 columns is possible. The vector "NoL" indicates, how many columns refer to each other.
Here is an example. NoL and N_min are known, X is what i am looking for:
NoL = [1 3 3]
N_min = 2
X=[
0 0 0 1 0 0 1;
0 0 0 1 0 1 0;
0 0 0 1 1 0 0;
0 0 1 0 0 0 1;
0 0 1 0 0 1 0;
0 0 1 0 1 0 0;
0 1 0 0 0 0 1;
0 1 0 0 0 1 0;
0 1 0 0 1 0 0;
1 0 0 0 0 0 1;
1 0 0 0 0 1 0;
1 0 0 0 1 0 0;
1 0 0 1 0 0 0;
1 0 1 0 0 0 0;
1 1 0 0 0 0 0]
NoL indicates, that the first column stands alone for itself, columns 2-4 and 5-7 refer to each other and in these columns, there must be at most one "one" per line, but could be all zero after all. N_min means, there are 2 "ones" in every line.
Until now i did it the following way (and it works fine until the matrix grows too large): I made a vector w and used "uperm" from Bruno Luong (<http://www.mathworks.com/matlabcentral/newsreader/view_thread/164470)>, then i deleted every line where my second condition is violated. Refered to my example at top:
w = [1 1 0 0 0 0 0]
W = uperm(w)
X = deletesomelines(W,NoL) %"deletesomelines" is a function written by myself to delete every line which violates the rule of just one "one" per line in refering columns
Problem is: with bigger Matrizes my PC keeps on running out of memory. Last thing that worked was a vector w with seven "ones" and 28 "zeros". uperm generated a Matrix with 35 columns and about 7 million lines. My PC was out of memory. And this is not the upper end of matrix sizes i want to work with.
My thoughts of solution:
a) Can someone please help me by converting the uperm-function of Bruno Luong into a logical function which uses just logical expressions instead of doubles? 35x7mio Matrix of datatype "double" needs 2GB, of type "logical" just 25 MB
b) Has anybody an idea of a special function for my problem? A "permutation of permutations" to directly get just the matrix i need instead of getting a very big one and deleting many lines?
2 Comments
James Tursa
on 22 Sep 2015
Do you have a C compiler? This might be an interesting problem for me to attack with a mex routine.
Answers (2)
See Also
Categories
Find more on Numeric Types in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!