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
- Düsseldorf Hbf (25 vol.)
- Frankfurt Hbf (80 vol.)
- Hannover Hbf (55 vol.)
- Aachen Hbf (60 vol.)
- Stuttgart Hbf (45 vol.)
- Dresden Hbf (100 vol.)
- Hamburg Hbf (95 vol.)
- Bremen Hbf (50 vol.)
- Dortmund Hbf (70 vol.)
- Nürnberg Hbf (85 vol.)
- Karlsruhe Hbf (90 vol.)
- Ulm Hbf (75 vol.)
- Mainz Hbf (45 vol.)
- Saarbrücken Hbf (25 vol.)
- Freiburg Hbf (50 vol.)
Tour 1
COST: 1390.377 km
LOAD: 395 vol.
- Karlsruhe Hbf | 90 vol.
- Stuttgart Hbf | 45 vol.
- Ulm Hbf | 75 vol.
- Nürnberg Hbf | 85 vol.
- Dresden Hbf | 100 vol.
Tour 2
COST: 1320.05 km
LOAD: 355 vol.
- Dortmund Hbf | 70 vol.
- Düsseldorf Hbf | 25 vol.
- Aachen Hbf | 60 vol.
- Saarbrücken Hbf | 25 vol.
- Freiburg Hbf | 50 vol.
- Frankfurt Hbf | 80 vol.
- Mainz Hbf | 45 vol.
Tour 3
COST: 745.233 km
LOAD: 200 vol.
- Hamburg Hbf | 95 vol.
- Bremen Hbf | 50 vol.
- Hannover Hbf | 55 vol.
LOAD: 395 vol.
- Karlsruhe Hbf | 90 vol.
- Stuttgart Hbf | 45 vol.
- Ulm Hbf | 75 vol.
- Nürnberg Hbf | 85 vol.
- Dresden Hbf | 100 vol.
LOAD: 355 vol.
- Dortmund Hbf | 70 vol.
- Düsseldorf Hbf | 25 vol.
- Aachen Hbf | 60 vol.
- Saarbrücken Hbf | 25 vol.
- Freiburg Hbf | 50 vol.
- Frankfurt Hbf | 80 vol.
- Mainz Hbf | 45 vol.
LOAD: 200 vol.
- Hamburg Hbf | 95 vol.
- Bremen Hbf | 50 vol.
- Hannover Hbf | 55 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: 950 vol. | Vehicle capacity: 400 vol. Loads: [0, 0, 25, 80, 55, 60, 45, 100, 95, 0, 50, 0, 70, 85, 90, 75, 0, 0, 0, 45, 0, 25, 0, 50] ITERATION Generation: #1 Best cost: 4337.434 | Path: [0, 2, 5, 12, 10, 4, 8, 21, 0, 19, 3, 14, 6, 15, 23, 0, 13, 7, 0] Best cost: 4271.748 | Path: [0, 4, 8, 10, 12, 2, 5, 19, 0, 3, 14, 6, 15, 13, 21, 0, 23, 7, 0] Best cost: 3837.784 | Path: [0, 6, 15, 14, 23, 21, 3, 2, 0, 12, 5, 19, 13, 7, 0, 4, 10, 8, 0] Best cost: 3695.904 | Path: [0, 19, 3, 14, 6, 15, 23, 0, 12, 2, 5, 21, 13, 7, 0, 4, 10, 8, 0] Best cost: 3676.637 | Path: [0, 3, 19, 14, 6, 15, 23, 0, 12, 2, 5, 21, 13, 7, 0, 4, 10, 8, 0] Best cost: 3580.298 | Path: [0, 14, 6, 15, 13, 7, 0, 12, 2, 5, 19, 3, 21, 23, 0, 4, 10, 8, 0] Best cost: 3565.990 | Path: [0, 7, 13, 15, 6, 14, 0, 12, 2, 5, 3, 19, 21, 23, 0, 4, 10, 8, 0] Generation: #2 Best cost: 3564.614 | Path: [0, 14, 6, 15, 13, 7, 0, 12, 2, 5, 3, 19, 21, 23, 0, 4, 10, 8, 0] Best cost: 3458.785 | Path: [0, 7, 13, 15, 6, 14, 0, 12, 2, 5, 21, 23, 3, 19, 0, 4, 10, 8, 0] OPTIMIZING each tour... Current: [[0, 7, 13, 15, 6, 14, 0], [0, 12, 2, 5, 21, 23, 3, 19, 0], [0, 4, 10, 8, 0]] [1] Cost: 1391.753 to 1390.377 | Optimized: [0, 14, 6, 15, 13, 7, 0] [3] Cost: 746.982 to 745.233 | Optimized: [0, 8, 10, 4, 0] ACO RESULTS [1/395 vol./1390.377 km] Kassel-Wilhelmshöhe -> Karlsruhe Hbf -> Stuttgart Hbf -> Ulm Hbf -> Nürnberg Hbf -> Dresden Hbf --> Kassel-Wilhelmshöhe [2/355 vol./1320.050 km] Kassel-Wilhelmshöhe -> Dortmund Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Frankfurt Hbf -> Mainz Hbf --> Kassel-Wilhelmshöhe [3/200 vol./ 745.233 km] Kassel-Wilhelmshöhe -> Hamburg Hbf -> Bremen Hbf -> Hannover Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3455.660 km.