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 (60 vol.)
- Frankfurt Hbf (70 vol.)
- Hannover Hbf (75 vol.)
- Aachen Hbf (90 vol.)
- Stuttgart Hbf (50 vol.)
- Dresden Hbf (25 vol.)
- Hamburg Hbf (45 vol.)
- München Hbf (55 vol.)
- Leipzig Hbf (70 vol.)
- Dortmund Hbf (85 vol.)
- Karlsruhe Hbf (30 vol.)
- Ulm Hbf (35 vol.)
- Köln Hbf (50 vol.)
- Kiel Hbf (75 vol.)
- Würzburg Hbf (20 vol.)
- Saarbrücken Hbf (60 vol.)
- Osnabrück Hbf (65 vol.)
Tour 1
COST: 1779.962 km
LOAD: 300 vol.
- München Hbf | 55 vol.
- Ulm Hbf | 35 vol.
- Stuttgart Hbf | 50 vol.
- Karlsruhe Hbf | 30 vol.
- Saarbrücken Hbf | 60 vol.
- Frankfurt Hbf | 70 vol.
Tour 2
COST: 1534.127 km
LOAD: 260 vol.
- Dortmund Hbf | 85 vol.
- Düsseldorf Hbf | 60 vol.
- Würzburg Hbf | 20 vol.
- Leipzig Hbf | 70 vol.
- Dresden Hbf | 25 vol.
Tour 3
COST: 1336.654 km
LOAD: 280 vol.
- Aachen Hbf | 90 vol.
- Köln Hbf | 50 vol.
- Osnabrück Hbf | 65 vol.
- Hannover Hbf | 75 vol.
Tour 4
COST: 732.557 km
LOAD: 120 vol.
- Hamburg Hbf | 45 vol.
- Kiel Hbf | 75 vol.
LOAD: 300 vol.
- München Hbf | 55 vol.
- Ulm Hbf | 35 vol.
- Stuttgart Hbf | 50 vol.
- Karlsruhe Hbf | 30 vol.
- Saarbrücken Hbf | 60 vol.
- Frankfurt Hbf | 70 vol.
LOAD: 260 vol.
- Dortmund Hbf | 85 vol.
- Düsseldorf Hbf | 60 vol.
- Würzburg Hbf | 20 vol.
- Leipzig Hbf | 70 vol.
- Dresden Hbf | 25 vol.
LOAD: 280 vol.
- Aachen Hbf | 90 vol.
- Köln Hbf | 50 vol.
- Osnabrück Hbf | 65 vol.
- Hannover Hbf | 75 vol.
LOAD: 120 vol.
- Hamburg Hbf | 45 vol.
- Kiel 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: 960 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 60, 70, 75, 90, 50, 25, 45, 55, 0, 70, 85, 0, 30, 35, 50, 0, 75, 0, 20, 60, 65, 0] ITERATION Generation: #1 Best cost: 6863.275 | Path: [1, 2, 16, 5, 12, 1, 7, 11, 4, 22, 8, 20, 1, 18, 3, 14, 6, 15, 1, 9, 21, 1] Best cost: 6596.256 | Path: [1, 3, 20, 6, 15, 14, 21, 7, 1, 11, 4, 22, 12, 1, 8, 18, 2, 16, 9, 1, 5, 1] Best cost: 6207.362 | Path: [1, 4, 22, 12, 2, 1, 7, 11, 20, 3, 14, 6, 15, 1, 8, 18, 16, 5, 1, 9, 21, 1] Best cost: 5958.785 | Path: [1, 5, 2, 16, 12, 1, 7, 11, 20, 3, 14, 6, 15, 1, 8, 18, 4, 22, 1, 9, 21, 1] Best cost: 5620.410 | Path: [1, 9, 15, 6, 14, 3, 20, 7, 1, 11, 4, 8, 18, 1, 22, 12, 2, 16, 1, 5, 21, 1] Best cost: 5617.621 | Path: [1, 20, 3, 14, 6, 15, 9, 7, 1, 11, 4, 8, 18, 1, 22, 12, 2, 16, 1, 5, 21, 1] Best cost: 5613.661 | Path: [1, 20, 3, 14, 6, 15, 9, 7, 1, 11, 4, 8, 18, 1, 22, 12, 2, 16, 1, 21, 5, 1] Best cost: 5486.934 | Path: [1, 9, 15, 6, 14, 21, 3, 1, 11, 7, 20, 4, 22, 8, 1, 12, 2, 16, 5, 1, 18, 1] Generation: #2 Best cost: 5486.122 | Path: [1, 9, 15, 6, 14, 21, 3, 1, 11, 7, 20, 12, 2, 1, 4, 22, 5, 16, 1, 8, 18, 1] OPTIMIZING each tour... Current: [[1, 9, 15, 6, 14, 21, 3, 1], [1, 11, 7, 20, 12, 2, 1], [1, 4, 22, 5, 16, 1], [1, 8, 18, 1]] [2] Cost: 1628.809 to 1534.127 | Optimized: [1, 12, 2, 20, 11, 7, 1] [3] Cost: 1344.794 to 1336.654 | Optimized: [1, 5, 16, 22, 4, 1] ACO RESULTS [1/300 vol./1779.962 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Saarbrücken Hbf -> Frankfurt Hbf --> Berlin Hbf [2/260 vol./1534.127 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Würzburg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/280 vol./1336.654 km] Berlin Hbf -> Aachen Hbf -> Köln Hbf -> Osnabrück Hbf -> Hannover Hbf --> Berlin Hbf [4/120 vol./ 732.557 km] Berlin Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5383.300 km.