Skip to content

Commit 5b51b5d

Browse files
authored
Add files via upload
1 parent 26fdd55 commit 5b51b5d

7 files changed

+44
-30
lines changed

R/contract.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#' Contraction hierarchies algorithm
22
#' @description Contract a graph by using contraction hierarchies algorithm
3-
#' @param Graph An object generated by cppRouting::makegraph() function.
3+
#' @param Graph An object generated by makegraph() or cpp_simplify() function.
44
#' @param silent Logical. If TRUE, progress is not displayed.
55
#' @return A contracted graph.
66
#' @details Contraction hierarchy is a speed-up technique for finding shortest path in a graph.
77
#' It consist of two steps : preprocessing phase and query. cpp_contract() preprocess the input graph to later use special query algorithm implemented in get_distance_pair(),get_distance_matrix() and get_path_pair() functions.
8-
#' To see the benefits of using contraction hierarchies, see the package description : https://github.com/vlarmet/cppRouting.
8+
#' To see the benefits of using contraction hierarchies, see the package description : \url{https://github.com/vlarmet/cppRouting/blob/master/README.md}.
99
#' @examples
1010
#' #Data describing edges of the graph
1111
#' edges<-data.frame(from_vertex=c(0,0,1,1,2,2,3,4,4),

R/get_detour.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' Return the nodes that can be reached in a detour time set around the shortest path
22
#'
3-
#' @param Graph An object generated by cppRouting::makegraph() function.
3+
#' @param Graph An object generated by makegraph() or cpp_simplify() function.
44
#' @param from A vector of one or more vertices from which shortest path are calculated (origin).
55
#' @param to A vector of one or more vertices (destination).
66
#' @param extra numeric. Additional cost

