@@ -57,6 +57,8 @@ library(cppRouting)
5757library(dplyr )
5858library(sf )
5959library(ggplot2 )
60+ library(concaveman )
61+ library(ggmap )
6062# setwd("")
6163# Reading french road data
6264roads <- read.csv(" roads.csv" ,colClasses = c(" character" ," character" ," numeric" ))
@@ -118,7 +120,7 @@ pair_dijkstra<-get_distance_pair(graph,origin,destination)
118120 ## Running Dijkstra ...
119121
120122 ## user system elapsed
121- ## 54.69 0.00 54.79
123+ ## 56.36 0.02 57.24
122124
123125``` r
124126# Benchmarks parallel
@@ -131,7 +133,7 @@ pair_dijkstra_par<-get_distance_pair(graph,origin,destination,allcores = TRUE)
131133 ## Running Dijkstra ...
132134
133135 ## user system elapsed
134- ## 70.31 0.00 17.97
136+ ## 71.52 0.08 19.59
135137
136138### Run A\* algorithm
137139
@@ -147,7 +149,7 @@ pair_astar<-get_distance_pair(graph,origin,destination,algorithm = "A*",constant
147149 ## Running A* ...
148150
149151 ## user system elapsed
150- ## 30.42 2.28 32.79
152+ ## 31.37 1.93 33.82
151153
152154``` r
153155# A* parallel
@@ -159,7 +161,7 @@ pair_astar_par<-get_distance_pair(graph,origin,destination,algorithm = "A*",cons
159161 ## Running A* ...
160162
161163 ## user system elapsed
162- ## 44.38 0.72 11.65
164+ ## 43.90 0.75 11.97
163165
164166A\* is the fastest one and the output is the same.
165167
@@ -168,12 +170,51 @@ head(cbind(pair_dijkstra,pair_astar,pair_dijkstra_par,pair_astar_par))
168170```
169171
170172 ## pair_dijkstra pair_astar pair_dijkstra_par pair_astar_par
171- ## [1,] 462.4514 462.4514 462.4514 462.4514
172- ## [2,] 114.1351 114.1351 114.1351 114.1351
173- ## [3,] 238.4923 238.4923 238.4923 238.4923
174- ## [4,] 490.4173 490.4173 490.4173 490.4173
175- ## [5,] 218.5715 218.5715 218.5715 218.5715
176- ## [6,] 482.1238 482.1238 482.1238 482.1238
173+ ## [1,] 347.4129 347.4129 347.4129 347.4129
174+ ## [2,] 331.9925 331.9925 331.9925 331.9925
175+ ## [3,] 196.9234 196.9234 196.9234 196.9234
176+ ## [4,] 427.4617 427.4617 427.4617 427.4617
177+ ## [5,] 196.4124 196.4124 196.4124 196.4124
178+ ## [6,] 313.8013 313.8013 313.8013 313.8013
179+
180+ Compute isochrones
181+ ------------------
182+
183+ Let's compute isochrones around Dijon city
184+
185+ ``` r
186+ # Compute isochrones
187+ iso <- get_isochrone(graph ,from = " 205793" ,lim = c(15 ,25 ,45 ,60 ,90 ,120 ))
188+ # Convert nodes to concave polygons with concaveman package
189+ poly <- lapply(iso [[1 ]],function (x ){
190+ x <- data.frame (noeuds = x ,stringsAsFactors = F )
191+ x <- left_join(x ,coord ,by = c(" noeuds" = " ID" ))
192+ return (concaveman(summarise(st_as_sf(x ,coords = c(" X" ," Y" ),crs = 2154 ))))
193+ })
194+
195+ poly <- do.call(rbind ,poly )
196+ poly $ time <- as.factor(names(iso [[1 ]]))
197+ # Multipolygon
198+ poly2 <- st_cast(poly ," MULTIPOLYGON" )
199+ poly2 $ time <- reorder(poly2 $ time ,c(120 ,90 ,60 ,45 ,25 ,15 ))
200+ # Reproject for plotting
201+ poly2 <- st_transform(poly2 ," +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" )
202+ # Import map backgroung
203+ dijon = get_map(location = c(lon = 5.041140 ,lat = 47.323025 ),zoom = 7 , source = " google" ,maptype = " toner-2010" )
204+ # Plot the map
205+ p <- ggmap(dijon )+
206+ geom_sf(data = poly2 ,aes(fill = time ),alpha = .5 ,inherit.aes = FALSE )+
207+ scale_fill_brewer(palette = " RdBu" )+
208+ labs(fill = " Minutes" )+
209+ ggtitle(" Isochrones around Dijon" )+
210+ theme(axis.text.x = element_blank(),
211+ axis.text.y = element_blank(),
212+ axis.ticks = element_blank(),
213+ axis.title.y = element_blank(),axis.title.x = element_blank())
214+ p
215+ ```
216+
217+ ![ ] ( readme_files/figure-markdown_github/unnamed-chunk-6-1.png )
177218
178219Applications
179220============
@@ -235,7 +276,7 @@ p<-ggplot()+
235276p
236277```
237278
238- ![ ] ( readme_files/figure-markdown_github/unnamed-chunk-8 -1.png )
279+ ![ ] ( readme_files/figure-markdown_github/unnamed-chunk-9 -1.png )
239280
240281Application 2 : Calculate the minimum travel time to the closest maternity ward in France
241282-----------------------------------------------------------------------------------------
@@ -277,7 +318,7 @@ p<-ggplot()+
277318p
278319```
279320
280- ![ ] ( readme_files/figure-markdown_github/unnamed-chunk-11 -1.png )
321+ ![ ] ( readme_files/figure-markdown_github/unnamed-chunk-12 -1.png )
281322
282323Benchmark with other R packages
283324===============================
@@ -304,7 +345,7 @@ system.time(
304345```
305346
306347 ## user system elapsed
307- ## 86.48 0.06 86.69
348+ ## 92.93 0.11 93.70
308349
309350``` r
310351# dodgr
@@ -325,7 +366,7 @@ test_dodgr<-dodgr_dists(graph=data.frame(roads2),from=origin,to=destination,para
325366```
326367
327368 ## user system elapsed
328- ## 85.02 0.08 85.27
369+ ## 89.75 0.08 90.28
329370
330371``` r
331372# cppRouting
@@ -335,7 +376,7 @@ test_cpp<-get_distance_matrix(graph,origin,destination,allcores = FALSE)
335376```
336377
337378 ## user system elapsed
338- ## 54.35 0.02 54.45
379+ ## 59.76 0.06 60.61
339380
340381### Distance matrix : parallel
341382
@@ -347,7 +388,7 @@ test_dodgr<-dodgr_dists(graph=data.frame(roads2),from=origin,to=destination,para
347388```
348389
349390 ## user system elapsed
350- ## 118.82 0.36 31.42
391+ ## 134.83 0.89 41.32
351392
352393``` r
353394# cppRouting
@@ -357,7 +398,7 @@ test_cpp<-get_distance_matrix(graph,origin,destination,allcores = TRUE)
357398```
358399
359400 ## user system elapsed
360- ## 69.43 0.00 17.73
401+ ## 76.25 0.10 21.98
361402
362403Benchmarking on shortest paths by pairs
363404---------------------------------------
@@ -373,7 +414,7 @@ test_dodgr<-dodgr_paths(graph=data.frame(roads2),from=origin,to=destination,pair
373414```
374415
375416 ## user system elapsed
376- ## 524.96 18.16 544.13
417+ ## 572.20 20.48 599.70
377418
378419``` r
379420# cppRouting
@@ -385,7 +426,7 @@ test_cpp<-get_path_pair(graph,origin,destination,algorithm = "A*",constant=110/0
385426 ## Running A* ...
386427
387428 ## user system elapsed
388- ## 7.88 0.01 7.90
429+ ## 8.30 0.04 8.35
389430
390431### Test similarity of the first travel
391432
@@ -394,13 +435,13 @@ test_cpp<-get_path_pair(graph,origin,destination,algorithm = "A*",constant=110/0
394435length(test_dodgr [[1 ]][[1 ]])
395436```
396437
397- ## [1] 324
438+ ## [1] 227
398439
399440``` r
400441length(test_cpp [[1 ]])
401442```
402443
403- ## [1] 324
444+ ## [1] 227
404445
405446``` r
406447# Setdiff
0 commit comments