
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
- Kassel-Wilhelmshöhe (95 vol.)
- Düsseldorf Hbf (55 vol.)
- Frankfurt Hbf (50 vol.)
- Aachen Hbf (60 vol.)
- Dresden Hbf (75 vol.)
- Hamburg Hbf (85 vol.)
- München Hbf (80 vol.)
- Bremen Hbf (20 vol.)
- Leipzig Hbf (100 vol.)
- Dortmund Hbf (65 vol.)
- Nürnberg Hbf (75 vol.)
- Karlsruhe Hbf (45 vol.)
- Ulm Hbf (55 vol.)
- Köln Hbf (25 vol.)
- Mannheim Hbf (100 vol.)
- Würzburg Hbf (65 vol.)
- Freiburg Hbf (20 vol.)
Tour 1
COST: 1837.188 km
LOAD: 300 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 55 vol.
- Karlsruhe Hbf | 45 vol.
- Freiburg Hbf | 20 vol.
- Mannheim Hbf | 100 vol.
Tour 2
COST: 1079.707 km
LOAD: 280 vol.
- Dresden Hbf | 75 vol.
- Leipzig Hbf | 100 vol.
- Bremen Hbf | 20 vol.
- Hamburg Hbf | 85 vol.
Tour 3
COST: 1370.534 km
LOAD: 300 vol.
- Dortmund Hbf | 65 vol.
- Düsseldorf Hbf | 55 vol.
- Köln Hbf | 25 vol.
- Aachen Hbf | 60 vol.
- Kassel-Wilhelmshöhe | 95 vol.
Tour 4
COST: 1209.291 km
LOAD: 190 vol.
- Frankfurt Hbf | 50 vol.
- Würzburg Hbf | 65 vol.
- Nürnberg Hbf | 75 vol.

LOAD: 300 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 55 vol.
- Karlsruhe Hbf | 45 vol.
- Freiburg Hbf | 20 vol.
- Mannheim Hbf | 100 vol.

LOAD: 280 vol.
- Dresden Hbf | 75 vol.
- Leipzig Hbf | 100 vol.
- Bremen Hbf | 20 vol.
- Hamburg Hbf | 85 vol.

LOAD: 300 vol.
- Dortmund Hbf | 65 vol.
- Düsseldorf Hbf | 55 vol.
- Köln Hbf | 25 vol.
- Aachen Hbf | 60 vol.
- Kassel-Wilhelmshöhe | 95 vol.

LOAD: 190 vol.
- Frankfurt Hbf | 50 vol.
- Würzburg Hbf | 65 vol.
- Nürnberg 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: 1070 vol. | Vehicle capacity: 300 vol. Loads: [95, 0, 55, 50, 0, 60, 0, 75, 85, 80, 20, 100, 65, 75, 45, 55, 25, 100, 0, 0, 65, 0, 0, 20] ITERATION Generation: #1 Best cost: 6117.195 | Path: [1, 0, 12, 2, 16, 5, 1, 11, 7, 13, 3, 1, 8, 10, 17, 14, 23, 1, 20, 15, 9, 1] Best cost: 6111.465 | Path: [1, 7, 11, 0, 16, 1, 8, 10, 12, 2, 5, 1, 13, 20, 17, 14, 1, 9, 15, 23, 3, 1] Best cost: 5971.581 | Path: [1, 0, 12, 2, 16, 5, 1, 7, 11, 3, 20, 1, 8, 10, 17, 14, 23, 1, 13, 9, 15, 1] Best cost: 5774.871 | Path: [1, 17, 14, 23, 15, 9, 1, 7, 11, 0, 10, 1, 8, 12, 2, 16, 5, 1, 13, 20, 3, 1] Best cost: 5618.498 | Path: [1, 9, 15, 14, 17, 23, 1, 7, 11, 10, 8, 1, 12, 2, 16, 5, 0, 1, 13, 20, 3, 1] Generation: #2 Best cost: 5556.134 | Path: [1, 17, 14, 23, 15, 9, 1, 7, 11, 10, 8, 1, 0, 12, 2, 16, 5, 1, 20, 3, 13, 1] OPTIMIZING each tour... Current: [[1, 17, 14, 23, 15, 9, 1], [1, 7, 11, 10, 8, 1], [1, 0, 12, 2, 16, 5, 1], [1, 20, 3, 13, 1]] [1] Cost: 1840.654 to 1837.188 | Optimized: [1, 9, 15, 14, 23, 17, 1] [3] Cost: 1372.044 to 1370.534 | Optimized: [1, 12, 2, 16, 5, 0, 1] [4] Cost: 1263.729 to 1209.291 | Optimized: [1, 3, 20, 13, 1] ACO RESULTS [1/300 vol./1837.188 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Mannheim Hbf --> Berlin Hbf [2/280 vol./1079.707 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [3/300 vol./1370.534 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [4/190 vol./1209.291 km] Berlin Hbf -> Frankfurt Hbf -> Würzburg Hbf -> Nürnberg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5496.720 km.