← covtsp
2026-04-02

60 Minutes Faster Than the World Record

The world record for visiting all 272 London Underground stations is 17h45m. An automated solver on public timetable data does it in 16h45m. That's one hour faster. This is how I got there, from 19h42m to 16h45m, across 19 progressive improvements.


Three attempts at the right abstraction

This project went through three distinct modeling approaches before landing on the current one. The progression matters because each attempt revealed a specific limitation that shaped the next.

Fig 0. Modeling evolution
v1: tspmetro

Static graph + Google Maps API

Scraped Wikipedia for station names, queried Google Maps for travel times between same-line stations, built a fixed-weight adjacency matrix. No time dependency at all.

v2: abandoned

Probabilistic headway models

Model train arrivals as distributions, compute expected wait times per station, score routes by expected total time. I abandoned this because there were too many parameters and no ground truth to validate against.

v3: covtsp (current)

GTFS backtesting on real timetables

Parse published timetable data, pick a date, simulate the exact schedule deterministically. No probability needed. You replay exact train times like a financial backtest.

v1: The static graph (tspmetro)

The first attempt treated the Underground as a classical weighted graph. Station names scraped from Wikipedia, travel times from the Google Maps Directions API (transit mode), stored in an adjacency matrix. The plan was Floyd-Warshall for all-pairs shortest paths, then solve TSP on the complete distance matrix.

The fundamental problem: edge weights are fixed. The graph says Baker Street → Bond Street costs 3 minutes, always. But in reality, if you arrive at Baker Street at 8:07 and the next Jubilee line train departs at 8:12, you wait 5 minutes, so the real cost is 8 minutes. And that wait time changes every minute of the day. A static graph can't distinguish between Kensington Olympia (9 trains/day) and Oxford Circus (one every 90 seconds).

The errors weren't small. The static graph estimated total routes at around 12 hours because it just sums the fixed edge weights along a path. In practice, the same route takes 18+ hours because you spend a huge fraction of the time waiting for trains. The gap between "travel time" and "elapsed time" is enormous on a network with 272 stations and headways ranging from 90 seconds to 2 hours. I ran the static solver's output through the real timetable and it missed dozens of connections, arriving at stations minutes after trains had left. That's what killed v1.

Fig 0a. Static graph vs time-expanded graph

Static (tspmetro)

3m 4m 2m A B C
Fixed weights. 3 nodes, 3 edges.
Same cost at 8am and 11pm.

Time-expanded (covtsp)

A B C
Time-dependent. 12 nodes, ~20 edges.
Costs depend on when you arrive.

v2: Probabilistic headway models (abandoned)

Realising the static graph couldn't capture time dependency, the next idea was to model it statistically. Treat train arrivals at each station as a probability distribution: Poisson for high-frequency lines, something heavier-tailed for infrequent branches. Then compute expected wait times per station and weight the graph edges accordingly. Stations with faster service get lower expected waits, making the TSP solver naturally prefer efficient connections.

The problems stacked up quickly:

v3: The backtesting insight

The breakthrough came from an analogy to quantitative finance. In finance, you don't model stock prices with probability distributions and compute expected returns. You backtest. You take historical price data for a specific day, run your strategy against it, and see what actually happens. No distribution assumptions, no parameter tuning, full determinism.

Transit works the same way. Every transit authority publishes their timetable in GTFS format, a set of CSV files listing every trip, every stop time, every calendar exception. Pick a date, filter the active services, and you get the exact schedule for that day. Every train departure, every arrival, no ambiguity.

Probabilistic

Model headways as distributions. Compute expected wait times. Score routes by expected total.

E[wait] = λ-1 per station
Σ parameters to tune
No ground truth to validate

GTFS backtesting

Parse real timetable. Pick a date. Simulate exactly. Every train is deterministic.

160,069 (station, time) nodes
1,262,131 edges
Zero free parameters

This gives us the time-expanded graph. Every node is a (station, departure_time) pair from the actual schedule. The solver doesn't estimate wait times. It knows exactly when the next train leaves, because it's in the timetable. And you can test against any historical date, comparing routes across weekdays, weekends, and disrupted services.


The time-expanded graph in detail

