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: 17 customers
- Berlin Hbf (40 vol.)
- Düsseldorf Hbf (55 vol.)
- Frankfurt Hbf (100 vol.)
- Hannover Hbf (65 vol.)
- Stuttgart Hbf (95 vol.)
- Dresden Hbf (85 vol.)
- Dortmund Hbf (95 vol.)
- Karlsruhe Hbf (60 vol.)
- Ulm Hbf (70 vol.)
- Köln Hbf (95 vol.)
- Mannheim Hbf (85 vol.)
- Kiel Hbf (35 vol.)
- Mainz Hbf (100 vol.)
- Würzburg Hbf (70 vol.)
- Saarbrücken Hbf (100 vol.)
- Osnabrück Hbf (75 vol.)
- Freiburg Hbf (55 vol.)
Tour 1
COST: 1591.853 km
LOAD: 395 vol.
- Dortmund Hbf | 95 vol.
- Osnabrück Hbf | 75 vol.
- Hannover Hbf | 65 vol.
- Kiel Hbf | 35 vol.
- Berlin Hbf | 40 vol.
- Dresden Hbf | 85 vol.
Tour 2
COST: 980.987 km
LOAD: 400 vol.
- Mainz Hbf | 100 vol.
- Mannheim Hbf | 85 vol.
- Karlsruhe Hbf | 60 vol.
- Freiburg Hbf | 55 vol.
- Frankfurt Hbf | 100 vol.
Tour 3
COST: 1224.139 km
LOAD: 390 vol.
- Würzburg Hbf | 70 vol.
- Ulm Hbf | 70 vol.
- Stuttgart Hbf | 95 vol.
- Saarbrücken Hbf | 100 vol.
- Düsseldorf Hbf | 55 vol.
Tour 4
COST: 481.046 km
LOAD: 95 vol.
- Köln Hbf | 95 vol.
LOAD: 395 vol.
- Dortmund Hbf | 95 vol.
- Osnabrück Hbf | 75 vol.
- Hannover Hbf | 65 vol.
- Kiel Hbf | 35 vol.
- Berlin Hbf | 40 vol.
- Dresden Hbf | 85 vol.
LOAD: 400 vol.
- Mainz Hbf | 100 vol.
- Mannheim Hbf | 85 vol.
- Karlsruhe Hbf | 60 vol.
- Freiburg Hbf | 55 vol.
- Frankfurt Hbf | 100 vol.
LOAD: 390 vol.
- Würzburg Hbf | 70 vol.
- Ulm Hbf | 70 vol.
- Stuttgart Hbf | 95 vol.
- Saarbrücken Hbf | 100 vol.
- Düsseldorf Hbf | 55 vol.
LOAD: 95 vol.
- Köln Hbf | 95 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: 1280 vol. | Vehicle capacity: 400 vol. Loads: [0, 40, 55, 100, 65, 0, 95, 85, 0, 0, 0, 0, 95, 0, 60, 70, 95, 85, 35, 100, 70, 100, 75, 55] ITERATION Generation: #1 Best cost: 5161.947 | Path: [0, 1, 7, 20, 3, 19, 0, 22, 12, 2, 16, 14, 0, 4, 18, 15, 6, 17, 0, 21, 23, 0] Best cost: 5023.582 | Path: [0, 2, 16, 12, 22, 4, 0, 19, 3, 17, 14, 23, 0, 20, 6, 15, 21, 1, 0, 7, 18, 0] Best cost: 4666.290 | Path: [0, 3, 19, 17, 14, 23, 0, 12, 2, 16, 22, 4, 0, 20, 6, 15, 21, 18, 0, 1, 7, 0] Best cost: 4628.945 | Path: [0, 14, 17, 19, 3, 2, 0, 12, 16, 22, 4, 18, 0, 20, 6, 15, 21, 23, 0, 7, 1, 0] Best cost: 4320.346 | Path: [0, 7, 1, 18, 4, 22, 12, 0, 3, 19, 17, 14, 23, 0, 20, 6, 15, 21, 2, 0, 16, 0] Generation: #3 Best cost: 4292.401 | Path: [0, 7, 1, 18, 4, 22, 12, 0, 3, 19, 17, 14, 23, 0, 20, 15, 6, 21, 2, 0, 16, 0] OPTIMIZING each tour... Current: [[0, 7, 1, 18, 4, 22, 12, 0], [0, 3, 19, 17, 14, 23, 0], [0, 20, 15, 6, 21, 2, 0], [0, 16, 0]] [1] Cost: 1601.734 to 1591.853 | Optimized: [0, 12, 22, 4, 18, 1, 7, 0] [2] Cost: 985.482 to 980.987 | Optimized: [0, 19, 17, 14, 23, 3, 0] ACO RESULTS [1/395 vol./1591.853 km] Kassel-Wilhelmshöhe -> Dortmund Hbf -> Osnabrück Hbf -> Hannover Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf --> Kassel-Wilhelmshöhe [2/400 vol./ 980.987 km] Kassel-Wilhelmshöhe -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe [3/390 vol./1224.139 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Ulm Hbf -> Stuttgart Hbf -> Saarbrücken Hbf -> Düsseldorf Hbf --> Kassel-Wilhelmshöhe [4/ 95 vol./ 481.046 km] Kassel-Wilhelmshöhe -> Köln Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4278.025 km.