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.0b3.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.0b3-cp314-cp314-win_amd64.whl (5.4 MB view details)

Uploaded CPython 3.14Windows x86-64

uxsim-1.14.0b3-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.0b3-cp314-cp314-macosx_10_15_universal2.whl (5.6 MB view details)

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

uxsim-1.14.0b3-cp313-cp313-win_amd64.whl (5.4 MB view details)

Uploaded CPython 3.13Windows x86-64

uxsim-1.14.0b3-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.0b3-cp313-cp313-macosx_10_14_universal2.whl (5.6 MB view details)

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

uxsim-1.14.0b3-cp312-cp312-win_amd64.whl (5.4 MB view details)

Uploaded CPython 3.12Windows x86-64

uxsim-1.14.0b3-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.0b3-cp312-cp312-macosx_10_14_universal2.whl (5.6 MB view details)

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

uxsim-1.14.0b3-cp311-cp311-win_amd64.whl (5.4 MB view details)

Uploaded CPython 3.11Windows x86-64

uxsim-1.14.0b3-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.0b3-cp311-cp311-macosx_10_14_universal2.whl (5.6 MB view details)

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

uxsim-1.14.0b3-cp310-cp310-win_amd64.whl (5.4 MB view details)

Uploaded CPython 3.10Windows x86-64

uxsim-1.14.0b3-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.0b3-cp310-cp310-macosx_10_14_universal2.whl (5.6 MB view details)

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

File details

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

File metadata

  • Download URL: uxsim-1.14.0b3.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.0b3.tar.gz
Algorithm Hash digest
SHA256 7bccd1956524312e189fe8004ce8e154c95eaf88c87bcfc679b86c6221776afe
MD5 a626f3a4edbfe36bebebdaa422f8391f
BLAKE2b-256 f6adee89a1aa5c936c88ff022d4e7a491d4f80046b768f937fba8b1f1b1d40bb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uxsim-1.14.0b3-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.0b3-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 0d205e9c5c40e0334a0c603e0c9d2f255ef5437e0884e040a3a4959c33f34ccd
MD5 279df66f81e73e3aa16500efce705423
BLAKE2b-256 d25bdbe29ebdbe4f37a77214678e11d8ad37019a14cef586edafe44b2af31fd9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b3-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 83dcf0546b2ea5ce33869a7ce66935e83d2bc9cdad549c6a66275d3311d6336a
MD5 c35f27831fc59e46d4d6ee1bd4ab98ec
BLAKE2b-256 24a1681699b239d60c8c69b0f62bc21b14c8d921449c285c5883bc1d4941c59f

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b3-cp314-cp314-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for uxsim-1.14.0b3-cp314-cp314-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 974802cc67b903c0476ccc4c4f04f6513f3f9d37142b236a99f707487ec837ff
MD5 54929cbc1e811bc70c41dc6c66a90287
BLAKE2b-256 1595ea3a1ab68264313a1034dd84c3ca698941e8add3acc7d546df0bfa3375d7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uxsim-1.14.0b3-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 5.4 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.0b3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ab182a4b7deca9a5996b50a4b090bac8b2f4a48c16920928d0d740656c4a8764
MD5 450bdd35701307ca6cdef65103f12439
BLAKE2b-256 667b5ddeb55b9d1f738eeb07b8c680588e73f2cf0c2b4faef2551546a8fd1700

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 35ac2149ef8bb565ee5b0c65889131d7fa27a1b1cb86eb5956fbd46768bc2d32
MD5 8320780a577de7afebe8da5a7dd2c009
BLAKE2b-256 f494bcd770c789945c86bce5e55aeede7eb8061c022279e0d474ce39691122d4

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b3-cp313-cp313-macosx_10_14_universal2.whl.

File metadata

File hashes

