feat(route-editor): "Optimise order" action (2-opt/Or-opt, one undo step) #53
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
public/wanderer!53
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/45-optimise-order"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #45.
What
An Optimise order button (shuffle icon, next to Reverse direction in the route editor). It reorders the anchors between the fixed start and end to shorten the route.
web/src/lib/util/route_order.ts, pure TS): works on haversine distances, and the first and last anchor never move. Up to 10 movable points it solves exactly (Held-Karp, well under 1 ms). Local search alone can stall in a local optimum, and the exact solve is cheap at that size. Above 10 it runs 2-opt + Or-opt (chains of up to 3, either way round) from the current order and from a nearest-neighbour order, keeping the shorter result. Starting from the current order means the result is never longer than the input.RouteResulthas no leg boundaries and segments carry their own track/off-road mode. A new leg keeps the mode of the old leg between the same two anchors, else it gets the sticky default mode.before → after; if not, nothing changes and the toast shows both lengths.applyReorderedRouterecords the anchor order and the route geometry as one entry, so undo and redo restore both together.en.jsononly.Not done
distance, so it can be added later.distance_from_startvalues aren't recomputed after a reorder. This matches how moving an anchor in the list behaves today.Tests
route_order.test.ts: brute-force optimality on 300 random cases (4–9 points) and 200 random loops; start and end stay fixed; loop direction is kept both ways; nothing is applied when the order is already optimal or only ties; the local search alone (forced) handles a zig-zag, a crossing and a misplaced point, reaching ≥ 90 % optimal and ≤ 15 % off on random small cases; results are never longer on 20–80 point cases;isLoop.valhalla_reorder.test.ts: only new legs are routed; same-direction legs are reused; modes carry over; invalid orders are rejected; exactly one undo entry, with undo and redo restoring anchors and geometry.npm run checkgives 0 errors (2 warnings on an existing<tbody>I didn't touch), andnpm run test:unit -- --rungives 860 passed, 13 skipped.Not yet tried in the browser.
🤖 Generated with Claude Code
https://claude.ai/code/session_01XMf4EGfBC9xbQ6rjD6HxgP
Shipped via batch PR #64 (
deploy0d0d85a4), which merged this branch head unchanged; live since 2026-11-05 ~19:30 CET inwanderer-web:deploy-676a7c62(homelab-flux #843). Forgejo does not mark stacked PRs as merged, so I am closing this by hand.🤖 Generated with Claude Code
Pull request closed