Currently, I am working on a project that involves NYC Taxi data, in which I am given where a person is picked up and dropped off in a network.
I am working with an ESRI
shapefile
, which I can load into R as an igraph
object with the shp2graph
package; I need to utilize Dijkstra's algorithm (or a similar shortest-path algorithm) to find the single shortest path between two given vertices. I thought that the get.shortest.paths()
method of the igraph
package would be my solution, but to my surprise, this calculates all shortest paths from a vertex to all others in a network.
To me, this seems like overkill, because I need only one single path between two specified nodes. I did some poking around online and in the igraph
documentation, but all I can find are methods surrounding calculating many shortest paths from a given vertex to all others.
Due to how computationally expensive it would be to calculate every single shortest path from a vertex, and then just select one from the behemoth of a list, I'm looking for a way to utilize Dijkstra's algorithm between two specified vertices in a graph. Is there a way to do this in the igraph
package, or if not, is there a good way to do this with a different package in R?
EDIT: In the end, I am hoping to look for a function that will take in the graph object and the ID of two vertices I wish to find the shortest path between, then return a list of paths/edges (or IDs) along that shortest path. This would help me to inspect each individual street along the shortest path between the two vertices.
EDIT: As an example of how I am currently using the function:
path <- get.shortest.paths(NYCgraph, from=32, mode="out")
. Something I would hope to find is path <- shortestPathFunction(NYCgraph, from=32, to=37)
to arbitrary calculate a shortest path between vertex ID 32 and vertex ID 37 (two random street intersections in the network).