View source: R/get_distance_mat.R
| get_distance_matrix | R Documentation | 
Compute all shortest distance between origin and destination nodes.
get_distance_matrix( Graph, from, to, algorithm = "phast", aggregate_aux = FALSE, allcores = FALSE )
| Graph | An object generated by makegraph, cpp_simplify or cpp_contract function. | 
| from | A vector of one or more vertices from which distances are calculated (origin). | 
| to | A vector of one or more vertices (destination). | 
| algorithm | Character. Only for contracted graph,  | 
| aggregate_aux | Logical. If  | 
| allcores | Logical (deprecated). If  | 
If graph is not contracted, get_distance_matrix() recursively perform Dijkstra algorithm for each from nodes.
If graph is contracted, the user has the choice between : 
 many to many contraction hierarchies (mch) : optimal for square matrix.
 PHAST (phast) : outperform mch on rectangular matrix
Shortest path is always computed according to the main edge weights, corresponding to the 3rd column of df argument in makegraph() function.
If aggregate_aux argument is TRUE, the values returned are the sum of auxiliary weights along shortest paths.
All algorithms are multithreaded. allcores argument is deprecated, please use RcppParallel::setThreadOptions() to set the number of threads.
See details in package website : https://github.com/vlarmet/cppRouting/blob/master/README.md
Matrix of shortest distances.
It is not possible to aggregate auxiliary weights on a Graph object coming from cpp_simplify function.
get_distance_pair, get_multi_paths
#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),
                    time = c(9,2,11,3,5,12,4,1,6),
                    dist = c(5,3,4,7,5,5,5,8,7))
#Construct directed  graph with travel time as principal weight, and distance as secondary weight
graph <- makegraph(edges[,1:3], directed=TRUE, aux = edges$dist)
#Get all nodes IDs
nodes <- graph$dict$ref
# Get matrix of shortest times between all nodes : the result are in time unit
time_mat <- get_distance_matrix(graph, from = nodes, to = nodes)
# Get matrix of distance according shortest times : the result are in distance unit
dist_mat <- get_distance_matrix(graph, from = nodes, to = nodes, aggregate_aux = TRUE)
print(time_mat)
print(dist_mat)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.