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: 17 customers
- Düsseldorf Hbf (40 vol.)
- Frankfurt Hbf (75 vol.)
- Stuttgart Hbf (95 vol.)
- Dresden Hbf (40 vol.)
- Hamburg Hbf (75 vol.)
- Bremen Hbf (40 vol.)
- Leipzig Hbf (100 vol.)
- Dortmund Hbf (20 vol.)
- Nürnberg Hbf (30 vol.)
- Karlsruhe Hbf (50 vol.)
- Ulm Hbf (50 vol.)
- Mannheim Hbf (55 vol.)
- Mainz Hbf (100 vol.)
- Würzburg Hbf (100 vol.)
- Saarbrücken Hbf (100 vol.)
- Osnabrück Hbf (60 vol.)
- Freiburg Hbf (65 vol.)
Tour 1
COST: 1740.202 km
LOAD: 290 vol.
- Ulm Hbf | 50 vol.
- Stuttgart Hbf | 95 vol.
- Karlsruhe Hbf | 50 vol.
- Freiburg Hbf | 65 vol.
- Nürnberg Hbf | 30 vol.
Tour 2
COST: 1441.629 km
LOAD: 295 vol.
- Mannheim Hbf | 55 vol.
- Würzburg Hbf | 100 vol.
- Leipzig Hbf | 100 vol.
- Dresden Hbf | 40 vol.
Tour 3
COST: 1261.592 km
LOAD: 235 vol.
- Dortmund Hbf | 20 vol.
- Düsseldorf Hbf | 40 vol.
- Osnabrück Hbf | 60 vol.
- Bremen Hbf | 40 vol.
- Hamburg Hbf | 75 vol.
Tour 4
COST: 1457.258 km
LOAD: 275 vol.
- Saarbrücken Hbf | 100 vol.
- Mainz Hbf | 100 vol.
- Frankfurt Hbf | 75 vol.
LOAD: 290 vol.
- Ulm Hbf | 50 vol.
- Stuttgart Hbf | 95 vol.
- Karlsruhe Hbf | 50 vol.
- Freiburg Hbf | 65 vol.
- Nürnberg Hbf | 30 vol.
LOAD: 295 vol.
- Mannheim Hbf | 55 vol.
- Würzburg Hbf | 100 vol.
- Leipzig Hbf | 100 vol.
- Dresden Hbf | 40 vol.
LOAD: 235 vol.
- Dortmund Hbf | 20 vol.
- Düsseldorf Hbf | 40 vol.
- Osnabrück Hbf | 60 vol.
- Bremen Hbf | 40 vol.
- Hamburg Hbf | 75 vol.
LOAD: 275 vol.
- Saarbrücken Hbf | 100 vol.
- Mainz Hbf | 100 vol.
- Frankfurt 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: 1095 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 40, 75, 0, 0, 95, 40, 75, 0, 40, 100, 20, 30, 50, 50, 0, 55, 0, 100, 100, 100, 60, 65] ITERATION Generation: #1 Best cost: 6583.594 | Path: [1, 2, 12, 22, 10, 8, 17, 1, 11, 7, 13, 20, 1, 3, 19, 21, 1, 15, 6, 14, 23, 1] Best cost: 6503.285 | Path: [1, 3, 19, 17, 14, 12, 1, 7, 11, 13, 20, 1, 8, 10, 22, 2, 23, 1, 6, 15, 21, 1] Best cost: 6320.515 | Path: [1, 6, 14, 17, 3, 12, 1, 7, 11, 13, 20, 1, 8, 10, 22, 2, 15, 1, 19, 21, 23, 1] Best cost: 6228.238 | Path: [1, 7, 11, 13, 20, 12, 1, 8, 10, 22, 2, 3, 1, 15, 6, 14, 17, 1, 19, 21, 23, 1] Best cost: 6038.340 | Path: [1, 8, 10, 22, 12, 2, 17, 1, 11, 7, 13, 20, 1, 3, 19, 21, 1, 23, 14, 6, 15, 1] Best cost: 6032.029 | Path: [1, 21, 23, 14, 17, 13, 1, 11, 7, 20, 15, 1, 8, 10, 22, 12, 2, 1, 19, 3, 6, 1] Best cost: 6006.569 | Path: [1, 8, 10, 22, 12, 2, 17, 1, 7, 11, 13, 20, 1, 15, 6, 14, 23, 1, 3, 19, 21, 1] Best cost: 5962.586 | Path: [1, 23, 14, 6, 15, 13, 1, 11, 7, 20, 17, 1, 8, 10, 22, 12, 2, 1, 3, 19, 21, 1] OPTIMIZING each tour... Current: [[1, 23, 14, 6, 15, 13, 1], [1, 11, 7, 20, 17, 1], [1, 8, 10, 22, 12, 2, 1], [1, 3, 19, 21, 1]] [1] Cost: 1745.751 to 1740.202 | Optimized: [1, 15, 6, 14, 23, 13, 1] [2] Cost: 1478.093 to 1441.629 | Optimized: [1, 17, 20, 11, 7, 1] [3] Cost: 1280.860 to 1261.592 | Optimized: [1, 12, 2, 22, 10, 8, 1] [4] Cost: 1457.882 to 1457.258 | Optimized: [1, 21, 19, 3, 1] ACO RESULTS [1/290 vol./1740.202 km] Berlin Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Nürnberg Hbf --> Berlin Hbf [2/295 vol./1441.629 km] Berlin Hbf -> Mannheim Hbf -> Würzburg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/235 vol./1261.592 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [4/275 vol./1457.258 km] Berlin Hbf -> Saarbrücken Hbf -> Mainz Hbf -> Frankfurt Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5900.681 km.