Route optimisation

What if the bus comes, but not to your stop?

Unlike Singapore, buses are not obligated to stop at designated poles, and may choose detours that are more profitable.

The schedule cannot help if the route itself is uncertain.

Live the journey
scheduled stop more profitable pickup Will it reach the stop?The published route cannot answer.
Published pathObserved movementRoadside demand

Four minutes means something only when the system is predictable.

In Singapore, a passenger can check the phone from an HDB block, see “4 min”, walk downstairs and reasonably expect the bus.

In a less predictable network, a newcomer may arrive on time and still lose. The bus may stop where regular passengers gather, avoid a congested lane, take the wider road, or never pass the marked stop.

The problem is not that people cannot read a schedule. The problem is that the schedule describes a journey the bus may not make.

4 min

Information becomes a promise

Route, stop and arrival estimate agree closely enough for a passenger to plan.

?

Imperfect information changes behaviour

New passengers wait longer, miss journeys and eventually avoid the bus because certainty belongs mainly to regular riders.

You cannot publish a reliable timetable for a route you cannot observe.

Operators may not know whether the bus reached the stop, used a smaller lane, bypassed traffic, paused for roadside passengers, or disappeared between GPS updates. Punishing a driver does not solve missing infrastructure, congestion or demand that lives away from the flag pole.

Passenger cost

A person who follows the timetable can be penalised for trusting it.

Operator blind spot

Arrival, dwell and departure cannot be measured if the route and stop event are uncertain.

Business opportunity

Reconstruct observed movement first. Then build schedules and predictions around how service actually behaves.

GPS traces→Route imputation→Stop-event inference→Reliable passenger information

First, reconstruct where the bus actually went.

GPS points are noisy and incomplete, but repeated traces reveal roads, detours and informal stopping patterns. Clustering turns those dots into route pieces that can be timed.

I want to see how the route is reconstructed
  1. Filter malformed and incomplete trajectories.
  2. Fit candidate values of k with repeated initialisations.
  3. Check silhouette, Calinski–Harabasz and Davies–Bouldin scores.
  4. Audit cluster geometry and degenerate solutions.
  5. Retain outliers visibly and serialise model state.
Raw GPS observations

Is the bus on a straight road, bend or junction?

Road shape changes travel time. A junction adds stopping and traffic risk. A curve changes driven distance. A straight segment supports steadier timing. The eigenvalue ratio helps distinguish their geometric fingerprints.

Let’s investigate why the geometry works

The covariance matrix summarises how the GPS cloud spreads. Its main axis follows the road, while its weaker axis captures sideways spread from curvature, junctions or noise.

Σ = (1/n) Σᵢ (xᵢ − μ)(xᵢ − μ)ᵀ

Dividing the smaller eigenvalue by the larger one removes orientation and scale. A small ratio suggests one dominant road direction. A larger ratio flags geometry that needs more investigation.

ρ = λ₂ / λ₁, with λ₁ ≥ λ₂ ≥ 0

The ratio ρ is invariant to rotation and uniform scaling. It describes shape, not orientation or physical size. It is still sensitive to outliers, mixtures and sampling density.

λ₁ 0λ₂ 0ρ 0Line-like

The score is a clue, not a verdict.

A curve, junction, noisy trace or a few outliers can look similar statistically. The model must separate road shape from bad data before timing consequences are assigned.

I want to understand this more deeply

This formal step turns visual intuition into a repeatable calculation, making route decisions auditable rather than subjective.

Robust alternative: use median-centred covariance, trim high-leverage points, or compare local tangent changes.

A threshold such as 0.05 is an empirical decision rule. It needs route-level validation, sensitivity analysis and error costs, not theorem-like wording.

Direction reveals the road condition ahead.

Bearing helps test whether the bus is moving along a straight road, turning through a bend, or entering a junction. Each condition changes the time budget. Circular statistics keeps 359° close to 1° so north does not break the analysis.

Let’s investigate direction properly

Ordinary averages treat 359° and 1° as far apart. Mapping bearings to the unit circle preserves direction, allowing the model to detect opposing flows, turns and junction-like patterns without a false discontinuity at north.

C = mean(cos θ), S = mean(sin θ)
Mean direction = atan2(S, C), concentration = √(C² + S²)

A low resultant length can mean wide directional uncertainty or a symmetric multimodal pattern. Always inspect the distribution before interpreting concentration.

Arithmetic mean 0°Circular mean 0°Resultant 0

Engineer the journey down to the second.

A 30-second GPS gap can contain an entire stop event. The bus may decelerate, board passengers, accelerate and leave before the next coordinate arrives.

Those missing seconds decide whether the passenger sees “arriving”, “departed”, or an estimate that is already wrong.

00 sGPS received
08 sdeceleration
14 sdoors open
22 sboarding
27 sacceleration
30 sGPS received

The model must infer what happened between the dots, not merely connect them.

Once the route is trusted, timing can become operational.

I want to understand how spacing changes

This decomposition separates spacing change into starting lateness, travel effects and dwell effects. Keeping their signs matters because one cause can offset another. That distinction supports diagnosis before dispatch optimisation.

δHₘ = δL₁ + Σᵣ δTᵣ + Σₖ δDₖ
|δHₘ| ≤ |δL₁| + Σᵣ|δTᵣ| + Σₖ|δDₖ|
Signed total 2 minSum of magnitudes 6 minCancellation 4 min

Curved roads hide distance that straight lines miss.

A straight chord cuts across the bend. More route segments follow the driven path more closely, improving the distance and travel-time estimate.

Let’s see why smaller segments improve timing

Travel time is accumulated segment by segment. If the route distance is underestimated, dividing by velocity does not remove the bias. Better geometry produces a better time estimate.

T̂ = Σᵣ d̂ᵣ / v̄ᵣ

Dividing by velocity preserves relative distance bias. If distance is underestimated by 8% and velocity is otherwise correct, travel time is also underestimated by 8%.

True arc Polyline Relative error

Thirty seconds of silence can hide the stop.

GPS may vanish in a tunnel, arrive only every 15 or 30 seconds, or miss a roadside pause. Between two updates, the bus could have slowed, stopped, boarded, diverted and left. Imputation estimates those unseen moments so arrival and departure logic does not pretend nothing happened.

  • Mean: A fast baseline, but it smooths away real variation.
  • KNN: Uses operationally similar moments nearby.
  • MICE: Creates several plausible histories so uncertainty remains visible.

Multiple imputation represents uncertainty through between-imputation variation. A single filled value hides that uncertainty.

Two GPS points do not tell the whole journey

The decisions data cannot make alone.

Thresholds, failure costs, route context and operational trade-offs still require human judgement.

GPS error may be spatially correlatedK-means ignores route orderClusters may mix directionsτ = 0.05 is empiricalMissingness may not be randomImputation uncertainty must propagateValidation must split by timeExisting-route accuracy does not prove transferRepeated tuning increases computeAnd many more

Let’s discuss the judgement behind the model.

contact@javierlee.com

Read the full derivation.

Definitions, derivations, algorithms, assumptions and imputation methods.

I want to investigate further

PDF opens in a new tab.

I build models that explain the system before trying to optimise it.

Mathematical modellingGeospatial machine learningAlgorithm designScientific judgementProduct thinking