Simulation
Medicine supply digital twin (5/14): routes with Clarke-Wright savings and 2-opt
What a delivery route costs, how the savings formula decides which units travel together, and how 2-opt undoes crossings. With the cost of every kilometre, every hour and every trip.
The fictional system’s regional warehouse delivers to its units by van. Each unit has its delivery day, and each day someone decides which van goes to which units and in what order. It is the vehicle routing problem, one of the most studied in operations research, and it has no practical exact solution with many stops: the number of possible routes grows faster than any power.
The twin uses two classic heuristics that, together, give very good routes in milliseconds.
First, what a route costs
Without cost there is no optimization. The twin charges for three things:
| Parameter | Model value |
|---|---|
| , cost per trip (vehicle, insurance, loading) | $350 |
| , cost per km (fuel and maintenance) | $9.50 |
| , driver cost per hour | $130 |
| , average speed | 55 km/h |
| , unloading per stop | 20 min |
| Maximum shift / capacity | 10 h / 8,000 L |
is the route’s kilometres and the number of stops. Distances are straight lines multiplied by 1.35, a typical road factor; with real data they are replaced by a road distance matrix.
Clarke-Wright: the saving from joining two stops
The 1964 idea is simple. Start with the worst possible plan: one van per unit, out and back. Then ask how much is saved if two units and are visited on the same trip:
Instead of returning to the warehouse from and setting out again towards (), you go straight from to (). Compute every saving, sort from largest to smallest, and merge routes in that order, as long as:
- and are on different routes and at an end of their route (a stop can’t be inserted in the middle);
- the merged route fits in the van and within the shift.
2-opt: undoing crossings
Clarke-Wright decides which units travel together, but the order within each route can end up poor. 2-opt tries removing two legs of the route and reconnecting it the other way round, that is, reversing a segment:
The change only touches two legs, so it is quick to evaluate:
If it is accepted and the search starts over; when no change improves the route, it is 2-optimal.
In the aid, the baseline is fixed zone routes: units are grouped by direction, up to three per van, and visited in the order they were registered. It’s a common way to organize deliveries when routes were defined years ago. On the starting map:
| Option | Trips | Km | Cost |
|---|---|---|---|
| Fixed zone routes | 6 | 1,153 | $16,473 |
| Clarke-Wright | 3 | 696 | $9,997 |
| Clarke-Wright + 2-opt | 3 | 693 | $9,965 |
Almost all the saving comes from joining (Clarke-Wright); 2-opt adds little because routes are short and Clarke-Wright already builds them in good order. With long routes of 10 or more stops, 2-opt matters more. Try other maps and lower the capacity: with small vans, each route carries fewer units and the saving from joining drops.
Routes and costs tab (“Rutas y costos”): the vans run the delivery routes to the 60 units. (Interface in Spanish.) · Open full screen
In the full twin
With the same visit days and the same loads, regrouping one week’s routes cut trips from 15 to 10, cost by 20 % and distance by 709 km. The aid overstates the saving because its baseline is clumsier than a real operation; 20 % is the number that matters.
The twin uses the same idea for urgent orders: it compares the cost of inserting the stop into that day’s route, wherever it fits most cheaply, against sending a dedicated trip. The cheapest insertion between and costs , the same logic as the saving but in reverse.
What comes next
Vans leave the warehouse and suppliers’ trucks arrive at it. In the next post, the yard and docks as a queue: how many docks are needed so trucks don’t wait for hours.