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: 16 customers
- Düsseldorf Hbf (95 vol.)
- Frankfurt Hbf (55 vol.)
- Hannover Hbf (100 vol.)
- Dresden Hbf (90 vol.)
- München Hbf (55 vol.)
- Bremen Hbf (55 vol.)
- Leipzig Hbf (100 vol.)
- Dortmund Hbf (20 vol.)
- Nürnberg Hbf (55 vol.)
- Karlsruhe Hbf (40 vol.)
- Ulm Hbf (65 vol.)
- Köln Hbf (95 vol.)
- Mannheim Hbf (45 vol.)
- Kiel Hbf (65 vol.)
- Mainz Hbf (80 vol.)
- Freiburg Hbf (30 vol.)
Tour 1
COST: 1349.281 km
LOAD: 290 vol.
- Dortmund Hbf | 20 vol.
- Düsseldorf Hbf | 95 vol.
- Köln Hbf | 95 vol.
- Mainz Hbf | 80 vol.
Tour 2
COST: 858.167 km
LOAD: 290 vol.
- Dresden Hbf | 90 vol.
- Leipzig Hbf | 100 vol.
- Hannover Hbf | 100 vol.
Tour 3
COST: 2088.722 km
LOAD: 290 vol.
- Kiel Hbf | 65 vol.
- Bremen Hbf | 55 vol.
- Frankfurt Hbf | 55 vol.
- Mannheim Hbf | 45 vol.
- Karlsruhe Hbf | 40 vol.
- Freiburg Hbf | 30 vol.
Tour 4
COST: 1357.805 km
LOAD: 175 vol.
- München Hbf | 55 vol.
- Ulm Hbf | 65 vol.
- Nürnberg Hbf | 55 vol.
LOAD: 290 vol.
- Dortmund Hbf | 20 vol.
- Düsseldorf Hbf | 95 vol.
- Köln Hbf | 95 vol.
- Mainz Hbf | 80 vol.
LOAD: 290 vol.
- Dresden Hbf | 90 vol.
- Leipzig Hbf | 100 vol.
- Hannover Hbf | 100 vol.
LOAD: 290 vol.
- Kiel Hbf | 65 vol.
- Bremen Hbf | 55 vol.
- Frankfurt Hbf | 55 vol.
- Mannheim Hbf | 45 vol.
- Karlsruhe Hbf | 40 vol.
- Freiburg Hbf | 30 vol.
LOAD: 175 vol.
- München Hbf | 55 vol.
- Ulm Hbf | 65 vol.
- Nürnberg 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: 1045 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 95, 55, 100, 0, 0, 90, 0, 55, 55, 100, 20, 55, 40, 65, 95, 45, 65, 80, 0, 0, 0, 30] ITERATION Generation: #1 Best cost: 6437.213 | Path: [1, 2, 16, 12, 19, 1, 7, 11, 13, 9, 1, 4, 10, 18, 3, 1, 14, 17, 23, 15, 1] Best cost: 6414.892 | Path: [1, 3, 19, 17, 14, 23, 12, 1, 7, 11, 4, 1, 18, 10, 2, 15, 1, 13, 9, 16, 1] Best cost: 6112.690 | Path: [1, 4, 10, 18, 12, 3, 1, 11, 7, 13, 9, 1, 19, 17, 14, 23, 15, 1, 16, 2, 1] Best cost: 6061.087 | Path: [1, 7, 11, 4, 1, 18, 10, 12, 2, 17, 1, 13, 9, 15, 14, 3, 23, 1, 19, 16, 1] Best cost: 5963.409 | Path: [1, 18, 10, 4, 12, 3, 1, 11, 7, 13, 9, 1, 19, 17, 14, 23, 15, 1, 16, 2, 1] Best cost: 5885.848 | Path: [1, 11, 7, 4, 1, 18, 10, 12, 2, 3, 1, 13, 9, 15, 14, 17, 23, 1, 19, 16, 1] Best cost: 5786.652 | Path: [1, 7, 11, 4, 1, 18, 10, 12, 2, 3, 1, 13, 9, 15, 14, 17, 23, 1, 19, 16, 1] Best cost: 5723.775 | Path: [1, 13, 9, 15, 14, 17, 23, 1, 11, 7, 4, 1, 19, 3, 16, 12, 1, 18, 10, 2, 1] Best cost: 5700.800 | Path: [1, 13, 9, 15, 14, 17, 23, 1, 7, 11, 4, 1, 10, 12, 2, 16, 1, 18, 3, 19, 1] Best cost: 5696.628 | Path: [1, 7, 11, 4, 1, 18, 10, 12, 2, 3, 1, 16, 19, 17, 14, 23, 1, 13, 9, 15, 1] Best cost: 5662.491 | Path: [1, 12, 2, 16, 19, 1, 7, 11, 4, 1, 18, 10, 3, 17, 14, 23, 1, 13, 9, 15, 1] OPTIMIZING each tour... Current: [[1, 12, 2, 16, 19, 1], [1, 7, 11, 4, 1], [1, 18, 10, 3, 17, 14, 23, 1], [1, 13, 9, 15, 1]] [4] Cost: 1366.321 to 1357.805 | Optimized: [1, 9, 15, 13, 1] ACO RESULTS [1/290 vol./1349.281 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Mainz Hbf --> Berlin Hbf [2/290 vol./ 858.167 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf --> Berlin Hbf [3/290 vol./2088.722 km] Berlin Hbf -> Kiel Hbf -> Bremen Hbf -> Frankfurt Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Berlin Hbf [4/175 vol./1357.805 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Nürnberg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5653.975 km.