Repository navigation
feat(solver): bound Clarke-Wright savings to nearest neighbours - #259
Conversation
Clarke-Wright asked the element-owner hook for every element of a route once per candidate owner: in the singleton pass, in owner-set and has-owner checks, and in completion. That is routes x owners x route length hook calls, which dominated the phase once savings stopped doing: 87% of a 20k-stop, 500-vehicle construction went to owner restriction checks. Each loop now resolves the route's (or element's) restriction once through list_placement's OwnerRestriction, which gains from_hook_owner and and, and tests each owner against it. The feasibility hook is still asked in the same order, so every decision is unchanged. Raw owner-hook answers are now interpreted only in list_placement, as for the other list phases. Construction-only runs of all 100 X instances give identical routes (2.84 s -> 2.48 s in total), as do synthetic stock-profile instances at 1k-8k stops.
list_clarke_wright scores every pair of unassigned elements, so its savings list holds 32 bytes per pair: 1.6 GB at 10k stops, 40 GB at 50k. With the pluggable route metric that was the last structure quadratic in the stops. `savings_neighbors = K` on a list_clarke_wright phase scores a pair only when one element is among the other's K nearest, about K entries per element. The neighbours come from a new optional list hook, savings_neighbors_fn (ListVariableMetadata, ListVariableSlot and the savings_neighbors_fn macro attribute); the compiler rejects a bounded phase on a slot without one. Each pair is scored once, left before right in the unassigned order, so the bounded savings are an ordered subset of the full list and a bound of at least n - 1 reproduces unbounded construction. Without the setting nothing changes. The domain = "cvrp" profile supplies cvrp::savings_neighbors, which asks the vehicle's RouteMetric::nearest. Its provided method ranks every pair (quadratic time, linear memory), which DenseMatrix uses; EuclideanMetric answers from a uniform grid, visiting cell rings until no closer stop can remain, with exactly the provided method's result. The compiled list slot keeps its size: the route bindings read the metric-class hook from the slot instead of holding a copy, and the setting is an Option<NonZeroU32>, which fits the construction config's existing padding: a larger config shifted the solver's heap layout and failed the cache-miss gate on unrelated cases. Synthetic stock-profile instances on EuclideanMetric, K = 40: stops unbounded K = 40 10k 13.2 s, 1.58 GB 0.30 s, 25 MB 20k 56.6 s, 6.29 GB 1.06 s, 52 MB 50k - 6.0 s, 164 MB 100k - 22.8 s, 389 MB Scores are equal at 20k and within 0.02% at 10k. On the 100 X instances K = 40 keeps the score of 90, improves the hard score of 2 and changes the soft score by -0.10% on average (median 0), in a fifth of the time. Closes #252
06fe6a7 to
b7e14ad
Compare
|
Qualifying Every case within budget: wall −0.85%..+0.48%, instructions −0.00%..+0.04%, allocations identical, simulated L1 misses −0.05%..+3.34%, LL misses −0.24%..+0.39%. A first run on |
Closes #252 (with #258, which made the distance source pluggable).
Two commits.
1.
perf(solver): resolve Clarke-Wright owner restrictions once per routeClarke-Wright asked the element-owner hook for every element of a route once per candidate owner: in the singleton pass, in the owner-set and has-owner checks, and in completion. That made routes × owners × route length hook calls. Once savings were bounded, this took 87% of a 20k-stop, 500-vehicle construction. Each loop now resolves the restriction once through
list_placement::OwnerRestriction(newfrom_hook_owner,and) and tests each owner against it. Feasibility is still asked in the same order, so every decision is unchanged. Raw owner-hook answers are now interpreted only inlist_placement, as AGENTS.md requires.2.
feat(solver): bound Clarke-Wright savings to nearest neighbourssavings_neighbors = Kon alist_clarke_wrightphase. It must be ≥ 1, and other heuristics reject it. A pair is scored only when one element is among the other's K nearest, so the list holds about K entries per element instead of n²/2. When the setting is absent, savings, their order and the merges are unchanged.savings_neighbors_fn,fn(&S, owner, values, k, &mut Vec<usize>), onListVariableMetadata,ListVariableSlotand thesavings_neighbors_fnmacro attribute. For a bounded phase on a slot without the hook, the compiler returnsMissingCapability { ListSavingsNeighbors }. Host-language slots do not declare it.domain = "cvrp"suppliescvrp::savings_neighbors, which calls the vehicle'sRouteMetric::nearest.DenseMatrixuses it.EuclideanMetricanswers from a uniform grid, visiting rings of cells until no closer stop can remain. Its result is exactly the provided method's (same rounded-distance-then-index key).docs/configuration.md(new "Bounded Clarke-Wright savings" section),docs/modeling.md,docs/extend-domain.md;public-api.txt.Verification
bounded_savingstests:Grid tests: grid neighbours equal the ranked scan on spread, clustered, duplicate, collinear and fine-lattice coordinates. A planted early stop of the ring search fails the fine-lattice test.
Other tests:
solver.tomland the cvrp profile, K ≥ n − 1 equals unbounded, and K = 3 assigns everyone.Default config is unchanged: construction-only Clarke-Wright on all 100 X instances gives identical routes (2.84 s → 2.48 s total), and synthetic instances at 1k–8k stops give identical routes.
Scale, synthetic stock-profile instances on
EuclideanMetric:Scores are equal at 20k and within 0.02% at 10k.
Quality on the 100 X instances (
DenseMatrix), K = 40 vs unbounded:make pre-releaseandmake examplespass.Full qualifying
make bench-zero-regressionagainstmain(73d1abac): posted below when it completes.