
Solving CVRP with ACO
Minimizing Travel Cost for Complex Delivery Problems
This scenario involves the Capacitated Vehicle Routing Problem,
solved using the meta-heuristics algorithm Ant Colony Optimization. Basically, VRP is a network consisting of a number of nodes
(sometimes called cities) and arcs connecting one to all others along with the corresponding costs.
Mostly, the aim is to minimize the cost in visiting each customer once and only once. The term
"capacitated" is added due to some capacity constraints on the vehicles (vcap).
Enter the problem. Some company wants to deliver loads to a number of customers. In this case, we
have 24 nodes based on the location of Germany's train stations (don't ask why). The delivery
always starts from and ends at the depot, visiting a list of customers in other cities. And then
a number of questions arise:
- How do we minimize the travel cost in terms of distance?
- How many trucks are required?
- Which cities are visited by the truck #1, #2. etc.?
- depot: [0..23], def = 0
- vcap: [200..400], def = 400
There is a way to set all the demands, but I don't think you are ready for that. 😉
VCAP: 300 vol.
ACTIVE: 17 customers
- Düsseldorf Hbf (70 vol.)
- Hannover Hbf (100 vol.)
- Aachen Hbf (45 vol.)
- Stuttgart Hbf (20 vol.)
- Dresden Hbf (90 vol.)
- Hamburg Hbf (30 vol.)
- München Hbf (45 vol.)
- Bremen Hbf (75 vol.)
- Leipzig Hbf (75 vol.)
- Nürnberg Hbf (75 vol.)
- Ulm Hbf (100 vol.)
- Köln Hbf (80 vol.)
- Mannheim Hbf (20 vol.)
- Mainz Hbf (70 vol.)
- Würzburg Hbf (45 vol.)
- Saarbrücken Hbf (90 vol.)
- Osnabrück Hbf (40 vol.)
Tour 1
COST: 1465.585 km
LOAD: 285 vol.
- Nürnberg Hbf | 75 vol.
- München Hbf | 45 vol.
- Ulm Hbf | 100 vol.
- Stuttgart Hbf | 20 vol.
- Würzburg Hbf | 45 vol.
Tour 2
COST: 1007.951 km
LOAD: 295 vol.
- Dresden Hbf | 90 vol.
- Leipzig Hbf | 75 vol.
- Hannover Hbf | 100 vol.
- Hamburg Hbf | 30 vol.
Tour 3
COST: 1681.81 km
LOAD: 295 vol.
- Mainz Hbf | 70 vol.
- Mannheim Hbf | 20 vol.
- Saarbrücken Hbf | 90 vol.
- Aachen Hbf | 45 vol.
- Düsseldorf Hbf | 70 vol.
Tour 4
COST: 1282.838 km
LOAD: 195 vol.
- Köln Hbf | 80 vol.
- Osnabrück Hbf | 40 vol.
- Bremen Hbf | 75 vol.

LOAD: 285 vol.
- Nürnberg Hbf | 75 vol.
- München Hbf | 45 vol.
- Ulm Hbf | 100 vol.
- Stuttgart Hbf | 20 vol.
- Würzburg Hbf | 45 vol.

LOAD: 295 vol.
- Dresden Hbf | 90 vol.
- Leipzig Hbf | 75 vol.
- Hannover Hbf | 100 vol.
- Hamburg Hbf | 30 vol.

LOAD: 295 vol.
- Mainz Hbf | 70 vol.
- Mannheim Hbf | 20 vol.
- Saarbrücken Hbf | 90 vol.
- Aachen Hbf | 45 vol.
- Düsseldorf Hbf | 70 vol.

LOAD: 195 vol.
- Köln Hbf | 80 vol.
- Osnabrück Hbf | 40 vol.
- Bremen Hbf | 75 vol.
#generations: 10 for global, 5 for local
#ants: 5 times #active_customers
ACO
Rel. importance of pheromones α = 1.0
Rel. importance of visibility β = 10.0
Trail persistance ρ = 0.5
Pheromone intensity Q = 10
See this wikipedia page to learn more.
NETWORK Depo: [1] Berlin Hbf | Number of cities: 24 | Total loads: 1070 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 70, 0, 100, 45, 20, 90, 30, 45, 75, 75, 0, 75, 0, 100, 80, 20, 0, 70, 45, 90, 40, 0] ITERATION Generation: #1 Best cost: 6331.996 | Path: [1, 2, 16, 5, 21, 1, 11, 7, 13, 20, 1, 8, 4, 10, 22, 17, 6, 1, 19, 15, 9, 1] Best cost: 6054.764 | Path: [1, 6, 15, 9, 13, 20, 1, 7, 11, 4, 8, 1, 22, 10, 16, 2, 17, 1, 19, 21, 5, 1] Best cost: 5919.244 | Path: [1, 9, 15, 6, 17, 19, 20, 1, 11, 7, 13, 5, 1, 4, 22, 10, 8, 1, 2, 16, 21, 1] Best cost: 5767.677 | Path: [1, 9, 15, 6, 17, 19, 20, 1, 7, 11, 4, 8, 1, 13, 21, 5, 16, 1, 22, 10, 2, 1] Best cost: 5739.003 | Path: [1, 19, 17, 21, 2, 5, 1, 7, 11, 4, 8, 1, 13, 20, 6, 15, 9, 1, 22, 10, 16, 1] Best cost: 5697.830 | Path: [1, 19, 17, 21, 16, 22, 1, 7, 11, 4, 8, 1, 20, 13, 9, 15, 6, 1, 10, 2, 5, 1] Best cost: 5690.270 | Path: [1, 9, 15, 6, 17, 19, 20, 1, 7, 11, 4, 8, 1, 10, 22, 16, 2, 1, 13, 21, 5, 1] Generation: #2 Best cost: 5644.727 | Path: [1, 19, 17, 21, 5, 2, 1, 7, 11, 4, 8, 1, 13, 20, 6, 15, 9, 1, 22, 10, 16, 1] Best cost: 5580.336 | Path: [1, 17, 19, 21, 5, 2, 1, 7, 11, 4, 8, 1, 13, 20, 6, 15, 9, 1, 10, 22, 16, 1] Best cost: 5563.862 | Path: [1, 9, 15, 6, 20, 13, 1, 7, 11, 4, 8, 1, 17, 19, 21, 5, 2, 1, 10, 22, 16, 1] OPTIMIZING each tour... Current: [[1, 9, 15, 6, 20, 13, 1], [1, 7, 11, 4, 8, 1], [1, 17, 19, 21, 5, 2, 1], [1, 10, 22, 16, 1]] [1] Cost: 1510.016 to 1465.585 | Optimized: [1, 13, 9, 15, 6, 20, 1] [3] Cost: 1743.076 to 1681.810 | Optimized: [1, 19, 17, 21, 5, 2, 1] [4] Cost: 1302.819 to 1282.838 | Optimized: [1, 16, 22, 10, 1] ACO RESULTS [1/285 vol./1465.585 km] Berlin Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Würzburg Hbf --> Berlin Hbf [2/295 vol./1007.951 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf -> Hamburg Hbf --> Berlin Hbf [3/295 vol./1681.810 km] Berlin Hbf -> Mainz Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Düsseldorf Hbf --> Berlin Hbf [4/195 vol./1282.838 km] Berlin Hbf -> Köln Hbf -> Osnabrück Hbf -> Bremen Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5438.184 km.