Dear all,
I wrote the simple code reported above. Basically, this code acts on set of bi-dimensional vectors (in particular, a set of 32 bi-dimensional vectors). To each vector is associated a position (that is calculated with the istruction Pos[] defined previously). The aim of the code is to find the smallest vector (in lexicographical order) that holds a possible position.
As you can see in code, I implemented a double nested For loop. For each element i of the set, the code:
1) Creates a boolean vector VV that contains the results of the istruction: Pos[TPal[[i]]] != Pos[TPal[[j]]]. This vector VV is then used to calculate if the element i of the set holds an univocal position (If[VV // Reduce, AppendTo[TPau, TPal[[i]]]]).
2) Compares the vector position (Pos[TPal[[i]]]) with all the other ones (Pos[TPal[[j]]]). If two vectors with the same position are found, they are stored in a set Gmin that will be sort at the end of the second loop. Finally, the duplicate elements are removed.
This code works well for shorter set (as the one shown in the example reported). But its complexity is very high, so if I move to longer set, the elaboration time increses very quickly. In particular, I need to increase the set length by a factor 8 for each elaboration (e.g., 32, 256, 2048, 16384, ecc.). Currently, the set 2048 long requires about 8 hour. My question if is it would be possible to reduce the complexity of the code in order to increase the maximum number of evaluations that I can do with a normal computer.
I hope I made myself clear and I thank you very much for your kind replies.
CODE
TPa = Table[{x, y}, {x, 1, 4}, {y, 1, 8}];
TPal = ArrayReshape[TPa, {8*4, 2}]
TPa // TraditionalForm
Table[Pos[{x, y}], {x, 1, 4}, {y, 1, 8}] // TraditionalForm
TPau = {{0, 0}};
For[
i = 1,
i <= 32,
i++,
VV = {True};
Gmin = {TPal[[i]]};
For[
j = 1,
j <= 32,
j++,
If[j != i, AppendTo[VV, Pos[TPal[[i]]] != Pos[TPal[[j]]]]];
If[j != i && Pos[TPal[[i]]] == Pos[TPal[[j]]],
AppendTo[Gmin, TPal[[j]]]];
];
If[VV // Reduce, AppendTo[TPau, TPal[[i]]],
AppendTo[TPau, (Gmin // Sort)[[1]]]];
]
Drop[TPau, 1];
TPauFin = % // DeleteDuplicates