
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: 20 customers
- Kassel-Wilhelmshöhe (70 vol.)
- Düsseldorf Hbf (90 vol.)
- Frankfurt Hbf (40 vol.)
- Hannover Hbf (65 vol.)
- Aachen Hbf (100 vol.)
- Stuttgart Hbf (20 vol.)
- Dresden Hbf (65 vol.)
- Hamburg Hbf (70 vol.)
- Bremen Hbf (25 vol.)
- Leipzig Hbf (35 vol.)
- Dortmund Hbf (35 vol.)
- Nürnberg Hbf (75 vol.)
- Karlsruhe Hbf (75 vol.)
- Ulm Hbf (50 vol.)
- Köln Hbf (80 vol.)
- Mannheim Hbf (95 vol.)
- Kiel Hbf (75 vol.)
- Mainz Hbf (20 vol.)
- Saarbrücken Hbf (25 vol.)
- Freiburg Hbf (65 vol.)
Tour 1
COST: 1531.583 km
LOAD: 300 vol.
- Frankfurt Hbf | 40 vol.
- Mainz Hbf | 20 vol.
- Mannheim Hbf | 95 vol.
- Karlsruhe Hbf | 75 vol.
- Stuttgart Hbf | 20 vol.
- Ulm Hbf | 50 vol.
Tour 2
COST: 1367.158 km
LOAD: 295 vol.
- Dortmund Hbf | 35 vol.
- Düsseldorf Hbf | 90 vol.
- Kassel-Wilhelmshöhe | 70 vol.
- Leipzig Hbf | 35 vol.
- Dresden Hbf | 65 vol.
Tour 3
COST: 2046.781 km
LOAD: 290 vol.
- Nürnberg Hbf | 75 vol.
- Freiburg Hbf | 65 vol.
- Saarbrücken Hbf | 25 vol.
- Aachen Hbf | 100 vol.
- Bremen Hbf | 25 vol.
Tour 4
COST: 1463.684 km
LOAD: 290 vol.
- Köln Hbf | 80 vol.
- Hannover Hbf | 65 vol.
- Hamburg Hbf | 70 vol.
- Kiel Hbf | 75 vol.

LOAD: 300 vol.
- Frankfurt Hbf | 40 vol.
- Mainz Hbf | 20 vol.
- Mannheim Hbf | 95 vol.
- Karlsruhe Hbf | 75 vol.
- Stuttgart Hbf | 20 vol.
- Ulm Hbf | 50 vol.

LOAD: 295 vol.
- Dortmund Hbf | 35 vol.
- Düsseldorf Hbf | 90 vol.
- Kassel-Wilhelmshöhe | 70 vol.
- Leipzig Hbf | 35 vol.
- Dresden Hbf | 65 vol.

LOAD: 290 vol.
- Nürnberg Hbf | 75 vol.
- Freiburg Hbf | 65 vol.
- Saarbrücken Hbf | 25 vol.
- Aachen Hbf | 100 vol.
- Bremen Hbf | 25 vol.

LOAD: 290 vol.
- Köln Hbf | 80 vol.
- Hannover Hbf | 65 vol.
- Hamburg Hbf | 70 vol.
- Kiel 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: 1175 vol. | Vehicle capacity: 300 vol. Loads: [70, 0, 90, 40, 65, 100, 20, 65, 70, 0, 25, 35, 35, 75, 75, 50, 80, 95, 75, 20, 0, 25, 0, 65] ITERATION Generation: #1 Best cost: 7908.448 | Path: [1, 0, 12, 2, 16, 19, 1, 11, 7, 13, 15, 6, 21, 10, 1, 8, 18, 4, 3, 1, 17, 14, 23, 1, 5, 1] Best cost: 7028.250 | Path: [1, 3, 19, 17, 14, 6, 15, 1, 7, 11, 13, 0, 12, 1, 4, 10, 8, 18, 23, 1, 2, 16, 5, 21, 1] Best cost: 6978.182 | Path: [1, 5, 16, 2, 19, 1, 7, 11, 0, 4, 10, 12, 1, 8, 18, 17, 3, 6, 1, 13, 15, 14, 23, 21, 1] Best cost: 6890.486 | Path: [1, 6, 14, 17, 3, 19, 21, 10, 1, 7, 11, 0, 12, 2, 1, 8, 18, 4, 16, 1, 13, 15, 23, 5, 1] Best cost: 6820.156 | Path: [1, 2, 16, 5, 19, 1, 7, 11, 4, 10, 8, 12, 1, 18, 0, 3, 17, 6, 1, 13, 15, 14, 23, 21, 1] Best cost: 6763.115 | Path: [1, 23, 14, 17, 19, 3, 1, 7, 11, 0, 12, 2, 1, 8, 18, 10, 4, 15, 1, 13, 6, 21, 16, 5, 1] Best cost: 6699.042 | Path: [1, 16, 2, 5, 21, 1, 11, 7, 0, 12, 4, 10, 1, 8, 18, 3, 19, 17, 1, 13, 15, 6, 14, 23, 1] Best cost: 6636.821 | Path: [1, 4, 10, 8, 18, 7, 1, 11, 0, 12, 16, 3, 19, 6, 1, 13, 15, 14, 17, 1, 5, 2, 21, 23, 1] Best cost: 6444.653 | Path: [1, 15, 6, 14, 17, 19, 3, 1, 7, 11, 0, 12, 2, 1, 13, 23, 21, 5, 10, 1, 8, 18, 4, 16, 1] OPTIMIZING each tour... Current: [[1, 15, 6, 14, 17, 19, 3, 1], [1, 7, 11, 0, 12, 2, 1], [1, 13, 23, 21, 5, 10, 1], [1, 8, 18, 4, 16, 1]] [1] Cost: 1532.173 to 1531.583 | Optimized: [1, 3, 19, 17, 14, 6, 15, 1] [2] Cost: 1367.312 to 1367.158 | Optimized: [1, 12, 2, 0, 11, 7, 1] [4] Cost: 1498.387 to 1463.684 | Optimized: [1, 16, 4, 8, 18, 1] ACO RESULTS [1/300 vol./1531.583 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Ulm Hbf --> Berlin Hbf [2/295 vol./1367.158 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Kassel-Wilhelmshöhe -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/290 vol./2046.781 km] Berlin Hbf -> Nürnberg Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Bremen Hbf --> Berlin Hbf [4/290 vol./1463.684 km] Berlin Hbf -> Köln Hbf -> Hannover Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6409.206 km.