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: 21 customers
- Düsseldorf Hbf (45 vol.)
- Frankfurt Hbf (75 vol.)
- Hannover Hbf (65 vol.)
- Aachen Hbf (40 vol.)
- Stuttgart Hbf (65 vol.)
- Dresden Hbf (20 vol.)
- München Hbf (55 vol.)
- Bremen Hbf (50 vol.)
- Leipzig Hbf (50 vol.)
- Dortmund Hbf (95 vol.)
- Nürnberg Hbf (20 vol.)
- Karlsruhe Hbf (95 vol.)
- Ulm Hbf (90 vol.)
- Köln Hbf (40 vol.)
- Mannheim Hbf (60 vol.)
- Kiel Hbf (90 vol.)
- Mainz Hbf (50 vol.)
- Würzburg Hbf (60 vol.)
- Saarbrücken Hbf (35 vol.)
- Osnabrück Hbf (20 vol.)
- Freiburg Hbf (75 vol.)
Tour 1
COST: 1390.776 km
LOAD: 400 vol.
- Nürnberg Hbf | 20 vol.
- München Hbf | 55 vol.
- Ulm Hbf | 90 vol.
- Stuttgart Hbf | 65 vol.
- Karlsruhe Hbf | 95 vol.
- Freiburg Hbf | 75 vol.
Tour 2
COST: 1131.233 km
LOAD: 400 vol.
- Frankfurt Hbf | 75 vol.
- Mainz Hbf | 50 vol.
- Saarbrücken Hbf | 35 vol.
- Aachen Hbf | 40 vol.
- Köln Hbf | 40 vol.
- Düsseldorf Hbf | 45 vol.
- Dortmund Hbf | 95 vol.
- Osnabrück Hbf | 20 vol.
Tour 3
COST: 1947.342 km
LOAD: 395 vol.
- Hannover Hbf | 65 vol.
- Bremen Hbf | 50 vol.
- Kiel Hbf | 90 vol.
- Leipzig Hbf | 50 vol.
- Dresden Hbf | 20 vol.
- Würzburg Hbf | 60 vol.
- Mannheim Hbf | 60 vol.
LOAD: 400 vol.
- Nürnberg Hbf | 20 vol.
- München Hbf | 55 vol.
- Ulm Hbf | 90 vol.
- Stuttgart Hbf | 65 vol.
- Karlsruhe Hbf | 95 vol.
- Freiburg Hbf | 75 vol.
LOAD: 400 vol.
- Frankfurt Hbf | 75 vol.
- Mainz Hbf | 50 vol.
- Saarbrücken Hbf | 35 vol.
- Aachen Hbf | 40 vol.
- Köln Hbf | 40 vol.
- Düsseldorf Hbf | 45 vol.
- Dortmund Hbf | 95 vol.
- Osnabrück Hbf | 20 vol.
LOAD: 395 vol.
- Hannover Hbf | 65 vol.
- Bremen Hbf | 50 vol.
- Kiel Hbf | 90 vol.
- Leipzig Hbf | 50 vol.
- Dresden Hbf | 20 vol.
- Würzburg Hbf | 60 vol.
- Mannheim Hbf | 60 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: 1195 vol. | Vehicle capacity: 400 vol. Loads: [0, 0, 45, 75, 65, 40, 65, 20, 0, 55, 50, 50, 95, 20, 95, 90, 40, 60, 90, 50, 60, 35, 20, 75] ITERATION Generation: #1 Best cost: 5673.649 | Path: [0, 2, 16, 5, 12, 22, 10, 4, 7, 13, 0, 3, 19, 17, 14, 6, 21, 0, 20, 15, 9, 23, 11, 0, 18, 0] Best cost: 5439.462 | Path: [0, 3, 19, 17, 14, 6, 9, 0, 12, 2, 16, 5, 22, 10, 4, 7, 13, 0, 20, 15, 23, 21, 11, 18, 0] Best cost: 5439.186 | Path: [0, 5, 16, 2, 12, 22, 10, 4, 7, 13, 0, 3, 19, 17, 14, 6, 9, 0, 20, 15, 23, 21, 11, 18, 0] Best cost: 5289.285 | Path: [0, 6, 15, 9, 13, 20, 3, 21, 0, 12, 16, 2, 5, 19, 17, 11, 7, 0, 4, 10, 22, 18, 14, 23, 0] Best cost: 5105.236 | Path: [0, 11, 7, 13, 20, 6, 14, 17, 22, 0, 4, 10, 18, 12, 2, 16, 0, 3, 19, 21, 23, 15, 9, 0, 5, 0] Best cost: 4781.474 | Path: [0, 23, 14, 6, 15, 9, 13, 0, 12, 2, 16, 5, 19, 3, 21, 22, 0, 4, 10, 18, 7, 11, 20, 17, 0] Best cost: 4739.896 | Path: [0, 16, 2, 12, 22, 10, 4, 11, 7, 0, 20, 13, 9, 15, 6, 14, 0, 3, 19, 17, 23, 21, 5, 0, 18, 0] Generation: #3 Best cost: 4655.896 | Path: [0, 23, 14, 6, 15, 9, 13, 0, 12, 2, 16, 5, 21, 19, 3, 22, 0, 4, 10, 18, 11, 7, 20, 17, 0] OPTIMIZING each tour... Current: [[0, 23, 14, 6, 15, 9, 13, 0], [0, 12, 2, 16, 5, 21, 19, 3, 22, 0], [0, 4, 10, 18, 11, 7, 20, 17, 0]] [1] Cost: 1405.998 to 1390.776 | Optimized: [0, 13, 9, 15, 6, 14, 23, 0] [2] Cost: 1302.556 to 1131.233 | Optimized: [0, 3, 19, 21, 5, 16, 2, 12, 22, 0] ACO RESULTS [1/400 vol./1390.776 km] Kassel-Wilhelmshöhe -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Kassel-Wilhelmshöhe [2/400 vol./1131.233 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Osnabrück Hbf --> Kassel-Wilhelmshöhe [3/395 vol./1947.342 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Bremen Hbf -> Kiel Hbf -> Leipzig Hbf -> Dresden Hbf -> Würzburg Hbf -> Mannheim Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 4469.351 km.