Skip to main content

UXsim: traffic flow simulator

Project description

UXsim: Fast network traffic flow simulator for Python

PyPi Conda Version Demo in Colab codecov PyPI - Downloads arXiv DOI citations Documentation Static Badge

UXsim is a free, open-source macroscopic and mesoscopic network traffic flow simulator written in Python. It simulates the movements of car travelers and traffic congestion in road networks. It is suitable for simulating large-scale (e.g., city-scale) traffic phenomena. UXsim is especially useful for scientific and educational purposes because of its simple, lightweight, and customizable features, but users are free to use UXsim for any purpose.

If you are interested, please see:

Main Features

  • Simple, lightweight, and easy-to-use Python implementation of modern standard models of dynamic network traffic flow
  • Macroscopic and mesoscopic traffic simulation: Simulating over 60000 vehicles in a city in 30 seconds, or even 1 million vehicles in a metropolitan area in 40 seconds depending on the simulation setting
  • Dynamic traffic assignment: Traffic flow simulation with a given network and time-dependent OD demand
    • Approximate solvers for Dynamic User Equilibrium and Dynamic System Optimum are also available
  • Theoretically valid models commonly used in academic and professional transportation research
  • Implementation of traffic control and management schemes such as taxi/shared-mobility, traffic signals, road pricing, and so on
  • Flexible and customizable thanks to pure Python implementation
    • Basic analysis of simulation results and their export to pandas.DataFrame and CSV files
    • Visualization of simulation results using Matplotlib; interactive GUI is also available
    • Can also be directly integrated with other Python-based frameworks, such as PyTorch for deep reinforcement learning traffic control
    • The main code uxsim.py is only about 1200 lines of code. Users may easily understand and customize it
    • Dependency-free: you can use the simulator by doing pip install uxsim only
  • Provides a seamless user experience by integrating scenario construction, simulation, and data analysis into a unified, transparent Python workflow

Simulation Examples

Large-scale scenario

Below are simulation results where approximately 60000 vehicles pass through a 10km x 10km grid network in 2 hours. The computation time was about 30 seconds on a standard desktop PC.

Visualization of link traffic states (thicker lines mean more vehicles, darker colors mean slower speeds) and some vehicle trajectories:

Vehicle trajectory diagram on a corridor of the above network:

Deep reinforcement learning signal control using PyTorch

A traffic signal controller is trained by deep reinforcement learning (DRL) using PyTorch. The left (or upper) scenario shows no control with fixed signal timing; the traffic demand exceeds the network capacity with the naive signal setting, and a gridlock occurs. The right (or bottom) scenario shows DRL control, where the traffic signal can be changed by observing queue length; although the demand level is the same, traffic flows smoothly. A Jupyter Notebook of this example is available.

Install

UXsim is available for Python version 3.10 or later.

Using pip

The simplest way is to use pip to install from PyPI:

pip install uxsim
Alternative methods for advanced users (click to see)

Using conda

You can also install with conda from conda-forge channel:

conda install uxsim

For the details, please see here.

Using pip with custom configuration

You can also use pip to install the GitHub version:

pip install -U -e git+https://github.com/toruseo/uxsim@main#egg=uxsim

Or any other (development) branch on this repo or your own fork:

pip install -U -e git+https://github.com/YOUR_FORK/uxsim@YOUR_BRANCH#egg=uxsim

Manual install

Download the uxsim directory from this Github repo or the latest release and place it in your local directory as follows:

your_project_directory/
├── uxsim/ 	# The uxsim directory
│ ├── uxsim.py 	# The main code of UXsim. You can customize this as you wish
│ └── ... 	# Other files and directories in uxsim
├── your_simulation_code.py 		# Your code if necessary
├── your_simulation_notebook.ipynb 	# Your Jupyter notebook if necessary
├── ... 	# Other files if necessary

This way, you can flexibly customize UXsim on your own.

Getting Started

As a simple example, the following code will simulate traffic flow in a Y-shaped network.

from uxsim import World

