View source: R/get_multi_paths.R
get_multi_paths | R Documentation |
Compute all shortest paths between origin and destination nodes.
get_multi_paths(Graph, from, to, keep = NULL, long = FALSE)
Graph |
An object generated by makegraph or cpp_simplify function. |
from |
A vector of one or more vertices from which shortest paths are calculated (origin). |
to |
A vector of one or more vertices (destination). |
keep |
numeric or character. Vertices of interest that will be returned. |
long |
logical. If |
get_multi_paths()
recursively perform Dijkstra algorithm for each 'from' nodes. It is the equivalent of get_distance_matrix, but it return the shortest path node sequence instead of the distance.
This algorithm is multithreaded. Please use RcppParallel::setThreadOptions()
to set the number of threads.
List or a data.frame containing shortest paths.
Be aware that if 'from' and 'to' have consequent size, output will require much memory space.
get_path_pair, get_isochrone, get_detour
#Choose number of cores used by cppRouting RcppParallel::setThreadOptions(numThreads = 1) #Data describing edges of the graph edges<-data.frame(from_vertex=c(0,0,1,1,2,2,3,4,4), to_vertex=c(1,3,2,4,4,5,1,3,5), cost=c(9,2,11,3,5,12,4,1,6)) #Get all nodes nodes<-unique(c(edges$from_vertex,edges$to_vertex)) #Construct directed graph directed_graph<-makegraph(edges,directed=TRUE) #Get all shortest paths (node sequences) between all nodes dir_paths<-get_multi_paths(Graph=directed_graph, from=nodes, to=nodes) print(dir_paths) #Get the same result in data.frame format dir_paths_df<-get_multi_paths(Graph=directed_graph, from=nodes, to=nodes, long = TRUE) print(dir_paths_df)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.