I have to sets of points, lets say set A and B
All the points of A have to 'move' to an point of B, but an point of B cannot be coupled to multiple points of A.
I need to find the best combination, where the total (walk) distance (added up from the distance between each pair) is the minimal.
I made an example in Java for demonstration purposes (currently bruteforce every possible combination and check which has the smallest total distance)
Example 1
Example 2
Green rectangles represent a point in set A, Cyan rects represents a point in set B, ignore the orange square
How would I approach this?
This is an assignment problem, which can be solved in O(n³) time by the Hungarian algorithm. It should not be too hard to find source code or implement it yourself.