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: 18 customers
- Kassel-Wilhelmshöhe (80 vol.)
- Düsseldorf Hbf (100 vol.)
- Frankfurt Hbf (40 vol.)
- Aachen Hbf (45 vol.)
- Stuttgart Hbf (35 vol.)
- Hamburg Hbf (75 vol.)
- München Hbf (80 vol.)
- Bremen Hbf (70 vol.)
- Leipzig Hbf (45 vol.)
- Nürnberg Hbf (65 vol.)
- Karlsruhe Hbf (40 vol.)
- Ulm Hbf (40 vol.)
- Köln Hbf (90 vol.)
- Mannheim Hbf (100 vol.)
- Kiel Hbf (20 vol.)
- Mainz Hbf (90 vol.)
- Würzburg Hbf (80 vol.)
- Freiburg Hbf (90 vol.)
Tour 1
COST: 1483.067 km
LOAD: 295 vol.
- Kassel-Wilhelmshöhe | 80 vol.
- Frankfurt Hbf | 40 vol.
- Mainz Hbf | 90 vol.
- Karlsruhe Hbf | 40 vol.
- Leipzig Hbf | 45 vol.
Tour 2
COST: 1606.11 km
LOAD: 300 vol.
- Kiel Hbf | 20 vol.
- Hamburg Hbf | 75 vol.
- Bremen Hbf | 70 vol.
- Köln Hbf | 90 vol.
- Aachen Hbf | 45 vol.
Tour 3
COST: 1465.585 km
LOAD: 300 vol.
- Nürnberg Hbf | 65 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 40 vol.
- Stuttgart Hbf | 35 vol.
- Würzburg Hbf | 80 vol.
Tour 4
COST: 1836.547 km
LOAD: 290 vol.
- Düsseldorf Hbf | 100 vol.
- Mannheim Hbf | 100 vol.
- Freiburg Hbf | 90 vol.
LOAD: 295 vol.
- Kassel-Wilhelmshöhe | 80 vol.
- Frankfurt Hbf | 40 vol.
- Mainz Hbf | 90 vol.
- Karlsruhe Hbf | 40 vol.
- Leipzig Hbf | 45 vol.
LOAD: 300 vol.
- Kiel Hbf | 20 vol.
- Hamburg Hbf | 75 vol.
- Bremen Hbf | 70 vol.
- Köln Hbf | 90 vol.
- Aachen Hbf | 45 vol.
LOAD: 300 vol.
- Nürnberg Hbf | 65 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 40 vol.
- Stuttgart Hbf | 35 vol.
- Würzburg Hbf | 80 vol.
LOAD: 290 vol.
- Düsseldorf Hbf | 100 vol.
- Mannheim Hbf | 100 vol.
- Freiburg Hbf | 90 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: 1185 vol. | Vehicle capacity: 300 vol. Loads: [80, 0, 100, 40, 0, 45, 35, 0, 75, 80, 70, 45, 0, 65, 40, 40, 90, 100, 20, 90, 80, 0, 0, 90] ITERATION Generation: #1 Best cost: 7581.277 | Path: [1, 0, 3, 19, 14, 6, 1, 11, 13, 20, 17, 1, 8, 18, 10, 16, 5, 1, 2, 23, 15, 1, 9, 1] Best cost: 7517.032 | Path: [1, 9, 15, 6, 14, 17, 1, 11, 13, 20, 3, 5, 18, 1, 8, 10, 0, 1, 19, 16, 2, 1, 23, 1] Best cost: 7516.663 | Path: [1, 23, 14, 17, 3, 18, 1, 11, 10, 8, 0, 1, 20, 13, 9, 15, 6, 1, 16, 2, 5, 1, 19, 1] Best cost: 6940.383 | Path: [1, 5, 16, 2, 3, 18, 1, 11, 0, 17, 14, 6, 1, 8, 10, 20, 13, 1, 9, 15, 19, 23, 1] Best cost: 6774.558 | Path: [1, 2, 16, 5, 3, 18, 1, 11, 0, 14, 17, 6, 1, 8, 10, 20, 13, 1, 9, 15, 23, 19, 1] Best cost: 6606.552 | Path: [1, 13, 20, 3, 19, 18, 1, 11, 0, 17, 14, 6, 1, 8, 10, 2, 5, 1, 9, 15, 23, 16, 1] Best cost: 6592.798 | Path: [1, 11, 0, 3, 19, 14, 1, 8, 18, 10, 16, 5, 1, 20, 13, 9, 15, 6, 1, 17, 23, 2, 1] Best cost: 6496.948 | Path: [1, 11, 0, 3, 19, 14, 1, 8, 18, 10, 16, 5, 1, 13, 20, 6, 15, 9, 1, 17, 23, 2, 1] Best cost: 6492.294 | Path: [1, 11, 0, 3, 19, 14, 1, 8, 18, 10, 16, 5, 1, 13, 20, 6, 15, 9, 1, 2, 17, 23, 1] Generation: #2 Best cost: 6481.465 | Path: [1, 18, 8, 10, 16, 5, 1, 11, 0, 3, 19, 14, 1, 13, 20, 6, 15, 9, 1, 2, 17, 23, 1] Generation: #8 Best cost: 6448.822 | Path: [1, 11, 0, 3, 19, 14, 1, 8, 18, 10, 16, 5, 1, 20, 6, 15, 9, 13, 1, 17, 23, 2, 1] OPTIMIZING each tour... Current: [[1, 11, 0, 3, 19, 14, 1], [1, 8, 18, 10, 16, 5, 1], [1, 20, 6, 15, 9, 13, 1], [1, 17, 23, 2, 1]] [1] Cost: 1512.318 to 1483.067 | Optimized: [1, 0, 3, 19, 14, 11, 1] [2] Cost: 1616.939 to 1606.110 | Optimized: [1, 18, 8, 10, 16, 5, 1] [3] Cost: 1478.364 to 1465.585 | Optimized: [1, 13, 9, 15, 6, 20, 1] [4] Cost: 1841.201 to 1836.547 | Optimized: [1, 2, 17, 23, 1] ACO RESULTS [1/295 vol./1483.067 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mainz Hbf -> Karlsruhe Hbf -> Leipzig Hbf --> Berlin Hbf [2/300 vol./1606.110 km] Berlin Hbf -> Kiel Hbf -> Hamburg Hbf -> Bremen Hbf -> Köln Hbf -> Aachen Hbf --> Berlin Hbf [3/300 vol./1465.585 km] Berlin Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Würzburg Hbf --> Berlin Hbf [4/290 vol./1836.547 km] Berlin Hbf -> Düsseldorf Hbf -> Mannheim Hbf -> Freiburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6391.309 km.