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: 20 customers
- Berlin Hbf (30 vol.)
- Düsseldorf Hbf (85 vol.)
- Frankfurt Hbf (35 vol.)
- Aachen Hbf (30 vol.)
- Stuttgart Hbf (80 vol.)
- Dresden Hbf (25 vol.)
- Hamburg Hbf (100 vol.)
- München Hbf (40 vol.)
- Bremen Hbf (55 vol.)
- Leipzig Hbf (45 vol.)
- Dortmund Hbf (25 vol.)
- Nürnberg Hbf (25 vol.)
- Ulm Hbf (80 vol.)
- Köln Hbf (40 vol.)
- Mannheim Hbf (25 vol.)
- Kiel Hbf (95 vol.)
- Mainz Hbf (55 vol.)
- Würzburg Hbf (55 vol.)
- Saarbrücken Hbf (75 vol.)
- Osnabrück Hbf (20 vol.)
Tour 1
COST: 1557.274 km
LOAD: 395 vol.
- Dortmund Hbf | 25 vol.
- Osnabrück Hbf | 20 vol.
- Bremen Hbf | 55 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 95 vol.
- Berlin Hbf | 30 vol.
- Dresden Hbf | 25 vol.
- Leipzig Hbf | 45 vol.
Tour 2
COST: 1181.217 km
LOAD: 395 vol.
- Würzburg Hbf | 55 vol.
- Nürnberg Hbf | 25 vol.
- München Hbf | 40 vol.
- Ulm Hbf | 80 vol.
- Stuttgart Hbf | 80 vol.
- Mannheim Hbf | 25 vol.
- Mainz Hbf | 55 vol.
- Frankfurt Hbf | 35 vol.
Tour 3
COST: 972.821 km
LOAD: 230 vol.
- Saarbrücken Hbf | 75 vol.
- Aachen Hbf | 30 vol.
- Köln Hbf | 40 vol.
- Düsseldorf Hbf | 85 vol.
LOAD: 395 vol.
- Dortmund Hbf | 25 vol.
- Osnabrück Hbf | 20 vol.
- Bremen Hbf | 55 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 95 vol.
- Berlin Hbf | 30 vol.
- Dresden Hbf | 25 vol.
- Leipzig Hbf | 45 vol.
LOAD: 395 vol.
- Würzburg Hbf | 55 vol.
- Nürnberg Hbf | 25 vol.
- München Hbf | 40 vol.
- Ulm Hbf | 80 vol.
- Stuttgart Hbf | 80 vol.
- Mannheim Hbf | 25 vol.
- Mainz Hbf | 55 vol.
- Frankfurt Hbf | 35 vol.
LOAD: 230 vol.
- Saarbrücken Hbf | 75 vol.
- Aachen Hbf | 30 vol.
- Köln Hbf | 40 vol.
- Düsseldorf Hbf | 85 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: 1020 vol. | Vehicle capacity: 400 vol. Loads: [0, 30, 85, 35, 0, 30, 80, 25, 100, 40, 55, 45, 25, 25, 0, 80, 40, 25, 95, 55, 55, 75, 20, 0] ITERATION Generation: #1 Best cost: 4848.916 | Path: [0, 1, 7, 11, 13, 20, 3, 19, 17, 6, 12, 0, 22, 10, 8, 18, 16, 2, 0, 5, 21, 15, 9, 0] Best cost: 4823.014 | Path: [0, 2, 16, 5, 12, 22, 10, 8, 1, 0, 3, 19, 17, 6, 15, 9, 13, 20, 0, 11, 7, 18, 21, 0] Best cost: 4111.524 | Path: [0, 3, 19, 17, 21, 6, 15, 9, 0, 22, 10, 8, 18, 1, 7, 11, 13, 0, 12, 2, 16, 5, 20, 0] Best cost: 3853.515 | Path: [0, 7, 11, 1, 18, 8, 10, 22, 12, 0, 3, 19, 17, 6, 15, 9, 13, 20, 0, 2, 16, 5, 21, 0] Best cost: 3762.888 | Path: [0, 11, 7, 1, 18, 8, 10, 22, 12, 0, 3, 19, 17, 6, 15, 9, 13, 20, 0, 2, 16, 5, 21, 0] Best cost: 3747.311 | Path: [0, 11, 7, 1, 8, 18, 10, 22, 12, 0, 20, 13, 9, 15, 6, 17, 19, 3, 0, 2, 16, 5, 21, 0] OPTIMIZING each tour... Current: [[0, 11, 7, 1, 8, 18, 10, 22, 12, 0], [0, 20, 13, 9, 15, 6, 17, 19, 3, 0], [0, 2, 16, 5, 21, 0]] [1] Cost: 1589.587 to 1557.274 | Optimized: [0, 12, 22, 10, 8, 18, 1, 7, 11, 0] [3] Cost: 976.507 to 972.821 | Optimized: [0, 21, 5, 16, 2, 0] ACO RESULTS [1/395 vol./1557.274 km] Kassel-Wilhelmshöhe -> Dortmund Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [2/395 vol./1181.217 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Mannheim Hbf -> Mainz Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe [3/230 vol./ 972.821 km] Kassel-Wilhelmshöhe -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3711.312 km.