LB-00 Network 12 terminals, 20 links

Network and routing

Twelve terminals, twenty physical links, and the search that turns them into a transit time.

rail, road and short-sea links click a terminal to route to it

LB-01 How the number is arrived at method

The network is a graph, and the answer is a shortest path

Twelve terminals, twenty physical links, three modes. Every link carries a mode, a circuity factor and therefore a running time; every terminal carries a dwell, and changing mode at one carries an interchange penalty on top.

What is computed rather than typed

  • Leg distance is the great-circle distance between the two terminals — haversine on the 6,371.0088 km mean earth radius — multiplied by that link’s circuity factor.
  • Leg time is that distance divided by the mode’s commercial average speed: 62 km/h for rail, 68 for road, 33 for a coastal feeder.
  • Node time is a real dwell. Rail to rail is 1.5 hours; rail to road is 4; anything involving a vessel is 10 to 12, because the box waits for a window.
  • Origin handling is 3 hours and destination release is 2.

Why the search minimises time, not distance

Because they give different answers, and a shipper would spot the difference immediately. On 34 of the 132 ordered pairs of terminals here, the fastest route is not the shortest one — in the worst case a 746 km route beats a 571 km one, because the short one needs two extra lifts.

The technical consequence is that the search state has to carry the mode the box arrived on, not just which terminal it is standing in. Dijkstra’s algorithm is only correct when the cost of leaving a node does not depend on how you reached it, and here it does: leaving Merrow by rail costs 1.5 hours if you arrived by rail and 4 if you arrived by road. Expanding the state to (terminal, arriving mode) restores that property and keeps the search exact.

Two implementations, on purpose

The same search is written twice: once in PHP for the pages the server renders, and once in JavaScript for the panel above. A test walks every ordered pair and asserts the two agree to the second. Numbers that appear on a quote should not be able to drift quietly.

Run the theme's self-test →