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: 18 customers
- Berlin Hbf (55 vol.)
- Düsseldorf Hbf (45 vol.)
- Frankfurt Hbf (30 vol.)
- Hannover Hbf (50 vol.)
- Stuttgart Hbf (70 vol.)
- Dresden Hbf (20 vol.)
- Bremen Hbf (75 vol.)
- Leipzig Hbf (80 vol.)
- Dortmund Hbf (40 vol.)
- Nürnberg Hbf (75 vol.)
- Karlsruhe Hbf (45 vol.)
- Ulm Hbf (55 vol.)
- Mannheim Hbf (35 vol.)
- Kiel Hbf (65 vol.)
- Mainz Hbf (35 vol.)
- Würzburg Hbf (85 vol.)
- Saarbrücken Hbf (70 vol.)
- Osnabrück Hbf (90 vol.)
Tour 1
COST: 1072.008 km
LOAD: 400 vol.
- Würzburg Hbf | 85 vol.
- Nürnberg Hbf | 75 vol.
- Ulm Hbf | 55 vol.
- Stuttgart Hbf | 70 vol.
- Karlsruhe Hbf | 45 vol.
- Mannheim Hbf | 35 vol.
- Mainz Hbf | 35 vol.
Tour 2
COST: 1271.793 km
LOAD: 400 vol.
- Frankfurt Hbf | 30 vol.
- Saarbrücken Hbf | 70 vol.
- Düsseldorf Hbf | 45 vol.
- Dortmund Hbf | 40 vol.
- Osnabrück Hbf | 90 vol.
- Bremen Hbf | 75 vol.
- Hannover Hbf | 50 vol.
Tour 3
COST: 1355.175 km
LOAD: 220 vol.
- Kiel Hbf | 65 vol.
- Berlin Hbf | 55 vol.
- Dresden Hbf | 20 vol.
- Leipzig Hbf | 80 vol.
LOAD: 400 vol.
- Würzburg Hbf | 85 vol.
- Nürnberg Hbf | 75 vol.
- Ulm Hbf | 55 vol.
- Stuttgart Hbf | 70 vol.
- Karlsruhe Hbf | 45 vol.
- Mannheim Hbf | 35 vol.
- Mainz Hbf | 35 vol.
LOAD: 400 vol.
- Frankfurt Hbf | 30 vol.
- Saarbrücken Hbf | 70 vol.
- Düsseldorf Hbf | 45 vol.
- Dortmund Hbf | 40 vol.
- Osnabrück Hbf | 90 vol.
- Bremen Hbf | 75 vol.
- Hannover Hbf | 50 vol.
LOAD: 220 vol.
- Kiel Hbf | 65 vol.
- Berlin Hbf | 55 vol.
- Dresden Hbf | 20 vol.
- Leipzig Hbf | 80 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: 1020 vol. | Vehicle capacity: 400 vol. Loads: [0, 55, 45, 30, 50, 0, 70, 20, 0, 0, 75, 80, 40, 75, 45, 55, 0, 35, 65, 35, 85, 70, 90, 0] ITERATION Generation: #1 Best cost: 4538.622 | Path: [0, 1, 11, 7, 13, 20, 3, 19, 0, 12, 2, 22, 10, 4, 18, 17, 0, 14, 6, 15, 21, 0] Best cost: 4429.673 | Path: [0, 3, 19, 17, 14, 6, 15, 13, 7, 0, 12, 2, 22, 10, 4, 18, 0, 20, 21, 11, 1, 0] Best cost: 4289.514 | Path: [0, 10, 22, 12, 2, 19, 3, 17, 14, 0, 4, 18, 1, 7, 11, 13, 15, 0, 20, 6, 21, 0] Best cost: 4053.292 | Path: [0, 15, 6, 14, 17, 3, 19, 21, 2, 0, 22, 12, 4, 10, 18, 1, 7, 0, 20, 13, 11, 0] Best cost: 3972.273 | Path: [0, 22, 10, 4, 12, 2, 19, 3, 17, 0, 20, 13, 6, 15, 14, 21, 0, 11, 7, 1, 18, 0] Best cost: 3813.813 | Path: [0, 4, 10, 22, 12, 2, 19, 3, 17, 0, 20, 13, 15, 6, 14, 21, 0, 11, 7, 1, 18, 0] Best cost: 3725.945 | Path: [0, 4, 10, 22, 12, 2, 21, 3, 0, 19, 17, 14, 6, 15, 13, 20, 0, 11, 7, 1, 18, 0] Best cost: 3704.120 | Path: [0, 20, 13, 15, 6, 14, 17, 19, 0, 3, 21, 2, 12, 22, 10, 4, 0, 11, 7, 1, 18, 0] OPTIMIZING each tour... Current: [[0, 20, 13, 15, 6, 14, 17, 19, 0], [0, 3, 21, 2, 12, 22, 10, 4, 0], [0, 11, 7, 1, 18, 0]] [3] Cost: 1360.319 to 1355.175 | Optimized: [0, 18, 1, 7, 11, 0] ACO RESULTS [1/400 vol./1072.008 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Mannheim Hbf -> Mainz Hbf --> Kassel-Wilhelmshöhe [2/400 vol./1271.793 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Saarbrücken Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hannover Hbf --> Kassel-Wilhelmshöhe [3/220 vol./1355.175 km] Kassel-Wilhelmshöhe -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3698.976 km.