
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: 15 customers
- Berlin Hbf (35 vol.)
- Frankfurt Hbf (40 vol.)
- Hannover Hbf (85 vol.)
- München Hbf (60 vol.)
- Bremen Hbf (40 vol.)
- Leipzig Hbf (45 vol.)
- Nürnberg Hbf (55 vol.)
- Karlsruhe Hbf (35 vol.)
- Ulm Hbf (60 vol.)
- Köln Hbf (30 vol.)
- Mannheim Hbf (100 vol.)
- Kiel Hbf (100 vol.)
- Mainz Hbf (35 vol.)
- Osnabrück Hbf (30 vol.)
- Freiburg Hbf (100 vol.)
Tour 1
COST: 1173.732 km
LOAD: 385 vol.
- Nürnberg Hbf | 55 vol.
- München Hbf | 60 vol.
- Ulm Hbf | 60 vol.
- Karlsruhe Hbf | 35 vol.
- Mannheim Hbf | 100 vol.
- Mainz Hbf | 35 vol.
- Frankfurt Hbf | 40 vol.
Tour 2
COST: 1716.966 km
LOAD: 365 vol.
- Köln Hbf | 30 vol.
- Osnabrück Hbf | 30 vol.
- Hannover Hbf | 85 vol.
- Bremen Hbf | 40 vol.
- Kiel Hbf | 100 vol.
- Berlin Hbf | 35 vol.
- Leipzig Hbf | 45 vol.
Tour 3
COST: 920.164 km
LOAD: 100 vol.
- Freiburg Hbf | 100 vol.

LOAD: 385 vol.
- Nürnberg Hbf | 55 vol.
- München Hbf | 60 vol.
- Ulm Hbf | 60 vol.
- Karlsruhe Hbf | 35 vol.
- Mannheim Hbf | 100 vol.
- Mainz Hbf | 35 vol.
- Frankfurt Hbf | 40 vol.

LOAD: 365 vol.
- Köln Hbf | 30 vol.
- Osnabrück Hbf | 30 vol.
- Hannover Hbf | 85 vol.
- Bremen Hbf | 40 vol.
- Kiel Hbf | 100 vol.
- Berlin Hbf | 35 vol.
- Leipzig Hbf | 45 vol.

LOAD: 100 vol.
- Freiburg Hbf | 100 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: 850 vol. | Vehicle capacity: 400 vol. Loads: [0, 35, 0, 40, 85, 0, 0, 0, 0, 60, 40, 45, 0, 55, 35, 60, 30, 100, 100, 35, 0, 0, 30, 100] ITERATION Generation: #1 Best cost: 4655.323 | Path: [0, 1, 11, 4, 10, 22, 19, 3, 14, 13, 0, 16, 17, 23, 15, 9, 0, 18, 0] Best cost: 4345.173 | Path: [0, 3, 19, 17, 14, 23, 15, 16, 0, 4, 10, 22, 18, 1, 11, 13, 0, 9, 0] Best cost: 4100.082 | Path: [0, 9, 15, 14, 17, 3, 19, 16, 22, 0, 4, 10, 18, 1, 11, 13, 0, 23, 0] Best cost: 4020.881 | Path: [0, 13, 9, 15, 14, 17, 19, 3, 0, 4, 22, 10, 18, 1, 11, 16, 0, 23, 0] Best cost: 3992.574 | Path: [0, 17, 14, 23, 15, 9, 16, 0, 22, 10, 4, 18, 1, 11, 13, 0, 19, 3, 0] Best cost: 3985.947 | Path: [0, 4, 10, 18, 22, 16, 3, 19, 14, 0, 17, 23, 15, 9, 13, 0, 11, 1, 0] Best cost: 3948.263 | Path: [0, 11, 1, 18, 4, 10, 22, 16, 19, 0, 3, 17, 14, 23, 15, 9, 0, 13, 0] Best cost: 3920.261 | Path: [0, 11, 1, 18, 10, 4, 22, 16, 19, 0, 3, 17, 14, 23, 15, 9, 0, 13, 0] Generation: #4 Best cost: 3833.583 | Path: [0, 13, 9, 15, 14, 17, 19, 3, 0, 16, 22, 10, 4, 18, 1, 11, 0, 23, 0] OPTIMIZING each tour... Current: [[0, 13, 9, 15, 14, 17, 19, 3, 0], [0, 16, 22, 10, 4, 18, 1, 11, 0], [0, 23, 0]] [2] Cost: 1739.687 to 1716.966 | Optimized: [0, 16, 22, 4, 10, 18, 1, 11, 0] ACO RESULTS [1/385 vol./1173.732 km] Kassel-Wilhelmshöhe -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Karlsruhe Hbf -> Mannheim Hbf -> Mainz Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe [2/365 vol./1716.966 km] Kassel-Wilhelmshöhe -> Köln Hbf -> Osnabrück Hbf -> Hannover Hbf -> Bremen Hbf -> Kiel Hbf -> Berlin Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [3/100 vol./ 920.164 km] Kassel-Wilhelmshöhe -> Freiburg Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3810.862 km.