get_multi_paths {cppRouting}R Documentation

Compute all shortest paths between origin and destination nodes.

Description

Compute all shortest paths between origin and destination nodes.

Usage

get_multi_paths(Graph, from, to, keep = NULL, long = FALSE)

Arguments

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 TRUE, a long data.frame is returned instead of a list.

Details

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.

Value

List or a data.frame containing shortest paths.

Note

Be aware that if 'from' and 'to' have consequent size, output will require much memory space.

See Also

get_path_pair, get_isochrone, get_detour

Examples

#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)

[Package cppRouting version 3.1 Index]