
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: 16 customers
- Berlin Hbf (90 vol.)
- Düsseldorf Hbf (60 vol.)
- Hannover Hbf (25 vol.)
- Aachen Hbf (70 vol.)
- Dresden Hbf (20 vol.)
- München Hbf (55 vol.)
- Bremen Hbf (65 vol.)
- Dortmund Hbf (100 vol.)
- Karlsruhe Hbf (55 vol.)
- Ulm Hbf (100 vol.)
- Köln Hbf (45 vol.)
- Kiel Hbf (70 vol.)
- Mainz Hbf (85 vol.)
- Würzburg Hbf (30 vol.)
- Saarbrücken Hbf (95 vol.)
- Freiburg Hbf (65 vol.)
Tour 1
COST: 1521.72 km
LOAD: 400 vol.
- Saarbrücken Hbf | 95 vol.
- Freiburg Hbf | 65 vol.
- Karlsruhe Hbf | 55 vol.
- Ulm Hbf | 100 vol.
- München Hbf | 55 vol.
- Würzburg Hbf | 30 vol.
Tour 2
COST: 1025.694 km
LOAD: 385 vol.
- Mainz Hbf | 85 vol.
- Köln Hbf | 45 vol.
- Aachen Hbf | 70 vol.
- Düsseldorf Hbf | 60 vol.
- Dortmund Hbf | 100 vol.
- Hannover Hbf | 25 vol.
Tour 3
COST: 1420.915 km
LOAD: 245 vol.
- Dresden Hbf | 20 vol.
- Berlin Hbf | 90 vol.
- Kiel Hbf | 70 vol.
- Bremen Hbf | 65 vol.

LOAD: 400 vol.
- Saarbrücken Hbf | 95 vol.
- Freiburg Hbf | 65 vol.
- Karlsruhe Hbf | 55 vol.
- Ulm Hbf | 100 vol.
- München Hbf | 55 vol.
- Würzburg Hbf | 30 vol.

LOAD: 385 vol.
- Mainz Hbf | 85 vol.
- Köln Hbf | 45 vol.
- Aachen Hbf | 70 vol.
- Düsseldorf Hbf | 60 vol.
- Dortmund Hbf | 100 vol.
- Hannover Hbf | 25 vol.

LOAD: 245 vol.
- Dresden Hbf | 20 vol.
- Berlin Hbf | 90 vol.
- Kiel Hbf | 70 vol.
- Bremen Hbf | 65 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: 1030 vol. | Vehicle capacity: 400 vol. Loads: [0, 90, 60, 0, 25, 70, 0, 20, 0, 55, 65, 0, 100, 0, 55, 100, 45, 0, 70, 85, 30, 95, 0, 65] ITERATION Generation: #1 Best cost: 4760.254 | Path: [0, 1, 7, 20, 19, 14, 23, 16, 0, 4, 10, 18, 12, 2, 5, 0, 21, 15, 9, 0] Best cost: 4478.769 | Path: [0, 2, 16, 12, 5, 21, 20, 0, 4, 10, 18, 1, 7, 19, 0, 15, 9, 23, 14, 0] Best cost: 4214.497 | Path: [0, 4, 10, 18, 1, 7, 20, 19, 0, 12, 2, 16, 5, 21, 0, 15, 9, 14, 23, 0] Best cost: 4191.341 | Path: [0, 9, 15, 14, 23, 21, 20, 0, 12, 2, 16, 5, 19, 4, 0, 10, 18, 1, 7, 0] Best cost: 4167.191 | Path: [0, 4, 10, 18, 1, 7, 20, 19, 0, 12, 2, 16, 5, 21, 0, 14, 23, 15, 9, 0] Best cost: 4162.687 | Path: [0, 21, 14, 23, 15, 9, 20, 0, 4, 10, 18, 1, 7, 19, 16, 0, 12, 2, 5, 0] Best cost: 4145.474 | Path: [0, 21, 14, 23, 15, 9, 20, 0, 12, 2, 16, 5, 19, 4, 0, 10, 18, 1, 7, 0] Best cost: 4124.783 | Path: [0, 20, 15, 9, 14, 23, 21, 0, 12, 2, 16, 5, 19, 4, 0, 7, 1, 18, 10, 0] Generation: #3 Best cost: 4108.923 | Path: [0, 20, 19, 21, 5, 16, 2, 0, 12, 4, 10, 18, 1, 7, 0, 14, 23, 15, 9, 0] Generation: #5 Best cost: 4074.898 | Path: [0, 21, 14, 23, 15, 9, 20, 0, 19, 16, 2, 5, 12, 4, 0, 10, 18, 1, 7, 0] OPTIMIZING each tour... Current: [[0, 21, 14, 23, 15, 9, 20, 0], [0, 19, 16, 2, 5, 12, 4, 0], [0, 10, 18, 1, 7, 0]] [1] Cost: 1581.550 to 1521.720 | Optimized: [0, 21, 23, 14, 15, 9, 20, 0] [2] Cost: 1072.327 to 1025.694 | Optimized: [0, 19, 16, 5, 2, 12, 4, 0] [3] Cost: 1421.021 to 1420.915 | Optimized: [0, 7, 1, 18, 10, 0] ACO RESULTS [1/400 vol./1521.720 km] Kassel-Wilhelmshöhe -> Saarbrücken Hbf -> Freiburg Hbf -> Karlsruhe Hbf -> Ulm Hbf -> München Hbf -> Würzburg Hbf --> Kassel-Wilhelmshöhe [2/385 vol./1025.694 km] Kassel-Wilhelmshöhe -> Mainz Hbf -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Hannover Hbf --> Kassel-Wilhelmshöhe [3/245 vol./1420.915 km] Kassel-Wilhelmshöhe -> Dresden Hbf -> Berlin Hbf -> Kiel Hbf -> Bremen Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3968.329 km.