Simulation

Two-Opt and Three-Opt — An Interactive Route Improvement Simulator

Untangle a crossing route one swap at a time, then watch the algorithm stall on a hill it cannot see past.

What this simulation shows

Once orders are grouped and a vehicle has a feasible route, the plan works: every customer is visited, capacity is respected, the driver can legally complete the day. Feasible is not the same as efficient, though, and the gap between a workable plan and a good one is worth hundreds of miles a day across a national fleet.

Human planners spot the difference instantly, because a bad route looks wrong. It crosses its own path. The vehicle heads east, doubles back west, then returns east again. Two-Opt is the formalisation of that instinct: take two links in the route, remove them, reconnect the ends the other way round, and keep the change only if the total gets shorter. Three-Opt does the same with three links, which allows rearrangements Two-Opt structurally cannot reach.

This simulator lets you apply both, step by step, to a route around Camden County.

How to use it

Use 1-Step 2-Opt repeatedly first. Each press performs exactly one swap, so you can see the crossing get untangled and the distance drop. It is the clearest possible demonstration that optimisation here is evolutionary rather than revolutionary: nobody throws away the day’s plan, they improve it incrementally.

Then press Complete 2-Opt and watch it run to exhaustion. This is the important moment. The algorithm stops, not because the route is optimal, but because every remaining two-link swap makes things worse. It has reached a local optimum.

The standard mental picture is climbing a hill in thick fog with one rule: only ever step upward. Eventually you stand on a summit and every direction leads down, so you stop — with no way of knowing that a far higher mountain sits just beyond the valley you refused to enter.

Now press Run 3-Opt. Because it can rearrange three links simultaneously, it often finds an improvement Two-Opt had already declared impossible. That is not Two-Opt being badly implemented. It is Two-Opt being unable to represent the move that was needed.

What to take away

Local search is cheap, fast, and explainable — three properties that matter enormously in an operational product where a planner has to trust and justify the output. Its limitation is structural: it can only evaluate the moves in its own vocabulary, and it stops the moment none of them help.

Everything that follows in this series exists to escape that stall. Simulated Annealing accepts a worse route temporarily; Tabu Search forbids backtracking; genetic algorithms abandon the single-solution model altogether.

Earl Rewrites the List

Two-Opt and Three-Opt algorithms reordering list items around Camden County to find the optimal route.

Route0.0mi
Saved0.0mi
Fixes0
StatusReady
Messy Run Earl's List Optimal
Optimizing gas mileage for the El Camino...

How to use this simulation

Change one input at a time, run the model, and compare the result with the starting state. Then repeat the experiment with a different constraint or strategy so you can see which relationships drive the outcome.

What to look for

Look for trade-offs, thresholds, feedback loops, and points where a locally attractive decision produces a worse system-wide result. The simulation is intended to make the article's idea observable, not to predict a real operation.

Limitations

This is a deliberately simplified model. It omits the data quality, exceptions, human judgement, and operational constraints of a live system, so treat its behaviour as an illustration of a mechanism rather than as a planning recommendation.

Back to Simulations