The problem on this graph is a Covering TSP: visit at least one node per required station (not every node), no return to start, minimizing elapsed time. NP-hard in general. Three edge types encode the full timetable:

Fig 1. TEG structure (3 stations, 5 time slots)
Baker St
Bond St
Oxford Cir
train 3m train 2m walk 12m wait wait
8:008:058:108:158:20
train leg
wait arc
walking
Each circle is a (station, time) node. Train legs go diagonally down-right (time advances, station changes). Wait arcs go horizontally (time advances, same station). Walking transfers skip stations. London TEG: 160K nodes, 1.26M edges from 272 stations.

The solver finds the minimum-time path that touches at least one node per required station. I use Dijkstra with early termination (~0.02s per step) on this graph.

Building the TEG starts with parsing the GTFS feed: stops.txt for station coordinates, stop_times.txt for every scheduled arrival and departure, trips.txt to group stop times into trips, and calendar.txt plus calendar_dates.txt to filter down to the services actually running on a given date. For London, that's about 11,000 trips on a typical weekday. Once the nodes and transit edges are placed, I compute walking transfers using a KDTree spatial index over station coordinates, filtered to cross-line pairs within 1.2km, then hit the Google Routes API for actual walking times on the 723 pairs that survive the dominance prune (described below). The whole graph builds in about 8 seconds on a single core.


The Kensington Olympia breakthrough

The single biggest optimization, worth 40 minutes, came from one station. Kensington Olympia is served by a shuttle from Earl's Court that runs 9 times per day: 5 morning (05:49–07:20), 4 evening (20:01–20:40). That's 9 TEG nodes for the entire day. Compare to Oxford Circus with hundreds.

Fig 2. Kensington Olympia: 9 trains/day
5 trains
no service · 13h dead zone
4
05:49 07:20 20:01 20:40

The greedy heuristic can't see 14 hours ahead. It optimizes locally, and by the time it reaches Earl's Court it's 20:41, one minute after the last shuttle. Cue a 60+ minute detour.

The fix is a prefix strategy: force K.O. first, before the greedy solver runs. This is a form of hard station scheduling: identify bottleneck stations with constrained service windows and handle them explicitly.

Before: evening K.O.
Start Ealing Broadway 06:33
Reach Earl's Ct at 20:41
Last shuttle was 20:40
60+ min backtrack detour
18h45m
After: morning K.O. prefix
Start Finchley Road 05:41
Earl's Ct → 05:49 shuttle
K.O. done → continue NN
40 min saved
18h03m

Urgency scoring and phase transitions

K.O. isn't the only bottleneck. Mill Hill East (single-track Northern line branch, limited evening service) and Heathrow T4 (separate Piccadilly loop) are also fragile. The solver detects these automatically by analyzing TEG sparsity.

We bias the nearest-neighbor with an urgency term:

score = travel_time + urgency_weight * time_until_last_service(station)

The weight has a sharp phase transition. From Euston Square:

Fig 3. Urgency phase transition (Euston Square start)
271/272
272/272
urg = 0.0 ↑ 0.16 urg = 1.0
Below 0.16: misses Mill Hill East. At 0.16: flips to 272/272 (+21 min). Not gradual, binary.

From Finchley Road the urgency weight doesn't matter because the route naturally covers Mill Hill East regardless. The solver's best variant: K.O. prefix + k=5 NN + urgency 0.5 + T4 injection via Hatton Cross.


The randomized search

The deterministic greedy solver is fast but rigid. It always makes the same choice at each step, so it always produces the same route from a given start. To escape that, I added epsilon-greedy randomization: at each step, with probability epsilon (typically 0.05 or 0.1), the solver picks a random unvisited station instead of the nearest one by urgency-weighted score. This injects enough variation that different trials explore meaningfully different orderings.

I ran 80,000+ trials across different start stations and start times. Each trial takes about 0.3 seconds on the TEG (Dijkstra dominates), so the full sweep runs in a few hours. The key insight was that the randomized solver had to include the hard station logic from the deterministic solver. Early versions of the randomized search just picked random stations without prefix visits or junction grabs, so they'd regularly miss K.O. or Terminal 4 and produce 271/272 routes. Once I wired the pairings into every random trial, the hit rate for 272/272 routes jumped from under 5% to over 60%.

