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: 17 customers
- Düsseldorf Hbf (80 vol.)
- Frankfurt Hbf (55 vol.)
- Hannover Hbf (50 vol.)
- Aachen Hbf (85 vol.)
- Stuttgart Hbf (45 vol.)
- Dresden Hbf (20 vol.)
- München Hbf (95 vol.)
- Bremen Hbf (55 vol.)
- Dortmund Hbf (85 vol.)
- Karlsruhe Hbf (65 vol.)
- Ulm Hbf (25 vol.)
- Mannheim Hbf (60 vol.)
- Kiel Hbf (50 vol.)
- Mainz Hbf (45 vol.)
- Würzburg Hbf (80 vol.)
- Saarbrücken Hbf (25 vol.)
- Freiburg Hbf (50 vol.)
Tour 1
COST: 1589.414 km
LOAD: 290 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 25 vol.
- Stuttgart Hbf | 45 vol.
- Karlsruhe Hbf | 65 vol.
- Mannheim Hbf | 60 vol.
Tour 2
COST: 1835.422 km
LOAD: 275 vol.
- Frankfurt Hbf | 55 vol.
- Mainz Hbf | 45 vol.
- Saarbrücken Hbf | 25 vol.
- Freiburg Hbf | 50 vol.
- Würzburg Hbf | 80 vol.
- Dresden Hbf | 20 vol.
Tour 3
COST: 1379.689 km
LOAD: 240 vol.
- Dortmund Hbf | 85 vol.
- Hannover Hbf | 50 vol.
- Bremen Hbf | 55 vol.
- Kiel Hbf | 50 vol.
Tour 4
COST: 1267.495 km
LOAD: 165 vol.
- Aachen Hbf | 85 vol.
- Düsseldorf Hbf | 80 vol.
LOAD: 290 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 25 vol.
- Stuttgart Hbf | 45 vol.
- Karlsruhe Hbf | 65 vol.
- Mannheim Hbf | 60 vol.
LOAD: 275 vol.
- Frankfurt Hbf | 55 vol.
- Mainz Hbf | 45 vol.
- Saarbrücken Hbf | 25 vol.
- Freiburg Hbf | 50 vol.
- Würzburg Hbf | 80 vol.
- Dresden Hbf | 20 vol.
LOAD: 240 vol.
- Dortmund Hbf | 85 vol.
- Hannover Hbf | 50 vol.
- Bremen Hbf | 55 vol.
- Kiel Hbf | 50 vol.
LOAD: 165 vol.
- Aachen Hbf | 85 vol.
- Düsseldorf Hbf | 80 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: 970 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 80, 55, 50, 85, 45, 20, 0, 95, 55, 0, 85, 0, 65, 25, 0, 60, 50, 45, 80, 25, 0, 50] ITERATION Generation: #1 Best cost: 7413.588 | Path: [1, 2, 12, 5, 19, 1, 7, 4, 10, 18, 3, 17, 1, 20, 6, 15, 9, 21, 1, 14, 23, 1] Best cost: 6805.793 | Path: [1, 3, 19, 17, 14, 6, 15, 1, 7, 20, 23, 21, 5, 1, 4, 10, 18, 12, 1, 9, 2, 1] Best cost: 6624.500 | Path: [1, 4, 10, 18, 12, 3, 1, 7, 20, 17, 14, 6, 15, 1, 2, 5, 19, 21, 23, 1, 9, 1] Best cost: 6514.705 | Path: [1, 5, 2, 12, 4, 1, 7, 20, 3, 19, 17, 21, 1, 18, 10, 14, 6, 15, 23, 1, 9, 1] Best cost: 6407.753 | Path: [1, 9, 15, 6, 14, 17, 1, 7, 20, 3, 19, 21, 23, 1, 4, 10, 18, 2, 1, 12, 5, 1] Best cost: 6386.629 | Path: [1, 23, 14, 17, 19, 3, 21, 1, 7, 20, 6, 15, 9, 1, 4, 10, 18, 12, 1, 2, 5, 1] Best cost: 6301.720 | Path: [1, 9, 15, 6, 14, 17, 1, 7, 20, 3, 19, 21, 23, 1, 4, 10, 12, 2, 1, 18, 5, 1] Best cost: 6288.465 | Path: [1, 17, 14, 6, 15, 9, 1, 7, 20, 3, 19, 21, 23, 1, 4, 10, 18, 12, 1, 2, 5, 1] Best cost: 6280.581 | Path: [1, 9, 15, 6, 14, 17, 1, 7, 20, 3, 19, 21, 23, 1, 4, 10, 18, 12, 1, 2, 5, 1] Best cost: 6237.348 | Path: [1, 23, 14, 17, 19, 3, 21, 1, 7, 20, 6, 15, 9, 1, 18, 10, 4, 12, 1, 2, 5, 1] Best cost: 6171.555 | Path: [1, 20, 3, 19, 17, 6, 1, 7, 9, 15, 14, 23, 21, 1, 18, 10, 4, 12, 1, 2, 5, 1] Generation: #2 Best cost: 6131.300 | Path: [1, 9, 15, 6, 14, 17, 1, 7, 20, 3, 19, 21, 23, 1, 18, 10, 4, 12, 1, 2, 5, 1] OPTIMIZING each tour... Current: [[1, 9, 15, 6, 14, 17, 1], [1, 7, 20, 3, 19, 21, 23, 1], [1, 18, 10, 4, 12, 1], [1, 2, 5, 1]] [2] Cost: 1890.987 to 1835.422 | Optimized: [1, 3, 19, 21, 23, 20, 7, 1] [3] Cost: 1382.775 to 1379.689 | Optimized: [1, 12, 4, 10, 18, 1] [4] Cost: 1268.124 to 1267.495 | Optimized: [1, 5, 2, 1] ACO RESULTS [1/290 vol./1589.414 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Mannheim Hbf --> Berlin Hbf [2/275 vol./1835.422 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Würzburg Hbf -> Dresden Hbf --> Berlin Hbf [3/240 vol./1379.689 km] Berlin Hbf -> Dortmund Hbf -> Hannover Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf [4/165 vol./1267.495 km] Berlin Hbf -> Aachen Hbf -> Düsseldorf Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6072.020 km.