knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

library(sf)
library(mapview)
mapviewOptions(
  vector.palette = colorRampPalette(
    c("#000004FF", "#420A68FF", "#932667FF", "#DD513AFF", "#FCA50AFF", "#FCFFA4FF")
  )
)

Tool for placing virtual stations in demand-responsive transport systems in villages by defining and minimizing a global energy (drtplanr, name is inspired by stplanr). The station locations are randomly initialized in the street network and iteratively optimized based on the reachable population in combination with walking and driving times.

The model in the package example optimizes the positions of virtual stations in an assumed on-demand shuttle service for the community of Jegenstorf in Bern, Switzerland.

Setup

library(drtplanr)
set.seed(123)

Example data sets

Load the package example data sets:

aoi <- 
  sf::st_read(system.file("example.gpkg", package="drtplanr"), layer = "aoi")

pop <- 
  sf::st_read(system.file("example.gpkg", package="drtplanr"), layer = "pop")

m <-
  mapview(aoi, alpha.region = 0, layer.name = "AOI", homebutton = FALSE) +
  mapview(pop, zcol = "n", alpha = 0, layer.name = "Population", homebutton = FALSE)
m

Initialize drtm model

Create a new demand reponsive transport model for the aoi 'Jegenstorf', with 10 randomly initialized virtual on-demand stations.

m <- drt_drtm(
  model_name = "Jegenstorf",
  aoi = aoi, pop = pop,
  n_vir = 15, m_seg = 100
)
m

Minimze the energy of the model

Iterate the model 100 times, where every iteration consists of:

  1. Relocate a virtual station randomly on the road segments.
  2. Calculate the new global energy of the model using the routing graphs.
  3. If the energy is lower than previuos iteration: Keep the new location of the virtual station; otherwise: Reset to the previous location.
m1 <- drt_iterate(m, 100)
m1 <- drt_iterate(m, 100)

Print model summary:

m1

Plotting

Energy curve

drt_plot(m1)

Station map

drt_map(m1)

Iterate again

The model state is saved in the model. This allows making copies and store different stages of the optimization.

m2 <- drt_import(
  system.file("Jegenstorf_i1000.RData", package="drtplanr")
)
m2 <- drt_iterate(m1, 900)

Print model summary:

m2

Visualize results

drt_plot(m2)
drt_map(m2)

Export and import

The drtplanr has functions to import and export the drtm objects. Furthermore graphics of the energy plot and the station map can be exported as images (.png).

# Export model
drt_export(m2, path = getwd())

# Import model
m2 <- drt_import("Jegenstorf_i1000.RData")

# Save graphics
drt_save_graphics(m2, path = getwd())

References



munterfinger/drtplanr documentation built on Oct. 3, 2021, 7:28 p.m.