0
$\begingroup$

This question already has an answer here:

I have two point set

SeedRandom[1]
pts1 = RandomReal[1, {10, 2}];
pts2 = RandomReal[1, {10, 2}];
Graphics[{PointSize[Medium], Red, Point[pts1], Blue, Point[pts2]}]

I want to get a match for every point,If I use Transpose directly,the total distance will very big like

pairs = Transpose[{pts1, pts2}];
totalDist = Total[EuclideanDistance @@@ pairs]

5.29783

How to get such pairs with smallest total distance in a high effciency method?

$\endgroup$

marked as duplicate by Quantum_Oli, Community Mar 28 '17 at 10:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ The Hungarian algorithm might help. $\endgroup$ – Martin Ender Mar 28 '17 at 9:08
  • $\begingroup$ As far as I am aware this is one of the fastest implementations for the assignment problem on this site. It returns a total distance of 2.54317 in under 1ms for your test case. $\endgroup$ – Quantum_Oli Mar 28 '17 at 10:09
  • $\begingroup$ Why can Community mark a question duplicate by itself (without voting)? $\endgroup$ – happy fish Mar 28 '17 at 11:53
  • $\begingroup$ @happyfish But it seem it is exactly a duplicate post~ $\endgroup$ – yode Mar 28 '17 at 12:16
  • 1
    $\begingroup$ @yode that's true, I just wonder why is the bot that sure about it. $\endgroup$ – happy fish Mar 28 '17 at 12:19