繁体   English   中英

如何通过添加额外的卡车来解决旅行商问题算法?

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

有人可以帮我解决这个问题。 首先这是一个问题,“疫苗分发是一个具有挑战性的问题。新型疫苗的运输和储存条件意味着目前只有一辆运输卡车,必须每辆运输卡车 12 小时访问英国的几个主要城市,以便公众能够接种疫苗。找到卡车通过这些城市的最佳路线。如果可以开发更多的卡车进行运输,这会降低总体时间成本多少?

城市总数为 15。如何再增加 1 辆卡车。 所以卡车的总数将是 2 以及如何添加更多的卡车以减少整体时间。

我想添加额外的卡车,如何为每辆卡车实施 12 小时的时间? 下面是我制定的代码。

***
# 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()
***

由于在每个城市花费的时间都相同(12 小时),因此一条路线的总时间为

city count * 12 + travel time on chosen route

由于城市计数 * 12 是常数,一辆卡车的问题是熟悉的最小生成树计算。 https://en.wikipedia.org/wiki/Minimum_spanning_tree

对于不止一辆卡车,必须将城市图划分为相同数量的子图,以最小化通过子图的最大行驶时间。 这就需要应用聚类分析https://en.wikipedia.org/wiki/Cluster_analysis

假设城市之间的旅行时间与它们之间的毕达哥拉斯距离成正比,并且 { 56, 15} 处的城市名称为“c56x15”,这是所有城市的最小生成树,总成本为 261

在此处输入图像描述

添加第二辆卡车并使用我得到的 KMeans 聚类算法

cluster1 总成本 67

在此处输入图像描述

cluster2 总成本 184

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM