Interactive Graph Theory Learning
Interactive Graph Theory Learning
Guest User
Using app without sign in
Vehicle routing (VRP) solver
Partitions graph into fleets and calculates delivery routes
Select an algorithm and generate steps to begin visualization
The multi-vehicle routing problem (VRP) extends the traveling salesman problem to a fleet: several vehicles start from a depot and must jointly visit all customers at minimum total cost. It is one of the most economically important NP-hard problems.
Classical constructive methods include the Clarke-Wright savings algorithm, which starts with one route per customer and merges routes in order of the distance saved, and cluster-first route-second approaches that group customers geographically before solving a TSP per cluster. Improvement phases apply 2-opt and or-opt moves within and between routes, and metaheuristics such as tabu search and large neighborhood search close most of the remaining gap to optimal.
VRP plans parcel delivery for postal and courier fleets, school bus routes, field service technician schedules, and waste collection circuits. Commercial routing engines solve VRP variants millions of times daily, making it a core skill for logistics and operations research engineers.
Routing several vehicles from one depot is TSP with an extra decision layer: first partition the customers among vehicles, then sequence each vehicle route.
// Cluster-first, route-second
MultiVehicleRouting(depot, customers, vehicleCount):
clusters = partition customers into vehicleCount groups
(by angle around the depot, or by k-means)
for each cluster:
route = solveTSP(depot + cluster)
// Then improve across routes:
repeat until no improvement:
relocate: move one customer to another route
exchange: swap two customers between routes
2-opt: uncross edges within a single routeThe two-phase structure matters because the phases pull against each other. A clustering that looks balanced geometrically can produce routes that are individually awkward, and the cross-route improvement moves are what repair that. Skipping the improvement phase typically leaves 10 to 20 percent on the table, which is far more than any gain from a better initial clustering.
Serve four customers from a central depot using two vehicles, and see why the obvious split beats the alternative.
Example graph: Depot at the origin. Customers north at (0,5), south at (0,-5), east at (5,0) and west at (-5,0). Travel cost is straight-line distance, and each vehicle starts and ends at the depot.
The better assignment costs about 34.14 against 40, purely from which customers share a vehicle. Sequencing within each route was trivial here since two customers admit only one order, so the entire difference came from the partitioning decision. That is the general lesson of multi-vehicle routing: the assignment usually matters more than the sequencing, which is the opposite of single-vehicle TSP where sequencing is the whole problem.
Time: NP-hard; O(n^2) per improvement pass · Space: O(n + V)
The problem contains TSP as the special case of a single vehicle, so it is NP-hard, and adding the partitioning decision makes it strictly harder in practice: there are Stirling-number-many ways to split n customers among V vehicles before any sequencing is considered. The cluster-first phase costs O(n log n) for an angular sweep or O(n·V·i) for k-means. Each TSP subproblem is solved heuristically, typically nearest neighbour plus 2-opt at O(m squared) per route for m customers. Cross-route improvement examines O(n squared) candidate relocations and exchanges per pass. Exact methods based on branch and price handle roughly 100 customers; heuristics scale to thousands.
The vehicle routing family is a set of increasingly constrained variants. Match the model to the real constraints or the solution will be infeasible.
| Alternative | Prefer it when | Cost |
|---|---|---|
| TSP | One vehicle and no capacity limits. The special case this generalises. | O(n^2·2^n) exact |
| CVRP | Vehicles have load limits, so partitions must respect capacity as well as geometry. | NP-hard |
| VRP with time windows | Customers must be served within specific intervals, which constrains sequencing heavily. | NP-hard |
| Clarke-Wright savings | A fast, classic constructive heuristic that merges routes by the savings from combining them. | O(n^2 log n) |
| Branch and price | Around 100 customers and a provable optimum is needed. | exponential |
Read the full article: The Vehicle Routing Problem
Related algorithms: Traveling Salesman Problem, Capacitated Vehicle Routing (CVRP), K-Means Logistics Clustering