I have a pgRouting network graph of ~ 1 mio edges and ~ 0.4 mio vertices. I want to find out something like "nearest facility" for bigger subsets.

E.g. i have a bigger number of source vertices and a bigger number of target vertices. I need to know the cost (!) of the shortest path from every source vertex to the closest (lowest cost) target (and it's id). Nothing more. The graph itself won't be changed anymore.

At the moment I use pgr_dijkstraCost which takes ~ 0.05 s per source vertex. This is fast, but I need to run thee whole query (with up to 20.000 sources and up to 100 targets) within < 15 s.

Is it realistic to reach this goal just by optimizing the graph?


As you mentioned, your current response is quite fast already, but you could try to run all computations in one query with pgr_dijkstraCostMatrix if you need a full matrix, or recently the shortest path functions also allow so called "combinations" as input,for example https://docs.pgrouting.org/latest/en/pgr_dijkstraCost.html#combinations. This way your network graph is only loaded once.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.