# How to get some pairing with smallest total distance in high effciency method [duplicate]

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?

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