Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
vlarmet authored Jun 16, 2019
1 parent 3822dd5 commit 74c3460
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 93 deletions.
37 changes: 15 additions & 22 deletions readme.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ For now, `cppRouting` can implement :
- uni-directional Dijkstra algorithm,
- bi-directional Dijkstra algorithm,
- uni-directional A* algorithm
- New bi-directional A* algorithm (Piljs & Post, 2009 : see http://repub.eur.nl/pub/16100/ei2009-10.pdf)

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

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.
A* is relevant if geographic coordinates of all nodes are provided. Note that coordinates should be expressed in a projection system.
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.
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.
`A*` and `NBA*` are relevant if geographic coordinates of all nodes are provided. Note that coordinates should be expressed in a projection system.
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.
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).

By default, constant is 1 and is designed for graphs with cost expressed in the same unit than coordinates (e.g meters).

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

##Examples
Expand Down Expand Up @@ -106,11 +105,6 @@ system.time(
pair_dijkstra<-get_distance_pair(graph,origin,destination)
)
#Parallel
system.time(
pair_dijkstra_par<-get_distance_pair(graph,origin,destination,allcores = TRUE)
)
```
####Using bi-directional Dijkstra algorithm
```{r,}
Expand All @@ -119,11 +113,6 @@ system.time(
pair_bidijkstra<-get_distance_pair(graph,origin,destination,algorithm = "bi")
)
#Parallel
system.time(
pair_bidijkstra_par<-get_distance_pair(graph,origin,destination,algorithm = "bi",allcores = TRUE)
)
```
####Using A* algorithm
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 :
Expand All @@ -133,17 +122,21 @@ system.time(
pair_astar<-get_distance_pair(graph,origin,destination,algorithm = "A*",constant = 110/0.06)
)
#Parallel
```
####Using NBA* algorithm
```{r,echo=TRUE}
#NBA* single node
system.time(
pair_astar_par<-get_distance_pair(graph,origin,destination,algorithm = "A*",constant = 110/0.06,allcores = TRUE)
pair_nba<-get_distance_pair(graph,origin,destination,algorithm = "NBA",constant = 110/0.06)
)
```
####Output
```
####Output
```{r,echo=TRUE}
head(cbind(pair_dijkstra,pair_bidijkstra,pair_astar,pair_dijkstra_par,pair_bidijkstra_par,pair_astar_par))
head(cbind(pair_dijkstra,pair_bidijkstra,pair_astar,pair_nba))
```
#####In `get_distance_pair` function, all the algorithms can be ran in parallel by setting TRUE to allcores argument.


###Compute isochrones
Expand Down Expand Up @@ -344,7 +337,7 @@ test_dodgr<-dodgr_paths(graph=data.frame(roads2),from=origin,to=destination,pair
#cppRouting
system.time(
test_cpp<-get_path_pair(graph,origin,destination,algorithm = "A*",constant=110/0.06)
test_cpp<-get_path_pair(graph,origin,destination,algorithm = "NBA",constant=110/0.06)
)
```
###Test similarity of the first travel
Expand Down
114 changes: 43 additions & 71 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Package presentation
- uni-directional Dijkstra algorithm,
- bi-directional Dijkstra algorithm,
- uni-directional A\* algorithm
- New bi-directional A\* algorithm (Piljs & Post, 2009 : see <http://repub.eur.nl/pub/16100/ei2009-10.pdf>)

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

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.
A\* is relevant if geographic coordinates of all nodes are provided. Note that coordinates should be expressed in a projection system.
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.
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).
`A*` and `NBA*` are relevant if geographic coordinates of all nodes are provided. Note that coordinates should be expressed in a projection system.
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.
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).

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

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

## user system elapsed
## 58.44 0.71 59.50

``` r
#Parallel
system.time(
pair_dijkstra_par<-get_distance_pair(graph,origin,destination,allcores = TRUE)
)
```

## Running Dijkstra ...

## user system elapsed
## 0.11 0.02 21.95
## 61.37 0.73 63.01

#### Using bi-directional Dijkstra algorithm

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

## user system elapsed
## 37.34 1.42 38.78

``` r
#Parallel
system.time(
pair_bidijkstra_par<-get_distance_pair(graph,origin,destination,algorithm = "bi",allcores = TRUE)
)
```

## Running bidirectional Dijkstra...

## user system elapsed
## 0.07 0.01 16.41
## 38.85 0.99 39.87

#### Using A\* algorithm

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

## user system elapsed
## 30.90 1.66 32.59
## 32.45 2.01 34.51

#### Using NBA\* algorithm

``` r
#Parallel
#NBA* single node
system.time(
pair_astar_par<-get_distance_pair(graph,origin,destination,algorithm = "A*",constant = 110/0.06,allcores = TRUE)
pair_nba<-get_distance_pair(graph,origin,destination,algorithm = "NBA",constant = 110/0.06)
)
```

