HomeAI & Machine LearningTransit Route & ETA Predictor

🚌 Transit Route & ETA Predictor

Interactive transit simulator: buses move across a real route network as Dijkstra's algorithm computes shortest paths and a live model predicts arrival times against actual — watch prediction error shrink as buses approach.

AI & Machine Learning3DAdvanced60 FPS
ai-public-transportation ↗ Open standalone

About the Transit Route & ETA Predictor

Every time a transit app tells you a bus is "4 minutes away," two very different pieces of computer science are working together behind the scenes. The first is shortest-path search: given a network of stops and travel times, find the fastest route from A to B. The second is live arrival prediction: given how traffic has actually behaved recently, estimate how long the next leg of a trip will really take — because a printed timetable is only ever a starting guess. This simulation implements both, for real, on a 16-stop route network.

Click any two stops to run a genuine Dijkstra's algorithm shortest-path search between them: watch the frontier of "settled" stops expand outward and the final route highlight once it's found. Meanwhile, up to four buses loop continuously around fixed routes. Each edge in the network has a randomly fluctuating traffic factor, and a live exponentially-weighted moving average model learns the current travel time for every edge from each bus that crosses it — so predicted ETAs adapt to conditions instead of following a fixed schedule. A running chart tracks how far predictions land from reality as traffic volatility changes.

Frequently Asked Questions

How does Dijkstra's algorithm actually compute the shortest route?

Dijkstra's algorithm keeps a running best-known distance to every stop, starting at 0 for the source and infinity for everywhere else. At each step it picks the unvisited stop with the smallest known distance, marks it settled, and relaxes every edge leaving it: if going through the settled stop gives a shorter path to a neighbour than the neighbour's current best, that best distance and its predecessor are updated. Because stops are always settled in order of increasing distance, once a stop is settled its distance can never improve again, and the algorithm halts as soon as the destination is settled. Walking the predecessor pointers backwards from the destination reconstructs the actual shortest path.

What is an exponentially-weighted moving average ETA model, and why does it beat a static timetable?

A static timetable assumes every trip along a segment takes the same scheduled duration regardless of conditions. An exponentially-weighted moving average (EWMA) instead keeps one running estimate per edge and updates it every time a bus actually traverses that edge: new_estimate = α · observed_time + (1 − α) · old_estimate. Because α is between 0 and 1, recent observations count more than old ones, so the estimate tracks current conditions while still smoothing out one-off noise from a single unusually fast or slow trip. This simulation uses α = 0.3.

Why does prediction error spike when traffic volatility is turned up?

The EWMA model can only react after it observes a completed trip, so it is fundamentally a lagging indicator. When the volatility slider increases how sharply per-edge traffic factors swing, the gap between "what the model last learned" and "what is actually happening right now" widens, so the mean absolute error between predicted and actual arrival times grows.

Why does the shortest path change even though the map itself never moves?

This simulation runs Dijkstra using each edge's live EWMA-predicted travel time rather than its fixed physical distance, so a query for the same two stops can return a different route once traffic conditions have shifted the learned weights enough that a previously slower path becomes the faster one.

⚙ Under the hood

Buses move across a route network as Dijkstra's algorithm computes shortest paths and a live model predicts arrival times.

Three.jsWebGLAIMachine Learning

3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)