dyntapy: dynamic and static traffic assignment in Python

Macroscopic Traffic Models, based on the idea that traffic in a city can be modelled much like a fluid, have been used to guide transport policy and mitigate congestion for more than 50 years. They find a fixed point in the interaction between two phenomena: (i) drivers make routing decisions based on the observed travel times and try to minimize their experienced travel times; (ii) route flows determine the congestion pattern and affect travel times. This fixed point may be further generalized to include choice of departure time, transport mode, activity location, and other behavioral dimensions. Building useful transport models is a balancing act between capturing realistic behavior and managing the computational complexity of models that are routinely used to simulate the journeys of thousands of cars simultaneously. Authors have created a variety of flavors of these models that emphasize preferences for one or another aspect of realism at the cost of others, see Bliemer et al. (2017) for a recent overview and classification.


Statement of need
Macroscopic Traffic Models, based on the idea that traffic in a city can be modelled much like a fluid, have been used to guide transport policy and mitigate congestion for more than 50 years. They find a fixed point in the interaction between two phenomena: (i) drivers make routing decisions based on the observed travel times and try to minimize their experienced travel times; (ii) route flows determine the congestion pattern and affect travel times. This fixed point may be further generalized to include choice of departure time, transport mode, activity location, and other behavioral dimensions. Building useful transport models is a balancing act between capturing realistic behavior and managing the computational complexity of models that are routinely used to simulate the journeys of thousands of cars simultaneously. Authors have created a variety of flavors of these models that emphasize preferences for one or another aspect of realism at the cost of others, see Bliemer et al. (2017) for a recent overview and classification.
Independent of the algorithm used, there are commonalities between the software that is used to model car traffic macroscopically. Namely, road network-and travel demand processing, representation of the same as efficient computational entities, and the visualization and processing of results. This is part of what dyntapy provides. Additionally, a selection of static and dynamic traffic assignment algorithms have been implemented and can be used by researchers in transport modeling to conduct studies in which the interaction with an assignment model and/or the accurate modeling of congestion is of concern. Commercial offerings are often expensive and do not allow one to make adjustments to the core of the algorithms. dyntapy is a useful starting point for studies that require such manipulation. dyntapy also lends itself to educational use and has already been used in traffic engineering courses at KU Leuven. Summary dyntapy is a python package for modeling car traffic macroscopically. It provides a few key features to researchers in traffic modeling: (i) extraction and formatting of road network graphs from OpenStreetMap using OSMnx (Boeing, 2017), following the GMNS standard (General Modeling Network Specification: https://github.com/zephyr-data-specs/GMNS); (ii) parsers for road network and travel demand information; (iii) fast shortest path computations; (iv) both static and dynamic traffic assignment algorithms; (v) selected link analysis 1 ; and (vi) flexible visualization tools.
The toolkit is designed to be extensible. The provided object-oriented specification of the road network, travel demand, and results are generic and allow for other assignment algorithms to be added without much additional effort. Because there is a shared definition of the modeling results, visualization tools can be used without modification for different algorithms. dyntapy utilizes Networkx (Hagberg et al., 2008) for managing the road network graph. Numpy (Harris et al., 2020) is used for fast array calculations and Numba (Lam et al., 2015) is used to accelerate computations that involve graph traversal via sparse matrices.
Bokeh 2 powers the flexible visualization of static and dynamic 3 assignment results, see Figure 1 and Figure 2 below.  We provide two algorithms for solving the deterministic Traffic Assignment Problem, namely, Dial's Algorithm B (Dial, 2006) and the Method of Successive Averages. For solving the stochastic uncongested Traffic Assignment Problem, we use Dial's Algorithm (Dial, 1971). For the deterministic Dynamic Assignment Problem we utilize the iterative link transmission model , as dynamic network loading component, an iterative route choice component introduced in Himpe (2016) based on quasi-reduced projection (Mahut et al., 2008) and travel time calculations of the MLI type as introduced in Long et al. (2011).
We welcome contributions by other authors to add to this selection. In the short term, the stochastic Dynamic Traffic Assignment model that was introduced in Verstraete & Tampère (2021) will be added to the list of available algorithms. dyntapy is being used for scenario analysis as part of DUET (Raes et al., 2021), a platform for digital twins of cities in which policy makers can explore the impact of road network changes on congestion and emissions.
For usage examples and tutorials we refer the reader to the dyntapy documentation.

Related packages
AequilibraE is a traffic modeling toolkit that offers a set of static assignments (Method of Successive Averages and different variants of the Frank-Wolfe Algorithm) paired with OpenStreetMap parsing. It is an open source alternative to commercial transport modeling software and provides comprehensive visualization and network management capabilities in QGIS. dyntapy differs from AequilibraE in functionality by its inclusion of dynamic models and command-driven visualization capabilities within Jupyter notebooks.
Similar to other popular graph packages, such as igraph (Csardi & Nepusz, 2006) and NetworkX, we offer shortest path computations. Our implementations are more than twice as fast as igraph and more than 20x faster than Networkx for road networks.

Outlook and use cases
In its current state, dyntapy is most interesting for assignment researchers, transport modelers, and students who want to get hands-on experiments with assignments.
Macro-and mesoscopic commercial modeling software offer some functionalities that are beyond what dyntapy provides and make it less suitable for studies in which realism is of chief concern. Namely, (i) support for specifying intersections in more details and calculating delays based on signals and priorities; and (ii) calibration routines for supply and demand for both static and dynamic assignments 4 . Support for intersection data both in the parser and as constraints in the models is a long term goal for dyntapy; however, data for intersections is currently not widely available. OpenStreetMap's encoding of intersections is not suitable for use in traffic models, partly because of its ambiguity, but also because it does not allow for specifying signal timings. GMNS fills this gap; however, the number of datasets available in this standard is still very limited.
Regarding (ii), there are currently no plans to add calibration to dyntapy. Intersections are the main causes of queuing in traffic models. Before we can hope to calibrate models we need to have more certainty about the specification of intersections.