I have a problem I need to solve, but I can't think of any easy and more important: fast solution. It's a bit like a part of a multiple traveling salesman problem.
First I have a matrix with X
rows and N
columns, N
is a static variable of my algorithm and X
can vary. Let's assume it looks like (here N = 5
):
matrix = [1 2 4 3 5; 4 3 1 2 5; 1 2 4 3 5; ]
matrix =
1 2 4 3 5
4 3 1 2 5
1 2 4 3 5
every row is seen as a "route" and contains all the unique numbers between 1 and N
Each route (= row) will be split in partial routes. That means, I have a breakpoint matrix which contains X
rows and M
(M < N
) columns. E.g.:
breakpoints = [2 3 4; 1 2 4; 1 3 4]
breakpoints =
2 3 4
1 2 4
1 3 4
The indices of each row of breakpoints
give the elements of the corresponding row of matrix
AFTER which the route will be split into partial routes. Just to make clear, let's regard the frist row as an example: breakpoints(1, :) = 2 3 4
which means, that the route matrix(1, :) = 1 2 4 3 5
will be split into the partial routes [1 2], [4], [3] and [5]
. The second row has the breakpoints breakpoints(2, :) = 1 2 4
which will split the second route matrix(2, :) = 4 3 1 2 5
into the partial routes [4], [3], [1 2] and [5]
.
Now my aim is to remove all rows from matrix
, whereas the partial routes are redundant duplicates, just in a different order. In this example row 2 is a duplicate of row 1. Row 3 is NO duplicate even if it has the same route as row 1, because there are different breakpoints which lead to the partial routes [1], [2 4], [3] and [5]
.
How could I do this cleanly and fast? Matrix can contain many elements, like X = 5e4
rows and N = 10
, M = 6
.