I have two point set

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]


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

  • $\begingroup$ The Hungarian algorithm might help. $\endgroup$ Mar 28, 2017 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$ Mar 28, 2017 at 10:09
  • $\begingroup$ Why can Community mark a question duplicate by itself (without voting)? $\endgroup$
    – vapor
    Mar 28, 2017 at 11:53
  • $\begingroup$ @happyfish But it seem it is exactly a duplicate post~ $\endgroup$
    – yode
    Mar 28, 2017 at 12:16
  • 1
    $\begingroup$ @yode that's true, I just wonder why is the bot that sure about it. $\endgroup$
    – vapor
    Mar 28, 2017 at 12:19