View source: R/get_path_pair.R
| get_path_pair | R Documentation |
Compute shortest path between origin and destination nodes.
get_path_pair(
Graph,
from,
to,
algorithm = "bi",
constant = 1,
keep = NULL,
long = FALSE
)
Graph |
An object generated by makegraph, cpp_simplify or cpp_contract 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). |
algorithm |
character. |
constant |
numeric. Constant to maintain the heuristic function admissible in A* and NBA algorithms. |
keep |
numeric or character. Vertices of interest that will be returned. |
long |
logical. If |
If graph is not contracted, the user has the choice between :
unidirectional Dijkstra (Dijkstra)
A star (A*) : projected coordinates should be provided
bidirectional Dijkstra (bi)
New bi-directional A star (NBA) : projected coordinates should be provided
If the input graph has been contracted by cpp_contract function, the algorithm is a modified bidirectional search.
When several shortest paths tie on the main edge weight, the exact node sequence returned for a
given from/to pair can differ between algorithms and graph representations (normal,
contracted or CCH), since each may break the tie differently. All of these paths are equally
optimal in terms of the main shortest distance.
In A* and NBA algorithms, euclidean distance is used as heuristic function.
All algorithms are multithreaded. Please use RcppParallel::setThreadOptions() to set the number of threads.
To understand the importance of constant parameter, see the package description : https://github.com/vlarmet/cppRouting/blob/master/README.md
list or a data.frame containing shortest path nodes between from and to.
from and from must be the same length.
get_multi_paths, 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 and undirected graph
directed_graph<-makegraph(edges,directed=TRUE)
non_directed<-makegraph(edges,directed=FALSE)
#Sampling origin and destination nodes
origin<-sample(nodes,10,replace=TRUE)
destination<-sample(nodes,10,replace=TRUE)
#Get distance between origin and destination in the two graphs
dir_paths<-get_path_pair(Graph=directed_graph, from=origin, to=destination)
non_dir_paths<-get_path_pair(Graph=non_directed, from=origin, to=destination)
print(dir_paths)
print(non_dir_paths)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.