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 (25 vol.)
- Düsseldorf Hbf (65 vol.)
- Frankfurt Hbf (65 vol.)
- Hannover Hbf (80 vol.)
- Aachen Hbf (45 vol.)
- Stuttgart Hbf (50 vol.)
- Dresden Hbf (90 vol.)
- Hamburg Hbf (20 vol.)
- München Hbf (50 vol.)
- Leipzig Hbf (60 vol.)
- Dortmund Hbf (75 vol.)
- Karlsruhe Hbf (35 vol.)
- Ulm Hbf (25 vol.)
- Köln Hbf (35 vol.)
- Kiel Hbf (20 vol.)
- Mainz Hbf (90 vol.)
- Saarbrücken Hbf (20 vol.)
- Freiburg Hbf (55 vol.)
Tour 1
COST: 1526.653 km
LOAD: 390 vol.
- München Hbf | 50 vol.
- Ulm Hbf | 25 vol.
- Stuttgart Hbf | 50 vol.
- Karlsruhe Hbf | 35 vol.
- Freiburg Hbf | 55 vol.
- Saarbrücken Hbf | 20 vol.
- Mainz Hbf | 90 vol.
- Frankfurt Hbf | 65 vol.
Tour 2
COST: 1555.793 km
LOAD: 370 vol.
- Dortmund Hbf | 75 vol.
- Hannover Hbf | 80 vol.
- Hamburg Hbf | 20 vol.
- Kiel Hbf | 20 vol.
- Berlin Hbf | 25 vol.
- Dresden Hbf | 90 vol.
- Leipzig Hbf | 60 vol.
Tour 3
COST: 621.944 km
LOAD: 145 vol.
- Köln Hbf | 35 vol.
- Aachen Hbf | 45 vol.
- Düsseldorf Hbf | 65 vol.
LOAD: 390 vol.
- München Hbf | 50 vol.
- Ulm Hbf | 25 vol.
- Stuttgart Hbf | 50 vol.
- Karlsruhe Hbf | 35 vol.
- Freiburg Hbf | 55 vol.
- Saarbrücken Hbf | 20 vol.
- Mainz Hbf | 90 vol.
- Frankfurt Hbf | 65 vol.
LOAD: 370 vol.
- Dortmund Hbf | 75 vol.
- Hannover Hbf | 80 vol.
- Hamburg Hbf | 20 vol.
- Kiel Hbf | 20 vol.
- Berlin Hbf | 25 vol.
- Dresden Hbf | 90 vol.
- Leipzig Hbf | 60 vol.
LOAD: 145 vol.
- Köln Hbf | 35 vol.
- Aachen Hbf | 45 vol.
- Düsseldorf 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: 905 vol. | Vehicle capacity: 400 vol. Loads: [0, 25, 65, 65, 80, 45, 50, 90, 20, 50, 0, 60, 75, 0, 35, 25, 35, 0, 20, 90, 0, 20, 0, 55] ITERATION Generation: #1 Best cost: 4997.901 | Path: [0, 1, 11, 7, 12, 2, 16, 5, 0, 4, 8, 18, 19, 3, 14, 6, 15, 0, 21, 23, 9, 0] Best cost: 4700.310 | Path: [0, 2, 16, 5, 12, 19, 3, 21, 0, 4, 8, 18, 1, 7, 11, 15, 6, 0, 14, 23, 9, 0] Best cost: 4179.116 | Path: [0, 3, 19, 21, 14, 6, 15, 9, 23, 0, 12, 2, 16, 5, 4, 8, 18, 1, 0, 11, 7, 0] Best cost: 4173.012 | Path: [0, 19, 3, 14, 6, 15, 9, 23, 21, 0, 12, 2, 16, 5, 4, 8, 18, 1, 0, 11, 7, 0] Best cost: 4046.987 | Path: [0, 9, 15, 6, 14, 23, 21, 3, 19, 0, 12, 2, 16, 5, 4, 8, 18, 1, 0, 11, 7, 0] Best cost: 3980.773 | Path: [0, 9, 15, 6, 14, 23, 21, 19, 3, 0, 12, 2, 16, 5, 4, 8, 18, 1, 0, 11, 7, 0] Best cost: 3938.037 | Path: [0, 23, 14, 6, 15, 9, 1, 7, 11, 0, 12, 2, 16, 5, 21, 19, 3, 0, 4, 8, 18, 0] Best cost: 3923.779 | Path: [0, 1, 11, 7, 9, 15, 6, 14, 23, 0, 12, 2, 16, 5, 21, 19, 3, 0, 4, 8, 18, 0] Generation: #2 Best cost: 3844.299 | Path: [0, 9, 15, 6, 14, 23, 21, 19, 3, 0, 4, 8, 18, 1, 7, 11, 12, 0, 2, 16, 5, 0] OPTIMIZING each tour... Current: [[0, 9, 15, 6, 14, 23, 21, 19, 3, 0], [0, 4, 8, 18, 1, 7, 11, 12, 0], [0, 2, 16, 5, 0]] [2] Cost: 1675.596 to 1555.793 | Optimized: [0, 12, 4, 8, 18, 1, 7, 11, 0] [3] Cost: 642.050 to 621.944 | Optimized: [0, 16, 5, 2, 0] ACO RESULTS [1/390 vol./1526.653 km] Kassel-Wilhelmshöhe -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Mainz Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe [2/370 vol./1555.793 km] Kassel-Wilhelmshöhe -> Dortmund Hbf -> Hannover Hbf -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [3/145 vol./ 621.944 km] Kassel-Wilhelmshöhe -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3704.390 km.