I want to find the K-farthest neighbors in a given undirected weighted graph (the graph is given as a sparse weight matrix, but I can use an representation advised). Just to make sure the problem is well-defined: I want to find k nodes which have maximal distance from one another. Solutions that are close to the optimal set are also ok - I just need it to find some farthest points in a mesh :)
-
1Just to clarify, in a graph there is more than one way of getting from A to B. You want the two nodes where the shortest distance between them is as long as possible, correct? – Isaac Nov 07 '12 at 16:56
-
Yes, except that I want K nodes and not 2 :) – olamundo Nov 07 '12 at 22:51
-
Are you looking for a solution that works for euclid distances, or something more general? Furthermore, how do you define the distance between k points? – Dennis Jaheruddin Nov 08 '12 at 12:40
-
@DennisJaheruddin - I am asking about a weighted grpah, not about points embedded in R^n.The distance is the usual "distance" between two nodes on a weighted graph: the minimal sum of weights on a path from a to b. – olamundo Nov 08 '12 at 13:25
-
So the maximum distance between a, b and c would be the longest path that includes only a, b and c? – Dennis Jaheruddin Nov 08 '12 at 13:49
-
@DennisJaheruddin - No. It would be the set {a,b,c} that maximizes the sum of distances between all 3 pairs |a-b|+|a-c|+|b-c| where | | is some norm – olamundo Nov 11 '12 at 00:05
1 Answers
Assuming you are just looking for a decent solution I would recommend a simple solution similar to the "furthest insertion" starting position for the travelling salesman problem:
- Add 1 point to the empty set, preferably one in the corner or in the edge (Of course you can just try all of them)
- Add the furthest point to the set (increase the distance most from current points in set)
- Keep repeating the previous step untill there are k points in the set
It will not be optimal but probably not very bad.
If you want to improve on this you could use a heuristic to improve on the result, for example:
- Consider the set with point 1 to j left out, j
- Try all possible points to substitute these j points
- record best possible solution
- Consider the set with point 2 to j+1 left out
etcetera
Furthermore if k is not too large, say less than 5, and the total amount of points is not too large, say less than 100, it will probably be easier to just calculate all possible combinations. This is assuming that the norm calculation can be done efficiently.
EDIT:
Once you know you want to implement this the regular way to continue is find something similar and edit it a bit to suit your needs. If you scroll down on this page you should find an example of furthest insertion. Editing it to follow your measure of 'far' should be managable.

- 21,208
- 8
- 66
- 122
-
Thanks, this is exactly what I meant - I actually wasn't looking for an algorithm but, for *matlab code* – olamundo Nov 11 '12 at 17:37
-