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: 19 customers
- Kassel-Wilhelmshöhe (45 vol.)
- Düsseldorf Hbf (20 vol.)
- Frankfurt Hbf (55 vol.)
- Hannover Hbf (75 vol.)
- Aachen Hbf (40 vol.)
- Stuttgart Hbf (85 vol.)
- Dresden Hbf (50 vol.)
- Hamburg Hbf (55 vol.)
- München Hbf (45 vol.)
- Bremen Hbf (45 vol.)
- Leipzig Hbf (95 vol.)
- Dortmund Hbf (60 vol.)
- Karlsruhe Hbf (20 vol.)
- Köln Hbf (30 vol.)
- Mannheim Hbf (100 vol.)
- Mainz Hbf (20 vol.)
- Würzburg Hbf (85 vol.)
- Saarbrücken Hbf (65 vol.)
- Freiburg Hbf (90 vol.)
Tour 1
COST: 1670.636 km
LOAD: 290 vol.
- Frankfurt Hbf | 55 vol.
- Mainz Hbf | 20 vol.
- Saarbrücken Hbf | 65 vol.
- Aachen Hbf | 40 vol.
- Köln Hbf | 30 vol.
- Düsseldorf Hbf | 20 vol.
- Dortmund Hbf | 60 vol.
Tour 2
COST: 1715.93 km
LOAD: 295 vol.
- Dresden Hbf | 50 vol.
- Leipzig Hbf | 95 vol.
- München Hbf | 45 vol.
- Stuttgart Hbf | 85 vol.
- Karlsruhe Hbf | 20 vol.
Tour 3
COST: 1096.949 km
LOAD: 220 vol.
- Kassel-Wilhelmshöhe | 45 vol.
- Hannover Hbf | 75 vol.
- Bremen Hbf | 45 vol.
- Hamburg Hbf | 55 vol.
Tour 4
COST: 1619.053 km
LOAD: 275 vol.
- Mannheim Hbf | 100 vol.
- Freiburg Hbf | 90 vol.
- Würzburg Hbf | 85 vol.
LOAD: 290 vol.
- Frankfurt Hbf | 55 vol.
- Mainz Hbf | 20 vol.
- Saarbrücken Hbf | 65 vol.
- Aachen Hbf | 40 vol.
- Köln Hbf | 30 vol.
- Düsseldorf Hbf | 20 vol.
- Dortmund Hbf | 60 vol.
LOAD: 295 vol.
- Dresden Hbf | 50 vol.
- Leipzig Hbf | 95 vol.
- München Hbf | 45 vol.
- Stuttgart Hbf | 85 vol.
- Karlsruhe Hbf | 20 vol.
LOAD: 220 vol.
- Kassel-Wilhelmshöhe | 45 vol.
- Hannover Hbf | 75 vol.
- Bremen Hbf | 45 vol.
- Hamburg Hbf | 55 vol.
LOAD: 275 vol.
- Mannheim Hbf | 100 vol.
- Freiburg Hbf | 90 vol.
- Würzburg Hbf | 85 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: 1080 vol. | Vehicle capacity: 300 vol. Loads: [45, 0, 20, 55, 75, 40, 85, 50, 55, 45, 45, 95, 60, 0, 20, 0, 30, 100, 0, 20, 85, 65, 0, 90] ITERATION Generation: #1 Best cost: 6654.545 | Path: [1, 0, 12, 2, 16, 5, 19, 3, 14, 1, 11, 7, 4, 10, 1, 8, 17, 21, 9, 1, 20, 6, 23, 1] Best cost: 6581.316 | Path: [1, 4, 10, 8, 12, 2, 16, 1, 11, 7, 20, 3, 1, 0, 17, 14, 6, 19, 1, 9, 23, 21, 5, 1] Best cost: 6493.220 | Path: [1, 6, 14, 17, 19, 3, 2, 1, 11, 7, 9, 20, 1, 8, 10, 4, 0, 12, 1, 16, 5, 21, 23, 1] Best cost: 6414.693 | Path: [1, 3, 19, 17, 14, 6, 2, 1, 7, 11, 4, 8, 1, 10, 12, 16, 5, 20, 1, 0, 21, 23, 9, 1] Best cost: 6341.911 | Path: [1, 9, 6, 14, 17, 19, 2, 1, 7, 11, 4, 8, 1, 10, 12, 16, 5, 21, 3, 1, 0, 20, 23, 1] Best cost: 6247.698 | Path: [1, 12, 2, 16, 5, 21, 19, 3, 1, 7, 11, 9, 6, 14, 1, 4, 10, 8, 0, 1, 17, 23, 20, 1] OPTIMIZING each tour... Current: [[1, 12, 2, 16, 5, 21, 19, 3, 1], [1, 7, 11, 9, 6, 14, 1], [1, 4, 10, 8, 0, 1], [1, 17, 23, 20, 1]] [1] Cost: 1671.737 to 1670.636 | Optimized: [1, 3, 19, 21, 5, 16, 2, 12, 1] [3] Cost: 1240.978 to 1096.949 | Optimized: [1, 0, 4, 10, 8, 1] ACO RESULTS [1/290 vol./1670.636 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf -> Dortmund Hbf --> Berlin Hbf [2/295 vol./1715.930 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> München Hbf -> Stuttgart Hbf -> Karlsruhe Hbf --> Berlin Hbf [3/220 vol./1096.949 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [4/275 vol./1619.053 km] Berlin Hbf -> Mannheim Hbf -> Freiburg Hbf -> Würzburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6102.568 km.