uxsim-rs is a pure Rust port of the UXsim macroscopic traffic simulator capable of modeling 50,000+ vehicles across metropolitan road networks in real time. It solves Newell's kinematic wave theory and triangular fundamental diagrams to simulate congestion spillbacks, signal coordination, and dynamic route choice.
$ cargo add uxsim-rs
Watch macroscopic flow packets propagate through multi-lane arterial links. Signal lights cause queue spillback across junctions. Move the glowing Player Render Bubble to watch macro packets smoothly hand off into full microscopic high-detail vehicles.
Explore the mathematical relationships governing density $k$, flow $q(k)$, and space-mean speed $v(k)$. Toggle between classic models and adjust network density to observe backward shockwave propagation speed $w$.
Vehicles travel freely near free-flow velocity \(v_f\). No backward queue formation.
Everything required to simulate an entire living metropolis while concentrating computing power precisely where the player or camera is looking.
Supports exact formulations of Greenshields parabolic flow, Newell simplified triangular, and trapezoidal capacity plateaus. Evaluates backward shockwave propagation speed \(w\) using the exact Rankine-Hugoniot jump condition to model realistic jam formation.
Directed links model physical road segments with length \(L\), multiple lanes, and finite storage capacity \(K = k_j \cdot L \cdot \text{lanes}\). Includes signalized intersections with 4-phase signal timing, queue spillback, and aggregated flow packet propagation.
Fast Dijkstra and \(A^*\) pathfinding engines calculate optimal routes based on dynamic congestion travel times rather than static road lengths. Vehicles autonomously re-route around unexpected bottlenecks, accidents, and temporary lane closures.
The RenderBubble spatial system continuously detects when macroscopic vehicles approach the player camera. Extracts precise 2D world position, forward heading, lane index, and speed for Bevy ECS or microscopic physics, then cleanly re-assimilates upon exit.
sumo-rsStandardized hydrodynamic traffic flow principles implemented in uxsim-rs.
Linear decrease of space-mean speed with density; parabolic flow-density curve with peak capacity at \(k_c = k_j / 2\).
Constant free-flow velocity branch and constant backward shockwave speed \(w\) branch, common in urban arterial modeling.
Conservation of vehicles across discontinuities; governs the speed of queue spillback and recovery wavefronts.
Finite physical storage limits triggering spillback when link reaches jam capacity \(K\).
Start building complex road networks and running city-scale simulations in seconds.
[dependencies]
uxsim-rs = "0.1"
glam = "0.29"
use glam::Vec2;
use uxsim_rs::prelude::*;
use uxsim_rs::{Link, RoadNetwork, TrafficSimulator};
use uxsim_rs::flow_model::{FlowModel, NewellTriangular};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut network = RoadNetwork::new();
// 1. Add intersection nodes
network.add_node(1, Vec2::new(0.0, 0.0))?;
network.add_node(2, Vec2::new(500.0, 0.0))?;
network.add_node(3, Vec2::new(1000.0, 0.0))?;
// 2. Add road links (length: 500m, 2 lanes, urban Newell model)
let flow_model = FlowModel::NewellTriangular(NewellTriangular::standard_urban());
network.add_link(Link::new(12, 1, 2, 500.0, 2, flow_model))?;
network.add_link(Link::new(23, 2, 3, 500.0, 2, flow_model))?;
// 3. Initialize simulator with 1.0s timestep
let mut sim = TrafficSimulator::new(network, 1.0);
// 4. Inject trips (A* dynamic auto-routing)
sim.add_trip(1001, 1, 3, 0.0)?;
// 5. Step simulation
for _ in 0..60 {
sim.step();
}
println!("Simulation step completed successfully!");
Ok(())
}
use glam::Vec2;
use uxsim_rs::handoff::RenderBubble;
fn sync_traffic_bubble(sim: &mut TrafficSimulator, player_pos: Vec2) {
let bubble = RenderBubble::new(player_pos, 150.0, 25.0);
// 1. Query macroscopic vehicles in bubble
let entering = sim.query_vehicles_in_bubble(&bubble);
for veh_id in entering {
if let Ok(handoff) = sim.handoff_to_micro(veh_id) {
// Spawn high-fidelity Bevy 3D entity
spawn_bevy_micro_car(
handoff.world_position,
handoff.forward_direction,
handoff.speed
);
}
}
}
Unlike legacy C++ microscopic simulators (like SUMO or VISSIM) that require complex C bindings and heavyweight IPC, uxsim-rs compiles cleanly via cargo build to WebAssembly, macOS, Linux, and Windows.
Every hydrodynamic principle, routing algorithm, and boundary handoff edge-case is rigorously tested.
Aggregated packet evaluation yields <0.8ms timestep latency across 50,000 background vehicles, leaving 95%+ of game frame budget for GPU graphics and game logic.