I have an even number of points, each with coordinates $(x, y, z)$. I need to group these points into pairs. The cost of pairing two points is the Euclidean distance between them. I'd like to find the optimal pairing such that the total cost is minimized. What would be a good way/algorithm to solve this?

For example, if you have points $\{a, b, c, d\}$, one possible pairing might be $\{a,d\}, \{b,c\}$. Points can only belong to a single pair.

My Ideas:
The problem seems similar to finding the minimum weighted bipartite matching for a graph. However, I'm not trying to match between two sets of points, just find pairs in a single set. It seems like you might be able to convert this problem to a bipartite graph by duplicating the set of points. This doesn't seem like the right way to do it though (seems like you'd be solving for each pair twice).

You could solve it using an algorithm for weighted matching on general graphs. Just convert the set of points to a complete graph (drawing edges between all possible pairs). It doesn't seem like those algorithms were designed to solve this kind of problem, though (I could be wrong though). So I can't help but wonder if there is a better way to do it.

  • $\begingroup$ I'm wondering if 2-opt would solve this. (generate an arbitrary pair, then keep optimizing until each pair of pairs is optimal) $\endgroup$ – John Dvorak Dec 20 '16 at 23:25
  • $\begingroup$ That might be something to look into. I'm thinking the "stable roommates problem" is the right direction; though, I can't say for sure whether "stable" translates over to minimum total cost. $\endgroup$ – Azmisov Dec 21 '16 at 3:39
  • 2
    $\begingroup$ Okay, I found out this problem is commonly called "minimum weighted euclidean matching" in academic literature. Seems like there are specialized algorithms that have O(log(n)*n^2) complexity. $\endgroup$ – Azmisov Dec 21 '16 at 6:14
  • 1
    $\begingroup$ Cool! Would you like to write an answer to your own question, where you summarize the most important result(s) and give one or more citations to research papers where those results are presented? $\endgroup$ – D.W. Dec 21 '16 at 7:07
  • $\begingroup$ Sure; I have to read through the technical papers first. $\endgroup$ – Azmisov Dec 21 '16 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.