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: 18 customers
- Frankfurt Hbf (40 vol.)
- Hannover Hbf (70 vol.)
- Aachen Hbf (50 vol.)
- Stuttgart Hbf (100 vol.)
- Hamburg Hbf (60 vol.)
- München Hbf (95 vol.)
- Bremen Hbf (20 vol.)
- Leipzig Hbf (80 vol.)
- Dortmund Hbf (60 vol.)
- Nürnberg Hbf (30 vol.)
- Karlsruhe Hbf (65 vol.)
- Ulm Hbf (80 vol.)
- Mannheim Hbf (55 vol.)
- Kiel Hbf (60 vol.)
- Mainz Hbf (75 vol.)
- Würzburg Hbf (40 vol.)
- Saarbrücken Hbf (55 vol.)
- Freiburg Hbf (25 vol.)
Tour 1
COST: 1292.496 km
LOAD: 385 vol.
- Mainz Hbf | 75 vol.
- Mannheim Hbf | 55 vol.
- Karlsruhe Hbf | 65 vol.
- Freiburg Hbf | 25 vol.
- Saarbrücken Hbf | 55 vol.
- Aachen Hbf | 50 vol.
- Dortmund Hbf | 60 vol.
Tour 2
COST: 1131.225 km
LOAD: 385 vol.
- Würzburg Hbf | 40 vol.
- Nürnberg Hbf | 30 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 80 vol.
- Stuttgart Hbf | 100 vol.
- Frankfurt Hbf | 40 vol.
Tour 3
COST: 1271.527 km
LOAD: 290 vol.
- Hannover Hbf | 70 vol.
- Hamburg Hbf | 60 vol.
- Kiel Hbf | 60 vol.
- Bremen Hbf | 20 vol.
- Leipzig Hbf | 80 vol.
LOAD: 385 vol.
- Mainz Hbf | 75 vol.
- Mannheim Hbf | 55 vol.
- Karlsruhe Hbf | 65 vol.
- Freiburg Hbf | 25 vol.
- Saarbrücken Hbf | 55 vol.
- Aachen Hbf | 50 vol.
- Dortmund Hbf | 60 vol.
LOAD: 385 vol.
- Würzburg Hbf | 40 vol.
- Nürnberg Hbf | 30 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 80 vol.
- Stuttgart Hbf | 100 vol.
- Frankfurt Hbf | 40 vol.
LOAD: 290 vol.
- Hannover Hbf | 70 vol.
- Hamburg Hbf | 60 vol.
- Kiel Hbf | 60 vol.
- Bremen Hbf | 20 vol.
- Leipzig Hbf | 80 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: 1060 vol. | Vehicle capacity: 400 vol. Loads: [0, 0, 0, 40, 70, 50, 100, 0, 60, 95, 20, 80, 60, 30, 65, 80, 0, 55, 60, 75, 40, 55, 0, 25] ITERATION Generation: #1 Best cost: 4709.207 | Path: [0, 3, 19, 17, 14, 6, 20, 23, 0, 12, 5, 21, 15, 9, 13, 10, 0, 4, 8, 18, 11, 0] Best cost: 4648.533 | Path: [0, 5, 12, 4, 10, 8, 18, 11, 0, 14, 17, 3, 19, 20, 13, 9, 0, 23, 6, 15, 21, 0] Best cost: 4309.841 | Path: [0, 6, 14, 17, 3, 19, 21, 0, 12, 5, 4, 10, 8, 18, 11, 0, 20, 13, 9, 15, 23, 0] Best cost: 4243.802 | Path: [0, 8, 18, 10, 4, 12, 5, 21, 23, 0, 3, 19, 17, 14, 6, 20, 0, 13, 9, 15, 11, 0] Best cost: 4117.960 | Path: [0, 8, 18, 10, 4, 12, 5, 3, 20, 0, 11, 13, 9, 15, 6, 0, 19, 17, 14, 23, 21, 0] Best cost: 4056.995 | Path: [0, 12, 5, 21, 17, 14, 6, 0, 3, 19, 20, 13, 9, 15, 23, 0, 4, 10, 8, 18, 11, 0] Best cost: 4025.411 | Path: [0, 20, 13, 9, 15, 6, 17, 0, 5, 12, 4, 10, 8, 18, 11, 0, 19, 3, 14, 23, 21, 0] Best cost: 3992.542 | Path: [0, 11, 4, 10, 8, 18, 12, 5, 0, 20, 13, 9, 15, 6, 17, 0, 3, 19, 14, 23, 21, 0] Generation: #2 Best cost: 3915.337 | Path: [0, 6, 15, 9, 13, 20, 3, 0, 12, 5, 19, 17, 14, 23, 21, 0, 4, 10, 8, 18, 11, 0] Best cost: 3902.199 | Path: [0, 6, 15, 9, 13, 20, 3, 0, 12, 5, 19, 17, 14, 23, 21, 0, 4, 8, 18, 10, 11, 0] Generation: #5 Best cost: 3773.129 | Path: [0, 12, 5, 21, 23, 14, 17, 19, 0, 3, 20, 13, 9, 15, 6, 0, 4, 10, 8, 18, 11, 0] OPTIMIZING each tour... Current: [[0, 12, 5, 21, 23, 14, 17, 19, 0], [0, 3, 20, 13, 9, 15, 6, 0], [0, 4, 10, 8, 18, 11, 0]] [1] Cost: 1297.805 to 1292.496 | Optimized: [0, 19, 17, 14, 23, 21, 5, 12, 0] [2] Cost: 1190.659 to 1131.225 | Optimized: [0, 20, 13, 9, 15, 6, 3, 0] [3] Cost: 1284.665 to 1271.527 | Optimized: [0, 4, 8, 18, 10, 11, 0] ACO RESULTS [1/385 vol./1292.496 km] Kassel-Wilhelmshöhe -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Dortmund Hbf --> Kassel-Wilhelmshöhe [2/385 vol./1131.225 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe [3/290 vol./1271.527 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Hamburg Hbf -> Kiel Hbf -> Bremen Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3695.248 km.