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
- Berlin Hbf (30 vol.)
- Düsseldorf Hbf (65 vol.)
- Frankfurt Hbf (40 vol.)
- Hannover Hbf (80 vol.)
- Aachen Hbf (95 vol.)
- Stuttgart Hbf (35 vol.)
- Hamburg Hbf (50 vol.)
- München Hbf (95 vol.)
- Bremen Hbf (40 vol.)
- Leipzig Hbf (20 vol.)
- Dortmund Hbf (100 vol.)
- Nürnberg Hbf (30 vol.)
- Ulm Hbf (60 vol.)
- Köln Hbf (30 vol.)
- Würzburg Hbf (55 vol.)
- Saarbrücken Hbf (65 vol.)
- Osnabrück Hbf (90 vol.)
- Freiburg Hbf (85 vol.)
Tour 1
COST: 1632.207 km
LOAD: 395 vol.
- Würzburg Hbf | 55 vol.
- Nürnberg Hbf | 30 vol.
- Leipzig Hbf | 20 vol.
- Berlin Hbf | 30 vol.
- Hamburg Hbf | 50 vol.
- Bremen Hbf | 40 vol.
- Hannover Hbf | 80 vol.
- Osnabrück Hbf | 90 vol.
Tour 2
COST: 1518.112 km
LOAD: 380 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 60 vol.
- Stuttgart Hbf | 35 vol.
- Freiburg Hbf | 85 vol.
- Saarbrücken Hbf | 65 vol.
- Frankfurt Hbf | 40 vol.
Tour 3
COST: 630.524 km
LOAD: 290 vol.
- Köln Hbf | 30 vol.
- Aachen Hbf | 95 vol.
- Düsseldorf Hbf | 65 vol.
- Dortmund Hbf | 100 vol.
LOAD: 395 vol.
- Würzburg Hbf | 55 vol.
- Nürnberg Hbf | 30 vol.
- Leipzig Hbf | 20 vol.
- Berlin Hbf | 30 vol.
- Hamburg Hbf | 50 vol.
- Bremen Hbf | 40 vol.
- Hannover Hbf | 80 vol.
- Osnabrück Hbf | 90 vol.
LOAD: 380 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 60 vol.
- Stuttgart Hbf | 35 vol.
- Freiburg Hbf | 85 vol.
- Saarbrücken Hbf | 65 vol.
- Frankfurt Hbf | 40 vol.
LOAD: 290 vol.
- Köln Hbf | 30 vol.
- Aachen Hbf | 95 vol.
- Düsseldorf Hbf | 65 vol.
- Dortmund Hbf | 100 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: 1065 vol. | Vehicle capacity: 400 vol. Loads: [0, 30, 65, 40, 80, 95, 35, 0, 50, 95, 40, 20, 100, 30, 0, 60, 30, 0, 0, 0, 55, 65, 90, 85] ITERATION Generation: #1 Best cost: 4673.369 | Path: [0, 1, 11, 4, 10, 8, 22, 2, 0, 12, 16, 5, 3, 21, 6, 13, 0, 20, 15, 9, 23, 0] Best cost: 4480.233 | Path: [0, 8, 10, 4, 22, 12, 16, 0, 3, 20, 13, 9, 15, 6, 23, 0, 5, 2, 21, 11, 1, 0] Best cost: 4420.623 | Path: [0, 9, 15, 6, 20, 13, 11, 1, 8, 0, 3, 21, 23, 16, 2, 12, 0, 22, 10, 4, 5, 0] Best cost: 4191.159 | Path: [0, 21, 23, 6, 15, 9, 13, 11, 0, 22, 10, 4, 8, 1, 12, 0, 2, 16, 5, 3, 20, 0] Best cost: 4113.500 | Path: [0, 12, 2, 16, 5, 21, 3, 0, 22, 10, 8, 4, 1, 11, 13, 20, 0, 6, 15, 9, 23, 0] Best cost: 4094.179 | Path: [0, 20, 13, 9, 15, 6, 23, 3, 0, 12, 2, 16, 5, 21, 11, 0, 22, 10, 4, 8, 1, 0] Best cost: 4047.030 | Path: [0, 11, 1, 8, 4, 10, 22, 2, 0, 12, 16, 5, 21, 3, 20, 0, 13, 9, 15, 6, 23, 0] Best cost: 3938.565 | Path: [0, 21, 23, 6, 15, 9, 13, 11, 0, 12, 2, 16, 5, 3, 20, 0, 22, 10, 4, 8, 1, 0] Generation: #2 Best cost: 3822.184 | Path: [0, 22, 10, 8, 4, 1, 11, 13, 20, 0, 3, 21, 23, 6, 15, 9, 0, 12, 2, 16, 5, 0] Generation: #7 Best cost: 3822.078 | Path: [0, 22, 10, 4, 8, 1, 11, 13, 20, 0, 3, 21, 23, 6, 15, 9, 0, 12, 2, 16, 5, 0] OPTIMIZING each tour... Current: [[0, 22, 10, 4, 8, 1, 11, 13, 20, 0], [0, 3, 21, 23, 6, 15, 9, 0], [0, 12, 2, 16, 5, 0]] [1] Cost: 1646.876 to 1632.207 | Optimized: [0, 20, 13, 11, 1, 8, 10, 4, 22, 0] [2] Cost: 1526.130 to 1518.112 | Optimized: [0, 9, 15, 6, 23, 21, 3, 0] [3] Cost: 649.072 to 630.524 | Optimized: [0, 16, 5, 2, 12, 0] ACO RESULTS [1/395 vol./1632.207 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Berlin Hbf -> Hamburg Hbf -> Bremen Hbf -> Hannover Hbf -> Osnabrück Hbf --> Kassel-Wilhelmshöhe [2/380 vol./1518.112 km] Kassel-Wilhelmshöhe -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe [3/290 vol./ 630.524 km] Kassel-Wilhelmshöhe -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Dortmund Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3780.843 km.