## Running A* ...
## Running NBA* ...

## user system elapsed
## 0.16 0.01 15.08
## 18.61 2.78 21.45

#### Output

``` r
head(cbind(pair_dijkstra,pair_bidijkstra,pair_astar,pair_dijkstra_par,pair_bidijkstra_par,pair_astar_par))
head(cbind(pair_dijkstra,pair_bidijkstra,pair_astar,pair_nba))
```

## pair_dijkstra pair_bidijkstra pair_astar pair_dijkstra_par
## [1,] 78.82095 78.82095 78.82095 78.82095
## [2,] 306.31827 306.31827 306.31827 306.31827
## [3,] 487.43158 487.43158 487.43158 487.43158
## [4,] 106.58475 106.58475 106.58475 106.58475
## [5,] 209.21585 209.21585 209.21585 209.21585
## [6,] 355.96210 355.96210 355.96210 355.96210
## pair_bidijkstra_par pair_astar_par
## [1,] 78.82095 78.82095
## [2,] 306.31827 306.31827
## [3,] 487.43158 487.43158
## [4,] 106.58475 106.58475
## [5,] 209.21585 209.21585
## [6,] 355.96210 355.96210
## pair_dijkstra pair_bidijkstra pair_astar pair_nba
## [1,] 475.9349 475.9349 475.9349 475.9349
## [2,] 502.9290 502.9290 502.9290 502.9290
## [3,] 512.4824 512.4824 512.4824 512.4824
## [4,] 246.4425 246.4425 246.4425 246.4425
## [5,] 776.0014 776.0014 776.0014 776.0014
## [6,] 109.4739 109.4739 109.4739 109.4739

##### In `get_distance_pair` function, all the algorithms can be ran in parallel by setting TRUE to allcores argument.

### Compute isochrones

Expand Down Expand Up @@ -257,7 +229,7 @@ p<-ggmap(dijon)+
p
```

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

Applications
============
Expand Down Expand Up @@ -319,7 +291,7 @@ p<-ggplot()+
p
```

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

Application 2 : Calculate the minimum travel time to the closest maternity ward in France
-----------------------------------------------------------------------------------------
Expand Down Expand Up @@ -361,7 +333,7 @@ p<-ggplot()+
p
```

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

Benchmark with other R packages
===============================
Expand All @@ -388,7 +360,7 @@ system.time(
```

## user system elapsed
## 85.69 0.06 85.76
## 84.08 0.03 84.26

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

## user system elapsed
## 84.42 0.03 84.59
## 83.94 0.08 84.15

``` r
#cppRouting
Expand All @@ -419,7 +391,7 @@ test_cpp<-get_distance_matrix(graph,origin,destination,allcores = FALSE)
```

## user system elapsed
## 57.71 0.56 58.28
## 57.52 0.35 57.92

#### Ouput

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

## [,1] [,2] [,3]
## 115900 503.3265 503.3265 503.3265
## 122467 406.0058 406.0058 406.0058
## 228275 338.3132 338.3132 338.3132
## 33061 266.5725 266.5725 266.5725
## 30412 151.0826 151.0826 151.0826
## 208187 436.1984 436.1984 436.1984
## 158924 453.1183 453.1183 453.1183
## 208013 485.0933 485.0933 485.0933
## 51666 203.5290 203.5290 203.5290
## 77929 241.8183 241.8183 241.8183
## 114669 391.8915 391.8915 391.8915
## 74916 669.7842 669.7842 669.7842

### Distance matrix : parallel

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

## user system elapsed
## 119.76 0.75 31.66
## 118.12 0.43 31.02

``` r
#cppRouting
Expand All @@ -455,7 +427,7 @@ test_cpp<-get_distance_matrix(graph,origin,destination,allcores = TRUE)
```

## user system elapsed
## 0.13 0.03 21.95
## 0.15 0.08 21.52

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

## user system elapsed
## 528.75 18.74 548.89
## 522.81 18.75 542.18

``` r
#cppRouting
system.time(
test_cpp<-get_path_pair(graph,origin,destination,algorithm = "A*",constant=110/0.06)
test_cpp<-get_path_pair(graph,origin,destination,algorithm = "NBA",constant=110/0.06)
)
```

## Running A* ...
## Running NBA* ...

## user system elapsed
## 7.81 0.06 7.95
## 5.00 0.34 5.34

### Test similarity of the first travel

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

## [1] 204
## [1] 130

``` r
length(test_cpp[[1]])
```

## [1] 204
## [1] 130

``` r
#Setdiff
Expand Down

0 comments on commit 74c3460

Please sign in to comment.