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: 19 customers
- Berlin Hbf (75 vol.)
- Düsseldorf Hbf (95 vol.)
- Frankfurt Hbf (100 vol.)
- Hannover Hbf (95 vol.)
- Aachen Hbf (45 vol.)
- Stuttgart Hbf (60 vol.)
- Dresden Hbf (55 vol.)
- Hamburg Hbf (80 vol.)
- München Hbf (75 vol.)
- Bremen Hbf (20 vol.)
- Dortmund Hbf (70 vol.)
- Nürnberg Hbf (95 vol.)
- Karlsruhe Hbf (50 vol.)
- Mannheim Hbf (20 vol.)
- Kiel Hbf (70 vol.)
- Mainz Hbf (55 vol.)
- Würzburg Hbf (60 vol.)
- Saarbrücken Hbf (60 vol.)
- Osnabrück Hbf (65 vol.)
Tour 1
COST: 1092.201 km
LOAD: 395 vol.
- Mainz Hbf | 55 vol.
- Mannheim Hbf | 20 vol.
- Karlsruhe Hbf | 50 vol.
- Saarbrücken Hbf | 60 vol.
- Aachen Hbf | 45 vol.
- Düsseldorf Hbf | 95 vol.
- Dortmund Hbf | 70 vol.
Tour 2
COST: 1114.595 km
LOAD: 390 vol.
- Würzburg Hbf | 60 vol.
- Nürnberg Hbf | 95 vol.
- München Hbf | 75 vol.
- Stuttgart Hbf | 60 vol.
- Frankfurt Hbf | 100 vol.
Tour 3
COST: 1440.283 km
LOAD: 395 vol.
- Hannover Hbf | 95 vol.
- Bremen Hbf | 20 vol.
- Hamburg Hbf | 80 vol.
- Kiel Hbf | 70 vol.
- Berlin Hbf | 75 vol.
- Dresden Hbf | 55 vol.
Tour 4
COST: 348.872 km
LOAD: 65 vol.
- Osnabrück Hbf | 65 vol.
LOAD: 395 vol.
- Mainz Hbf | 55 vol.
- Mannheim Hbf | 20 vol.
- Karlsruhe Hbf | 50 vol.
- Saarbrücken Hbf | 60 vol.
- Aachen Hbf | 45 vol.
- Düsseldorf Hbf | 95 vol.
- Dortmund Hbf | 70 vol.
LOAD: 390 vol.
- Würzburg Hbf | 60 vol.
- Nürnberg Hbf | 95 vol.
- München Hbf | 75 vol.
- Stuttgart Hbf | 60 vol.
- Frankfurt Hbf | 100 vol.
LOAD: 395 vol.
- Hannover Hbf | 95 vol.
- Bremen Hbf | 20 vol.
- Hamburg Hbf | 80 vol.
- Kiel Hbf | 70 vol.
- Berlin Hbf | 75 vol.
- Dresden Hbf | 55 vol.
LOAD: 65 vol.
- Osnabrück 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: 1245 vol. | Vehicle capacity: 400 vol. Loads: [0, 75, 95, 100, 95, 45, 60, 55, 80, 75, 20, 0, 70, 95, 50, 0, 0, 20, 70, 55, 60, 60, 65, 0] ITERATION Generation: #1 Best cost: 5505.681 | Path: [0, 1, 7, 13, 20, 3, 0, 12, 2, 5, 4, 10, 22, 0, 19, 17, 14, 6, 21, 9, 8, 0, 18, 0] Best cost: 5503.400 | Path: [0, 2, 12, 22, 10, 4, 5, 0, 8, 18, 7, 1, 13, 17, 0, 6, 14, 21, 19, 3, 20, 0, 9, 0] Best cost: 5279.753 | Path: [0, 4, 10, 22, 12, 2, 5, 0, 19, 3, 17, 14, 6, 20, 7, 0, 13, 9, 21, 8, 18, 0, 1, 0] Best cost: 5262.988 | Path: [0, 5, 2, 12, 22, 10, 4, 0, 3, 19, 17, 14, 6, 20, 7, 0, 8, 18, 21, 9, 13, 0, 1, 0] Best cost: 5177.942 | Path: [0, 6, 14, 17, 19, 3, 20, 5, 0, 12, 2, 22, 10, 8, 18, 0, 4, 7, 1, 13, 9, 0, 21, 0] Best cost: 5059.002 | Path: [0, 7, 1, 8, 18, 10, 22, 17, 0, 12, 2, 5, 20, 13, 0, 19, 3, 14, 6, 21, 9, 0, 4, 0] Best cost: 4955.153 | Path: [0, 8, 18, 10, 22, 12, 2, 0, 4, 1, 7, 13, 20, 17, 0, 19, 3, 14, 6, 21, 5, 0, 9, 0] Best cost: 4734.894 | Path: [0, 9, 13, 20, 3, 19, 0, 12, 2, 5, 21, 17, 14, 6, 0, 22, 10, 4, 8, 18, 7, 0, 1, 0] Best cost: 4717.944 | Path: [0, 12, 2, 5, 19, 3, 17, 0, 4, 10, 22, 8, 18, 7, 0, 20, 13, 9, 6, 14, 21, 0, 1, 0] Best cost: 4364.337 | Path: [0, 4, 10, 8, 18, 1, 7, 0, 20, 13, 9, 6, 14, 17, 0, 12, 2, 5, 19, 3, 0, 22, 21, 0] Best cost: 4243.568 | Path: [0, 7, 1, 4, 10, 8, 18, 0, 12, 2, 5, 3, 19, 17, 0, 20, 13, 9, 6, 14, 21, 0, 22, 0] Best cost: 4178.318 | Path: [0, 4, 10, 8, 18, 22, 12, 0, 20, 13, 9, 6, 14, 17, 0, 3, 19, 21, 5, 2, 0, 1, 7, 0] Best cost: 4156.237 | Path: [0, 9, 13, 20, 3, 19, 0, 4, 10, 8, 18, 1, 7, 0, 12, 2, 5, 21, 17, 14, 6, 0, 22, 0] Generation: #2 Best cost: 4047.905 | Path: [0, 4, 10, 8, 18, 1, 7, 0, 12, 2, 5, 19, 3, 17, 0, 20, 13, 9, 6, 14, 21, 0, 22, 0] Generation: #7 Best cost: 4047.905 | Path: [0, 12, 2, 5, 19, 3, 17, 0, 4, 10, 8, 18, 1, 7, 0, 20, 13, 9, 6, 14, 21, 0, 22, 0] Generation: #9 Best cost: 3996.260 | Path: [0, 12, 2, 5, 21, 14, 17, 19, 0, 20, 13, 9, 6, 3, 0, 4, 10, 8, 18, 1, 7, 0, 22, 0] OPTIMIZING each tour... Current: [[0, 12, 2, 5, 21, 14, 17, 19, 0], [0, 20, 13, 9, 6, 3, 0], [0, 4, 10, 8, 18, 1, 7, 0], [0, 22, 0]] [1] Cost: 1092.510 to 1092.201 | Optimized: [0, 19, 17, 14, 21, 5, 2, 12, 0] ACO RESULTS [1/395 vol./1092.201 km] Kassel-Wilhelmshöhe -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Dortmund Hbf --> Kassel-Wilhelmshöhe [2/390 vol./1114.595 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Stuttgart Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe [3/395 vol./1440.283 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf --> Kassel-Wilhelmshöhe [4/ 65 vol./ 348.872 km] Kassel-Wilhelmshöhe -> Osnabrück Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 3995.951 km.