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: 20 customers
- Berlin Hbf (90 vol.)
- Hannover Hbf (100 vol.)
- Aachen Hbf (100 vol.)
- Stuttgart Hbf (60 vol.)
- Dresden Hbf (100 vol.)
- München Hbf (40 vol.)
- Bremen Hbf (75 vol.)
- Leipzig Hbf (90 vol.)
- Dortmund Hbf (35 vol.)
- Nürnberg Hbf (100 vol.)
- Karlsruhe Hbf (50 vol.)
- Ulm Hbf (65 vol.)
- Köln Hbf (80 vol.)
- Mannheim Hbf (45 vol.)
- Kiel Hbf (100 vol.)
- Mainz Hbf (100 vol.)
- Würzburg Hbf (60 vol.)
- Saarbrücken Hbf (100 vol.)
- Osnabrück Hbf (55 vol.)
- Freiburg Hbf (35 vol.)
Tour 1
COST: 1047.518 km
LOAD: 380 vol.
- Hannover Hbf | 100 vol.
- Berlin Hbf | 90 vol.
- Dresden Hbf | 100 vol.
- Leipzig Hbf | 90 vol.
Tour 2
COST: 1265.901 km
LOAD: 400 vol.
- Karlsruhe Hbf | 50 vol.
- Freiburg Hbf | 35 vol.
- Saarbrücken Hbf | 100 vol.
- Aachen Hbf | 100 vol.
- Köln Hbf | 80 vol.
- Dortmund Hbf | 35 vol.
Tour 3
COST: 1132.374 km
LOAD: 370 vol.
- Würzburg Hbf | 60 vol.
- Nürnberg Hbf | 100 vol.
- München Hbf | 40 vol.
- Ulm Hbf | 65 vol.
- Stuttgart Hbf | 60 vol.
- Mannheim Hbf | 45 vol.
Tour 4
COST: 1344.684 km
LOAD: 330 vol.
- Mainz Hbf | 100 vol.
- Osnabrück Hbf | 55 vol.
- Bremen Hbf | 75 vol.
- Kiel Hbf | 100 vol.
LOAD: 380 vol.
- Hannover Hbf | 100 vol.
- Berlin Hbf | 90 vol.
- Dresden Hbf | 100 vol.
- Leipzig Hbf | 90 vol.
LOAD: 400 vol.
- Karlsruhe Hbf | 50 vol.
- Freiburg Hbf | 35 vol.
- Saarbrücken Hbf | 100 vol.
- Aachen Hbf | 100 vol.
- Köln Hbf | 80 vol.
- Dortmund Hbf | 35 vol.
LOAD: 370 vol.
- Würzburg Hbf | 60 vol.
- Nürnberg Hbf | 100 vol.
- München Hbf | 40 vol.
- Ulm Hbf | 65 vol.
- Stuttgart Hbf | 60 vol.
- Mannheim Hbf | 45 vol.
LOAD: 330 vol.
- Mainz Hbf | 100 vol.
- Osnabrück Hbf | 55 vol.
- Bremen Hbf | 75 vol.
- Kiel Hbf | 100 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: 1480 vol. | Vehicle capacity: 400 vol. Loads: [0, 90, 0, 0, 100, 100, 60, 100, 0, 40, 75, 90, 35, 100, 50, 65, 80, 45, 100, 100, 60, 100, 55, 35] ITERATION Generation: #1 Best cost: 5740.120 | Path: [0, 1, 11, 7, 13, 0, 4, 10, 22, 12, 16, 17, 0, 19, 14, 6, 15, 9, 20, 0, 5, 21, 23, 18, 0] Best cost: 5404.862 | Path: [0, 4, 10, 22, 12, 16, 14, 0, 20, 13, 6, 15, 9, 17, 0, 19, 21, 23, 5, 0, 11, 7, 1, 18, 0] Best cost: 5375.330 | Path: [0, 6, 14, 17, 19, 16, 12, 0, 20, 13, 9, 15, 21, 23, 0, 22, 10, 4, 11, 0, 5, 18, 1, 7, 0] Best cost: 5334.626 | Path: [0, 9, 15, 6, 14, 17, 19, 23, 0, 22, 4, 10, 18, 12, 0, 16, 5, 21, 20, 0, 11, 7, 1, 13, 0] Best cost: 5158.629 | Path: [0, 10, 4, 22, 12, 16, 17, 0, 20, 13, 9, 15, 6, 14, 0, 5, 19, 21, 23, 0, 11, 7, 1, 18, 0] Best cost: 5038.452 | Path: [0, 4, 10, 22, 12, 16, 17, 0, 20, 13, 9, 15, 6, 14, 0, 19, 21, 23, 5, 0, 11, 7, 1, 18, 0] Best cost: 5002.721 | Path: [0, 17, 14, 6, 15, 9, 13, 23, 0, 4, 10, 22, 12, 16, 0, 20, 19, 21, 5, 0, 11, 7, 1, 18, 0] Best cost: 4952.177 | Path: [0, 20, 13, 9, 15, 6, 14, 0, 12, 16, 5, 21, 17, 23, 0, 4, 22, 10, 18, 0, 19, 11, 7, 1, 0] Generation: #2 Best cost: 4817.239 | Path: [0, 20, 13, 9, 15, 6, 14, 0, 19, 17, 21, 23, 5, 0, 12, 16, 22, 10, 4, 0, 11, 7, 1, 18, 0] Generation: #3 Best cost: 4797.581 | Path: [0, 11, 7, 1, 4, 0, 12, 16, 5, 21, 23, 14, 0, 20, 13, 9, 15, 6, 17, 0, 22, 10, 18, 19, 0] OPTIMIZING each tour... Current: [[0, 11, 7, 1, 4, 0], [0, 12, 16, 5, 21, 23, 14, 0], [0, 20, 13, 9, 15, 6, 17, 0], [0, 22, 10, 18, 19, 0]] [1] Cost: 1048.114 to 1047.518 | Optimized: [0, 4, 1, 7, 11, 0] [2] Cost: 1270.394 to 1265.901 | Optimized: [0, 14, 23, 21, 5, 16, 12, 0] [4] Cost: 1346.699 to 1344.684 | Optimized: [0, 19, 22, 10, 18, 0] ACO RESULTS [1/380 vol./1047.518 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [2/400 vol./1265.901 km] Kassel-Wilhelmshöhe -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Dortmund Hbf --> Kassel-Wilhelmshöhe [3/370 vol./1132.374 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Mannheim Hbf --> Kassel-Wilhelmshöhe [4/330 vol./1344.684 km] Kassel-Wilhelmshöhe -> Mainz Hbf -> Osnabrück Hbf -> Bremen Hbf -> Kiel Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4790.477 km.