sym-metanet is a Python package to model traffic networks with the METANET framework, a collection of tools to mathematically model the macroscopic behaviour of traffic in highway systems (see [1] and [2] for more details).
To install the package, run
pip install sym-metanet
sym-metanet has the following dependencies
- Python 3.8 or higher
- NetworkX
and optionally
For playing around with the source code instead, run
git clone https://github.com/FilippoAiraldi/sym-metanet.git
In METANET, a highway network is represented as a directed graph whose edges are stretches of highways, a.k.a. links. Each link bridges between nodes (that have no physical meaning), which in turn can host origins (sources of traffic flow) and destinations (sinks of flow). For instance, to create a very simple network consisting of a single link connecting an origin to a destination, we can do as follows:
import sym_metanet as metanet
...
N1 = metanet.Node(name="N1")
N2 = metanet.Node(name="N2")
L1 = metanet.Link(segments, lanes, L, rho_max, rho_crit, v_free, a, name="L1")
O1 = metanet.Origin(C[0], name="O1")
D3 = metanet.Destination(name="D3")
net = metanet.Network().add_path(origin=O1, path=(N1, L1, N2, L2, N3), destination=D3)
Once the network is built, we can validate it and use, e.g., CasADi, to symbolically construct a function that represents the dynamics governing this network (according to METANET).
net.is_valid(raises=True)
T = 10 / 3600 # sampling time
metanet.engines.use("casadi", sym_type="SX")
F = metanet.engine.to_function(net=net, T=T)
Function F
can be then used to simulate the state transitions of the network in the context of, e.g., highway traffic control (see [2] for more details).
Our examples folder contains an example on how to get started with this package.
This code is symbolic-engine-agnostic, in the sense that it does not rely on a particular implementation of the underlying engine for symbolic computations. In other words, it is relatively easy to create a new engine for modelling networks with a new specific symbolic library (e.g., SimPy) by implementing the abstract class sym_metanet.engines.core.EngineBase
. An engine implemented in CasADi is already shipped but requires the symbolic library to be installed. Additionally, the engine is also implemented in NumPy (does not allow symbolic computations though).
The repository is provided under the MIT License. See the LICENSE file included with this repository.
Filippo Airaldi, PhD Candidate [f.airaldi@tudelft.nl | filippoairaldi@gmail.com]
Delft Center for Systems and Control in Delft University of Technology
Copyright (c) 2023 Filippo Airaldi.
Copyright notice: Technische Universiteit Delft hereby disclaims all copyright interest in the program “sym-metanet” (Symbolic Modelling of Highway Traffic Networks with METANET) written by the Author(s). Prof. Dr. Ir. Fred van Keulen, Dean of 3mE.
[1] A. Messmer and Papageorgiou, “METANET: a macroscopic simulation program for motorway networks,” Traffic Engineering and Control, vol. 31, pp. 466–470, 1990.
[2] Hegyi, A., 2004. Model predictive control for integrating traffic control measures. Netherlands TRAIL Research School.