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 (70 vol.)
- Düsseldorf Hbf (30 vol.)
- Hannover Hbf (95 vol.)
- Aachen Hbf (30 vol.)
- Stuttgart Hbf (20 vol.)
- Dresden Hbf (90 vol.)
- München Hbf (80 vol.)
- Bremen Hbf (40 vol.)
- Leipzig Hbf (95 vol.)
- Dortmund Hbf (95 vol.)
- Karlsruhe Hbf (65 vol.)
- Ulm Hbf (80 vol.)
- Mannheim Hbf (45 vol.)
- Kiel Hbf (50 vol.)
- Mainz Hbf (50 vol.)
- Würzburg Hbf (40 vol.)
- Saarbrücken Hbf (20 vol.)
- Osnabrück Hbf (90 vol.)
- Freiburg Hbf (55 vol.)
Tour 1
COST: 1384.978 km
LOAD: 400 vol.
- Osnabrück Hbf | 90 vol.
- Bremen Hbf | 40 vol.
- Dortmund Hbf | 95 vol.
- Düsseldorf Hbf | 30 vol.
- Aachen Hbf | 30 vol.
- Saarbrücken Hbf | 20 vol.
- Mannheim Hbf | 45 vol.
- Mainz Hbf | 50 vol.
Tour 2
COST: 1362.303 km
LOAD: 400 vol.
- Hannover Hbf | 95 vol.
- Kiel Hbf | 50 vol.
- Berlin Hbf | 70 vol.
- Dresden Hbf | 90 vol.
- Leipzig Hbf | 95 vol.
Tour 3
COST: 1413.811 km
LOAD: 340 vol.
- Freiburg Hbf | 55 vol.
- Karlsruhe Hbf | 65 vol.
- Stuttgart Hbf | 20 vol.
- Ulm Hbf | 80 vol.
- München Hbf | 80 vol.
- Würzburg Hbf | 40 vol.
LOAD: 400 vol.
- Osnabrück Hbf | 90 vol.
- Bremen Hbf | 40 vol.
- Dortmund Hbf | 95 vol.
- Düsseldorf Hbf | 30 vol.
- Aachen Hbf | 30 vol.
- Saarbrücken Hbf | 20 vol.
- Mannheim Hbf | 45 vol.
- Mainz Hbf | 50 vol.
LOAD: 400 vol.
- Hannover Hbf | 95 vol.
- Kiel Hbf | 50 vol.
- Berlin Hbf | 70 vol.
- Dresden Hbf | 90 vol.
- Leipzig Hbf | 95 vol.
LOAD: 340 vol.
- Freiburg Hbf | 55 vol.
- Karlsruhe Hbf | 65 vol.
- Stuttgart Hbf | 20 vol.
- Ulm Hbf | 80 vol.
- München Hbf | 80 vol.
- Würzburg Hbf | 40 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: 1140 vol. | Vehicle capacity: 400 vol. Loads: [0, 70, 30, 0, 95, 30, 20, 90, 0, 80, 40, 95, 95, 0, 65, 80, 0, 45, 50, 50, 40, 20, 90, 55] ITERATION Generation: #1 Best cost: 5244.666 | Path: [0, 1, 7, 11, 4, 10, 0, 12, 2, 5, 19, 17, 14, 6, 20, 21, 0, 22, 18, 9, 15, 23, 0] Best cost: 5133.121 | Path: [0, 2, 5, 12, 22, 10, 4, 21, 0, 11, 7, 1, 18, 17, 19, 0, 20, 6, 14, 23, 15, 9, 0] Best cost: 4960.208 | Path: [0, 6, 14, 17, 19, 21, 23, 15, 20, 0, 2, 5, 12, 22, 10, 4, 0, 11, 7, 1, 18, 9, 0] Best cost: 4927.783 | Path: [0, 15, 6, 14, 17, 19, 21, 23, 20, 0, 12, 2, 5, 22, 10, 4, 0, 11, 7, 1, 18, 9, 0] Best cost: 4905.167 | Path: [0, 19, 17, 14, 6, 15, 9, 20, 21, 0, 4, 10, 22, 12, 2, 5, 0, 11, 7, 1, 18, 23, 0] Best cost: 4897.712 | Path: [0, 20, 19, 17, 14, 6, 15, 9, 21, 0, 4, 10, 22, 12, 2, 5, 0, 11, 7, 1, 18, 23, 0] Best cost: 4839.677 | Path: [0, 23, 14, 17, 19, 20, 6, 15, 21, 0, 12, 2, 5, 22, 10, 4, 0, 18, 1, 11, 7, 9, 0] Best cost: 4786.932 | Path: [0, 4, 10, 22, 12, 2, 5, 21, 0, 19, 17, 14, 6, 15, 9, 20, 0, 11, 7, 1, 18, 23, 0] Best cost: 4709.963 | Path: [0, 18, 10, 22, 12, 2, 5, 19, 0, 4, 11, 7, 1, 20, 0, 17, 14, 6, 15, 9, 21, 23, 0] Best cost: 4679.505 | Path: [0, 10, 22, 12, 2, 5, 17, 14, 0, 4, 18, 1, 11, 7, 0, 20, 6, 15, 9, 19, 21, 23, 0] Best cost: 4510.768 | Path: [0, 18, 10, 22, 12, 2, 5, 19, 0, 4, 1, 11, 7, 20, 0, 17, 14, 6, 15, 9, 23, 21, 0] Best cost: 4474.906 | Path: [0, 18, 10, 22, 12, 2, 5, 19, 0, 4, 1, 7, 11, 20, 0, 17, 14, 6, 15, 9, 23, 21, 0] Generation: #2 Best cost: 4341.662 | Path: [0, 10, 22, 12, 2, 5, 21, 17, 19, 0, 4, 18, 1, 11, 7, 0, 20, 6, 15, 9, 14, 23, 0] OPTIMIZING each tour... Current: [[0, 10, 22, 12, 2, 5, 21, 17, 19, 0], [0, 4, 18, 1, 11, 7, 0], [0, 20, 6, 15, 9, 14, 23, 0]] [1] Cost: 1403.315 to 1384.978 | Optimized: [0, 22, 10, 12, 2, 5, 21, 17, 19, 0] [2] Cost: 1457.315 to 1362.303 | Optimized: [0, 4, 18, 1, 7, 11, 0] [3] Cost: 1481.032 to 1413.811 | Optimized: [0, 23, 14, 6, 15, 9, 20, 0] ACO RESULTS [1/400 vol./1384.978 km] Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Bremen Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Saarbrücken Hbf -> Mannheim Hbf -> Mainz Hbf --> Kassel-Wilhelmshöhe [2/400 vol./1362.303 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [3/340 vol./1413.811 km] Kassel-Wilhelmshöhe -> Freiburg Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Ulm Hbf -> München Hbf -> Würzburg Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 4161.092 km.