| Title: | Fast and Memory Efficient Spatial Interaction Models |
|---|---|
| Description: | Building on top of the 'RcppArmadillo' linear algebra functionalities to do fast spatial interaction models in the context of urban analytics, geography, transport modelling. It uses the Newton root search algorithm to determine the optimal cost exponent and can run country level models with thousands of origins and destinations. It aims at implementing an easy approach based on matrices, that can originate from various routing and processing steps earlier in an workflow. Currently, the simplest form of production, destination and doubly constrained models are implemented. Schlosser et al. (2023) <doi:10.48550/arXiv.2309.02112>. |
| Authors: | Ivann Schlosser [aut, cre]
|
| Maintainer: | Ivann Schlosser <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2 |
| Built: | 2026-06-03 09:20:31 UTC |
| Source: | https://github.com/ischlo/cppsim |
Function to calibrate the A and B coefficients of the gravity model through
Function to check availability of OPENMP to run in parallel. If openmp is found, this function returns TRUE
cpp_found_openmp()cpp_found_openmp()
distance_test
distance_testdistance_test
distance_testA 983x983 matrix of distances between MSOAs in London. Computed using the London road network from OpenStreetMap and the cppRouting package.
Ivann Schlosser, 2022
flows_london
flows_londonflows_london
flows_londonA data.table with flows information
ONS, Office for National Statistics, 2011
flows_test
flows_testflows_test
flows_testA matrix of size 983x983 containing flows of users using walking or cycling as the main method of commute.
UK Census, 2011
london_msoa
london_msoalondon_msoa
london_msoaA data.table with London MSOA, their centroids and geometries
ONS, Office for National Statistics, 2011
This function is the C++ implementation of run_model, it will run a doubly constrained model
run_model(flows, distance, beta = 0.25)run_model(flows, distance, beta = 0.25)
flows |
A integer matrix of Origin-Destination flows. |
distance |
a distance matrix between origins and destinations, provide distance in km. |
beta |
Exponent to use when calculating the cost function. |
A list containing an integer matrix with predicted values.
data(flows_test) data(distance_test) model_test <- run_model(flows_test,distance_test)data(flows_test) data(distance_test) model_test <- run_model(flows_test,distance_test)
This function is the C++ implementation of run_model, it will run a model
flows |
A integer matrix of Origin-Destination flows. |
distance |
a distance matrix between origins and destinations. |
beta |
Exponent to use when calculating the cost function. |
This function is the C++ implementation of run_model, it will run a singly constrained model there must be a match in the dimensions, when running a production constrained model, any(dim(distance) == length(flows)) must be TRUE if no values for weight are provided, a vector with ones is used
run_model_single(flows, distance, weight = NULL, beta = 0.25)run_model_single(flows, distance, weight = NULL, beta = 0.25)
flows |
A vector of either origin (production constrained) or destination (attraction constrained) flows. |
distance |
a distance matrix between origins and destinations, provide distance in km. |
weight |
a vector of weights for the unconstrained part of the model. |
beta |
Exponent to use when calculating the cost function, default .25. |
A list containing a matrix with predicted values.
data(flows_test) data(distance_test) flows_test <- apply(flows_test,MARGIN = 1,FUN = sum) model_test <- run_model_single(flows_test,distance_test)data(flows_test) data(distance_test) flows_test <- apply(flows_test,MARGIN = 1,FUN = sum) model_test <- run_model_single(flows_test,distance_test)
this script takes flows data, distance matrix, and a reference beta parameter and finds the optimal beta value for the model, runs it, and returns the result and the beta of best fit.
currently only the exp value is accepted for the cost_fun parameter.
simulation(flows_matrix, dist_matrix, beta_offset = 0.25)simulation(flows_matrix, dist_matrix, beta_offset = 0.25)
flows_matrix |
a integer matrix of flows |
dist_matrix |
a distance matrix containing numeric values in kilometers |
beta_offset |
an offset from 0 from which to start looking for the best fit value. |
creates a folder based on the run_name parameter to which images and files are written. The file run_name_best_fit.rds contain the matrices with values from the model , and the quality of fit values for the beta values.
data(flows_test) data(distance_test) model <- simulation(flows_test,distance_test)data(flows_test) data(distance_test) model <- simulation(flows_test,distance_test)