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
- Berlin Hbf (90 vol.)
- Düsseldorf Hbf (35 vol.)
- Frankfurt Hbf (100 vol.)
- Stuttgart Hbf (50 vol.)
- Dresden Hbf (45 vol.)
- Hamburg Hbf (40 vol.)
- München Hbf (55 vol.)
- Bremen Hbf (50 vol.)
- Leipzig Hbf (25 vol.)
- Dortmund Hbf (30 vol.)
- Nürnberg Hbf (95 vol.)
- Karlsruhe Hbf (100 vol.)
- Ulm Hbf (95 vol.)
- Köln Hbf (50 vol.)
- Mannheim Hbf (20 vol.)
- Kiel Hbf (35 vol.)
- Mainz Hbf (25 vol.)
- Würzburg Hbf (55 vol.)
- Saarbrücken Hbf (80 vol.)
- Osnabrück Hbf (100 vol.)
- Freiburg Hbf (80 vol.)
Tour 1
COST: 1217.225 km
LOAD: 395 vol.
- Dortmund Hbf | 30 vol.
- Düsseldorf Hbf | 35 vol.
- Köln Hbf | 50 vol.
- Saarbrücken Hbf | 80 vol.
- Freiburg Hbf | 80 vol.
- Karlsruhe Hbf | 100 vol.
- Mannheim Hbf | 20 vol.
Tour 2
COST: 1446.531 km
LOAD: 385 vol.
- Osnabrück Hbf | 100 vol.
- Bremen Hbf | 50 vol.
- Hamburg Hbf | 40 vol.
- Kiel Hbf | 35 vol.
- Berlin Hbf | 90 vol.
- Dresden Hbf | 45 vol.
- Leipzig Hbf | 25 vol.
Tour 3
COST: 1157.722 km
LOAD: 375 vol.
- Würzburg Hbf | 55 vol.
- Nürnberg Hbf | 95 vol.
- München Hbf | 55 vol.
- Ulm Hbf | 95 vol.
- Stuttgart Hbf | 50 vol.
- Mainz Hbf | 25 vol.
Tour 4
COST: 399.342 km
LOAD: 100 vol.
- Frankfurt Hbf | 100 vol.
LOAD: 395 vol.
- Dortmund Hbf | 30 vol.
- Düsseldorf Hbf | 35 vol.
- Köln Hbf | 50 vol.
- Saarbrücken Hbf | 80 vol.
- Freiburg Hbf | 80 vol.
- Karlsruhe Hbf | 100 vol.
- Mannheim Hbf | 20 vol.
LOAD: 385 vol.
- Osnabrück Hbf | 100 vol.
- Bremen Hbf | 50 vol.
- Hamburg Hbf | 40 vol.
- Kiel Hbf | 35 vol.
- Berlin Hbf | 90 vol.
- Dresden Hbf | 45 vol.
- Leipzig Hbf | 25 vol.
LOAD: 375 vol.
- Würzburg Hbf | 55 vol.
- Nürnberg Hbf | 95 vol.
- München Hbf | 55 vol.
- Ulm Hbf | 95 vol.
- Stuttgart Hbf | 50 vol.
- Mainz Hbf | 25 vol.
LOAD: 100 vol.
- Frankfurt 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: 1255 vol. | Vehicle capacity: 400 vol. Loads: [0, 90, 35, 100, 0, 0, 50, 45, 40, 55, 50, 25, 30, 95, 100, 95, 50, 20, 35, 25, 55, 80, 100, 80] ITERATION Generation: #1 Best cost: 5578.568 | Path: [0, 1, 7, 11, 13, 20, 19, 17, 12, 0, 22, 10, 8, 18, 16, 2, 21, 0, 3, 14, 6, 15, 9, 0, 23, 0] Best cost: 5433.105 | Path: [0, 2, 16, 12, 22, 10, 8, 18, 11, 19, 0, 3, 17, 14, 6, 15, 0, 20, 13, 9, 21, 23, 0, 7, 1, 0] Best cost: 5339.817 | Path: [0, 3, 19, 17, 14, 6, 15, 0, 22, 10, 8, 18, 12, 2, 16, 20, 0, 11, 7, 1, 13, 9, 23, 0, 21, 0] Best cost: 5113.656 | Path: [0, 6, 15, 14, 17, 19, 3, 0, 22, 10, 8, 18, 1, 11, 7, 0, 12, 2, 16, 23, 21, 13, 0, 20, 9, 0] Best cost: 4665.362 | Path: [0, 7, 11, 1, 18, 8, 10, 22, 0, 12, 2, 16, 3, 19, 17, 14, 0, 20, 13, 9, 15, 6, 0, 21, 23, 0] Best cost: 4584.519 | Path: [0, 11, 7, 1, 8, 18, 10, 22, 0, 12, 2, 16, 3, 19, 17, 14, 0, 20, 13, 9, 15, 6, 0, 23, 21, 0] Best cost: 4544.557 | Path: [0, 22, 10, 8, 18, 1, 7, 11, 0, 12, 2, 16, 19, 3, 17, 14, 0, 20, 13, 9, 15, 6, 0, 21, 23, 0] Best cost: 4516.432 | Path: [0, 3, 19, 17, 14, 6, 15, 0, 20, 13, 9, 23, 21, 2, 0, 22, 10, 8, 18, 1, 7, 11, 0, 12, 16, 0] Best cost: 4382.774 | Path: [0, 20, 13, 9, 15, 6, 17, 19, 0, 3, 14, 23, 21, 12, 0, 22, 10, 8, 18, 1, 11, 7, 0, 16, 2, 0] Generation: #4 Best cost: 4380.839 | Path: [0, 20, 13, 9, 15, 6, 17, 19, 0, 3, 14, 23, 21, 2, 0, 22, 10, 8, 18, 1, 11, 7, 0, 12, 16, 0] Best cost: 4285.827 | Path: [0, 20, 13, 9, 15, 6, 17, 19, 0, 3, 14, 23, 21, 2, 0, 22, 10, 8, 18, 1, 7, 11, 0, 12, 16, 0] Generation: #8 Best cost: 4285.827 | Path: [0, 22, 10, 8, 18, 1, 7, 11, 0, 20, 13, 9, 15, 6, 17, 19, 0, 3, 14, 23, 21, 2, 0, 12, 16, 0] Generation: #9 Best cost: 4220.820 | Path: [0, 12, 2, 16, 21, 23, 14, 17, 0, 22, 10, 8, 18, 1, 7, 11, 0, 20, 13, 9, 15, 6, 19, 0, 3, 0] OPTIMIZING each tour... Current: [[0, 12, 2, 16, 21, 23, 14, 17, 0], [0, 22, 10, 8, 18, 1, 7, 11, 0], [0, 20, 13, 9, 15, 6, 19, 0], [0, 3, 0]] No changes made. ACO RESULTS [1/395 vol./1217.225 km] Kassel-Wilhelmshöhe -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Karlsruhe Hbf -> Mannheim Hbf --> Kassel-Wilhelmshöhe [2/385 vol./1446.531 km] Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [3/375 vol./1157.722 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Mainz Hbf --> Kassel-Wilhelmshöhe [4/100 vol./ 399.342 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4220.820 km.