
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: 18 customers
- Berlin Hbf (20 vol.)
- Frankfurt Hbf (70 vol.)
- Hannover Hbf (45 vol.)
- Aachen Hbf (35 vol.)
- Stuttgart Hbf (20 vol.)
- Dresden Hbf (45 vol.)
- Hamburg Hbf (30 vol.)
- Bremen Hbf (35 vol.)
- Leipzig Hbf (50 vol.)
- Nürnberg Hbf (40 vol.)
- Karlsruhe Hbf (20 vol.)
- Ulm Hbf (40 vol.)
- Köln Hbf (45 vol.)
- Mannheim Hbf (75 vol.)
- Kiel Hbf (20 vol.)
- Mainz Hbf (45 vol.)
- Saarbrücken Hbf (80 vol.)
- Freiburg Hbf (100 vol.)
Tour 1
COST: 1293.027 km
LOAD: 400 vol.
- Mainz Hbf | 45 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 20 vol.
- Freiburg Hbf | 100 vol.
- Saarbrücken Hbf | 80 vol.
- Aachen Hbf | 35 vol.
- Köln Hbf | 45 vol.
Tour 2
COST: 2117.406 km
LOAD: 345 vol.
- Hannover Hbf | 45 vol.
- Bremen Hbf | 35 vol.
- Hamburg Hbf | 30 vol.
- Kiel Hbf | 20 vol.
- Berlin Hbf | 20 vol.
- Dresden Hbf | 45 vol.
- Leipzig Hbf | 50 vol.
- Nürnberg Hbf | 40 vol.
- Ulm Hbf | 40 vol.
- Stuttgart Hbf | 20 vol.
Tour 3
COST: 399.342 km
LOAD: 70 vol.
- Frankfurt Hbf | 70 vol.

LOAD: 400 vol.
- Mainz Hbf | 45 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 20 vol.
- Freiburg Hbf | 100 vol.
- Saarbrücken Hbf | 80 vol.
- Aachen Hbf | 35 vol.
- Köln Hbf | 45 vol.

LOAD: 345 vol.
- Hannover Hbf | 45 vol.
- Bremen Hbf | 35 vol.
- Hamburg Hbf | 30 vol.
- Kiel Hbf | 20 vol.
- Berlin Hbf | 20 vol.
- Dresden Hbf | 45 vol.
- Leipzig Hbf | 50 vol.
- Nürnberg Hbf | 40 vol.
- Ulm Hbf | 40 vol.
- Stuttgart Hbf | 20 vol.

LOAD: 70 vol.
- Frankfurt Hbf | 70 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: 815 vol. | Vehicle capacity: 400 vol. Loads: [0, 20, 0, 70, 45, 35, 20, 45, 30, 0, 35, 50, 0, 40, 20, 40, 45, 75, 20, 45, 0, 80, 0, 100] ITERATION Generation: #1 Best cost: 5010.031 | Path: [0, 1, 11, 7, 4, 10, 8, 18, 16, 5, 19, 14, 0, 3, 17, 6, 15, 13, 23, 0, 21, 0] Best cost: 4542.334 | Path: [0, 4, 10, 8, 18, 1, 11, 7, 13, 14, 17, 6, 0, 3, 19, 16, 5, 21, 23, 0, 15, 0] Best cost: 4260.719 | Path: [0, 8, 18, 10, 4, 1, 7, 11, 13, 15, 6, 14, 5, 0, 3, 19, 17, 21, 23, 0, 16, 0] Best cost: 4124.670 | Path: [0, 4, 10, 8, 18, 1, 11, 7, 13, 15, 6, 14, 5, 0, 3, 19, 17, 21, 23, 0, 16, 0] Best cost: 4120.875 | Path: [0, 4, 10, 8, 18, 1, 7, 11, 13, 15, 6, 14, 5, 0, 19, 3, 17, 21, 23, 0, 16, 0] Best cost: 4098.448 | Path: [0, 4, 10, 8, 18, 1, 7, 11, 13, 15, 6, 14, 5, 0, 3, 19, 17, 21, 23, 0, 16, 0] Generation: #3 Best cost: 3974.753 | Path: [0, 10, 8, 18, 1, 11, 7, 13, 15, 6, 14, 17, 0, 3, 19, 21, 23, 16, 5, 0, 4, 0] Generation: #4 Best cost: 3843.193 | Path: [0, 16, 5, 21, 23, 14, 17, 19, 0, 4, 10, 8, 18, 1, 11, 7, 13, 15, 6, 0, 3, 0] OPTIMIZING each tour... Current: [[0, 16, 5, 21, 23, 14, 17, 19, 0], [0, 4, 10, 8, 18, 1, 11, 7, 13, 15, 6, 0], [0, 3, 0]] [1] Cost: 1300.223 to 1293.027 | Optimized: [0, 19, 17, 14, 23, 21, 5, 16, 0] [2] Cost: 2143.628 to 2117.406 | Optimized: [0, 4, 10, 8, 18, 1, 7, 11, 13, 15, 6, 0] ACO RESULTS [1/400 vol./1293.027 km] Kassel-Wilhelmshöhe -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf --> Kassel-Wilhelmshöhe [2/345 vol./2117.406 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Nürnberg Hbf -> Ulm Hbf -> Stuttgart Hbf --> Kassel-Wilhelmshöhe [3/ 70 vol./ 399.342 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3809.775 km.