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 (85 vol.)
- Düsseldorf Hbf (65 vol.)
- Frankfurt Hbf (80 vol.)
- Hannover Hbf (80 vol.)
- Aachen Hbf (55 vol.)
- Stuttgart Hbf (75 vol.)
- Hamburg Hbf (75 vol.)
- Bremen Hbf (50 vol.)
- Leipzig Hbf (45 vol.)
- Nürnberg Hbf (100 vol.)
- Ulm Hbf (55 vol.)
- Köln Hbf (75 vol.)
- Mannheim Hbf (65 vol.)
- Kiel Hbf (95 vol.)
- Würzburg Hbf (40 vol.)
- Saarbrücken Hbf (80 vol.)
- Osnabrück Hbf (85 vol.)
- Freiburg Hbf (80 vol.)
Tour 1
COST: 937.097 km
LOAD: 385 vol.
- Hannover Hbf | 80 vol.
- Hamburg Hbf | 75 vol.
- Kiel Hbf | 95 vol.
- Bremen Hbf | 50 vol.
- Osnabrück Hbf | 85 vol.
Tour 2
COST: 1022.374 km
LOAD: 375 vol.
- Nürnberg Hbf | 100 vol.
- Ulm Hbf | 55 vol.
- Stuttgart Hbf | 75 vol.
- Mannheim Hbf | 65 vol.
- Frankfurt Hbf | 80 vol.
Tour 3
COST: 1345.459 km
LOAD: 395 vol.
- Düsseldorf Hbf | 65 vol.
- Köln Hbf | 75 vol.
- Aachen Hbf | 55 vol.
- Saarbrücken Hbf | 80 vol.
- Freiburg Hbf | 80 vol.
- Würzburg Hbf | 40 vol.
Tour 4
COST: 849.361 km
LOAD: 130 vol.
- Berlin Hbf | 85 vol.
- Leipzig Hbf | 45 vol.
LOAD: 385 vol.
- Hannover Hbf | 80 vol.
- Hamburg Hbf | 75 vol.
- Kiel Hbf | 95 vol.
- Bremen Hbf | 50 vol.
- Osnabrück Hbf | 85 vol.
LOAD: 375 vol.
- Nürnberg Hbf | 100 vol.
- Ulm Hbf | 55 vol.
- Stuttgart Hbf | 75 vol.
- Mannheim Hbf | 65 vol.
- Frankfurt Hbf | 80 vol.
LOAD: 395 vol.
- Düsseldorf Hbf | 65 vol.
- Köln Hbf | 75 vol.
- Aachen Hbf | 55 vol.
- Saarbrücken Hbf | 80 vol.
- Freiburg Hbf | 80 vol.
- Würzburg Hbf | 40 vol.
LOAD: 130 vol.
- Berlin Hbf | 85 vol.
- Leipzig Hbf | 45 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: 1285 vol. | Vehicle capacity: 400 vol. Loads: [0, 85, 65, 80, 80, 55, 75, 0, 75, 0, 50, 45, 0, 100, 0, 55, 75, 65, 95, 0, 40, 80, 85, 80] ITERATION Generation: #1 Best cost: 6015.823 | Path: [0, 1, 11, 4, 10, 22, 5, 0, 3, 17, 6, 15, 20, 21, 0, 2, 16, 13, 23, 8, 0, 18, 0] Best cost: 4307.407 | Path: [0, 2, 16, 5, 21, 17, 20, 0, 22, 10, 8, 18, 4, 0, 3, 13, 15, 6, 23, 0, 11, 1, 0] Best cost: 4300.562 | Path: [0, 10, 8, 18, 4, 22, 0, 3, 17, 6, 15, 13, 0, 2, 16, 5, 21, 23, 20, 0, 11, 1, 0] Best cost: 4237.283 | Path: [0, 3, 17, 6, 15, 13, 0, 4, 10, 8, 18, 22, 0, 2, 16, 5, 21, 23, 20, 0, 11, 1, 0] Best cost: 4184.681 | Path: [0, 3, 17, 6, 15, 13, 0, 22, 10, 8, 18, 4, 0, 16, 2, 5, 21, 23, 20, 0, 11, 1, 0] Generation: #2 Best cost: 4165.155 | Path: [0, 22, 10, 8, 18, 4, 0, 3, 17, 6, 15, 13, 0, 2, 16, 5, 21, 23, 20, 0, 11, 1, 0] Generation: #3 Best cost: 4158.417 | Path: [0, 4, 8, 18, 10, 22, 0, 3, 17, 6, 15, 13, 0, 2, 16, 5, 21, 23, 20, 0, 11, 1, 0] OPTIMIZING each tour... Current: [[0, 4, 8, 18, 10, 22, 0], [0, 3, 17, 6, 15, 13, 0], [0, 2, 16, 5, 21, 23, 20, 0], [0, 11, 1, 0]] [2] Cost: 1026.473 to 1022.374 | Optimized: [0, 13, 15, 6, 17, 3, 0] [4] Cost: 849.388 to 849.361 | Optimized: [0, 1, 11, 0] ACO RESULTS [1/385 vol./ 937.097 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Hamburg Hbf -> Kiel Hbf -> Bremen Hbf -> Osnabrück Hbf --> Kassel-Wilhelmshöhe [2/375 vol./1022.374 km] Kassel-Wilhelmshöhe -> Nürnberg Hbf -> Ulm Hbf -> Stuttgart Hbf -> Mannheim Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe [3/395 vol./1345.459 km] Kassel-Wilhelmshöhe -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Würzburg Hbf --> Kassel-Wilhelmshöhe [4/130 vol./ 849.361 km] Kassel-Wilhelmshöhe -> Berlin Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4154.291 km.