UDST / pandana

Pandas Network Analysis by UrbanSim: fast accessibility metrics and shortest paths, using contraction hierarchies :world_map:
http://udst.github.io/pandana
GNU Affero General Public License v3.0
386 stars 84 forks source link

Expose shortest path functionality #39

Open gregerhardt opened 9 years ago

gregerhardt commented 9 years ago

Can the underlying shortest path functionality in pananda be exposed so it can be called using a python method? Given a node pair A-B, I want to get back 1) the impedance from A to B, and 2) the sequence of node or link IDs that define the shortest path from A to B. Doing this for a list of node pairs is even better.

My specific use case is that I am matching probe vehicle GPS points to the a network. Since they are only collected every 60 seconds, I need to impute the path between points, so I end up building many "short" shortest paths to do so. My current implementation works, but is slow, and I'm hoping your multi-threaded C++ implementation can speed things up.

pandana looks like it could turn into a nice general purpose networks container for transportation modelling/analysis, and I think exposing more of this functionality would help in that regard. Many thanks!

gregerhardt commented 9 years ago

UPDATE: I've come to a solution that serves my needs for the time being, so this is not a time-critical issue for me. Although if it is implemented, I would look into switching over.

It is a bit tangential, but in case anyone is interested, here are some of the tools that I've used or looked into:

I am using the DTA Anway classes (https://code.google.com/p/dta/) to store my networks. This is derived from a dynamic traffic assignment project, but gives me a package to read networks in a couple of different formats, and deal with intersection control, centroid connectors and such things. I originally used an SP algorithm implemented in this package, but I was naively re-calculating the paths with each call, so it was slow.

To speed things up, I considered: pandana, networkX, aequilibrae, and scipy. Of those, I found:

My bottlneck is currently in matching points to the N nearest links, but that is another topic.

fscottfoti commented 9 years ago

Thanks for the summary Gregory. As you mentioned, the SP in Pandana does exist on the C++ side but hasn't yet been exposed in Python, and it shouldn't be too much work to do so. It's always been on our roadmap but it's good to know that there's interest so that we can prioritize it. Since the underlying SP implementation uses contraction hierarchies (we use older code from the OSRM project), this should be quite fast, although if you use scipy to do the all pairs shortest path I think that should be efficient as well. I think that approach would fail for very large networks - like 200k edges, which is what we typically use for the 9 county Bay Area local street network. Will let you know as we make progress!

gregerhardt commented 9 years ago

Thanks, Fletcher.

Yeah, I'm currently using a City of SF network that has about 30k edges, so I can imagine 200k making it blow up due to having to store the return matrices in memory.

songololo commented 9 years ago

Hey Greg, (hi from London!) if you specifically need high performance (via C++ bindings and multiprocessor support) then have a look at graph-tool. Not sure how it fares in Windows, though worked quite well for me on Ubuntu. (When running natively on Mac then it isn't able to utilise all processor cores.) You can also do some interesting things by moving the data to and from numpy and you can load / save to graphML format.

knaaptime commented 4 years ago

wanted to vote +1 on this. We'd be really interested to use pandana for network-based spatial weights in pysal and this would be an easy way to get there

smmaurer commented 4 years ago

It looks like this was implemented in #48 and included in the v0.4.0 release, actually, but left out of the change log.

https://github.com/UDST/pandana/blob/master/pandana/network.py#L174-L203

Does this provide what you need?

knaaptime commented 4 years ago

oh awesome! though as fletcher mentioned,

a nice extension of this would be to get a dataframe of shortest paths, in parallel

which would be ideal

knaaptime commented 4 years ago

for my part, this is essentially the same request as #120 and #56