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

Uploaded CPython 3.14Windows x86-64

uxsim-1.14.0b2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (5.6 MB view details)

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

uxsim-1.14.0b2-cp314-cp314-macosx_10_15_universal2.whl (5.7 MB view details)

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

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

Uploaded CPython 3.13Windows x86-64

uxsim-1.14.0b2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (5.6 MB view details)

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

uxsim-1.14.0b2-cp313-cp313-macosx_10_13_universal2.whl (5.7 MB view details)

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

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

Uploaded CPython 3.12Windows x86-64

uxsim-1.14.0b2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (5.6 MB view details)

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

uxsim-1.14.0b2-cp312-cp312-macosx_10_13_universal2.whl (5.7 MB view details)

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

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

Uploaded CPython 3.11Windows x86-64

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

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

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

Uploaded CPython 3.10Windows x86-64

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

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

File details

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

File metadata

  • Download URL: uxsim-1.14.0b2.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.0b2.tar.gz
Algorithm Hash digest
SHA256 87443f2ea46b21bad2267631715f85db5aceb451b667defa21b70ba73ffbbc22
MD5 2b8a47c1bc7f0446c5d68edfeeccc0b6
BLAKE2b-256 4116283f0bd81879eaab81247aee9e65a93418928ece336452fe0a0e990174fa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uxsim-1.14.0b2-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 5.5 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.0b2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 456af1d376136ebaafab0a7be636bd12f8f4f396ef5ee14e82e4fae4898d8f99
MD5 f9f8f05b81f20e48b864abf87649515b
BLAKE2b-256 0008b0e2ea25998376df72a55315f3a07d83532b39ed236ea7fb55a4baa5bf36

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 28da24ac36367be24e542abf7020b9b5d40f4f5c13613e7b022c3a0862724250
MD5 9a16cdcfa55695d34fc6cd358b0a6b0b
BLAKE2b-256 e1cce57f6616f43f844e4832d046ff74d5133cce5f59ae6f36bd6cc0445f76e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b2-cp314-cp314-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 af29c31937070e71c20635fd8f16623968acc1054183ff2f24dfb9d6a2018218
MD5 54ee557f248191f83a7973e5f99b3c17
BLAKE2b-256 89f7f1b19ee43817f164824c4bc8a24e794e339490fdfe1ea1f606e5b7cae21d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uxsim-1.14.0b2-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.0b2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3442d35d56493f6a27e76c142393318add80d593b7b415e369c01283a1c55435
MD5 82a58e7b62bbb5ee422e644b690edf86
BLAKE2b-256 aeb1bf1b2d2c923c187d7c336a880b4b9ea2b0fff2db2bb2eaacab17c98c3783

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4281e04b95a17083cdc153e7c0bff2417c98265d54889a94d83d833d74e5112a
MD5 df01876282c7800cfd297309e84576ab
BLAKE2b-256 19b8315646ef2cb472a3b76d980e0cc2a3bffa7f6c4c2d50b20523c651c77819

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b2-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for uxsim-1.14.0b2-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 cf1a13421b5fdd96943dbc76df120a121c7c8bb4f85e5a42e79d3500a82211c5
MD5 a392237fa8df39a432b643cbfba9f182
BLAKE2b-256 faca054ec9d9d717d7f8a7e606060b0864998fd0c4afbc56663633ec56ae5abb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uxsim-1.14.0b2-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.0b2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 293bda3b23a16c74258e959ad588334f2a3c5b2ed8e874dd3b77dae641180f6a
MD5 f42821eb9369da33059865e13c34c188
BLAKE2b-256 08a111e413a68ee5796c1c9c5e084959661d4d45b21ea8d74dd3e9958540dad9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9ecfe77cd7a334677a441979ea7efa90df6f0364755d7b13ce8cde40e5ccc25d
MD5 c0cb4670d4e815f30ab57a41fd5995f9
BLAKE2b-256 1d282a8241b96857cf3438a272b7eb7b4ea4375b9da08587de4287e722a1c3a9

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b2-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for uxsim-1.14.0b2-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 f21bc5312cd1356cb4c8d665fe0fb7e367133677db709549c55538d55b9e9b08
MD5 f5251e3a2a96d042a7fcbc9bb5c6d8f0
BLAKE2b-256 af04ceeda5f1bce2aa6c2df845223679ad005d362cf18a1dcaddad46e65e28ae

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uxsim-1.14.0b2-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.0b2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9b8d77232d0d6a1619caebfd7b1f4d72bfd1e0631752bb307e4810caec48494f
MD5 9b47db461aa4c302b591f8d00fb86262
BLAKE2b-256 2aac1a22dab50a99039ca2a5b0f2d99b47d70cf19aa81a9563f4dc63f16dd012

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d41d8cb82f55ce54bd2e3ec0b2082e98f61de91710055d966a44a2e63f73c476
MD5 9f6c1d63c1e8cc4bde0927fca3d3b0b9
BLAKE2b-256 0aab697dffbec0124f2bbb45ce06e8039679a5a2fd034e1b76f44f18c2d61678

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b2-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for uxsim-1.14.0b2-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 2b4f754346c69b1534dba7666ec3b1bc261e7ad064262c49eb1f814744fed3c7
MD5 5ea70252749cde6fc6b94a8bb6eb1f49
BLAKE2b-256 4efc132208d04cef5703ebd6998fb699a8ea999c04940308d8e0f6ea3143af52

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uxsim-1.14.0b2-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.0b2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ac8170ff9d023637d2ae52d06d993d6103898605e9e356326b3543459aa1ea33
MD5 814a15137d4b6487415295b35014adb5
BLAKE2b-256 e3ac717dd41d06155d2875ea835c5f2937f9a5581e3f4b88d6e894b118059d1e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uxsim-1.14.0b2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7187778090fa59b601bf25b982e88e74d8ada45106f8ca10f632b176fea5665a
MD5 59a28d4d2db57a501692b981cc88baa8
BLAKE2b-256 6432dc34f7e21e1a9a4de054b849c5d3352ae496699082a455e35e68206f2c3a

See more details on using hashes here.

File details

Details for the file uxsim-1.14.0b2-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for uxsim-1.14.0b2-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 48e1f4b84241bfc70cfb6434670bb806d350837790912b52e066af1a951b61a1
MD5 4cc4c0276f5d554309595abbbf943e1c
BLAKE2b-256 ab3bfbc4016956ffacd2a63487c434f006b44972d7d7c24caf89e73bb6564914

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