For two sets of $n$ dimensional points this is their distance matrix:
| $p_{11}$ | $p_{12}$ | $p_{13}$ | |
|---|---|---|---|
| $p_{21}$ | 1 | 2 | 3 |
| $p_{22}$ | 2 | 5 | 3 |
| $p_{23}$ | 2 | 3 | 1 |
| $p_{24}$ | 2 | 1 | 8 |
How can I get the $n$ points of $p_{1i}$ that give the minimum sum of distances in the most efficient way possible.
So far best I could do was apply the Hungarian assignment algorithm in a loop for all possible teams (this takes $\binom{i}{n}$ loops though and is not very efficient)
The solution for n=2 would follow this procedure: find the minimum sum of the minimum distances that each couple of p1,i gives for each row, for example:
$(p_{1,1}, p_{1,2}) = 1^{*}+2+2+1 = 6$
$(p_{1,2}, p_{1,3}) = 2+3+1+1 = 7$
$(p_{1,1}, p_{1,3}) = 1+2+1+2 = 6$
So the optimal couple would be either $(p_{1,1}, p_{1,2})$ or $(p_{1,1}, p_{1,3})$
explanation of the $1^{*}$: its the $min(d(p_{2,1},p_{1,1}), d(p_{2,1},p_{1,2}))=1$