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: 300 vol.
ACTIVE: 20 customers
- Kassel-Wilhelmshöhe (90 vol.)
- Düsseldorf Hbf (25 vol.)
- Frankfurt Hbf (90 vol.)
- Hannover Hbf (55 vol.)
- Aachen Hbf (100 vol.)
- Stuttgart Hbf (55 vol.)
- Dresden Hbf (90 vol.)
- Hamburg Hbf (60 vol.)
- Leipzig Hbf (80 vol.)
- Dortmund Hbf (65 vol.)
- Nürnberg Hbf (75 vol.)
- Karlsruhe Hbf (90 vol.)
- Ulm Hbf (85 vol.)
- Köln Hbf (55 vol.)
- Mannheim Hbf (100 vol.)
- Kiel Hbf (25 vol.)
- Mainz Hbf (55 vol.)
- Würzburg Hbf (90 vol.)
- Saarbrücken Hbf (95 vol.)
- Freiburg Hbf (45 vol.)
Tour 1
COST: 1430.419 km
LOAD: 300 vol.
- Mainz Hbf | 55 vol.
- Mannheim Hbf | 100 vol.
- Karlsruhe Hbf | 90 vol.
- Stuttgart Hbf | 55 vol.
Tour 2
COST: 1007.951 km
LOAD: 285 vol.
- Dresden Hbf | 90 vol.
- Leipzig Hbf | 80 vol.
- Hannover Hbf | 55 vol.
- Hamburg Hbf | 60 vol.
Tour 3
COST: 1598.675 km
LOAD: 270 vol.
- Dortmund Hbf | 65 vol.
- Düsseldorf Hbf | 25 vol.
- Köln Hbf | 55 vol.
- Aachen Hbf | 100 vol.
- Kiel Hbf | 25 vol.
Tour 4
COST: 1190.918 km
LOAD: 270 vol.
- Kassel-Wilhelmshöhe | 90 vol.
- Frankfurt Hbf | 90 vol.
- Würzburg Hbf | 90 vol.
Tour 5
COST: 1845.66 km
LOAD: 300 vol.
- Saarbrücken Hbf | 95 vol.
- Freiburg Hbf | 45 vol.
- Ulm Hbf | 85 vol.
- Nürnberg Hbf | 75 vol.
LOAD: 300 vol.
- Mainz Hbf | 55 vol.
- Mannheim Hbf | 100 vol.
- Karlsruhe Hbf | 90 vol.
- Stuttgart Hbf | 55 vol.
LOAD: 285 vol.
- Dresden Hbf | 90 vol.
- Leipzig Hbf | 80 vol.
- Hannover Hbf | 55 vol.
- Hamburg Hbf | 60 vol.
LOAD: 270 vol.
- Dortmund Hbf | 65 vol.
- Düsseldorf Hbf | 25 vol.
- Köln Hbf | 55 vol.
- Aachen Hbf | 100 vol.
- Kiel Hbf | 25 vol.
LOAD: 270 vol.
- Kassel-Wilhelmshöhe | 90 vol.
- Frankfurt Hbf | 90 vol.
- Würzburg Hbf | 90 vol.
LOAD: 300 vol.
- Saarbrücken Hbf | 95 vol.
- Freiburg Hbf | 45 vol.
- Ulm Hbf | 85 vol.
- Nürnberg Hbf | 75 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: [1] Berlin Hbf | Number of cities: 24 | Total loads: 1425 vol. | Vehicle capacity: 300 vol. Loads: [90, 0, 25, 90, 55, 100, 55, 90, 60, 0, 0, 80, 65, 75, 90, 85, 55, 100, 25, 55, 90, 95, 0, 45] ITERATION Generation: #1 Best cost: 8463.504 | Path: [1, 0, 4, 8, 18, 2, 23, 1, 11, 7, 13, 6, 1, 12, 16, 5, 19, 1, 20, 3, 17, 1, 15, 14, 21, 1] Best cost: 7920.500 | Path: [1, 2, 16, 5, 12, 19, 1, 11, 7, 0, 18, 1, 8, 4, 20, 3, 1, 13, 6, 15, 23, 1, 17, 14, 21, 1] Best cost: 7886.515 | Path: [1, 8, 18, 4, 0, 12, 1, 11, 7, 13, 6, 1, 20, 3, 19, 16, 1, 2, 5, 17, 23, 1, 15, 14, 21, 1] Best cost: 7847.688 | Path: [1, 13, 20, 3, 2, 1, 11, 7, 4, 8, 1, 18, 0, 12, 16, 19, 1, 15, 6, 14, 23, 1, 5, 17, 21, 1] Best cost: 7780.285 | Path: [1, 18, 8, 4, 0, 12, 1, 7, 11, 20, 2, 1, 13, 6, 14, 23, 1, 16, 5, 19, 3, 1, 17, 21, 15, 1] Best cost: 7416.902 | Path: [1, 20, 19, 3, 6, 1, 7, 11, 4, 8, 1, 0, 12, 2, 16, 18, 1, 13, 15, 14, 23, 1, 5, 21, 17, 1] Best cost: 7329.315 | Path: [1, 12, 2, 16, 5, 19, 1, 7, 11, 4, 8, 1, 18, 0, 3, 20, 1, 15, 6, 14, 23, 1, 13, 17, 21, 1] Best cost: 7081.409 | Path: [1, 6, 14, 17, 19, 1, 7, 11, 4, 8, 1, 18, 12, 2, 16, 5, 1, 0, 3, 20, 1, 13, 15, 23, 21, 1] OPTIMIZING each tour... Current: [[1, 6, 14, 17, 19, 1], [1, 7, 11, 4, 8, 1], [1, 18, 12, 2, 16, 5, 1], [1, 0, 3, 20, 1], [1, 13, 15, 23, 21, 1]] [1] Cost: 1433.676 to 1430.419 | Optimized: [1, 19, 17, 14, 6, 1] [3] Cost: 1601.238 to 1598.675 | Optimized: [1, 12, 2, 16, 5, 18, 1] [5] Cost: 1847.626 to 1845.660 | Optimized: [1, 21, 23, 15, 13, 1] ACO RESULTS [1/300 vol./1430.419 km] Berlin Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf --> Berlin Hbf [2/285 vol./1007.951 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf -> Hamburg Hbf --> Berlin Hbf [3/270 vol./1598.675 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Kiel Hbf --> Berlin Hbf [4/270 vol./1190.918 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Würzburg Hbf --> Berlin Hbf [5/300 vol./1845.660 km] Berlin Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Ulm Hbf -> Nürnberg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 7073.623 km.