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.0b6.tar.gz (43.7 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.0b6-cp314-cp314-win_amd64.whl (5.6 MB view details)

Uploaded CPython 3.14Windows x86-64

uxsim-1.14.0b6-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.0b6-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.0b6-cp313-cp313-win_amd64.whl (5.7 MB view details)

Uploaded CPython 3.13Windows x86-64

uxsim-1.14.0b6-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.0b6-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.0b6-cp312-cp312-win_amd64.whl (5.7 MB view details)

Uploaded CPython 3.12Windows x86-64

uxsim-1.14.0b6-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.0b6-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.0b6-cp311-cp311-win_amd64.whl (5.7 MB view details)

Uploaded CPython 3.11Windows x86-64

uxsim-1.14.0b6-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.0b6-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.0b6-cp310-cp310-win_amd64.whl (5.7 MB view details)

Uploaded CPython 3.10Windows x86-64

uxsim-1.14.0b6-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.0b6-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.0b6.tar.gz.

File metadata

  • Download URL: uxsim-1.14.0b6.tar.gz
  • Upload date:
  • Size: 43.7 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.0b6.tar.gz
Algorithm Hash digest
SHA256 57a310a7cf91f8da824a4168e175fe84ca929bd088ec51211ad4d851b1c2dfac
MD5 4a1386ce5e2c8147d5eee5097ee3918e
BLAKE2b-256 9f72e0c1b85d8c1afcaef3f25b41cb5d37dee6890963795d6ab3966ccf999e5d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uxsim-1.14.0b6-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 5.6 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.0b6-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 a100133dc86eb1d601f159ea2a64d1b2be0fa95ea617e4335b35dd65050b1bb3
MD5 6469f54e2e184ae00b547aa297584bef
BLAKE2b-256 d6fee67b0383efac9d3cb2c066c1bb83de57df11d8363568a8c5ef1517f408e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b6-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ffe0fb15b2f4849422101ca8e77717226d3c854a696145051ec4aae5ca58bef4
MD5 10dce42a2c813f6a4a4e68833707c1a4
BLAKE2b-256 2d1cb49672470428e74b84b2fb4b64bfddf3ebbbe1e32350f3c8490b84f102b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b6-cp314-cp314-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 9e0b300846df4866b6d103243271c4dba1046600817ec2608fec8b6b76b92ba3
MD5 7bb0af200289c7cd5f0e5ea9f1ca8af5
BLAKE2b-256 22fea880ebde41ca89601554d64f98c08c5550504aeed2cd62537e347ae40a17

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uxsim-1.14.0b6-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 5.7 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.0b6-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 21b1fc39d4ce3b8d048d0a9637933fc20ccd19b9201689ad090f094db30e5bf6
MD5 a2cf4d396be46c89ede4c155ae7ffd93
BLAKE2b-256 9ce8232d3ad99436663e617f43efa468d7acf5a46e8c5d07013101f24e2f0178

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b6-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2f6f1806181c5925e5c8d2dfff9c16e3027b4756a6a610134728752cb7ab7886
MD5 352b08bb1a65358be40215b516536964
BLAKE2b-256 85e8a1c19f72c7e9c9d7ee52bdcef140e6dcb1477bf603e2a6f9a29d8c542c9c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b6-cp313-cp313-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 5f95adbd2fbf3dc00252fffd446c87fe93b15a59e1531f2812d781e77f143f02
MD5 d5c6c4ed4b4aa69051b2206aa902c69d
BLAKE2b-256 49261874503032c7c354196485ab3458a57f18280943c77f4ed49aa85b53deb1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uxsim-1.14.0b6-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 5.7 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.0b6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 88979a42b23a18d670f0428affb07c2f9b449640be0b8f32ae3da4134aedc89d
MD5 709de7c7a8ed3dc2fc7c4a476a0da730
BLAKE2b-256 f5ec58defb41bb5215d1eda7a7b3e26d98b92f4c9ce8baa23594a221f439165b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b6-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dc3d22b8a13ba90ae07afed002c9a44866bf94f3ff42dec10d220386a75c6394
MD5 f8ac1c19a3376ab3c5fbfe8d5c29d563
BLAKE2b-256 0fb4b062ca3c0f9f5a31052339a8bb737442dd262f8eed218bf78bd7fd85faa8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b6-cp312-cp312-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 ca9ba36d3cf74a5083d7c9cb5c589c07a24932bba0929fc5978fea4589a728a5
MD5 ccb8fe55eea46aca60b04a869ee16d5f
BLAKE2b-256 1b2c29bb857f90aa3683a7cdf37a592fe7248032d53c7d8b167ddd1ada510ac3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uxsim-1.14.0b6-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 5.7 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.0b6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c05c85d55fc65a9efceb0b5b7ea1805274bf30afd24026e4181acaeefb6228d2
MD5 3ea21a5048dbe2c4a49486dfbcfd169d
BLAKE2b-256 01e5dd3f794f59c3355829b73ea90c7480090c826e97f0329b26844b00a711cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b6-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5c188f07b3791609a9504ddf28eb4e693ecd6d18715f5c3c43a4ca44a9ffb89b
MD5 7c3a6ad30d34777cff4d721ff34d5986
BLAKE2b-256 c03d62ad647fdb075c6d884d16e52ad24b911affe2bec25be4515b23d19f276f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b6-cp311-cp311-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 d31fe7160d85a30b7110ed6489b70b1afe869400834a6da3865fb212d7c1b296
MD5 8104521a41a3a6a0b9ac820864ab444d
BLAKE2b-256 8841b1df95d467b576a7e505142b3ae7f328a509a92471a491956b50cb2991b4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uxsim-1.14.0b6-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 5.7 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.0b6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e910d005528f8f67744c8caddc07b6967f8c16150c021e18042479299bbe3402
MD5 7c0eb56b43661a74b9b871354881f5fd
BLAKE2b-256 21e0913b44566a41ffa0ff4511d9e9bc4d632484c3eedd31652c5add9043d859

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b6-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 18452354caeff2dbc726c50971a2528f923524cda221ccbcffcf2a6d2157cc98
MD5 06aeb7f1a07e11f5e69016f149668443
BLAKE2b-256 8bbce59dbf9d326a2a9d1eac7228ee3b2288c8fd978241687a44dd54449b0eaf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b6-cp310-cp310-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 ec3cf6864e2416b2e41932f9d161dff772180e47ca047ffe4b54b84a25dd2fd3
MD5 dc96bab19d820cb6f32606f8b936dd4f
BLAKE2b-256 91be43dba7237ee5adb387e7c812911970c6f094ce83539bb62b51f64e8bb43a

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