Skip to content

About

Traffic Simulator based on rust

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Traffic Simulator

A Bevy-based 2D traffic simulator that builds a road network from real OpenStreetMap data and runs an agent-based simulation on top of it — currently tuned around Gurgaon, India. It parses .osm.pbf extracts, lets you pick a bounding box to load, spawns vehicles that route across the resulting graph, and gives you live controls/analytics/editing tools while it runs.

Features

  • Real-world road networks — parses OpenStreetMap .osm.pbf extracts into a routable graph (petgraph + fast_paths for pathfinding).
  • Interactive area selection — scan a map file, pan/zoom an overview, and drag-select the bounding box you want to simulate before it's loaded.
  • Agent-based simulation — vehicles (car, auto-rickshaw, motorcycle, bus) spawn, route, and move along the network with configurable per-type mix and "chaos" behavior (signal obedience, lane discipline, aggression, honking).
  • Traffic signals & intersections — signal phases are built from the road graph and can be enriched with real signal/stop-sign/speed-limit data from Mapillary.
  • POI-driven spawn/attraction weighting — points of interest (e.g. assets/hotspots_gurgaon.json) bias where vehicles spawn from and head to, classified by category.
  • Live dashboard & analytics — throughput, average speed, congestion, and vehicle-count metrics plotted in real time (egui_plot).
  • Scenario save/load & compare — save the current sim config (spawn rate, chaos, time of day, vehicle mix, bbox) as a JSON scenario under assets/scenarios/, reload it later, and compare two recorded metric snapshots side by side.
  • Edit mode — place/remove traffic signals and edit roads directly on the map, with edits persisted as a named JSON diff.
  • Congestion heatmap overlay and a day/night simulation clock with time-jump controls.

Requirements

  • Rust (2024 edition toolchain)
  • A .osm.pbf map extract (see Map data below)

Getting started

cargo run --release

On startup the app picks the largest .osm.pbf file in assets/maps/, quick-scans it, then opens the area-selection screen where you drag a bounding box and load the simulation.

Controls

Action Keys
Pan Two-finger swipe / WASD / Arrow keys / Right- or middle-click drag
Zoom Pinch / Ctrl+Scroll
Reset view R / Home
Toggle edit mode E
Pause/resume simulation Space
Back to area selection Esc
Toggle this help panel H

The top bar switches between Controls, Dashboard, Scenarios, and Compare tabs while a simulation is active.

Map data

assets/maps/*.osm.pbf files are gitignored (GitHub rejects files over 100MB) and are not stored in this repo. Source an extract for the area you want to simulate — e.g. via Geofabrik, BBBike, or an Overpass/osmium extract for a specific bounding box — and drop it into assets/maps/.

northern-zone-260306.osm.pbf (209MB, covering the Gurgaon/northern-zone area) was previously tracked in git history but has since been removed and lost locally. It was sourced from OpenStreetMap — re-download/re-extract it if needed.

Optional: Mapillary enrichment

Set MAPILLARY_TOKEN in a .env file at the repo root to enrich the parsed network with real-world traffic signal, stop sign, and speed limit positions from the Mapillary API:

MAPILLARY_TOKEN=your_token_here

This is optional — without it, the app logs that enrichment is skipped and falls back to signal placement inferred from the road graph alone.

Scenarios & POI data

  • assets/scenarios/*.json — saved simulation scenarios (bbox, spawn rate, chaos level, time of day/week, vehicle mix, chaos distribution). morning_rush.json is included as an example.
  • assets/hotspots_gurgaon.json — named points of interest with spawn/attraction weights and categories (commercial, transit, etc.) used to bias vehicle spawning and routing.

Project layout

src/
  main.rs             App state machine (Scanning → AreaSelection → Loading → Simulation)
  map/                OSM parsing, road network construction, scanning, tile fetching, Mapillary
  simulation/         Agents, pathfinding, physics, signals, spawning, sim clock
  rendering/          Map/agent/signal/POI rendering, congestion overlay, camera
  scenarios/          Scenario loading and edit persistence
  ui/                 egui panels: controls, dashboard, scenarios, compare, edit mode, help
  analytics/          Live metrics collection

Dependencies

Built on Bevy 0.18 with bevy_egui for UI, osmpbf for OSM parsing, petgraph/fast_paths for the road graph and routing, and egui_plot for charts. See Cargo.toml for the full list.

About

Traffic Simulator based on rust

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages