I don't know if this a well known problem or is reducible to one, but here is what I am struggling with since last few days.
Let X_1, X_2, X_3 .. X_n be sets of integers.
In each set X_i, we have m (equal for all sets) elements x_i,j : j = 1...m.
My goal is to pick a single element from each set, such that the sum of pairwise differences between all the selected elements is least possible.
I started off with a slightly different problem of minimizing the sum of serial-differences (that is, sum of differences between elements selected from consecutive sets).The forward computation in DP is as follows:
Let F(i, j) be the cost to select element j from set i.
F(i, j) = min_k F(i - 1, k) + |x(i-1,k) - x(i, j)|
That is, we select k-th element in the previous set and then evaluate the cost of selecting j-th element in the current set. The cost of current step is equal to the absolute difference between the k-th element in set i-1 and j-th element in set i.
However, my real problem does not depend on the order of the sets X_1, ... X_n. In essence, the dynamic programming is giving me something, but as I said, it is a related but different problem of finding the "chain" of elements, one from each set, such that the sum of "serial" differences is minimized.
From a basic analysis, I see that a naive solution to this problem would be to generate all permutations of the n sets and then solve it using dynamic programming for each permutation. This is intractable, but when n is small enough - we can even take this dumb exhaustive approach.
I am unable to figure out if this problem can be solved using a polynomial algorithm at all, or if it can be reduced to one of the known NP-hard/complete problems in which case, I will go for an approximate algorithm by modeling it as a quadratic program.
Please advise me or point me to some reading material.
Thanks.
[Edit 1]
Adding an example here for the convenience of discussion:
X = [[11, 24, 38], [12, 21, 33], [13, 22], [15, 23]]
The solution is 24, 21, 22, 23 (possibly irrelevant, but my DP gives me 11, 12, 13, 15, I have constructed this example particularly to fail my DP.).
[Edit 2]
I guess this is not an NP-complete problem. The solution that we can expand from the DP is as follows [Not sure if correct, but seems like it]:
The solution contains at least one element from each set.
So, let us select any set (preferably smallest, if the sizes vary), and remove it from the list.
Lets call it X\Xp where Xp is the set removed.
Now for each element x in \Xp, construct a new set X' = X\Xp U {x}.
We solve the DP m-times and compute the objective function (sum of pairwise distances) and then we can pick the best of them.
The DP itself takes O(nm^2) and we run this m-times, so we have O(nm^3).