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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.10Windows x86-64

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

File metadata

  • Download URL: uxsim-1.14.0b5.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.0b5.tar.gz
Algorithm Hash digest
SHA256 5287ad8576ae5b49b715f1b6b54a88c738fdf3ee26d42c3884feb6db24ff20c7
MD5 376ac524628d2dc5ad750710cbba8cc3
BLAKE2b-256 c6b31dbd76907127d03fe49342f6fc92f486e507b613878e913264c38b916f68

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uxsim-1.14.0b5-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.0b5-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 10ffacf4bcfd93b7e870e9e0ccce1a216d18420844c96db13ae029e287b7126d
MD5 14c03151a45e1b3ec70b15838b6fcbb2
BLAKE2b-256 9958be89e1e02fffb5593a2c5bb94036ea4a9fea51df8650d53d9534695582ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b5-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 023f461aa65ced722afba1bbe419a3785b75386d31d30adfc584d713459c0dc6
MD5 8eda9ed8a5b50ebc264ddaff895e0832
BLAKE2b-256 14607636433e22d8cc49b64ad4a7cb17a43765f7195af0a15cdfa0d2e9242195

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b5-cp314-cp314-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 4f508f825c5dc1562e390f9c3f2b29d84c0bbe3428e5e8f0cfcfa6c3cb1b81c4
MD5 32f71c67caa7b7878d41f9f49506ad21
BLAKE2b-256 7dbb7c6ee71f032bed3b38e5c1d81cce42bc761537679d3702780671093cec9d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uxsim-1.14.0b5-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.0b5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6cd482a83187b792f71018286438ceb77d33dbd2b0cff2d8eb438384bed3041c
MD5 9849e11ef42ce0aa9e1cb35b20a62e50
BLAKE2b-256 a7eb81a0dd6b535925eabd96a7075caaaddc8a1774bce455e8c084b5321c40e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0f98244041c2df912a6f8081050a3451597d0581a1cb6417162accae362e1312
MD5 7feca4d4f3704d6b5eade9de2d0a7a65
BLAKE2b-256 71a68c5790ed1518a2429d8e0919c28b8a1b8c7862755f0c5f8c5b6ba2a9bd0a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b5-cp313-cp313-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 11939c57573759b2fd7cffb9ba373c789886e7f82bd1c657720858a08f929105
MD5 140cda91f59bbab024b160f9fd8ee54c
BLAKE2b-256 6edd8fb172fd633bd806ccae5f8211ea3347736a14fce27c8a757af772e217f0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uxsim-1.14.0b5-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.0b5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5b24d0427fb2ea03185524e0d46efdcb904396d1d667a753c9b08e4f0fc85c81
MD5 d72657c8bec5850bb2a82d70f07b4376
BLAKE2b-256 f81aeba2261d1d9c3fcd07f2b1b7fef93040e38af44507bb5675161e5f1495f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 36b7617b848e7ca8c77cf044102d91ec9963eae2eee7ef7b7f81318b8c307859
MD5 3fc54691105402e45e9e805472036e27
BLAKE2b-256 74683641730fc2b3f3067019f3e2f2665f72eb222d8cf77dd63265c402937057

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b5-cp312-cp312-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 8e41eb39c893044023e40b302b73ce4ebfd1c6cd001c1562467f7ac8beb58025
MD5 c7ba4aca8e016597b9748a4bacdea0c6
BLAKE2b-256 ac8c8c56c9c6d3acefbc6a2fd6f3dc7891fd89f752f4d8b706f1f13f75d78ece

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uxsim-1.14.0b5-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.0b5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d04c9dc48b34a001c78b2a7ba7da694bd845f05b1e45057b2a5d08b9c0cd9abb
MD5 2a6fb9d3010f93661571db76a8f7612d
BLAKE2b-256 178c53b71cfcd9d23da88089ad8c03e1f95c082b9be6a5dab6f4fd20fc66ba69

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6425554a28db51a11c5c11f0233609ca894ef25c6099564751f6ce9124db5117
MD5 0320a233fa2dfa3e5db86b5faa6d87df
BLAKE2b-256 c68b25569512008507adbf6055c5c793af69dead09e09eb62cc8f3797d6a4ddd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b5-cp311-cp311-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 f286115233c477d56a71625905e88276ade2a86022a87b33a867f58056f7d108
MD5 9da5face5a791e3c10683cf966a49bb8
BLAKE2b-256 543ed4be4989d4c5cdb501e8b309f096270e1635b6752cd588617dff2776a16c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uxsim-1.14.0b5-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.0b5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 89cc98c280a786ceecf27123ce396c628ce8db6b4708442691ff245bd0ac695b
MD5 70b9d28c8fa7d6870e18681cabf2ca57
BLAKE2b-256 d0ef00d9a800a70647671ee8debd4a24cd52c107a1b536999ff36b3945e1e3d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 95c9e93cd73fc474add956fdbe4245252016da5aaae22733f81a0eee9c6c9b9c
MD5 e22f23a54ac6bd25237dd049424fbcfe
BLAKE2b-256 751eac047690872b86185c695054d732032491cac49f062158d1db21e132b0ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b5-cp310-cp310-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 b3ee1db2d0300542f6d77d49e759c891c0d74a911614f74705d17e8cf799b80c
MD5 7f328ff58b81b764048c6eb43c2f518a
BLAKE2b-256 d34ca9bd6e0bdc5f55fb05debd31ad5df053097cba507e1ca165e65bb762e2e4

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