The distribution of results is interesting: most 272/272 trials land between 17h and 18h, with a long tail down toward 16h45m. The best route found so far sits well into that tail, which suggests there's probably still room below 16h30m with more trials or smarter perturbation strategies.


Results

Improvement curve

The solver improved from 19h42m to 16h45m across 19 incremental improvements. Each improvement was saved with the full 272-station route.

Fig 5. Solver improvement over time
#TimeStart StationStartMethodvs Record
119h42mBattersea Power Station05:00Deterministic pairings+117 min
318h43mArsenal05:35Deterministic pairings+58 min
518h16mBromley-by-Bow05:30Deterministic pairings+31 min
618h03mChesham05:00Deterministic pairings+18 min
717h30mUpminster06:14Deterministic pairings−15 min
817h12mUpminster06:15Randomized (eps=0.05)−33 min
1517h01mUpminster05:57Randomized (eps=0.05)−44 min
1616h58mUpminster05:59Randomized (eps=0.05)−47 min
1716h57mUpminster06:02Randomized (eps=0.05)−48 min
1816h53mUpminster06:05Randomized (eps=0.1)−52 min
1916h45mUpminster06:09Randomized (eps=0.1)−60 min
Fig 6. Time vs improvement number
20h 19h 18h 17h WR 17h45m 19h42m 18h03m 17h30m 16h45m Improvement # beat record

The two biggest jumps: start station discovery (Chesham→Upminster, −33 min) and randomized search with pairings (deterministic→randomized, −45 min from the same station).

Multi-city

CityStationsTimeTEG
London Underground27216h45m160K nodes / 1.26M edges
NYC Subway47521h35m228K nodes / 656K edges
Berlin U-Bahn1707h53msmaller, denser

Same algorithm, different GTFS feeds. Drop in a config and solve.


What didn't work

The fundamental issue: local search doesn't work on TEGs. Small reorderings cascade because arrival times shift, changing which trains are available everywhere downstream. Classical TSP moves assume edge weights are fixed. Here they're not.


Running transfer filtering: $375 → $7

Tube Challenge competitors run between stations. It's sometimes faster to run from a branch end to a nearby station on a different line than to backtrack. Computing running times needs the Google Routes API. All-pairs for 272 stations: 37,128 queries, ~$375.

Fig 4. Three-stage filtering pipeline
37,128 All station pairs ~$375
↓ haversine ≤ 20km
21,774 Within distance cutoff ~$218
↓ at least one branch terminus (last 3 stops)
10,921 Terminus-connected, cross-line ~$109
↓ train dominance prune
723 Worth computing ~$7

The dominance prune

For each candidate pair (A, B):

crow_flies = haversine(A, B) / sprint_speed  // optimistic: straight line
train_time = shortest_path(A, B)  // optimistic: no headway wait

if crow_flies ≥ train_time: eliminate  // running can never win

Both sides are lower bounds. If the train's lower bound beats running's lower bound, the inequality holds for all real values. The prune is provably correct and cannot discard a useful shortcut. Eliminates 93% of remaining pairs. These 723 pairs are now integrated into the TEG as running transfer edges.


What got us past the record

Three changes took the solver from 18h03m (18 min behind) to 16h45m (60 min ahead):

Upminster works because of its position in the network. It's the eastern terminus of the District line, which gives it direct access to a long east-west corridor through central London. Starting there early (around 06:09) means the solver can sweep the eastern branches first while morning service is ramping up, then move west through the dense central zone during peak frequency. The alternative start stations I tried in northwestern London (Chesham, Amersham) force the solver to backtrack south through the Metropolitan line before it can reach the central network, burning 30-40 minutes on low-frequency branch service.

The start time sweep was 272 stations times roughly 200 candidate start times (every minute from 05:00 to 08:20), so about 54,000 deterministic trials. Most stations cluster within 30 minutes of each other, but outliers like Upminster and a few District/Central line termini sit well below the median. The sensitivity to start time is surprisingly sharp: at Upminster, 06:09 catches a specific District line train that connects to a Hammersmith & City service at Barking, and missing that by 6 minutes means waiting for the next one, which cascades into a later arrival at every subsequent junction.

What's next


Source on GitHub  ·  London route viewer  ·  Back to covtsp