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: 15 customers
- Düsseldorf Hbf (45 vol.)
- Frankfurt Hbf (70 vol.)
- Hannover Hbf (100 vol.)
- Aachen Hbf (50 vol.)
- Stuttgart Hbf (80 vol.)
- Hamburg Hbf (90 vol.)
- München Hbf (60 vol.)
- Leipzig Hbf (35 vol.)
- Dortmund Hbf (60 vol.)
- Karlsruhe Hbf (55 vol.)
- Ulm Hbf (95 vol.)
- Mainz Hbf (25 vol.)
- Würzburg Hbf (90 vol.)
- Saarbrücken Hbf (30 vol.)
- Osnabrück Hbf (45 vol.)
Tour 1
COST: 1571.395 km
LOAD: 290 vol.
- München Hbf | 60 vol.
- Ulm Hbf | 95 vol.
- Stuttgart Hbf | 80 vol.
- Karlsruhe Hbf | 55 vol.
Tour 2
COST: 1716.073 km
LOAD: 300 vol.
- Leipzig Hbf | 35 vol.
- Würzburg Hbf | 90 vol.
- Frankfurt Hbf | 70 vol.
- Mainz Hbf | 25 vol.
- Saarbrücken Hbf | 30 vol.
- Aachen Hbf | 50 vol.
Tour 3
COST: 1160.908 km
LOAD: 250 vol.
- Dortmund Hbf | 60 vol.
- Düsseldorf Hbf | 45 vol.
- Osnabrück Hbf | 45 vol.
- Hannover Hbf | 100 vol.
Tour 4
COST: 566.367 km
LOAD: 90 vol.
- Hamburg Hbf | 90 vol.
LOAD: 290 vol.
- München Hbf | 60 vol.
- Ulm Hbf | 95 vol.
- Stuttgart Hbf | 80 vol.
- Karlsruhe Hbf | 55 vol.
LOAD: 300 vol.
- Leipzig Hbf | 35 vol.
- Würzburg Hbf | 90 vol.
- Frankfurt Hbf | 70 vol.
- Mainz Hbf | 25 vol.
- Saarbrücken Hbf | 30 vol.
- Aachen Hbf | 50 vol.
LOAD: 250 vol.
- Dortmund Hbf | 60 vol.
- Düsseldorf Hbf | 45 vol.
- Osnabrück Hbf | 45 vol.
- Hannover Hbf | 100 vol.
LOAD: 90 vol.
- Hamburg Hbf | 90 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: 930 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 45, 70, 100, 50, 80, 0, 90, 60, 0, 35, 60, 0, 55, 95, 0, 0, 0, 25, 90, 30, 45, 0] ITERATION Generation: #1 Best cost: 6706.957 | Path: [1, 2, 12, 22, 4, 5, 1, 11, 8, 20, 3, 1, 6, 15, 14, 19, 21, 1, 9, 1] Best cost: 6250.971 | Path: [1, 3, 19, 14, 6, 21, 11, 1, 8, 4, 22, 12, 1, 20, 15, 9, 2, 1, 5, 1] Best cost: 6014.587 | Path: [1, 5, 2, 12, 22, 4, 1, 11, 20, 3, 19, 21, 1, 8, 6, 14, 9, 1, 15, 1] Best cost: 6001.833 | Path: [1, 8, 4, 22, 12, 1, 11, 20, 19, 3, 14, 1, 6, 15, 9, 21, 1, 2, 5, 1] Best cost: 5792.021 | Path: [1, 12, 2, 5, 3, 19, 21, 1, 11, 4, 22, 8, 1, 20, 6, 15, 1, 9, 14, 1] Best cost: 5732.522 | Path: [1, 5, 2, 12, 22, 4, 1, 11, 3, 19, 21, 14, 6, 1, 8, 20, 15, 1, 9, 1] Best cost: 5721.646 | Path: [1, 8, 4, 22, 12, 1, 11, 20, 3, 19, 14, 1, 9, 15, 6, 21, 1, 5, 2, 1] Best cost: 5108.266 | Path: [1, 14, 6, 15, 9, 1, 11, 20, 19, 3, 21, 5, 1, 4, 22, 12, 2, 1, 8, 1] Best cost: 5044.510 | Path: [1, 14, 6, 15, 9, 1, 11, 20, 3, 19, 21, 5, 1, 4, 22, 12, 2, 1, 8, 1] Best cost: 5035.657 | Path: [1, 14, 6, 15, 9, 1, 4, 22, 12, 2, 5, 1, 11, 20, 3, 19, 21, 1, 8, 1] Generation: #3 Best cost: 5030.132 | Path: [1, 9, 15, 6, 14, 1, 11, 20, 3, 19, 21, 5, 1, 4, 22, 12, 2, 1, 8, 1] OPTIMIZING each tour... Current: [[1, 9, 15, 6, 14, 1], [1, 11, 20, 3, 19, 21, 5, 1], [1, 4, 22, 12, 2, 1], [1, 8, 1]] [3] Cost: 1176.297 to 1160.908 | Optimized: [1, 12, 2, 22, 4, 1] ACO RESULTS [1/290 vol./1571.395 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf --> Berlin Hbf [2/300 vol./1716.073 km] Berlin Hbf -> Leipzig Hbf -> Würzburg Hbf -> Frankfurt Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Aachen Hbf --> Berlin Hbf [3/250 vol./1160.908 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Osnabrück Hbf -> Hannover Hbf --> Berlin Hbf [4/ 90 vol./ 566.367 km] Berlin Hbf -> Hamburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5014.743 km.