Given a situation like this:
where the position of the triangles is given (it does not need to be calculated by an algorithm). I would like to find clusters of circles around the triangles. Each cluster should contain a given number of circles (in this example every cluster gets 4 circles) and the clusters should be formed in such a way that the average of the average distances from the center of each triangle to the center of every circle in its cluster is minimal. In mathematical notation, the goal is to minimize the value:
So given the example above, the desired output would probably look like this:
Is there an algorithm to calculate this?