# Define the main simulation
# Units are standardized to seconds (s) and meters (m)
W = World(
    name="",    # Scenario name
    deltan=5,   # Simulation aggregation unit delta n
    tmax=1200,  # Total simulation time (s)
    print_mode=1, save_mode=1, show_mode=1,    # Various options
    random_seed=0    # Set the random seed
)

# Define the scenario
# Create nodes
W.addNode(name="orig1", x=0, y=0)  #xy coords are for visualization 
W.addNode(name="orig2", x=0, y=2)
W.addNode(name="merge", x=1, y=1)
W.addNode(name="dest", x=2, y=1)

# Create links between nodes
W.addLink(name="link1", start_node="orig1", end_node="merge", length=1000, free_flow_speed=20, number_of_lanes=1)
W.addLink(name="link2", start_node="orig2", end_node="merge", length=1000, free_flow_speed=20, number_of_lanes=1)
W.addLink(name="link3", start_node="merge", end_node="dest", length=1000, free_flow_speed=20, number_of_lanes=1)

# Create OD traffic demand between nodes
W.adddemand(orig="orig1", dest="dest", t_start=0, t_end=1000, flow=0.45)
W.adddemand(orig="orig2", dest="dest", t_start=400, t_end=1000, flow=0.6)

# Run the simulation to the end
W.exec_simulation()

# Print summary of simulation result
W.analyzer.print_simple_stats()

# Visualize snapshots of network traffic state for several timesteps
W.analyzer.network(t=100, detailed=1, network_font_size=12)
W.analyzer.network(t=600, detailed=1, network_font_size=12)
W.analyzer.network(t=800, detailed=1, network_font_size=12)

It will output text to the terminal and images to the out directory like below:

simulation setting:
 scenario name:
 simulation duration:    1200 s
 number of vehicles:     810 veh
 total road length:      3000 m
 time discret. width:    5 s
 platoon size:           5 veh
 number of timesteps:    240
 number of platoons:     162
 number of links:        3
 number of nodes:        4
 setup time:             0.00 s
simulating...
      time| # of vehicles| ave speed| computation time
       0 s|        0 vehs|   0.0 m/s|     0.00 s
     600 s|      130 vehs|  13.7 m/s|     0.03 s
    1195 s|       75 vehs|  12.3 m/s|     0.06 s
 simulation finished
results:
 average speed:  11.6 m/s
 number of completed trips:      735 / 810
 average travel time of trips:   162.6 s
 average delay of trips:         62.6 s
 delay ratio:                    0.385

Further Reading

To learn more about UXsim, please see:

Terms of Use & License

UXsim is released under the MIT License. You are free to use it as long as the source is acknowledged.

When publishing works based on UXsim, please cite:

