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 (80 vol.)
- Düsseldorf Hbf (90 vol.)
- Frankfurt Hbf (90 vol.)
- Hannover Hbf (30 vol.)
- Aachen Hbf (60 vol.)
- Stuttgart Hbf (80 vol.)
- Dresden Hbf (35 vol.)
- München Hbf (55 vol.)
- Bremen Hbf (65 vol.)
- Leipzig Hbf (35 vol.)
- Dortmund Hbf (55 vol.)
- Nürnberg Hbf (75 vol.)
- Karlsruhe Hbf (95 vol.)
- Ulm Hbf (55 vol.)
- Köln Hbf (35 vol.)
- Mannheim Hbf (75 vol.)
- Mainz Hbf (45 vol.)
- Würzburg Hbf (85 vol.)
- Saarbrücken Hbf (20 vol.)
- Osnabrück Hbf (40 vol.)
- Freiburg Hbf (25 vol.)
Tour 1
COST: 1280.025 km
LOAD: 400 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 95 vol.
- Freiburg Hbf | 25 vol.
- Saarbrücken Hbf | 20 vol.
- Aachen Hbf | 60 vol.
- Köln Hbf | 35 vol.
- Düsseldorf Hbf | 90 vol.
Tour 2
COST: 1157.722 km
LOAD: 395 vol.
- Würzburg Hbf | 85 vol.
- Nürnberg Hbf | 75 vol.
- München Hbf | 55 vol.
- Ulm Hbf | 55 vol.
- Stuttgart Hbf | 80 vol.
- Mainz Hbf | 45 vol.
Tour 3
COST: 1392.298 km
LOAD: 340 vol.
- Dortmund Hbf | 55 vol.
- Osnabrück Hbf | 40 vol.
- Bremen Hbf | 65 vol.
- Hannover Hbf | 30 vol.
- Berlin Hbf | 80 vol.
- Dresden Hbf | 35 vol.
- Leipzig Hbf | 35 vol.
Tour 4
COST: 399.342 km
LOAD: 90 vol.
- Frankfurt Hbf | 90 vol.
LOAD: 400 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 95 vol.
- Freiburg Hbf | 25 vol.
- Saarbrücken Hbf | 20 vol.
- Aachen Hbf | 60 vol.
- Köln Hbf | 35 vol.
- Düsseldorf Hbf | 90 vol.
LOAD: 395 vol.
- Würzburg Hbf | 85 vol.
- Nürnberg Hbf | 75 vol.
- München Hbf | 55 vol.
- Ulm Hbf | 55 vol.
- Stuttgart Hbf | 80 vol.
- Mainz Hbf | 45 vol.
LOAD: 340 vol.
- Dortmund Hbf | 55 vol.
- Osnabrück Hbf | 40 vol.
- Bremen Hbf | 65 vol.
- Hannover Hbf | 30 vol.
- Berlin Hbf | 80 vol.
- Dresden Hbf | 35 vol.
- Leipzig Hbf | 35 vol.
LOAD: 90 vol.
- Frankfurt Hbf | 90 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: 1225 vol. | Vehicle capacity: 400 vol. Loads: [0, 80, 90, 90, 30, 60, 80, 35, 0, 55, 65, 35, 55, 75, 95, 55, 35, 75, 0, 45, 85, 20, 40, 25] ITERATION Generation: #1 Best cost: 5624.364 | Path: [0, 1, 11, 7, 4, 10, 22, 12, 16, 21, 0, 3, 19, 17, 14, 6, 0, 2, 5, 20, 13, 9, 23, 0, 15, 0] Best cost: 5487.627 | Path: [0, 2, 16, 5, 12, 22, 4, 10, 21, 0, 3, 19, 17, 14, 6, 0, 20, 13, 9, 15, 23, 11, 7, 0, 1, 0] Best cost: 5430.735 | Path: [0, 3, 19, 17, 14, 6, 0, 12, 2, 16, 5, 22, 10, 4, 21, 0, 20, 13, 9, 15, 23, 11, 7, 0, 1, 0] Best cost: 4875.270 | Path: [0, 4, 10, 22, 12, 2, 16, 5, 21, 0, 20, 13, 9, 15, 6, 19, 0, 3, 17, 14, 23, 7, 11, 0, 1, 0] Best cost: 4839.037 | Path: [0, 3, 19, 17, 14, 6, 0, 22, 12, 2, 16, 5, 21, 23, 15, 0, 4, 10, 1, 7, 11, 13, 9, 0, 20, 0] Best cost: 4759.212 | Path: [0, 12, 2, 16, 5, 21, 17, 19, 0, 22, 10, 4, 1, 7, 11, 13, 23, 0, 3, 14, 6, 15, 9, 0, 20, 0] Best cost: 4739.334 | Path: [0, 20, 13, 9, 15, 6, 23, 21, 0, 12, 2, 16, 5, 22, 10, 4, 0, 3, 19, 17, 14, 11, 7, 0, 1, 0] Best cost: 4641.445 | Path: [0, 14, 17, 19, 3, 20, 0, 11, 7, 1, 4, 22, 12, 2, 16, 0, 5, 21, 23, 6, 15, 9, 13, 0, 10, 0] Best cost: 4591.597 | Path: [0, 11, 7, 1, 4, 22, 12, 2, 16, 0, 3, 19, 17, 14, 6, 0, 20, 13, 9, 15, 23, 21, 5, 0, 10, 0] Generation: #2 Best cost: 4447.923 | Path: [0, 2, 16, 5, 21, 17, 14, 23, 0, 20, 13, 9, 15, 6, 19, 0, 12, 22, 10, 4, 11, 7, 1, 0, 3, 0] OPTIMIZING each tour... Current: [[0, 2, 16, 5, 21, 17, 14, 23, 0], [0, 20, 13, 9, 15, 6, 19, 0], [0, 12, 22, 10, 4, 11, 7, 1, 0], [0, 3, 0]] [1] Cost: 1396.563 to 1280.025 | Optimized: [0, 17, 14, 23, 21, 5, 16, 2, 0] [3] Cost: 1494.296 to 1392.298 | Optimized: [0, 12, 22, 10, 4, 1, 7, 11, 0] ACO RESULTS [1/400 vol./1280.025 km] Kassel-Wilhelmshöhe -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf --> Kassel-Wilhelmshöhe [2/395 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 [3/340 vol./1392.298 km] Kassel-Wilhelmshöhe -> Dortmund Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hannover Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [4/ 90 vol./ 399.342 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4229.387 km.