Hashes for uxsim-1.14.0b3-cp313-cp313-macosx_10_14_universal2.whl
Algorithm Hash digest
SHA256 297f8d37032b12d1da272fb5e9de9dea12726d895f4febb8f53ace56188d0529
MD5 080e5cf68b11adcf3a6a417b3abe7ef3
BLAKE2b-256 8dceb76748670c83c52edfad9d9d5d6374a971e9c0d3fa3d1e795014d30210ed

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uxsim-1.14.0b3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 5.4 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.0b3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1f6cb5e47f7f80e701ca5e1b238bce0a5c2d36515be6edc96a31924bd617654d
MD5 9fa73a44aee7ae22d92500df008582a4
BLAKE2b-256 ca1a3a4e9a1c082dffb43a3ff2c3f4a420acfe82822274cf2e31daf5ec31f10c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ecc3535b5b970d5f915b7eaa43ae752bb702bf5eae32450de622bec21d712d50
MD5 fe403c11af2b14d5f077cc6b6ba26f48
BLAKE2b-256 af197464880211a4ffe690b4c72d8eb0b21fca5f42ae324a3b553e57673d9209

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b3-cp312-cp312-macosx_10_14_universal2.whl.

File metadata

File hashes

Hashes for uxsim-1.14.0b3-cp312-cp312-macosx_10_14_universal2.whl
Algorithm Hash digest
SHA256 d9eac93e51ec3296231f58f391b906ce6226e37a0ec2089eabe1677efa8d7603
MD5 1e18e0eb7c60c8190b02fa89039cb181
BLAKE2b-256 290208320d645fe00e436ddec0436e4d11d948e9e2074e49d5851c4a9b2d25be

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uxsim-1.14.0b3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 5.4 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.0b3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9314bdee3a2200c4eec6bad1f215d89c19d056e37e50474f92b6c57ba01f45d4
MD5 77644842a9349a1820446728aed32706
BLAKE2b-256 423f4e54c28fb6e8324014d85b2f6b03de2c650db536f43e9e5d2e2be14673d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 93dbb41bda2205b6c559b9356a2a7091b726fcbe778bf73d915c7e2dd8a9a112
MD5 9ebc35118afd6ab3ef6a36222f893e98
BLAKE2b-256 f37c3e7beb24a1bf3645d89309657b9bf5c2a21a7b535f10fb8da1ddb177c317

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b3-cp311-cp311-macosx_10_14_universal2.whl.

File metadata

File hashes

Hashes for uxsim-1.14.0b3-cp311-cp311-macosx_10_14_universal2.whl
Algorithm Hash digest
SHA256 c85a929bb6a20a3a7f6047c53dd80527b6b8a7544077efab719f051b489f4189
MD5 bd1b152c8d4c48933921e327381875d0
BLAKE2b-256 4e7e2ea13a5f4bf29cc2448835ca0c4f0a7a98f5ee1dbe37c6451796c27272f2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uxsim-1.14.0b3-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 5.4 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.0b3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6d35c9d653a2b9e91f9fe66d2310475ac1248da64d6f0e26444dadeed7df229e
MD5 50c9c8434673047966d53100013dd02f
BLAKE2b-256 c0d55117e4ee5d231ec7d0f9f3fff87c650d9b732a05682ba55001cd9322f4fd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a5661d2679188542f633341a3c1074d1d853cf7f38e10b52b0098164ca0051c1
MD5 9ded379bfe4f9371c87a5d3f7150bcba
BLAKE2b-256 c65517499aab39a712a93c98cccbbce70743516bced4da6701fbf67e6b5131f6

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b3-cp310-cp310-macosx_10_14_universal2.whl.

File metadata

File hashes

Hashes for uxsim-1.14.0b3-cp310-cp310-macosx_10_14_universal2.whl
Algorithm Hash digest
SHA256 6b0bcb3641149e637e8f24c25140d86f0896f76e43d4bbc02dc02d609756437d
MD5 d13580a954549c5246d3cc6b0c95d4b0
BLAKE2b-256 e02c848e022825988dabc0b7ec7861383990f276e8e48da9af0dc698a90a4b3f

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