1

I'm using the LEMON library in a project of mine and I have a doubt about how to best use it to evaluate a complete distance matrix between vertices in a given set.

So, consider we are given a large graph (represented as a ListDigraph), a subset of vertices S and we need to evaluate all shortest paths between any two vertices in S.

The easiest way to do that would be running the Dijkstra algorithm for each combination of two vertices in S, but of course this not the best idea in terms of efficiency.

One thing that I thought was to evaluate one path from a vertex i to a vertex j, both in S, and then search the ProcessedMap for any other vertex in S. If I find one, say k, I already have the distance from i to k. This would most probably reduce the number of calls to the algorithm. However I still think there should be a better solution in lemon.

Is adding multiple sources of any help? I didn't quite understand yet the behaviour of the class Dijkstra when using this feature.

Thank you =)

BrunoB
  • 337
  • 1
  • 4
  • 16
  • How dense is the graph? – David Eisenstat Oct 29 '15 at 22:01
  • One quick improvement over running Dijkstra on all vertex *pairs* is to just run it to completion on all *vertices*: It computes the shortest path from a given vertex to *all* other vertices in (asymptotically) the same time as the shortest path to a given other vertex. – j_random_hacker Oct 30 '15 at 06:03
  • @DavidEisenstat ~30k vertices and |S| is ~400. It takes several minutes sometimes if I do in the easiest way – BrunoB Oct 30 '15 at 09:20
  • @j_random_hacker My graph is an OpenStreetMap map and S contains some vertices added into the map later. The thing is that I only need the distances between these vertices in S which are not as much as the vertices on the map. If they are kind of clustered in the same region it would be a waste of time running the algorithm for all vertices – BrunoB Oct 30 '15 at 09:24
  • Ah, if it's a road network, then there are some very efficient shortest path algorithms in the literature specifically designed for it. – David Eisenstat Oct 30 '15 at 11:44

0 Answers0