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 (80 vol.)
- Frankfurt Hbf (95 vol.)
- Hannover Hbf (25 vol.)
- Stuttgart Hbf (25 vol.)
- München Hbf (80 vol.)
- Bremen Hbf (95 vol.)
- Dortmund Hbf (45 vol.)
- Karlsruhe Hbf (20 vol.)
- Ulm Hbf (20 vol.)
- Mannheim Hbf (65 vol.)
- Kiel Hbf (70 vol.)
- Mainz Hbf (35 vol.)
- Würzburg Hbf (60 vol.)
- Saarbrücken Hbf (100 vol.)
- Osnabrück Hbf (25 vol.)
Tour 1
COST: 1445.155 km
LOAD: 300 vol.
- Frankfurt Hbf | 95 vol.
- Mainz Hbf | 35 vol.
- Mannheim Hbf | 65 vol.
- Karlsruhe Hbf | 20 vol.
- Stuttgart Hbf | 25 vol.
- Würzburg Hbf | 60 vol.
Tour 2
COST: 1854.824 km
LOAD: 280 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 20 vol.
- Saarbrücken Hbf | 100 vol.
- Düsseldorf Hbf | 80 vol.
Tour 3
COST: 1308.174 km
LOAD: 260 vol.
- Kiel Hbf | 70 vol.
- Bremen Hbf | 95 vol.
- Osnabrück Hbf | 25 vol.
- Dortmund Hbf | 45 vol.
- Hannover Hbf | 25 vol.
LOAD: 300 vol.
- Frankfurt Hbf | 95 vol.
- Mainz Hbf | 35 vol.
- Mannheim Hbf | 65 vol.
- Karlsruhe Hbf | 20 vol.
- Stuttgart Hbf | 25 vol.
- Würzburg Hbf | 60 vol.
LOAD: 280 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 20 vol.
- Saarbrücken Hbf | 100 vol.
- Düsseldorf Hbf | 80 vol.
LOAD: 260 vol.
- Kiel Hbf | 70 vol.
- Bremen Hbf | 95 vol.
- Osnabrück Hbf | 25 vol.
- Dortmund Hbf | 45 vol.
- Hannover Hbf | 25 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: 840 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 80, 95, 25, 0, 25, 0, 0, 80, 95, 0, 45, 0, 20, 20, 0, 65, 70, 35, 60, 100, 25, 0] ITERATION Generation: #1 Best cost: 5920.459 | Path: [1, 2, 12, 22, 10, 4, 14, 1, 18, 3, 19, 17, 6, 1, 9, 15, 20, 21, 1] Best cost: 5597.344 | Path: [1, 3, 19, 17, 14, 6, 15, 22, 1, 4, 10, 18, 12, 20, 1, 2, 21, 9, 1] Best cost: 5576.075 | Path: [1, 4, 10, 22, 12, 2, 6, 1, 18, 19, 3, 17, 14, 1, 20, 15, 9, 21, 1] Best cost: 5103.930 | Path: [1, 9, 15, 6, 14, 17, 19, 12, 1, 4, 22, 10, 18, 2, 1, 20, 3, 21, 1] Best cost: 5080.159 | Path: [1, 15, 6, 14, 17, 19, 3, 4, 1, 18, 10, 22, 12, 20, 1, 9, 21, 2, 1] Best cost: 5056.074 | Path: [1, 21, 17, 14, 6, 15, 20, 1, 4, 10, 22, 12, 2, 1, 18, 3, 19, 9, 1] Best cost: 4911.509 | Path: [1, 9, 15, 6, 14, 17, 19, 4, 22, 1, 18, 10, 12, 2, 1, 20, 3, 21, 1] Generation: #2 Best cost: 4870.713 | Path: [1, 9, 15, 6, 14, 17, 19, 12, 1, 18, 10, 4, 22, 2, 1, 20, 3, 21, 1] Generation: #3 Best cost: 4796.677 | Path: [1, 20, 3, 19, 17, 14, 6, 1, 9, 15, 21, 2, 1, 4, 10, 22, 12, 18, 1] OPTIMIZING each tour... Current: [[1, 20, 3, 19, 17, 14, 6, 1], [1, 9, 15, 21, 2, 1], [1, 4, 10, 22, 12, 18, 1]] [1] Cost: 1501.937 to 1445.155 | Optimized: [1, 3, 19, 17, 14, 6, 20, 1] [3] Cost: 1439.916 to 1308.174 | Optimized: [1, 18, 10, 22, 12, 4, 1] ACO RESULTS [1/300 vol./1445.155 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Würzburg Hbf --> Berlin Hbf [2/280 vol./1854.824 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Saarbrücken Hbf -> Düsseldorf Hbf --> Berlin Hbf [3/260 vol./1308.174 km] Berlin Hbf -> Kiel Hbf -> Bremen Hbf -> Osnabrück Hbf -> Dortmund Hbf -> Hannover Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4608.153 km.