You have a complete bipartite graph that one part is numbers and other one is points. Weight's of edge in this graph is euclidean distance between numbers and points. And you're task is finding matching with minimal weight.
This is known problem and has a well known algorithm named as Hungarian Algorithm
:
From Wiki:
We are given a nonnegative n×n matrix, where the element in the i-th
row and j-th column represents the cost of assigning the j-th point to
the i-th number. We have to find an assignment of the point to the
numbers that has minimum cost. If the goal is to find the assignment
that yields the maximum cost, the problem can be altered to fit the
setting by replacing each cost with the maximum cost subtracted by the
cost.
The algorithm is easier to describe if we formulate the problem using
a bipartite graph. We have a complete bipartite graph G=(S, T; E) with
n number vertices (S) and n point vertices (T), and each edge has a
nonnegative cost c(i,j). We want to find a perfect matching with
minimum cost. The Hungarian method is a combinatorial optimization
algorithm which solves the assignment problem in polynomial time and
which anticipated later primal-dual methods. f
For detailed algorithm and code you can take a look at topcoder article
and this pdf maybe to use
there is a media file to describe it.
(This video explains why the Hungarian algorithm works)
algorithm :
step 1:- prepare a cost matrix.if the cost matrix is not a square
matrix then add a dummy row(column) with zero cost element.
step 2:- subtract the minimum element in each row from all the
elements of the respective rows.
step 3:- further modify the resulting matrix by subtracting the
minimum elememnt of each column from all the elements of the
respective columns.thus obtain the modified matrix.
step 4:- then,draw minimum no of horizontal and vertical lines to
cover all zeros in the resulting matrix.let the minimum no of lines be
N.now there are 2 possible cases.
case 1 - if N=n,where n is the order of matrix,then an optimal
assignment can be made.so make the assignment to get the required
solution.
case 2 - if N less than n then proceed to step 5
step 5: determine the smallest uncovered element in the
matrix(element not covered by N lines).subtract this minimum element
from all uncovered elements and add the same elements at the
intersection of horizontal and vertical lines.thus the second modified
matrix is obtained.
step 6:- repeat step(3) and (4) untill we get the case (1) of step 4.
step 7:- (to make zero assignments) examine the rows successively
untill a row-wise exactly single zero is found.circle(o) this zero to
make the assignment.then mark a cross(x) over all zeros if lying in
the column of the circled zero,showing that they can't be considered
for future assignment.continue in this manner untill all the zeros
have been examined. repeat the same procedure for column also.
step 8:- repeat the step 6 succeccively until one of the following
situation arises- (i)if no unmarked zeros is left,then the process
ends or (ii) if there lies more than one of the unmarked zero in any
column or row then,circle one of the unmarked zeros arbitrarily and
mark a cross in the cell of remaining zeros in its row or
column.repeat the process untill no unmarked zero is left in the
matrix.
step 9:- thus exactly one marked circled zero in each row and each
column of the matrix is obtained. the assignment corresponding to
these marked circle zeros will give the optimal assignment.
For details see wiki and http://www.ams.jhu.edu/~castello/362/Handouts/hungarian.pdf