Noqet
Noqet

Reputation: 33

ClosestFirstIterator with "max hops" cap per path

I am trying to use JgraphT to create a network graph for a redundant topology, and I'm interested in getting the closest node to another node, but the topology doesn't allow above a certain amount of hops to avoid loops. I was wondering if there is a way to quickly get vertices similarly to the way closestFirstIterator returns them, but with a cap on the amount of hops there can be for each path. I've noticed the closestFirstIterator constructor with the radius cap (which caps the accumulated weight from each hop), but that is not what I'm looking for.

Upvotes: 3

Views: 249

Answers (2)

dot
dot

Reputation: 61

You could use DijkstraShortestPath<V,E> and filter out the long paths you don't want, with a performance loss of course, but an alternative.

Upvotes: 0

Bimp
Bimp

Reputation: 494

You probably need the KShortestPaths class, which includes a nMaxHops option

EDIT: I do have to note that I noticed considerably better performance with BellmanFordShortestPath if you're interested in the best path for each vertice, but you'll have to provide the vertices yourself and use something like GraphPathImpl to convert the set of edges into a GraphPath

Upvotes: 2

Related Questions