how to solve Travelling salesman problem algorithm by adding additional trucks?

Viewed 121

Can someone help me with this problem. Firstly this is the question "Vaccine distribution is a challenging problem. The conditions for transport and storage of novel vaccines mean only one transport truck currently exists and must visit several of the main cities of the UK for 12 hours each to allow for the public to be vaccinated. Find an optimal route for the truck to take through these cities. If additional trucks could be developed for transportation how much would this lower the overall time cost?"

the total number of cities are 15. How to add 1 more truck to it. so the total number of trucks will be 2 and how to add more truck to reduce the overall time.

I want to add additional truck and how to implement the 12 hours time for each? below is my code that i have worked out.

***
# Doing our imports
import random, numpy, math, copy, matplotlib.pyplot as plt
# Randomly create some cities (these could be specified in a list of 2-d lists like a 2-d array)
#cities = [random.sample(range(100), 2) for x in range(15)];
# Fix cities to be a set list:
cities = [[56, 15], [62, 34], [46, 49], [89, 59], [3, 44], [13, 25], [13, 90], [33, 87], [87, 58], [99, 24], [19, 4], [11, 28], [4, 0], [70, 32], [80, 31]]
tour = random.sample(range(15),15);
print('Initial Guess:\n')
plt.plot([cities[tour[i % 15]][0] for i in range(16)], [cities[tour[i % 15]][1] for i in range(16)], 'xr-');
plt.show()

for temperature in numpy.logspace(0,5,num=100000)[::-1]:
  [i,j] = sorted(random.sample(range(15),2));
  newTour =  tour[:i] + tour[j:j+1] +  tour[i+1:j] + tour[i:i+1] + tour[j+1:];
  if math.exp( ( sum([ math.sqrt(sum([(cities[tour[(k+1) % 15]][d] - cities[tour[k % 15]][d])**2 for d in [0,1] ])) for k in [j,j-1,i,i-1]]) - sum([math.sqrt(sum([(cities[newTour[(k+1) % 15]][d] - cities[newTour[k % 15]][d])**2 for d in [0,1] ])) for k in [j,j-1,i,i-1]])) / temperature) > random.random():
    tour = copy.copy(newTour);
print('\nFinal Path:\n')
plt.plot([cities[tour[i % 15]][0] for i in range(16)], [cities[tour[i % 15]][1] for i in range(16)], 'xb-');
plt.show()
***
1 Answers

Since the time spent at every city is the same ( 12 hours ) the total time for a route is

city count * 12 + travel time on chosen route

Since city count * 12 is constant, the problem for one truck is the familiar calculation of a minimum spanning tree. https://en.wikipedia.org/wiki/Minimum_spanning_tree

For more than one truck, the graph of cities must be partitioned into the same number of sub-graphs so as to minimize the the maximum travel time through the sub-graphs. This requires the application of cluster analysis https://en.wikipedia.org/wiki/Cluster_analysis

Assuming that the travel time between cities is proportional to the pythagorian distance between them and that the name of the city at { 56, 15} is "c56x15" here is a minimum spanning tree for all your cities, withc total cost 261

enter image description here

Adding a second truck and using the KMeans clustering algorithm I get

cluster1 total cost 67

enter image description here

cluster2 total cost 184

enter image description here

Related