Skip to content

Commit 74c3460

Browse files
authored
Add files via upload
1 parent 3822dd5 commit 74c3460

2 files changed

Lines changed: 58 additions & 93 deletions

File tree

readme.Rmd

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ For now, `cppRouting` can implement :
1818
- uni-directional Dijkstra algorithm,
1919
- bi-directional Dijkstra algorithm,
2020
- uni-directional A* algorithm
21+
- New bi-directional A* algorithm (Piljs & Post, 2009 : see http://repub.eur.nl/pub/16100/ei2009-10.pdf)
2122

2223
All these functions are written in C++ and use std::priority_queue container from the Standard Template Library.
2324
This package have been made with `Rcpp` and `parallel` packages.
@@ -52,12 +53,10 @@ Data has to be a 3 columns data.frame or matrix containing from, to and a cost/d
5253
- Isochrones/isodistances with one or multiple breaks.
5354

5455
The choice between all the algorithms is available for `get_distance_pair` and `get_path_pair`. In these functions, uni-directional Dijkstra algorithm is stopped when the destination node is reached.
55-
A* is relevant if geographic coordinates of all nodes are provided. Note that coordinates should be expressed in a projection system.
56-
To be accurate and efficient, `A*` algorithm should use an admissible heuristic function (here the Euclidean distance), e.g cost and heuristic function must be expressed in the same unit.
57-
In `cppRouting`, heuristic function `h` is defined such that : h(xi,yi,xdestination,ydestination)/k, with a constant k; so in the case where coordinates are expressed in meters and cost is expressed in time, k is the maximum speed allowed on the road.
56+
`A*` and `NBA*` are relevant if geographic coordinates of all nodes are provided. Note that coordinates should be expressed in a projection system.
57+
To be accurate and efficient, `A*` and `NBA*` algorithms should use an admissible heuristic function (here the Euclidean distance), e.g cost and heuristic function must be expressed in the same unit.
58+
In `cppRouting`, heuristic function `h` is defined such that : h(xi,yi,xdestination,ydestination)/k, with a constant k; so in the case where coordinates are expressed in meters and cost is expressed in time, k is the maximum speed allowed on the road. By default, constant is 1 and is designed for graphs with cost expressed in the same unit than coordinates (e.g meters).
5859

59-
By default, constant is 1 and is designed for graphs with cost expressed in the same unit than coordinates (e.g meters).
60-
6160
If coordinates cannot be provided, bi-directional Dijkstra algorithm can offer a good alternative to A* in terms of performance.
6261

6362
##Examples
@@ -106,11 +105,6 @@ system.time(
106105
pair_dijkstra<-get_distance_pair(graph,origin,destination)
107106
)
108107
109-
#Parallel
110-
system.time(
111-
pair_dijkstra_par<-get_distance_pair(graph,origin,destination,allcores = TRUE)
112-
)
113-
114108
```
115109
####Using bi-directional Dijkstra algorithm
116110
```{r,}
@@ -119,11 +113,6 @@ system.time(
119113
pair_bidijkstra<-get_distance_pair(graph,origin,destination,algorithm = "bi")
120114
)
121115
122-
#Parallel
123-
system.time(
124-
pair_bidijkstra_par<-get_distance_pair(graph,origin,destination,algorithm = "bi",allcores = TRUE)
125-
)
126-
127116
```
128117
####Using A* algorithm
129118
Coordinates are defined in meters and max speed is 110km/h; so for the heuristic function to be admissible, the constant equal 110/0.06 :
@@ -133,17 +122,21 @@ system.time(
133122
pair_astar<-get_distance_pair(graph,origin,destination,algorithm = "A*",constant = 110/0.06)
134123
)
135124
136-
#Parallel
125+
```
126+
####Using NBA* algorithm
127+
```{r,echo=TRUE}
128+
#NBA* single node
137129
system.time(
138-
pair_astar_par<-get_distance_pair(graph,origin,destination,algorithm = "A*",constant = 110/0.06,allcores = TRUE)
130+
pair_nba<-get_distance_pair(graph,origin,destination,algorithm = "NBA",constant = 110/0.06)
139131
)
140-
```
141132
142-
####Output
143-
133+
```
134+
####Output
144135
```{r,echo=TRUE}
145-
head(cbind(pair_dijkstra,pair_bidijkstra,pair_astar,pair_dijkstra_par,pair_bidijkstra_par,pair_astar_par))
136+
head(cbind(pair_dijkstra,pair_bidijkstra,pair_astar,pair_nba))
137+
146138
```
139+
#####In `get_distance_pair` function, all the algorithms can be ran in parallel by setting TRUE to allcores argument.
147140

148141

149142
###Compute isochrones
@@ -344,7 +337,7 @@ test_dodgr<-dodgr_paths(graph=data.frame(roads2),from=origin,to=destination,pair
344337
345338
#cppRouting
346339
system.time(
347-
test_cpp<-get_path_pair(graph,origin,destination,algorithm = "A*",constant=110/0.06)
340+
test_cpp<-get_path_pair(graph,origin,destination,algorithm = "NBA",constant=110/0.06)
348341
)
349342
```
350343
###Test similarity of the first travel

readme.md

Lines changed: 43 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Package presentation
1111
- uni-directional Dijkstra algorithm,
1212
- bi-directional Dijkstra algorithm,
1313
- uni-directional A\* algorithm
14+
- New bi-directional A\* algorithm (Piljs & Post, 2009 : see <http://repub.eur.nl/pub/16100/ei2009-10.pdf>)
1415

1516
All these functions are written in C++ and use std::priority\_queue container from the Standard Template Library.
1617
This package have been made with `Rcpp` and `parallel` packages.
@@ -50,11 +51,9 @@ Main functions
5051
- Isochrones/isodistances with one or multiple breaks.
5152

5253
The choice between all the algorithms is available for `get_distance_pair` and `get_path_pair`. In these functions, uni-directional Dijkstra algorithm is stopped when the destination node is reached.
53-
A\* is relevant if geographic coordinates of all nodes are provided. Note that coordinates should be expressed in a projection system.
54-
To be accurate and efficient, `A*` algorithm should use an admissible heuristic function (here the Euclidean distance), e.g cost and heuristic function must be expressed in the same unit.
55-
In `cppRouting`, heuristic function `h` is defined such that : h(xi,yi,xdestination,ydestination)/k, with a constant k; so in the case where coordinates are expressed in meters and cost is expressed in time, k is the maximum speed allowed on the road.
56-
57-
By default, constant is 1 and is designed for graphs with cost expressed in the same unit than coordinates (e.g meters).
54+
`A*` and `NBA*` are relevant if geographic coordinates of all nodes are provided. Note that coordinates should be expressed in a projection system.
55+
To be accurate and efficient, `A*` and `NBA*` algorithms should use an admissible heuristic function (here the Euclidean distance), e.g cost and heuristic function must be expressed in the same unit.
56+
In `cppRouting`, heuristic function `h` is defined such that : h(xi,yi,xdestination,ydestination)/k, with a constant k; so in the case where coordinates are expressed in meters and cost is expressed in time, k is the maximum speed allowed on the road. By default, constant is 1 and is designed for graphs with cost expressed in the same unit than coordinates (e.g meters).
5857

5958
If coordinates cannot be provided, bi-directional Dijkstra algorithm can offer a good alternative to A\* in terms of performance.
6059

@@ -132,19 +131,7 @@ pair_dijkstra<-get_distance_pair(graph,origin,destination)
132131
## Running Dijkstra ...
133132

134133
## user system elapsed
135-
## 58.44 0.71 59.50
136-
137-
``` r
138-
#Parallel
139-
system.time(
140-
pair_dijkstra_par<-get_distance_pair(graph,origin,destination,allcores = TRUE)
141-
)
142-
```
143-
144-
## Running Dijkstra ...
145-
146-
## user system elapsed
147-
## 0.11 0.02 21.95
134+
## 61.37 0.73 63.01
148135

149136
#### Using bi-directional Dijkstra algorithm
150137

@@ -158,19 +145,7 @@ pair_bidijkstra<-get_distance_pair(graph,origin,destination,algorithm = "bi")
158145
## Running bidirectional Dijkstra...
159146

160147
## user system elapsed
161-
## 37.34 1.42 38.78
162-
163-
``` r
164-
#Parallel
165-
system.time(
166-
pair_bidijkstra_par<-get_distance_pair(graph,origin,destination,algorithm = "bi",allcores = TRUE)
167-
)
168-
```
169-
170-
## Running bidirectional Dijkstra...
171-
172-
## user system elapsed
173-
## 0.07 0.01 16.41
148+
## 38.85 0.99 39.87
174149

175150
#### Using A\* algorithm
176151

@@ -186,40 +161,37 @@ pair_astar<-get_distance_pair(graph,origin,destination,algorithm = "A*",constant
186161
## Running A* ...
187162

188163
## user system elapsed
189-
## 30.90 1.66 32.59
164+
## 32.45 2.01 34.51
165+
166+
#### Using NBA\* algorithm
190167

191168
``` r
192-
#Parallel
169+
#NBA* single node
193170
system.time(
194-
pair_astar_par<-get_distance_pair(graph,origin,destination,algorithm = "A*",constant = 110/0.06,allcores = TRUE)
171+
pair_nba<-get_distance_pair(graph,origin,destination,algorithm = "NBA",constant = 110/0.06)
195172
)
196173
```
197174

198-
## Running A* ...
175+
## Running NBA* ...
199176

200177
## user system elapsed
201-
## 0.16 0.01 15.08
178+
## 18.61 2.78 21.45
202179

203180
#### Output
204181

205182
``` r
206-
head(cbind(pair_dijkstra,pair_bidijkstra,pair_astar,pair_dijkstra_par,pair_bidijkstra_par,pair_astar_par))
183+
head(cbind(pair_dijkstra,pair_bidijkstra,pair_astar,pair_nba))
207184
```
208185

209-
## pair_dijkstra pair_bidijkstra pair_astar pair_dijkstra_par
210-
## [1,] 78.82095 78.82095 78.82095 78.82095
211-
## [2,] 306.31827 306.31827 306.31827 306.31827
212-
## [3,] 487.43158 487.43158 487.43158 487.43158
213-
## [4,] 106.58475 106.58475 106.58475 106.58475
214-
## [5,] 209.21585 209.21585 209.21585 209.21585
215-
## [6,] 355.96210 355.96210 355.96210 355.96210
216-
## pair_bidijkstra_par pair_astar_par
217-
## [1,] 78.82095 78.82095
218-
## [2,] 306.31827 306.31827
219-
## [3,] 487.43158 487.43158
220-
## [4,] 106.58475 106.58475
221-
## [5,] 209.21585 209.21585
222-
## [6,] 355.96210 355.96210
186+
## pair_dijkstra pair_bidijkstra pair_astar pair_nba
187+
## [1,] 475.9349 475.9349 475.9349 475.9349
188+
## [2,] 502.9290 502.9290 502.9290 502.9290
189+
## [3,] 512.4824 512.4824 512.4824 512.4824
190+
## [4,] 246.4425 246.4425 246.4425 246.4425
191+
## [5,] 776.0014 776.0014 776.0014 776.0014
192+
## [6,] 109.4739 109.4739 109.4739 109.4739
193+
194+
##### In `get_distance_pair` function, all the algorithms can be ran in parallel by setting TRUE to allcores argument.
223195

224196
### Compute isochrones
225197

@@ -257,7 +229,7 @@ p<-ggmap(dijon)+
257229
p
258230
```
259231

260-
![](readme_files/figure-markdown_github/unnamed-chunk-7-1.png)
232+
![](readme_files/figure-markdown_github/unnamed-chunk-8-1.png)
261233

262234
Applications
263235
============
@@ -319,7 +291,7 @@ p<-ggplot()+
319291
p
320292
```
321293

322-
![](readme_files/figure-markdown_github/unnamed-chunk-10-1.png)
294+
![](readme_files/figure-markdown_github/unnamed-chunk-11-1.png)
323295

324296
Application 2 : Calculate the minimum travel time to the closest maternity ward in France
325297
-----------------------------------------------------------------------------------------
@@ -361,7 +333,7 @@ p<-ggplot()+
361333
p
362334
```
363335

364-
![](readme_files/figure-markdown_github/unnamed-chunk-13-1.png)
336+
![](readme_files/figure-markdown_github/unnamed-chunk-14-1.png)
365337

366338
Benchmark with other R packages
367339
===============================
@@ -388,7 +360,7 @@ system.time(
388360
```
389361

390362
## user system elapsed
391-
## 85.69 0.06 85.76
363+
## 84.08 0.03 84.26
392364

393365
``` r
394366
#dodgr
@@ -409,7 +381,7 @@ test_dodgr<-dodgr_dists(graph=data.frame(roads2),from=origin,to=destination,para
409381
```
410382

411383
## user system elapsed
412-
## 84.42 0.03 84.59
384+
## 83.94 0.08 84.15
413385

414386
``` r
415387
#cppRouting
@@ -419,7 +391,7 @@ test_cpp<-get_distance_matrix(graph,origin,destination,allcores = FALSE)
419391
```
420392

421393
## user system elapsed
422-
## 57.71 0.56 58.28
394+
## 57.52 0.35 57.92
423395

424396
#### Ouput
425397

@@ -428,12 +400,12 @@ head(cbind(test_igraph[,1],test_dodgr[,1],test_cpp[,1]))
428400
```
429401

430402
## [,1] [,2] [,3]
431-
## 115900 503.3265 503.3265 503.3265
432-
## 122467 406.0058 406.0058 406.0058
433-
## 228275 338.3132 338.3132 338.3132
434-
## 33061 266.5725 266.5725 266.5725
435-
## 30412 151.0826 151.0826 151.0826
436-
## 208187 436.1984 436.1984 436.1984
403+
## 158924 453.1183 453.1183 453.1183
404+
## 208013 485.0933 485.0933 485.0933
405+
## 51666 203.5290 203.5290 203.5290
406+
## 77929 241.8183 241.8183 241.8183
407+
## 114669 391.8915 391.8915 391.8915
408+
## 74916 669.7842 669.7842 669.7842
437409

438410
### Distance matrix : parallel
439411

@@ -445,7 +417,7 @@ test_dodgr<-dodgr_dists(graph=data.frame(roads2),from=origin,to=destination,para
445417
```
446418

447419
## user system elapsed
448-
## 119.76 0.75 31.66
420+
## 118.12 0.43 31.02
449421

450422
``` r
451423
#cppRouting
@@ -455,7 +427,7 @@ test_cpp<-get_distance_matrix(graph,origin,destination,allcores = TRUE)
455427
```
456428

457429
## user system elapsed
458-
## 0.13 0.03 21.95
430+
## 0.15 0.08 21.52
459431

460432
Benchmark on computing shortest paths by pairs
461433
----------------------------------------------
@@ -471,19 +443,19 @@ test_dodgr<-dodgr_paths(graph=data.frame(roads2),from=origin,to=destination,pair
471443
```
472444

473445
## user system elapsed
474-
## 528.75 18.74 548.89
446+
## 522.81 18.75 542.18
475447

476448
``` r
477449
#cppRouting
478450
system.time(
479-
test_cpp<-get_path_pair(graph,origin,destination,algorithm = "A*",constant=110/0.06)
451+
test_cpp<-get_path_pair(graph,origin,destination,algorithm = "NBA",constant=110/0.06)
480452
)
481453
```
482454

483-
## Running A* ...
455+
## Running NBA* ...
484456

485457
## user system elapsed
486-
## 7.81 0.06 7.95
458+
## 5.00 0.34 5.34
487459

488460
### Test similarity of the first travel
489461

@@ -492,13 +464,13 @@ test_cpp<-get_path_pair(graph,origin,destination,algorithm = "A*",constant=110/0
492464
length(test_dodgr[[1]][[1]])
493465
```
494466

495-
## [1] 204
467+
## [1] 130
496468

497469
``` r
498470
length(test_cpp[[1]])
499471
```
500472

501-
## [1] 204
473+
## [1] 130
502474

503475
``` r
504476
#Setdiff

0 commit comments

Comments
 (0)