@Article{seo2025joss,
  author    = {Toru Seo},
  journal   = {Journal of Open Source Software},
  title     = {{UXsim}: lightweight mesoscopic traffic flow simulator in pure {Python}},
  year      = {2025},
  number    = {106},
  pages     = {7617},
  volume    = {10},
  doi       = {10.21105/joss.07617},
  publisher = {The Open Journal},
  url       = {https://doi.org/10.21105/joss.07617},
}

If you need more detailed information, please also cite:

Works using UXsim are summarized on the Github Wiki page. Please feel free to edit.

Contributing and Discussion

Contributions are welcome! Please see the Contributing Guideline.

If you have any questions or suggestions, please post them to the Issues or Discussions (in English or Japanese).

I (Toru Seo) work on this project in my spare time. Please understand that my response may be delayed.

Acknowledgments

UXsim is based on various works in traffic flow theory and related fields. We acknowledge the contributions of the research community in advancing this field. Specifically, UXsim directly uses the following works:

Related Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uxsim-1.14.0b4.tar.gz (43.6 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

uxsim-1.14.0b4-cp314-cp314-win_amd64.whl (5.4 MB view details)

Uploaded CPython 3.14Windows x86-64

uxsim-1.14.0b4-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

uxsim-1.14.0b4-cp314-cp314-macosx_11_0_universal2.whl (5.6 MB view details)

Uploaded CPython 3.14macOS 11.0+ universal2 (ARM64, x86-64)

uxsim-1.14.0b4-cp313-cp313-win_amd64.whl (5.5 MB view details)

Uploaded CPython 3.13Windows x86-64

uxsim-1.14.0b4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

uxsim-1.14.0b4-cp313-cp313-macosx_11_0_universal2.whl (5.6 MB view details)

Uploaded CPython 3.13macOS 11.0+ universal2 (ARM64, x86-64)

uxsim-1.14.0b4-cp312-cp312-win_amd64.whl (5.5 MB view details)

Uploaded CPython 3.12Windows x86-64

uxsim-1.14.0b4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

uxsim-1.14.0b4-cp312-cp312-macosx_11_0_universal2.whl (5.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ universal2 (ARM64, x86-64)

uxsim-1.14.0b4-cp311-cp311-win_amd64.whl (5.5 MB view details)

Uploaded CPython 3.11Windows x86-64

uxsim-1.14.0b4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

uxsim-1.14.0b4-cp311-cp311-macosx_11_0_universal2.whl (5.6 MB view details)

Uploaded CPython 3.11macOS 11.0+ universal2 (ARM64, x86-64)

uxsim-1.14.0b4-cp310-cp310-win_amd64.whl (5.5 MB view details)

Uploaded CPython 3.10Windows x86-64

uxsim-1.14.0b4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

uxsim-1.14.0b4-cp310-cp310-macosx_11_0_universal2.whl (5.6 MB view details)

Uploaded CPython 3.10macOS 11.0+ universal2 (ARM64, x86-64)

File details

Details for the file uxsim-1.14.0b4.tar.gz.

File metadata

  • Download URL: uxsim-1.14.0b4.tar.gz
  • Upload date:
  • Size: 43.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for uxsim-1.14.0b4.tar.gz
Algorithm Hash digest
SHA256 59b365f7cad3c9f53e59b44f7f7e56c93037dcd0c7fd22e02b15070cb761e8de
MD5 586fb39ed0c926feabed89d6d339f1b8
BLAKE2b-256 7f7f0a21299dfa9f6ac1c82664397a8bace6fc92080af250d3205b28d803bb30

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b4-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: uxsim-1.14.0b4-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 5.4 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for uxsim-1.14.0b4-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 806836ad2962a8dd76ab80fb46a73072d38d4b666ae4fb37507c4809f8f30455
MD5 18c6ff742ef6bc25329b9f71245bcb29
BLAKE2b-256 1a7492737ee94849e77801cd8ac81810b62a36c50389b4dcb5670bf001ed7ff5

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b4-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for uxsim-1.14.0b4-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 79be54226c4dd6fd318d5e00b2e008879f9524a09a8d1fec68ad2b7d3d7588c5
MD5 026575de5163e422de9f96c2989909e2
BLAKE2b-256 4bf28469830c19e5b83ed4c073e72a533a523a2ff414e77d4f1a94ffdcd4ff7e

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b4-cp314-cp314-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for uxsim-1.14.0b4-cp314-cp314-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 1a2c8522a17b5da453e98be5b449a18e038961b98c65296b223c14b8394294f6
MD5 8710178490abcbb27b0374c2fd241363
BLAKE2b-256 6afae298670b9bf35818011a05d3790c2ad3a227523af3c5c670b4ec78994604

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b4-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: uxsim-1.14.0b4-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 5.5 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for uxsim-1.14.0b4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ce5d12e27209cc4ed420537c0d6f94e483a49ab38e96b4980d97951109267022
MD5 175d44abd8bbde547e81486cf79f1b59
BLAKE2b-256 ef9ca380e0bd61c90fbdab501b3be5d773d179f458ebfa90764ac7304576c7a1

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for uxsim-1.14.0b4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0f28f5f8cdf93c59ae8539ea54141149ce3ff83bdc26361741276a07f13a5dd5
MD5 79fe2bb658ac1ba2894aea5e177f5e9f
BLAKE2b-256 6819b965971aa849629f92614775b7bcb1455d7d296c9df9efa833c1fb85a01f

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b4-cp313-cp313-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for uxsim-1.14.0b4-cp313-cp313-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 0cce8947b5ead418a9b3a0238c5aac49b333cf0c00823d66fa35140673aec247
MD5 dbb78234cd6b4bf01b7d76b7e3f2e145
BLAKE2b-256 7b5eaa373f0aad60acef5461d31512983cd68ac5c3b884e11f3059f3c7a1b25c

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b4-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: uxsim-1.14.0b4-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 5.5 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for uxsim-1.14.0b4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6a7f1f65c02ee4804291e4ad31b2a4027e2d99b78be476309be1d2c53af96b54
MD5 012cae860ce92ce569e8884a257092f2
BLAKE2b-256 c1e24d8602169f66db757706303fcee830a912f67e4edd47d73b902a32bd4d1a

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for uxsim-1.14.0b4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2494c85232947b3baeb4a4fa42d62e3d148b554ca35b2aaf3aa126c925f73690
MD5 e3f92854590c001c614c9ae9b109d104
BLAKE2b-256 01c26235f4e2fbe47d8bdbccba4d8706f2fc4bf966d13b01b60922be1a9188d8

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b4-cp312-cp312-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for uxsim-1.14.0b4-cp312-cp312-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 7716b3d39de4be57475f330c75043301640959b0e6d06253b8a21db87ddbda75
MD5 bf6537bcc74c975189fd237aeef00fc0
BLAKE2b-256 c852916f0ed1ad34ff666f6ad2fd44ac0834618054280dc2e85e36b81f1180ee

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b4-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: uxsim-1.14.0b4-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 5.5 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for uxsim-1.14.0b4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 02e9f7eb6f7baa11bfd97047f13765549103cfd15aa05c70a4a4658f3e142520
MD5 41265c79bb676aa3578cee9fba90abc0
BLAKE2b-256 af86502b71a8eb8c2a4320edea362539626f45f0c0d0dba29180642bcf3676e8

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for uxsim-1.14.0b4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 50066e1770b82f998c6c6c0445905c81fa47596333f9caeb5ef5b9361a9af8c3
MD5 7a9d383e3acf8690ef467f8396e296a4
BLAKE2b-256 874d559fa7417aec040d83a0797da6163718ec72e6e72a3840707db5d3637121

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b4-cp311-cp311-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for uxsim-1.14.0b4-cp311-cp311-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 698b759785d18d8e34079d04a19f2551d6b09513fc86a5e741f20b90947352c1
MD5 61e74b38da14c7e29c14b5cfa32d40d1
BLAKE2b-256 5ecbb8dda4bf31e47d9bca5ff3b096487b830e31c938820587c080b9c6bd3bda

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b4-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: uxsim-1.14.0b4-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 5.5 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for uxsim-1.14.0b4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e8357ef0bd5e6285de33eb76f5581f7b3984713f0b33d8cbabbe52a65df78608
MD5 0d9c552c75b046cb7b9b96a0b4ba74e2
BLAKE2b-256 13445a411d0e3346d3f799c70f27c7ebc3630efe94a30f0a7152376b83a36f64

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for uxsim-1.14.0b4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3e86f794bab12dd0a99750db1b07ae629ec07d020612353edc9314fd7e7da21a
MD5 353744f317905ca15196da5632b9347f
BLAKE2b-256 12a610c118bd642f5641f4022f9390198962ab7a3d46139f20060c936e62862e

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b4-cp310-cp310-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for uxsim-1.14.0b4-cp310-cp310-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 4260938e75498b4e2377b27ec2d07fd9194b67f35f6da8b4550a771d968955ed
MD5 ca5790ad4714468b85647ea09d7693fd
BLAKE2b-256 4b259588ea0a3989411561a816ee699b2f180c166db857d72130f262ad62f040

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page