Interactive Graph Theory Learning
Interactive Graph Theory Learning
Guest User
Using app without sign in
Capacitated vehicle routing solver
Calculates optimal delivery routes while strictly respecting individual truck capacities.
Select an algorithm and generate steps to begin visualization
The capacitated vehicle routing problem (CVRP) adds a load limit to each vehicle: routes must be planned so the total demand on each route never exceeds vehicle capacity. This constraint makes the problem far more realistic and harder than plain routing.
The Clarke-Wright savings heuristic remains the standard starting point, merging routes only when the combined demand fits within capacity. Sweep algorithms rotate a ray around the depot to form capacity-feasible clusters, then route each cluster as a TSP. Exact branch-and-cut-and-price solvers handle up to a few hundred customers, while modern metaheuristics such as hybrid genetic search deliver near-optimal solutions for thousands.
CVRP governs truck load planning in distribution, beverage and grocery delivery, fuel tanker scheduling, and last-mile e-commerce fulfillment where van capacity binds. Cost savings of a few percent from better routing translate into large sums at fleet scale.
CVRP adds a load limit to vehicle routing, so partitioning becomes bin packing and routing becomes TSP, coupled together. Clarke-Wright savings is the classic constructive method.
ClarkeWright(depot, customers, capacity):
// Start with one dedicated route per customer
route[i] = depot -> i -> depot for every i
// Saving from serving i and j on one route
for every pair (i, j):
saving[i][j] = d(depot,i) + d(depot,j) - d(i,j)
sort pairs by saving, descending
for each pair (i, j) in that order:
if i and j are on different routes
and both are route endpoints
and combined demand <= capacity:
merge the two routesThe savings formula is the whole idea: serving i and j separately costs two round trips, while serving them together replaces one outbound and one return leg with the direct hop from i to j. The saving is exactly what that substitution avoids. The capacity check is what makes this CVRP rather than plain routing, and it is why the highest-saving merge is often rejected.
Serve four customers with vehicles of capacity 10 and see the capacity constraint override the best geometric merge.
Example graph: Depot at the origin. Customers A at distance 5 with demand 6, B at distance 5 with demand 6, C at distance 8 with demand 3 and D at distance 8 with demand 3. A and B are close together, as are C and D.
Three routes: A alone, B alone, and C with D together. The geometrically obvious pairing of A with B is exactly the one capacity forbids, which is the defining characteristic of CVRP. An algorithm that partitions purely on distance and checks capacity afterwards will keep producing infeasible plans; capacity has to be part of the merge decision itself, not a filter applied at the end.
Time: NP-hard; O(n^2 log n) Clarke-Wright · Space: O(n^2)
Clarke-Wright computes a saving for every pair of customers at O(n squared), sorts them at O(n squared log n), and then performs a linear scan with near-constant-time route lookups, so the sort dominates at O(n squared log n). Memory holds the savings list at O(n squared). The problem is NP-hard twice over: it contains TSP through the routing decision and bin packing through the capacity-constrained partition, and neither is polynomial. Exact methods based on branch and cut and price solve instances of roughly 100 to 200 customers. Metaheuristics such as large neighbourhood search routinely reach within 1 to 2 percent of the best known solutions on instances of several thousand customers.
CVRP sits in the middle of the routing family. Check which constraints your operation actually has.
| Alternative | Prefer it when | Cost |
|---|---|---|
| Plain multi-vehicle routing | Vehicles have no meaningful load limit, so partitioning is driven by geometry alone. | NP-hard |
| VRP with time windows | Deliveries must land inside specific intervals, adding a scheduling dimension on top of capacity. | NP-hard |
| Bin packing | Only the assignment matters and travel cost is irrelevant. The capacity half of CVRP in isolation. | NP-hard, FFD is 11/9-approx |
| Large neighbourhood search | Large real instances. Repeatedly destroys and repairs part of the solution, and is the practical state of the art. | tunable |
| Sweep algorithm | A fast alternative construction: sweep by angle, cutting a new route whenever capacity would be exceeded. | O(n log n) |
Read the full article: The Vehicle Routing Problem
Related algorithms: Fleet Dispatching (mTSP), Traveling Salesman Problem, Facility Location