R/get_distance_mat.R

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
#' @param algorithm Character. Only for contracted graph, "mch" for Many to many CH, "phast" for PHAST algorithm
77
#' @param allcores Logical. If TRUE, all cores are used.
88
#' @return Matrix of shortest distances.
9-
#' @note If graph is not contracted, get_distance_matrix() recursively perform Dijkstra algorithm for each 'from' nodes.
9+
#' @details If graph is not contracted, get_distance_matrix() recursively perform Dijkstra algorithm for each 'from' nodes.
1010
#' If graph is contracted, the user has the choice between : \itemize{
11-
#' \item many to many contraction hierarchies (mch) : should be applied if the matrix is square or 'almost' square.
11+
#' \item many to many contraction hierarchies (mch) : optimal for square matrix.
1212
#' \item PHAST (phast) : outperform mch on rectangular matrix
1313
#' }
14-
#' See details in package website : https://github.com/vlarmet/cppRouting/blob/master/README.md
14+
#' See details in package website : \url{https://github.com/vlarmet/cppRouting/blob/master/README.md}
1515
#' @examples
1616
#' #Data describing edges of the graph
1717
#' edges<-data.frame(from_vertex=c(0,0,1,1,2,2,3,4,4),
@@ -87,24 +87,24 @@ get_distance_matrix<-function(Graph,from,to,algorithm="phast",allcores=FALSE){
8787
}
8888
else{
8989

90-
test<-data.frame(id=Graph$dict$id,rank=(Graph$nbnode)-Graph$rank)
90+
invrank<-(Graph$nbnode)-Graph$rank
9191

9292
if (allcores==TRUE){
9393

9494
if (length(to)< length(from)){
95-
res<-Phast_par(test$rank[to_id+1],
96-
test$rank[from_id+1],
97-
test$rank[match(Graph$data$to,test$id)],
98-
test$rank[match(Graph$data$from,test$id)],
95+
res<-Phast_par(invrank[to_id+1],
96+
invrank[from_id+1],
97+
invrank[Graph$data$to+1],
98+
invrank[Graph$data$from+1],
9999
Graph$data[,3],
100100
Graph$nbnode)
101101

102102
}
103103
else {
104-
res<-Phast_par(test$rank[from_id+1],
105-
test$rank[to_id+1],
106-
test$rank[match(Graph$data$from,test$id)],
107-
test$rank[match(Graph$data$to,test$id)],
104+
res<-Phast_par(invrank[from_id+1],
105+
invrank[to_id+1],
106+
invrank[Graph$data$from+1],
107+
invrank[Graph$data$to+1],
108108
Graph$data[,3],
109109
Graph$nbnode)
110110

@@ -113,8 +113,8 @@ get_distance_matrix<-function(Graph,from,to,algorithm="phast",allcores=FALSE){
113113

114114
}
115115
else {
116-
if (length(to)< length(from)) res<-Phast3(test$rank[to_id+1],test$rank[from_id+1],test$rank[match(Graph$data$to,test$id)],test$rank[match(Graph$data$from,test$id)],Graph$data[,3],Graph$nbnode)
117-
else res<-Phast3(test$rank[from_id+1],test$rank[to_id+1],test$rank[match(Graph$data$from,test$id)],test$rank[match(Graph$data$to,test$id)],Graph$data[,3],Graph$nbnode)
116+
if (length(to)< length(from)) res<-Phast3(invrank[to_id+1],invrank[from_id+1],invrank[Graph$data$to+1],invrank[Graph$data$from+1],Graph$data[,3],Graph$nbnode)
117+
else res<-Phast3(invrank[from_id+1],invrank[to_id+1],invrank[Graph$data$from+1],invrank[Graph$data$to+1],Graph$data[,3],Graph$nbnode)
118118
}
119119
}
120120

R/get_distance_pair.R

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@
44
#' @param from A vector of one or more vertices from which distances are calculated (origin).
55
#' @param to A vector of one or more vertices (destination).
66
#' @param algorithm character. "Dijkstra" for uni-directional Dijkstra, "bi" for bi-directional Dijkstra, "A*" for A star unidirectional search or "NBA" for New bi-directional A star .Default to "Dijkstra"
7-
#' @param constant numeric. Constant to maintain the heuristic function admissible in A* algorithm.
7+
#' @param constant numeric. Constant to maintain the heuristic function admissible in A* and NBA algorithms.
88
#' Default to 1, when cost is expressed in the same unit than coordinates. See details
99
#' @param allcores Logical. If TRUE, all cores are used.
1010
#' @return Vector of shortest distances.
1111
#' @note 'from' and 'to' must be the same length.
12-
#' @details If the input graph has been contracted by cpp_contract() function, the algorithm is a modified bidirectional search.
13-
#' To perform A* and New Bidirectional A star, projected coordinates should be provided in the Graph object.
12+
#' @details If graph is not contracted, the user has the choice between : \itemize{
13+
#' \item unidirectional Dijkstra (Dijkstra)
14+
#' \item A star (A*) : projected coordinates should be provided
15+
#' \item bidirectional Dijkstra (bi)
16+
#' \item New bi-directional A star (NBA) : projected coordinates should be provided
17+
#' }
18+
#'
19+
#' If the input graph has been contracted by cpp_contract() function, the algorithm is a modified bidirectional search.
20+
#'
1421
#' In A* and New Bidirectional A star algorithms, euclidean distance is used as heuristic function.
15-
#' To understand how A star algorithm work, see https://en.wikipedia.org/wiki/A*_search_algorithm .
16-
#' To understand the importance of constant parameter, see the package description : https://github.com/vlarmet/cppRouting
22+
#' To understand how A star algorithm work, see \url{https://en.wikipedia.org/wiki/A*_search_algorithm}.
23+
#' To understand the importance of constant parameter, see the package description : \url{https://github.com/vlarmet/cppRouting/blob/master/README.md}
1724
#' @examples
1825
#' #Data describing edges of the graph
1926
#' edges<-data.frame(from_vertex=c(0,0,1,1,2,2,3,4,4),

R/get_multi_paths.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' Compute all shortest paths between origin and destination nodes.
22
#'
3-
#' @param Graph An object generated by cppRouting::makegraph() function.
3+
#' @param Graph An object generated by makegraph() or cpp_simplify() function.
44
#' @param from A vector of one or more vertices from which shortest paths are calculated (origin).
55
#' @param to A vector of one or more vertices (destination).
66
#' @param keep numeric or character. Vertices of interest that will be returned.

R/get_path_pair.R

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' Compute shortest path between origin and destination nodes.
22
#'
3-
#' @param Graph An object generated by cppRouting::makegraph() function.
3+
#' @param Graph An object generated by makegraph(), cpp_simplify() or cpp_contract() function.
44
#' @param from A vector of one or more vertices from which shortest paths are calculated (origin).
55
#' @param to A vector of one or more vertices (destination).
66
#' @param algorithm character. "Dijkstra" for uni-directional Dijkstra, "bi" for bi-directional Dijkstra, "A*" for A star unidirectional search or "NBA" for New bi-directional A star .Default to "Dijkstra"
@@ -10,11 +10,18 @@
1010
#' Default to 1, when cost is expressed in the same unit than coordinates. See details
1111
#' @return List or a data.frame containing shortest path nodes between from and to.
1212
#' @note 'from' and 'to' must be the same length.
13-
#' @details If the input graph has been contracted by cpp_contract() function, the algorithm is a modified bidirectional search.
14-
#' To perform A* and New Bidirectional A star, projected coordinates should be provided in the Graph object.
13+
#' @details If graph is not contracted, the user has the choice between : \itemize{
14+
#' \item unidirectional Dijkstra (Dijkstra)
15+
#' \item A star (A*) : projected coordinates should be provided
16+
#' \item bidirectional Dijkstra (bi)
17+
#' \item New bi-directional A star (NBA) : projected coordinates should be provided
18+
#' }
19+
#'
20+
#' If the input graph has been contracted by cpp_contract() function, the algorithm is a modified bidirectional search.
21+
#'
1522
#' In A* and New Bidirectional A star algorithms, euclidean distance is used as heuristic function.
16-
#' To understand how A star algorithm work, see https://en.wikipedia.org/wiki/A*_search_algorithm .
17-
#' To understand the importance of constant parameter, see the package description : https://github.com/vlarmet/cppRouting
23+
#' To understand how A star algorithm work, see \url{https://en.wikipedia.org/wiki/A*_search_algorithm}.
24+
#' To understand the importance of constant parameter, see the package description : \url{https://github.com/vlarmet/cppRouting/blob/master/README.md}
1825
#' @examples
1926
#' #Data describing edges of the graph
2027
#' edges<-data.frame(from_vertex=c(0,0,1,1,2,2,3,4,4),

R/simplify.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#' Reduce the number of edges by removing non-intersection nodes, duplicated edges and isolated loops in the graph.
22
#'
3-
#' @param Graph An object generated by cppRouting::makegraph() function.
3+
#' @param Graph An object generated by makegraph() function.
44
#' @param keep Character or integer vector. Nodes of interest that will not be removed. Default to NULL
55
#' @param rm_loop Logical. if TRUE, isolated loops as removed. Default to TRUE
66
#' @param iterate Logical. If TRUE, process is repeated until only intersection nodes remain in the graph. Default to FALSE
77
#' @param silent Logical. If TRUE and iterate set to TRUE, number of iteration and number of removed nodes are printed to the console.
88
#' @return The simplified cppRouting graph
9-
#' @details To understand why process can be iterated, see the package description : https://github.com/vlarmet/cppRouting
9+
#' @details To understand why process can be iterated, see the package description : \url{https://github.com/vlarmet/cppRouting/blob/master/README.md}
1010
#'
1111
#' The first iteration usually eliminates the majority of non-intersection nodes and is therefore faster.
1212
#' @examples

0 commit comments

Comments
 (0)