u-routing
Vehicle routing optimization library providing building-block algorithms for TSP, CVRP, and VRPTW variants.
Features
- Models — Customer, Vehicle, Route, Solution, TimeWindow, RoutingProblem trait
- Distance — Dense distance/travel-time matrix with nearest-neighbor lookup
- Evaluation — Route feasibility checking (capacity, time windows, max distance/duration)
- Constructive heuristics — Nearest Neighbor (O(n²)), Clarke-Wright Savings (O(n² log n))
- Local search — Intra-route 2-opt (Croes 1958), inter-route Relocate (Or 1976)
- Genetic algorithm — Giant tour + Prins (2004) split DP, OX crossover, 2-opt refinement
- ALNS — Random/Worst/Shaw removal + Greedy/Regret-k insertion (Ropke & Pisinger 2006)
Quick Start
use ;
use DistanceMatrix;
use nearest_neighbor;
use ;
let customers = vec!;
let dm = from_customers;
let vehicles = vec!;
// Constructive → Local search pipeline
let initial = nearest_neighbor;
let improved = relocate_improve;
println!;
GA Solver
use Customer;
use DistanceMatrix;
use RoutingGaProblem;
use ;
let customers = vec!;
let dm = from_customers;
let problem = new;
let config = default
.with_population_size
.with_max_generations;
let result = run;
println!;
ALNS Solver
use Customer;
use DistanceMatrix;
use ;
use ;
let customers = vec!;
let dm = from_customers;
let problem = new;
let destroy = vec!;
let repair = vec!;
let config = default.with_max_iterations.with_seed;
let result = run;
println!;
Architecture
u-routing
├── models/ Domain types (Customer, Vehicle, Route, Solution)
├── distance/ Distance matrix
├── evaluation/ Route evaluator + constraint checking
├── constructive/ Nearest Neighbor, Clarke-Wright Savings
├── local_search/ 2-opt, Relocate
├── ga/ Giant tour + Split DP + GaProblem bridge
└── alns/ Destroy/Repair operators + AlnsProblem bridge
Dependencies
u-metaheur— GA/ALNS frameworku-numflow— Math primitives, RNG
References
- Clarke, G. & Wright, J.W. (1964). "Scheduling of Vehicles from a Central Depot to a Number of Delivery Points"
- Croes, G.A. (1958). "A method for solving traveling salesman problems"
- Or, I. (1976). "Traveling Salesman-Type Combinatorial Problems and Their Relation to the Logistics of Blood Banking"
- Prins, C. (2004). "A simple and effective evolutionary algorithm for the vehicle routing problem"
- Ropke, S. & Pisinger, D. (2006). "An Adaptive Large Neighborhood Search Heuristic for the Pickup and Delivery Problem with Time Windows"
- Shaw, P. (1998). "Using Constraint Programming and Local Search Methods to Solve Vehicle Routing Problems"
WebAssembly / npm
Available as an npm package via wasm-pack.
Quick Start
import init from '@iyulab/u-routing';
await ;
const result = ;
Functions
solve_vrp(input) -> VrpOutput
Solve a capacitated VRP with optional time windows. Four solver methods available.
Methods: "nn" (Nearest Neighbor), "savings" (Clarke-Wright), "ga" (Genetic Algorithm + Split DP), "alns" (Adaptive Large Neighborhood Search).
Input:
GA config uses population_size, max_generations, mutation_rate, elite_ratio.
ALNS config uses max_iterations. Both accept seed.
Config constraints:
| Parameter | Method | Constraint | Default |
|---|---|---|---|
population_size |
GA | >= 2 | 50 |
max_generations |
GA | >= 1 | 200 |
mutation_rate |
GA | 0.0 – 1.0 (clamped) | 0.1 |
elite_ratio |
GA | 0.0 – 1.0; must not fill entire population | 0.1 |
max_iterations |
ALNS | >= 1 | 500 |
seed |
Both | any u64 (optional) | random |
Error handling:
solve_vrp() returns a JS error (string) for:
- Invalid JSON input (missing required fields, wrong types)
- Unknown method name
- Invalid config values (e.g.,
population_size: 0,max_iterations: 0)
Errors are returned as rejected promises — they never cause RuntimeError: unreachable panics.
Output:
Related
- u-numflow — Mathematical optimization primitives
- u-metaheur — Metaheuristic algorithms
- u-schedule — Scheduling optimization