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: 20 customers
- Kassel-Wilhelmshöhe (70 vol.)
- Düsseldorf Hbf (35 vol.)
- Frankfurt Hbf (45 vol.)
- Hannover Hbf (50 vol.)
- Aachen Hbf (60 vol.)
- Dresden Hbf (45 vol.)
- Hamburg Hbf (80 vol.)
- München Hbf (50 vol.)
- Leipzig Hbf (40 vol.)
- Dortmund Hbf (75 vol.)
- Nürnberg Hbf (85 vol.)
- Karlsruhe Hbf (100 vol.)
- Ulm Hbf (55 vol.)
- Köln Hbf (70 vol.)
- Mannheim Hbf (75 vol.)
- Kiel Hbf (95 vol.)
- Mainz Hbf (90 vol.)
- Würzburg Hbf (40 vol.)
- Saarbrücken Hbf (25 vol.)
- Osnabrück Hbf (80 vol.)
Tour 1
COST: 1573.588 km
LOAD: 280 vol.
- München Hbf | 50 vol.
- Ulm Hbf | 55 vol.
- Karlsruhe Hbf | 100 vol.
- Mannheim Hbf | 75 vol.
Tour 2
COST: 1726.802 km
LOAD: 280 vol.
- Frankfurt Hbf | 45 vol.
- Saarbrücken Hbf | 25 vol.
- Würzburg Hbf | 40 vol.
- Nürnberg Hbf | 85 vol.
- Leipzig Hbf | 40 vol.
- Dresden Hbf | 45 vol.
Tour 3
COST: 1312.887 km
LOAD: 290 vol.
- Dortmund Hbf | 75 vol.
- Düsseldorf Hbf | 35 vol.
- Köln Hbf | 70 vol.
- Aachen Hbf | 60 vol.
- Hannover Hbf | 50 vol.
Tour 4
COST: 1389.278 km
LOAD: 240 vol.
- Mainz Hbf | 90 vol.
- Kassel-Wilhelmshöhe | 70 vol.
- Osnabrück Hbf | 80 vol.
Tour 5
COST: 732.557 km
LOAD: 175 vol.
- Hamburg Hbf | 80 vol.
- Kiel Hbf | 95 vol.
LOAD: 280 vol.
- München Hbf | 50 vol.
- Ulm Hbf | 55 vol.
- Karlsruhe Hbf | 100 vol.
- Mannheim Hbf | 75 vol.
LOAD: 280 vol.
- Frankfurt Hbf | 45 vol.
- Saarbrücken Hbf | 25 vol.
- Würzburg Hbf | 40 vol.
- Nürnberg Hbf | 85 vol.
- Leipzig Hbf | 40 vol.
- Dresden Hbf | 45 vol.
LOAD: 290 vol.
- Dortmund Hbf | 75 vol.
- Düsseldorf Hbf | 35 vol.
- Köln Hbf | 70 vol.
- Aachen Hbf | 60 vol.
- Hannover Hbf | 50 vol.
LOAD: 240 vol.
- Mainz Hbf | 90 vol.
- Kassel-Wilhelmshöhe | 70 vol.
- Osnabrück Hbf | 80 vol.
LOAD: 175 vol.
- Hamburg Hbf | 80 vol.
- Kiel Hbf | 95 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: 1265 vol. | Vehicle capacity: 300 vol. Loads: [70, 0, 35, 45, 50, 60, 0, 45, 80, 50, 0, 40, 75, 85, 100, 55, 70, 75, 95, 90, 40, 25, 80, 0] ITERATION Generation: #1 Best cost: 8113.725 | Path: [1, 0, 22, 12, 2, 21, 1, 11, 7, 13, 20, 3, 1, 4, 8, 18, 16, 1, 5, 19, 17, 15, 1, 9, 14, 1] Best cost: 7827.393 | Path: [1, 2, 16, 5, 12, 3, 1, 7, 11, 13, 20, 17, 1, 4, 22, 0, 19, 1, 8, 18, 14, 21, 1, 9, 15, 1] Best cost: 7427.961 | Path: [1, 4, 8, 18, 0, 1, 7, 11, 13, 20, 19, 1, 22, 12, 2, 16, 21, 1, 9, 15, 14, 17, 1, 3, 5, 1] Best cost: 7274.597 | Path: [1, 5, 16, 2, 12, 4, 1, 11, 7, 13, 20, 3, 21, 1, 8, 18, 22, 1, 0, 19, 17, 15, 1, 9, 14, 1] Best cost: 7257.692 | Path: [1, 8, 18, 4, 0, 1, 11, 7, 20, 3, 19, 21, 1, 22, 12, 2, 16, 1, 13, 9, 15, 14, 1, 17, 5, 1] Best cost: 7133.644 | Path: [1, 11, 7, 13, 20, 3, 2, 1, 8, 18, 4, 0, 1, 22, 12, 16, 5, 1, 19, 17, 14, 21, 1, 9, 15, 1] Best cost: 7054.014 | Path: [1, 21, 14, 17, 3, 20, 1, 11, 7, 13, 9, 15, 1, 8, 18, 4, 0, 1, 12, 2, 16, 5, 1, 22, 19, 1] Best cost: 7030.275 | Path: [1, 21, 14, 17, 3, 20, 1, 11, 7, 13, 9, 15, 1, 4, 22, 12, 2, 5, 1, 8, 18, 0, 1, 19, 16, 1] Best cost: 6771.703 | Path: [1, 9, 15, 14, 17, 1, 11, 7, 13, 20, 3, 21, 1, 12, 2, 16, 5, 4, 1, 22, 0, 19, 1, 8, 18, 1] OPTIMIZING each tour... Current: [[1, 9, 15, 14, 17, 1], [1, 11, 7, 13, 20, 3, 21, 1], [1, 12, 2, 16, 5, 4, 1], [1, 22, 0, 19, 1], [1, 8, 18, 1]] [2] Cost: 1762.601 to 1726.802 | Optimized: [1, 3, 21, 20, 13, 11, 7, 1] [4] Cost: 1390.070 to 1389.278 | Optimized: [1, 19, 0, 22, 1] ACO RESULTS [1/280 vol./1573.588 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Karlsruhe Hbf -> Mannheim Hbf --> Berlin Hbf [2/280 vol./1726.802 km] Berlin Hbf -> Frankfurt Hbf -> Saarbrücken Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/290 vol./1312.887 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Hannover Hbf --> Berlin Hbf [4/240 vol./1389.278 km] Berlin Hbf -> Mainz Hbf -> Kassel-Wilhelmshöhe -> Osnabrück Hbf --> Berlin Hbf [5/175 vol./ 732.557 km] Berlin Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6735.112 km.