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: 16 customers
- Hannover Hbf (75 vol.)
- Stuttgart Hbf (70 vol.)
- Dresden Hbf (35 vol.)
- Hamburg Hbf (65 vol.)
- München Hbf (60 vol.)
- Bremen Hbf (65 vol.)
- Leipzig Hbf (80 vol.)
- Nürnberg Hbf (50 vol.)
- Ulm Hbf (50 vol.)
- Köln Hbf (55 vol.)
- Mannheim Hbf (35 vol.)
- Mainz Hbf (45 vol.)
- Würzburg Hbf (80 vol.)
- Saarbrücken Hbf (75 vol.)
- Osnabrück Hbf (30 vol.)
- Freiburg Hbf (50 vol.)
Tour 1
COST: 1528.426 km
LOAD: 380 vol.
- Mainz Hbf | 45 vol.
- Mannheim Hbf | 35 vol.
- Stuttgart Hbf | 70 vol.
- Ulm Hbf | 50 vol.
- Freiburg Hbf | 50 vol.
- Saarbrücken Hbf | 75 vol.
- Köln Hbf | 55 vol.
Tour 2
COST: 1520.191 km
LOAD: 380 vol.
- Würzburg Hbf | 80 vol.
- Nürnberg Hbf | 50 vol.
- München Hbf | 60 vol.
- Dresden Hbf | 35 vol.
- Leipzig Hbf | 80 vol.
- Hannover Hbf | 75 vol.
Tour 3
COST: 739.898 km
LOAD: 160 vol.
- Osnabrück Hbf | 30 vol.
- Bremen Hbf | 65 vol.
- Hamburg Hbf | 65 vol.
LOAD: 380 vol.
- Mainz Hbf | 45 vol.
- Mannheim Hbf | 35 vol.
- Stuttgart Hbf | 70 vol.
- Ulm Hbf | 50 vol.
- Freiburg Hbf | 50 vol.
- Saarbrücken Hbf | 75 vol.
- Köln Hbf | 55 vol.
LOAD: 380 vol.
- Würzburg Hbf | 80 vol.
- Nürnberg Hbf | 50 vol.
- München Hbf | 60 vol.
- Dresden Hbf | 35 vol.
- Leipzig Hbf | 80 vol.
- Hannover Hbf | 75 vol.
LOAD: 160 vol.
- Osnabrück Hbf | 30 vol.
- Bremen Hbf | 65 vol.
- Hamburg Hbf | 65 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: 920 vol. | Vehicle capacity: 400 vol. Loads: [0, 0, 0, 0, 75, 0, 70, 35, 65, 60, 65, 80, 0, 50, 0, 50, 55, 35, 0, 45, 80, 75, 30, 50] ITERATION Generation: #1 Best cost: 4541.505 | Path: [0, 4, 10, 22, 16, 19, 17, 6, 0, 20, 13, 9, 15, 23, 21, 7, 0, 11, 8, 0] Best cost: 4496.837 | Path: [0, 6, 15, 9, 13, 20, 19, 17, 0, 22, 10, 4, 8, 11, 7, 23, 0, 16, 21, 0] Best cost: 4304.775 | Path: [0, 8, 10, 22, 4, 11, 7, 13, 0, 16, 19, 17, 21, 6, 15, 9, 0, 20, 23, 0] Best cost: 4225.449 | Path: [0, 16, 19, 17, 21, 23, 6, 15, 0, 22, 4, 8, 10, 11, 7, 13, 0, 20, 9, 0] Best cost: 4101.536 | Path: [0, 19, 17, 21, 23, 6, 15, 9, 0, 22, 4, 10, 8, 16, 20, 0, 11, 7, 13, 0] Best cost: 4096.576 | Path: [0, 23, 21, 19, 17, 6, 15, 9, 0, 22, 10, 8, 4, 11, 7, 13, 0, 20, 16, 0] Best cost: 3982.059 | Path: [0, 19, 17, 21, 23, 6, 15, 9, 0, 22, 10, 8, 4, 16, 20, 0, 11, 7, 13, 0] Best cost: 3980.052 | Path: [0, 19, 17, 21, 23, 6, 15, 9, 0, 11, 7, 13, 20, 16, 22, 10, 0, 4, 8, 0] Best cost: 3979.613 | Path: [0, 22, 10, 8, 4, 11, 7, 13, 0, 17, 19, 21, 23, 6, 15, 9, 0, 16, 20, 0] Generation: #2 Best cost: 3916.739 | Path: [0, 19, 17, 21, 23, 6, 15, 9, 0, 22, 10, 8, 4, 11, 7, 13, 0, 20, 16, 0] Best cost: 3808.581 | Path: [0, 16, 19, 17, 21, 23, 6, 15, 0, 20, 13, 9, 7, 11, 4, 0, 22, 10, 8, 0] OPTIMIZING each tour... Current: [[0, 16, 19, 17, 21, 23, 6, 15, 0], [0, 20, 13, 9, 7, 11, 4, 0], [0, 22, 10, 8, 0]] [1] Cost: 1548.492 to 1528.426 | Optimized: [0, 19, 17, 6, 15, 23, 21, 16, 0] ACO RESULTS [1/380 vol./1528.426 km] Kassel-Wilhelmshöhe -> Mainz Hbf -> Mannheim Hbf -> Stuttgart Hbf -> Ulm Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Köln Hbf --> Kassel-Wilhelmshöhe [2/380 vol./1520.191 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf --> Kassel-Wilhelmshöhe [3/160 vol./ 739.898 km] Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3788.515 km.