K-means algorithm, improved to work with matrix of distances instead of coordinates.