Calculate the distance matrix D for each point in Set A and all points in Set B.
pre_pair = cur_pair
Remove points from Set A and B in pre_pair and cur_pair
A randomly selected point from Set A match with the point from Set B of maximum probability to get the matching pair pre_pair
Swap the positions of pre_pair and cur_pair in Set B
Calculate the probability matrix P from the D matrix
No
A randomly selected point from Set A match with the point from Set B of maximum probability to get the matching pair cur_pair
Define Set ADefine Set B
If Set B is empty
If the pre_pair connection does not intersect the cur_dir connection
End
Yes