Skip to content

feat(cvrp)!: read leg distances through a pluggable route metric - #258

Merged
blackopsrepl merged 1 commit into
mainfrom
feat/cvrp-route-metric
Nov 13, 2026
Merged

blackopsrepl merged 1 commit into
mainfrom
feat/cvrp-route-metric

Conversation

@blackopsrepl

Copy link
Copy Markdown
Collaborator

Part of #252 (the pluggable distance source; the bounded Clarke-Wright follows in the next PR and closes the issue).

Breaking: ProblemData's distance_matrix and travel_times fields are replaced by metric, and VrpSolution gains type Metric: RouteMetric. Migration:

impl VrpSolution for Plan {
    type Metric = DenseMatrix;
    // ...
}
ProblemData { metric: DenseMatrix::new(distance_matrix, travel_times), /* ... */ }

Changes

  • RouteMetric trait: 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 existing UNREACHABLE / negative-value semantics.
  • ProblemData<M = DenseMatrix> with pub 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. TSPLIB EUC_2D: sqrt(dx² + dy²) rounded half away from zero; travel time = length / speed rounded the same way. Memory linear in the stops.
  • Facade re-exports RouteMetric, DenseMatrix, EuclideanMetric; cvrp and facade wireframes, the cvrp crate README and docs/modeling.md updated; in-repo test domains migrated.

Verification

  • New metric_tests: rounding, out-of-range legs, constructor panics, DenseMatrix coverage of ragged rows, and every stock helper and meter giving identical answers on an EuclideanMetric and its tabulated DenseMatrix. Trybuild pass case for a domain = "cvrp" model on EuclideanMetric.
  • Clarke-Wright construction on all 100 X instances: identical routes and scores against main with DenseMatrix, and with EuclideanMetric.
  • Clarke-Wright + 200 default local-search steps (single-threaded, seeded) on X-n101-k25, X-n181-k23, X-n228-k23: identical routes and scores, both metrics. DenseMatrix instructions vs main: −0.19%, −0.05%, −0.04% (perf stat -r 3, ±0.01%).
  • make pre-release and make examples pass.
  • No file in solverforge-solver, -scoring, -core or -config changes, so the selector-cursor gate binaries are unaffected; no gate run.

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;`.
@blackopsrepl
blackopsrepl merged commit 73d1aba into main Nov 13, 2026
7 checks passed
@blackopsrepl
blackopsrepl deleted the feat/cvrp-route-metric branch November 13, 2026 03:26
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.

1 participant