Guest User
Using app without sign in

Practice book
Graph Theory Through Problems300 Exercises with Hints, Worked Algorithms and Complete Solutions
By Mohammed Islam Hadjoudj
Learn graph theory by solving problems: 300 exercises, from routine checks to challenging proofs, each with a complete solution.
Also by the authorGraph Algorithms for Coding Interviews100 solved interview problems with visual explanations and Python solutions.View on AmazonSelect an algorithm and generate steps to begin visualization
Cluster by angle, then route each truck
Capacitated vehicle routing: sweep the customers by angle around the depot into trucks, then route each truck
Select an algorithm and generate steps to begin visualization
The sweep algorithm is a classic heuristic for the capacitated vehicle routing problem: trucks of limited capacity leave a depot, deliver to customers with known demands and come back, and the total distance should be as small as possible. Billy Gillett and Leland Miller published it in 1974. It is a cluster-first, route-second method: first decide which customers share a truck, then find the best order within each truck.
Every customer gets an angle around the depot, and the customers are sorted by angle. A ray from the depot then sweeps around, starting after the widest gap between two neighbouring customers, and loads each customer it meets onto the current truck. When the next customer's demand would exceed the truck's capacity, that truck is closed and a new one starts. Finally each truck's customers are put in the shortest round trip from the depot, a small travelling salesman problem solved exactly when there are only a few stops. The sweep itself takes O(n log n) time; distances along the road network are shortest-path distances.
The sweep suits delivery and collection rounds where customers are spread around a central depot: parcel and grocery delivery, school buses, waste collection and field service. It is quick, easy to explain and gives compact service areas that do not overlap, so it is often the first heuristic taught for vehicle routing. On this site it can be compared with the Clarke-Wright savings method on the same instance.
The sweep algorithm of Gillett and Miller is a cluster-first, route-second heuristic. A ray rotates around the depot and collects customers into a truck until the next one would exceed its capacity, and then each truck gets its own short round trip.
Sweep(depot, customers, capacity):
sort the customers by their angle around the depot
start just after the widest gap between two angles
truck = 1, load = 0
for each customer c in angle order:
if load + demand(c) > capacity:
truck = truck + 1, load = 0
put c on the truck, load = load + demand(c)
for each truck:
order its customers by the shortest round trip
return the routesThe angular order keeps every cluster in one wedge of the map, so customers on the same truck are near each other and the routes do not cross. Capacity is checked as customers are added, so every cluster is feasible by construction. The only freedom left is the starting angle, which is why practical versions try several.
Plan deliveries on the example this page loads: a depot A in the middle of eight customers, with trucks of capacity 20. It is the same network as the capacitated vehicle routing page, so the two methods can be compared.
Example graph: Depot A with spokes to every customer and a ring road around them. Demands B 4, C 6, D 3, E 7, F 5, G 4, H 6 and I 3, 38 in total, so at least two trucks are needed. Spoke lengths range from 10 to 14 and ring segments from 8 to 10.
The sweep plan uses 2 trucks and a total distance of 101, both loaded to 19 out of 20. On this network it beats Clarke-Wright savings, which uses 3 trucks and 111, because Clarke-Wright merges greedily and is left with C, whose demand of 6 no longer fits on either of the other routes. On other networks the order is often reversed, which is why the two are usually run side by side.
Time: O(n log n) plus the routing step · Space: O(n)
Computing the angles is O(n) and sorting them O(n log n). The sweep itself is one pass. The routing step solves a small travelling salesman problem for each truck. Clusters are usually small enough for an exact method, or else a fast heuristic such as nearest neighbour plus 2-opt is used, so the routing cost depends on the cluster size k rather than on n. Running the sweep from every possible starting customer and keeping the best plan multiplies the cost by n and usually improves the result noticeably.
The sweep is one of the two classical construction heuristics for capacitated routing. Others improve on both.
| Alternative | Prefer it when | Cost |
|---|---|---|
| Clarke-Wright savings | Customers are not spread radially around the depot, or travel times do not follow straight-line geometry. | O(n^2 log n) |
| Fisher-Jaikumar | You want a better clustering step, choosing seed customers and solving a generalised assignment problem. | heavier |
| k-means then TSP | Clusters should be compact rather than wedge shaped, for example with a depot at the edge of the area. | O(n k i) plus routing |
| Large neighbourhood search | Large real instances where a few percent of distance matters. It repeatedly destroys and repairs part of the plan. | tunable |
Related algorithms: Capacitated Vehicle Routing (CVRP), Fleet Dispatching (mTSP), Traveling Salesman Problem, Christofides