I have a set S of n points in dimension d for which I can calculate all pairwise distances if need be. I need to select k points in this set so that t
Here's a working (brute-force) implementation for small n, which if nothing else shows the expressiveness of generator comprehensions:
selection = max(
itertools.combinations(points, k),
key=lambda candidate: sum(
dist(p, q) for p, q in itertools.combinations(candidate, 2)
)
)
Although this ends up calling dist
a lot:
(k! / 2! / (k-2)!) * (n! / k! / (n-k)! == n! /(2(k-2)!(n-k)!)