Skip to content

perf(solver): keep Clarke-Wright owner admission incremental - #257

Merged
blackopsrepl merged 1 commit into
mainfrom
perf/clarke-wright-owner-admission
Nov 13, 2026
Merged

blackopsrepl merged 1 commit into
mainfrom
perf/clarke-wright-owner-admission

Conversation

@blackopsrepl

Copy link
Copy Markdown
Collaborator

Closes #254.

Every accept or reject decision of the Clarke-Wright merge loop, and therefore every constructed route, is unchanged; only redundant owner work is removed.

Changes

  1. Incremental admission (owner_admission.rs). The merge loop keeps, beside the routes:
    • metric-class route counts, so the fast class check is O(1) per attempt instead of rebuilding two BTreeMaps over every route;
    • whether each route has any feasible owner, learned once and updated for the merged route only, so "more routes than owners" is settled from counts (still rejecting while any route has no feasible owner, exactly as before);
    • each route's owner set once at most owners + 1 routes are live, which is when a matching decides admission. Sets are not kept for the early phase, so memory stays linear in routes instead of routes × owners.
      The post-loop assignment reuses the kept sets.
  2. Shared savings feasibility per metric class. ListVariableMetadata and ListVariableSlot gain savings_feasible_shared_by_metric_class (default false, builder with_savings_feasible_shared_by_metric_class). The domain = "cvrp" macro profile declares it: the stock savings_feasible reads only the owner's ProblemData, which is what savings_metric_class groups by, and the profile forbids overriding either hook. Declared, one owner per class answers savings_feasible for the class (merge candidates, singletons, completion seeding). route_owner_allows stays per owner; explicit hook paths and dynamic slots keep asking every owner.
  3. Buffers. The candidate route, its values and its elements are assembled in per-phase buffers instead of cloning both routes and building three vectors per attempt.

public-api.txt, the solver and macros wireframes and docs/extend-domain.md are updated.

Verification

  • admission_oracle test: the incremental admission against the old whole-route-set recomputation (kept in the test as the oracle) on 800 seeded random instances (1-5 owners, 1-3 metric classes, per-owner and per-class feasibility, partial fixed owners); every attempt agrees and the final owner sets match. Planting a bug in the ownerless or matching checks fails it.

  • shared_savings_feasibility_asks_one_owner_per_metric_class: identical routes with fewer than half the savings_feasible calls. Macro test: the cvrp profile emits true, explicit hooks false.

  • Construction-only Clarke-Wright on all 100 X instances (TSPLIB, fleet from -k), stock profile: identical routes on every instance; total 17.4 s → 2.9 s.

  • Synthetic stock-profile instances (seeded coordinates, one vehicle per 40 stops), identical routes:

    Stops main this PR
    1,000 0.32 s 0.10 s
    2,000 2.0 s 0.41 s
    4,000 14.3 s 1.8 s
    8,000 102.1 s 7.8 s

    At 4,000 stops owner feasibility is now ~2% of the phase (was ~57%); the rest is savings generation and sorting, which Make the stock CVRP profile able to scale linearly in memory, with no regression #252 bounds.

  • uc-deliveries test suite against this branch: passes.

  • make pre-release and make examples pass.

  • Full qualifying make bench-zero-regression against main (4910340): posted below when it completes.

Every Clarke-Wright merge attempt re-derived the feasible owners of every
buffered route against every owner whenever routes outnumbered owners, which
is every attempt early in the phase. The working solution does not change
during the merge loop, so only the merged route's owners can change. On the
stock CVRP profile at 4,000 stops 57% of the phase went to that re-checking,
and phase time grew 5-6.5x per doubling of the stop count.

The merge loop now keeps its admission state beside the routes:

- metric-class route counts, so the fast class check costs O(1) per attempt;
- whether each route has any feasible owner, learned once and updated for the
  merged route, so "more routes than owners" is settled from counts;
- each route's owner set once few enough routes remain for a matching to
  decide, updated for the merged route only.

The stock domain = "cvrp" profile now declares savings feasibility shared by
metric class (ListVariableMetadata and ListVariableSlot gain
savings_feasible_shared_by_metric_class with a builder): its hook reads only
the owner's ProblemData, which is what the stock metric class groups by, so
one owner per class answers for the class. Per-owner element restrictions
stay per owner, and explicit hook paths keep asking every owner. The
compiled route bindings fold their five hook-declared flags into two, so the
compiled list slot keeps its size and the runner's heap layout. The candidate
route is assembled in reused buffers instead of cloning both routes on every
attempt.

Every accept or reject decision is unchanged. A seeded differential test
drives the incremental admission against the whole-set recomputation over
800 random instances; every Clarke-Wright test and the uc-deliveries suite
pass. Construction-only runs of all 100 X instances give identical routes
(17.4 s -> 2.9 s in total), and synthetic stock-profile instances give
identical routes at 1k/2k/4k/8k stops with phase time
0.32/2.0/14.3/102.1 s -> 0.10/0.41/1.8/7.8 s.

Closes #254
@blackopsrepl
blackopsrepl force-pushed the perf/clarke-wright-owner-admission branch from bcddb11 to 651894d Compare November 13, 2026 00:36
@blackopsrepl

Copy link
Copy Markdown
Collaborator Author

Qualifying make bench-zero-regression, candidate 651894df vs main 4910340a: passed. 14 cases, 5 symbol-hash layouts, 51 trials, semantic_match=true on every case.

Every case within budget: wall −0.27%..+1.15%, instructions −0.04%..+0.00%, allocations identical, simulated L1 misses −0.14%..+0.32%, LL misses −0.05%..+0.37%.

A first run on bcddb111 failed simulated cache misses (construction_first_fit L1 +11.2%, list_swap LL +5.9%) with identical semantics: the new flag grew the compiled list slot from 400 to 408 bytes and shifted the runner's heap layout. The amended commit folds the route bindings' five hook-declared flags into two so the slot stays 400 bytes; this run is on that commit.

@blackopsrepl
blackopsrepl merged commit 07c883d into main Nov 13, 2026
7 checks passed
@blackopsrepl
blackopsrepl deleted the perf/clarke-wright-owner-admission branch November 13, 2026 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make Clarke-Wright construction skip redundant owner-feasibility checks, with identical output

1 participant