knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" ) library(trafficr)
trafficr is a package for static traffic assignment R code. Currently, the program can solve the static traffic assignment problem using user equilibrium (UE) for the city network in urban traffic assignment. The solution is achieved using the Frank-Wolfe algorithm. Package is based on dodgr package for all-or-nothing assignment, route and time data.
Following steps explain the setup and how to run the procedures and extract flows and maps.
devtools::install_github("douglascm/trafficr")
Package devtools is required for the installation, install with install.packages('devtools')
Import into the current environment all three required datasets:
demand <- fread("path to file")
- Required columns: - orig: origin id (integer) - dest: destination id (integer)
head(sioux_demand)
network <- st_read("path to file")
- Required columns: - id_link: link id (integer) - ffs_fw: forward free flow speed in km/h (numeric) - ffs_bw: backward free flow speed in km/h (numeric) - cap_fw: forward link capacity in veh/h (numeric) - cap_bw: backward link capacity in veh/h (numeric) - Optional columns: - addv_fw: forward additional cost (numeric) - addv_bw: backward additional cost (numeric) - wg_fw: forward cost weight (numeric) - wg_bw: backward cost weight (numeric) - alpha: alpha BPR function parameter (numeric) - beta: beta BPR function parameter (numeric) - cost: actual network cost, used instead of geometric distance and speed (numeric)
head(sioux_network)
zones <- st_read("path to file")
- Required columns: - id_zone: link id (integer) - longitude: Longitude in WGS84 (numeric) - latitude: Latitude in WGS84 (numeric)
head(sioux_zones)
Use the following methods to perform operations:
configure_graph()
Tranforms network data from source network and zones and outputs a list with 2 elemens, 1 being the graph and 2 being the transformed zones:
configure_graph(network,zones,turn_penalty,left_side,addvalue_cols,weighted,performance_measures,use_cost_col)
configure_demand()
Tranforms demand data from source origin and destination to match origin and destination from graph/zone objects:
configure_demand(demand,zones)
solve_ue()
Solve the traffic flow assignment model (user equilibrium) by Frank-Wolfe algorithm (all the necessary data must be properly input into the model in advance).
solve_ue(graph,demand,col,max_iterations)
Next is an example of the structure to run the entire code, with additional functions that are documented inside R:
flist <- configure_graph(sioux_network,sioux_zones,use_cost_col=TRUE) graph <- flist[[1]] zones <- flist[[2]] demand <- configure_demand(sioux_demand,zones) graph <- solve_ue(graph,demand,col = 'demand') times <- get_times(graph,demand) paths <- get_paths(graph,demand) network <- graph_to_sf(graph,sioux_network) plot_flowmap(network,show_labels = T)
Feel free to send an email to douglas.capelossi@gmail.com if you have questions or concerns.
Future releases will have an implementation of other traffic assignment algorithms such as Gradient Projection, Origin-based assignment, and Algorithm B.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.