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: 400 vol.
ACTIVE: 19 customers
- Berlin Hbf (55 vol.)
- Düsseldorf Hbf (90 vol.)
- Frankfurt Hbf (35 vol.)
- Hannover Hbf (30 vol.)
- Stuttgart Hbf (35 vol.)
- Dresden Hbf (65 vol.)
- München Hbf (100 vol.)
- Bremen Hbf (25 vol.)
- Leipzig Hbf (20 vol.)
- Dortmund Hbf (85 vol.)
- Nürnberg Hbf (55 vol.)
- Karlsruhe Hbf (55 vol.)
- Ulm Hbf (20 vol.)
- Köln Hbf (25 vol.)
- Mannheim Hbf (40 vol.)
- Kiel Hbf (35 vol.)
- Mainz Hbf (55 vol.)
- Saarbrücken Hbf (90 vol.)
- Freiburg Hbf (80 vol.)
Tour 1
COST: 1189.558 km
LOAD: 395 vol.
- Nürnberg Hbf | 55 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 20 vol.
- Stuttgart Hbf | 35 vol.
- Karlsruhe Hbf | 55 vol.
- Mannheim Hbf | 40 vol.
- Mainz Hbf | 55 vol.
- Frankfurt Hbf | 35 vol.
Tour 2
COST: 2411.216 km
LOAD: 400 vol.
- Hannover Hbf | 30 vol.
- Bremen Hbf | 25 vol.
- Kiel Hbf | 35 vol.
- Berlin Hbf | 55 vol.
- Dresden Hbf | 65 vol.
- Leipzig Hbf | 20 vol.
- Saarbrücken Hbf | 90 vol.
- Freiburg Hbf | 80 vol.
Tour 3
COST: 509.83 km
LOAD: 200 vol.
- Dortmund Hbf | 85 vol.
- Düsseldorf Hbf | 90 vol.
- Köln Hbf | 25 vol.
LOAD: 395 vol.
- Nürnberg Hbf | 55 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 20 vol.
- Stuttgart Hbf | 35 vol.
- Karlsruhe Hbf | 55 vol.
- Mannheim Hbf | 40 vol.
- Mainz Hbf | 55 vol.
- Frankfurt Hbf | 35 vol.
LOAD: 400 vol.
- Hannover Hbf | 30 vol.
- Bremen Hbf | 25 vol.
- Kiel Hbf | 35 vol.
- Berlin Hbf | 55 vol.
- Dresden Hbf | 65 vol.
- Leipzig Hbf | 20 vol.
- Saarbrücken Hbf | 90 vol.
- Freiburg Hbf | 80 vol.
LOAD: 200 vol.
- Dortmund Hbf | 85 vol.
- Düsseldorf Hbf | 90 vol.
- Köln Hbf | 25 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: [0] Kassel-Wilhelmshöhe | Number of cities: 24 | Total loads: 995 vol. | Vehicle capacity: 400 vol. Loads: [0, 55, 90, 35, 30, 0, 35, 65, 0, 100, 25, 20, 85, 55, 55, 20, 25, 40, 35, 55, 0, 90, 0, 80] ITERATION Generation: #1 Best cost: 5463.436 | Path: [0, 1, 11, 7, 13, 15, 6, 14, 17, 19, 0, 12, 2, 16, 3, 21, 10, 4, 0, 23, 9, 18, 0] Best cost: 4860.352 | Path: [0, 2, 16, 12, 4, 10, 18, 1, 11, 3, 0, 19, 17, 14, 6, 15, 9, 13, 0, 21, 23, 7, 0] Best cost: 4555.295 | Path: [0, 3, 19, 17, 14, 6, 15, 13, 9, 0, 12, 2, 16, 21, 23, 4, 0, 11, 7, 1, 10, 18, 0] Best cost: 4517.877 | Path: [0, 14, 17, 3, 19, 16, 2, 12, 0, 4, 10, 18, 1, 7, 11, 13, 9, 0, 21, 6, 15, 23, 0] Best cost: 4388.950 | Path: [0, 21, 17, 14, 6, 15, 9, 13, 0, 12, 2, 16, 3, 19, 23, 4, 0, 10, 18, 1, 7, 11, 0] Best cost: 4356.952 | Path: [0, 4, 10, 18, 1, 11, 7, 9, 15, 6, 0, 12, 16, 2, 21, 19, 3, 0, 17, 14, 23, 13, 0] Best cost: 4313.385 | Path: [0, 19, 3, 17, 14, 6, 15, 9, 13, 0, 12, 2, 16, 21, 23, 11, 0, 4, 10, 18, 1, 7, 0] Best cost: 4307.796 | Path: [0, 11, 7, 1, 18, 10, 4, 12, 16, 19, 0, 3, 17, 14, 6, 15, 9, 13, 0, 2, 21, 23, 0] Best cost: 4290.958 | Path: [0, 3, 19, 17, 14, 6, 15, 9, 13, 0, 12, 2, 16, 21, 23, 11, 0, 4, 10, 18, 1, 7, 0] Best cost: 4171.297 | Path: [0, 3, 19, 17, 14, 6, 15, 9, 13, 0, 12, 2, 16, 21, 23, 4, 0, 11, 7, 1, 18, 10, 0] Best cost: 4157.735 | Path: [0, 13, 9, 15, 6, 14, 17, 19, 3, 0, 12, 2, 16, 21, 23, 4, 0, 11, 7, 1, 18, 10, 0] Generation: #4 Best cost: 4145.524 | Path: [0, 3, 19, 17, 14, 6, 15, 9, 13, 0, 4, 10, 18, 1, 11, 7, 23, 21, 0, 12, 2, 16, 0] OPTIMIZING each tour... Current: [[0, 3, 19, 17, 14, 6, 15, 9, 13, 0], [0, 4, 10, 18, 1, 11, 7, 23, 21, 0], [0, 12, 2, 16, 0]] [1] Cost: 1203.120 to 1189.558 | Optimized: [0, 13, 9, 15, 6, 14, 17, 19, 3, 0] [2] Cost: 2432.574 to 2411.216 | Optimized: [0, 4, 10, 18, 1, 7, 11, 21, 23, 0] ACO RESULTS [1/395 vol./1189.558 km] Kassel-Wilhelmshöhe -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Mannheim Hbf -> Mainz Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe [2/400 vol./2411.216 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Bremen Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Saarbrücken Hbf -> Freiburg Hbf --> Kassel-Wilhelmshöhe [3/200 vol./ 509.830 km] Kassel-Wilhelmshöhe -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 4110.604 km.