Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTP tweaks #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions test_otp.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ remotes::install_cran(pkgs)
sapply(pkgs, require, character.only = TRUE)
```

We'll set the Java version to 17 (the recommended version is 17 according to [opentripplanner docs](https://docs.ropensci.org/opentripplanner/articles/OTPv2.html)) for the folder with [rJavaEnv](http://www.ekotov.pro/rJavaEnv/) as follows:

```{r}
#| label: Set Java version
if (!requireNamespace("remotes", quietly = TRUE)) {
install.packages("remotes")
}

remotes::install_github("e-kotov/rJavaEnv")
rJavaEnv::java_quick_install(version = 17)
```

Check you have the correct Java version:

```{r}
otp_check_java(2)
```

The following code is to test the performance of the OTP routing engine running locally controlled by the `opentripplanner` package with a sample of Origins and Destinations

We will read the OD data produced for this test
Expand Down Expand Up @@ -46,25 +64,25 @@ The following codes will prepare the folders and files that are required for the

#### Creating the folder structure

We create a folder for the Leeds, which will be used as a router in the OTP functions
We create a folder for the leeds, which will be used as a router in the OTP functions
```{r}
#| label: dir-create
dir.create("OTP/graphs/Leeds",recursive = T,showWarnings = F)
dir.create("OTP/graphs/leeds",recursive = T,showWarnings = F)
```

Using the `osmextract` package we can extract the OSM data
```{r}
#| label: osm-get
leeds_osm <- osmextract::oe_get("Leeds",
download_directory = "OTP/graphs/Leeds")
leeds_osm <- osmextract::oe_get("leeds",
download_directory = "OTP/graphs/leeds")
```

Specifying the paths

```{r}
#| label: dir-paths
path_data <- file.path("OTP")
path_otp <- otp_dl_jar(path_data,cache = T)
path_otp <- otp_dl_jar(path_data, cache = T, version = "2.2.0")
```

Creating the config file for the router. For this purpose we are going to use the default values
Expand All @@ -77,7 +95,7 @@ otp_validate_config(router_config)
# router_config$routingDefaults$$triangleTimeFactor ### For speed optimisation
otp_write_config(router_config, # Save the config file
dir = path_data,
router = "Leeds")
router = "leeds")
}
```

Expand All @@ -87,17 +105,26 @@ we built the graph with the following code.
```{r}
#| label: graph-prep
if(!file.exists("OTP/graphs/leeds/Graph.obj")){
log1 <- otp_build_graph(otp = path_otp,router = "Leeds", dir = path_data,memory = 15000)
log1 <- otp_build_graph(otp = path_otp,router = "leeds", dir = path_data,memory = 15000)
}
```

We initialise the OTP server once the graph has been built
```{r}
#| label: init-server
log2 <- otp_setup(otp = path_otp, dir = path_data,router = "Leeds",memory = 15e3)
otpcon <- otp_connect(timezone = "Europe/London",router = "Leeds")
#| eval: true
log2 <- otp_setup(otp = path_otp, dir = path_data,router = "leeds",memory = 15e3)
```

Connect to the server as follows:

```{r}
otpcon <- otp_connect(timezone = "Europe/London", router = "leeds")

```

Check the OTP server is running by navigating to `http://localhost:8080/` in your browser

Using the `otp_plan` function, we can generate the routes for the origins and destinations. We will use `system.time` to measure the time used for processing the routes
```{r}
#| label: route-extract
Expand Down