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: 22 customers
- Kassel-Wilhelmshöhe (20 vol.)
- Düsseldorf Hbf (55 vol.)
- Frankfurt Hbf (95 vol.)
- Hannover Hbf (40 vol.)
- Aachen Hbf (70 vol.)
- Stuttgart Hbf (25 vol.)
- Dresden Hbf (25 vol.)
- Hamburg Hbf (85 vol.)
- München Hbf (85 vol.)
- Bremen Hbf (25 vol.)
- Leipzig Hbf (40 vol.)
- Dortmund Hbf (90 vol.)
- Nürnberg Hbf (100 vol.)
- Karlsruhe Hbf (70 vol.)
- Ulm Hbf (100 vol.)
- Köln Hbf (95 vol.)
- Mannheim Hbf (70 vol.)
- Kiel Hbf (25 vol.)
- Mainz Hbf (40 vol.)
- Würzburg Hbf (40 vol.)
- Saarbrücken Hbf (50 vol.)
- Freiburg Hbf (90 vol.)
Tour 1
COST: 1621.955 km
LOAD: 300 vol.
- München Hbf | 85 vol.
- Ulm Hbf | 100 vol.
- Stuttgart Hbf | 25 vol.
- Karlsruhe Hbf | 70 vol.
- Kassel-Wilhelmshöhe | 20 vol.
Tour 2
COST: 1371.845 km
LOAD: 300 vol.
- Frankfurt Hbf | 95 vol.
- Würzburg Hbf | 40 vol.
- Nürnberg Hbf | 100 vol.
- Leipzig Hbf | 40 vol.
- Dresden Hbf | 25 vol.
Tour 3
COST: 1391.824 km
LOAD: 265 vol.
- Dortmund Hbf | 90 vol.
- Hannover Hbf | 40 vol.
- Bremen Hbf | 25 vol.
- Hamburg Hbf | 85 vol.
- Kiel Hbf | 25 vol.
Tour 4
COST: 1782.98 km
LOAD: 250 vol.
- Mainz Hbf | 40 vol.
- Mannheim Hbf | 70 vol.
- Freiburg Hbf | 90 vol.
- Saarbrücken Hbf | 50 vol.
Tour 5
COST: 1303.404 km
LOAD: 220 vol.
- Aachen Hbf | 70 vol.
- Köln Hbf | 95 vol.
- Düsseldorf Hbf | 55 vol.
LOAD: 300 vol.
- München Hbf | 85 vol.
- Ulm Hbf | 100 vol.
- Stuttgart Hbf | 25 vol.
- Karlsruhe Hbf | 70 vol.
- Kassel-Wilhelmshöhe | 20 vol.
LOAD: 300 vol.
- Frankfurt Hbf | 95 vol.
- Würzburg Hbf | 40 vol.
- Nürnberg Hbf | 100 vol.
- Leipzig Hbf | 40 vol.
- Dresden Hbf | 25 vol.
LOAD: 265 vol.
- Dortmund Hbf | 90 vol.
- Hannover Hbf | 40 vol.
- Bremen Hbf | 25 vol.
- Hamburg Hbf | 85 vol.
- Kiel Hbf | 25 vol.
LOAD: 250 vol.
- Mainz Hbf | 40 vol.
- Mannheim Hbf | 70 vol.
- Freiburg Hbf | 90 vol.
- Saarbrücken Hbf | 50 vol.
LOAD: 220 vol.
- Aachen Hbf | 70 vol.
- Köln Hbf | 95 vol.
- Düsseldorf Hbf | 55 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: 1335 vol. | Vehicle capacity: 300 vol. Loads: [20, 0, 55, 95, 40, 70, 25, 25, 85, 85, 25, 40, 90, 100, 70, 100, 95, 70, 25, 40, 40, 50, 0, 90] ITERATION Generation: #1 Best cost: 8956.692 | Path: [1, 0, 11, 7, 19, 3, 17, 1, 8, 18, 4, 10, 12, 6, 1, 13, 20, 14, 21, 1, 15, 9, 23, 1, 2, 16, 5, 1] Best cost: 8559.897 | Path: [1, 2, 16, 5, 19, 20, 1, 7, 11, 0, 12, 4, 8, 1, 18, 10, 3, 17, 14, 1, 15, 6, 13, 21, 1, 9, 23, 1] Best cost: 8243.141 | Path: [1, 3, 19, 17, 14, 6, 1, 7, 11, 0, 12, 2, 5, 1, 4, 10, 8, 18, 16, 1, 13, 20, 15, 21, 1, 9, 23, 1] Best cost: 8167.271 | Path: [1, 5, 16, 2, 19, 20, 1, 11, 7, 13, 9, 6, 0, 1, 4, 10, 8, 18, 12, 1, 3, 17, 14, 21, 1, 15, 23, 1] Best cost: 7923.727 | Path: [1, 8, 18, 4, 10, 12, 0, 1, 11, 7, 13, 20, 3, 1, 19, 17, 14, 6, 9, 1, 2, 16, 5, 21, 1, 15, 23, 1] Best cost: 7751.775 | Path: [1, 15, 6, 14, 17, 0, 1, 11, 7, 13, 20, 3, 1, 8, 18, 10, 4, 12, 1, 2, 16, 5, 19, 1, 9, 23, 21, 1] Best cost: 7645.054 | Path: [1, 11, 7, 20, 6, 14, 17, 0, 1, 8, 18, 10, 4, 12, 1, 2, 16, 5, 19, 1, 13, 9, 15, 1, 3, 21, 23, 1] Best cost: 7612.906 | Path: [1, 18, 8, 10, 4, 0, 12, 1, 11, 7, 13, 20, 3, 1, 9, 15, 6, 14, 1, 19, 17, 23, 21, 1, 16, 2, 5, 1] Best cost: 7563.537 | Path: [1, 9, 15, 6, 14, 0, 1, 11, 7, 13, 20, 3, 1, 8, 18, 10, 4, 12, 1, 19, 17, 21, 23, 1, 5, 2, 16, 1] Generation: #3 Best cost: 7545.194 | Path: [1, 15, 6, 14, 17, 0, 1, 7, 11, 13, 20, 3, 1, 8, 18, 10, 4, 12, 1, 9, 23, 21, 19, 1, 2, 16, 5, 1] Best cost: 7544.331 | Path: [1, 9, 15, 6, 14, 0, 1, 11, 7, 13, 20, 3, 1, 8, 18, 10, 4, 12, 1, 19, 17, 21, 23, 1, 2, 16, 5, 1] OPTIMIZING each tour... Current: [[1, 9, 15, 6, 14, 0, 1], [1, 11, 7, 13, 20, 3, 1], [1, 8, 18, 10, 4, 12, 1], [1, 19, 17, 21, 23, 1], [1, 2, 16, 5, 1]] [2] Cost: 1403.375 to 1371.845 | Optimized: [1, 3, 20, 13, 11, 7, 1] [3] Cost: 1413.389 to 1391.824 | Optimized: [1, 12, 4, 10, 8, 18, 1] [4] Cost: 1801.357 to 1782.980 | Optimized: [1, 19, 17, 23, 21, 1] [5] Cost: 1304.255 to 1303.404 | Optimized: [1, 5, 16, 2, 1] ACO RESULTS [1/300 vol./1621.955 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [2/300 vol./1371.845 km] Berlin Hbf -> Frankfurt Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/265 vol./1391.824 km] Berlin Hbf -> Dortmund Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/250 vol./1782.980 km] Berlin Hbf -> Mainz Hbf -> Mannheim Hbf -> Freiburg Hbf -> Saarbrücken Hbf --> Berlin Hbf [5/220 vol./1303.404 km] Berlin Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 7472.008 km.