How to match two sets of points based on the closeset distance? I have a set of points (tiny triangles) $K=\{1,2,\ldots, k\}$ and a set points (tiny circles) $N=\{1,2,\ldots, n\}$ and a matrix of positive real values $\mathbf{D}=\left[d_{ij}\right]$ for all $i\in K$ and for all $j\in N$. The entry of the matrix $d_{ij}$ can be viewed as the Euclidean distance between triangle $i$ and circle $j$.

I would like to assign the triangles to the circles with the constraint that each assigned point is assigned to its closest neighbor. Also, the assignment must be one-to-one. For example, let 

$$
\mathbf{D}=\begin{pmatrix}
1 &amp; 1 &amp; 5\\
2 &amp; 3 &amp; 1\\
5 &amp; 8 &amp; 6
\end{pmatrix}.
$$
Now:


triangle 1 would like to be assigned to circle 1 or 2 and then 3 (we have a tie);
triangle 2 would like to be assigned to circle 3 then 1 and then 2;
triangle 3 would like to be assigned to circle 1 then 3 and then 2;


How can I solve this problem?

I thought of creating a list of preferences based on $\mathbf{D}$ like in the example:


List of preference for triangle 1: 1, 2, 3
List of preference for triangle 2: 3, 1, 2
List of preference for triangle 3: 1, 3, 2


But how can I continue on solving this?
You have an instance of a bipartite matching problem. There are some variations on the problem. I think you're looking for a minimum cost bipartite matching, but maybe you're looking for a stable matching.