For some years I have been working on a project. The project has come to a point where an optimization requires. But, I don't know how to do it. I am an amateur in
JAVA btw.
I create matrices; 4X3
String matrices let's say. Each column of the matrix is a 1D-Array of Strings. Each array consists of the letters {a,b,c,d}. Hence, to create a matrix I generate three 1D-Arrays of Strings.
My objective is to generate all possible 4X3 matrices whith all combinations of the letters {a,b,c,d}.
I do these by the following program segment. Please have a look.
Once I generate my matrices, I do my calculations (that I did not include here) below. I need to create all those combinations and the algorithm that I gave above works perfectly.
So far so good. The problem is the rest. The project has come to a point that I do NOT need to do my computations for all (i,j,k) triplets of the for-loops! I need a clearing (omit, drop) of (i,j,k) triplets. I do NOT want to do my calculations for all (i,j,k) that is 24x24x24=13.824 times.
I need all the combinations of the string {a,b,c,d} and these three for-loops, but I do not need all (i,j,k) triplets. So, some (i,j,k) triplets should be droped; the calculations (that I did not include here) should not be done for those triplets.
To drop those triplets, I need to apply two processes that I described at the end of my first message. If we suppose that two methods are independent from each other, then the first method is trivial: that is "do the calculations if i<=j<=k". But, what about the second one?
There are two rules to achieve this clearing.
1) If I have generated the matriks (i,j,k)=(0,1,6), I do not need any
exchange of the columns. That is I do not need any of matrices (1,0,6), (1,6,0), (0,6,1), (6,1,0) etc.
2) If we can reach matrix (i',j',k') from a matrix (i,j,k) by interchanging any two letters in every column, then we do not need to generate one of them.
Ex. from matrix (0,1,2), we reach matrix (6,7,8) by interchanging 'a' and 'b' in (0,1,2). That is,
0 abcd 1 abdc 2 acbd
6 bacd 7 badc 8 bcad
Anybody has any suggestion to do it? How can I aplly these two methods to for-loops to clear some of (i,j,k) triplets?