Repository navigation
feat(cvrp)!: read leg distances through a pluggable route metric - #258
Merged
Merged
Conversation
ProblemData required two dense tables, distance_matrix and travel_times, so the stock domain = "cvrp" profile needed 16 bytes per stop pair: 1.6 GB at 10k stops and 40 GB at 50k, before any solving. ProblemData<M = DenseMatrix> now holds a `metric: M` whose RouteMetric implementation answers distance, travel_time and whether a route's legs are all defined. VrpSolution names it with `type Metric`. The stock helpers, both meters and the route checks read legs only through it, monomorphized per metric, with the same UNREACHABLE and negative-value semantics. - DenseMatrix holds the supplied [from][to] tables unchanged, rows of any length included; existing models migrate to it. - EuclideanMetric computes legs on demand from coordinates and a speed (TSPLIB EUC_2D: sqrt(dx^2 + dy^2) rounded half away from zero, travel time = length / speed rounded the same way), in memory linear in the stops. The facade re-exports RouteMetric, DenseMatrix and EuclideanMetric. Routes and scores are unchanged: Clarke-Wright construction on all 100 X instances and Clarke-Wright plus 200 local-search steps on X-n101, X-n181 and X-n228 give identical routes and scores against main, with DenseMatrix and with EuclideanMetric. Local-search instruction counts change by -0.19%, -0.05% and -0.04%. Refs #252 BREAKING CHANGE: ProblemData's distance_matrix and travel_times fields are replaced by `metric`, and VrpSolution gains `type Metric: RouteMetric`. Migrate with `metric: DenseMatrix::new(distance_matrix, travel_times)` and `type Metric = DenseMatrix;`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #252 (the pluggable distance source; the bounded Clarke-Wright follows in the next PR and closes the issue).
Breaking:
ProblemData'sdistance_matrixandtravel_timesfields are replaced bymetric, andVrpSolutiongainstype Metric: RouteMetric. Migration:Changes
RouteMetrictrait:distance,travel_time,covers(route, depot, max_node). Every stock helper, both meters and the route checks read legs only through it, monomorphized per metric, with the existingUNREACHABLE/ negative-value semantics.ProblemData<M = DenseMatrix>withpub metric: M.DenseMatrix: the supplied[from][to]tables, unchanged storage (rows of any length; a leg outside a row is undefined, exactly as before).EuclideanMetric(opt-in): coordinates plus speed, legs computed on demand. TSPLIBEUC_2D:sqrt(dx² + dy²)rounded half away from zero; travel time = length / speed rounded the same way. Memory linear in the stops.RouteMetric,DenseMatrix,EuclideanMetric; cvrp and facade wireframes, the cvrp crate README anddocs/modeling.mdupdated; in-repo test domains migrated.Verification
metric_tests: rounding, out-of-range legs, constructor panics,DenseMatrixcoverage of ragged rows, and every stock helper and meter giving identical answers on anEuclideanMetricand its tabulatedDenseMatrix. Trybuild pass case for adomain = "cvrp"model onEuclideanMetric.mainwithDenseMatrix, and withEuclideanMetric.DenseMatrixinstructions vsmain: −0.19%, −0.05%, −0.04% (perf stat -r 3, ±0.01%).make pre-releaseandmake examplespass.solverforge-solver,-scoring,-coreor-configchanges, so the selector-cursor gate binaries are unaffected; no gate run.