x = [4475,4475,4475,4475,5450,5475,5475,4575,5425,5425,5425,5425,5425,6000,6375,6000,6375,6475,6475,6475,6475,6100,6350,6350,6100,6550,5775,6075,6375,6375,6075,5775,6975,6675,6675,6875,6850,6600,6600,6850,7100,7100,7100,7100,7100,6925,6925,6925,6925,6925,6925,7700,7850,7700,7750,8125,8500,8500,7600,8350,7975,8350,9375,9531,9475,9275,10375,9687,9843,9999,10155,10311,10467,10623,10779,10935,11091,11247,11403,11559,11175,11275,10650,11275,11125,11025,11000,11000,11650,11725,12500,11715,11871,12027,12183,12339,12495,12651,12807,12963,13325,13100,12825,12850,13585,13585,13585,13585,13585,13585,13585,13585,13585,13585,13585,13585,13585,13585,13585,13585,13585,13585,13585,13585]
y = [8657,8969,9407,9719,10475,9750,8650,8425,3300,3000,2400,2100,1800,2375,2375,3375,3375,4675,4875,5275,5475,6675,6675,7275,7275,7625,8650,8650,8650,9750,9750,9750,9750,9750,8650,8650,7275,7275,6675,6675,5425,5275,5075,4875,4675,3300,3000,2700,2400,2100,1800,3725,3700,4725,7475,7525,7475,8225,9025,9025,9075,9775,11225,11225,10275,10050,9525,11225,11225,11225,11225,11225,11225,11225,11225,11225,11225,11225,11225,11225,9800,9475,9400,9175,5350,4750,4600,3600,3350,4825,5950,11225,11225,11225,11225,11225,11225,11225,11225,11225,6100,4625,3800,2425,1975,2131,2287,2443,2599,2755,2911,3067,3223,3379,9615,9771,9927,10083,10239,10395,10551,10707,10863,11019]
n = len(x)
想把以上数据改成导入csv文件的Berlin52里的数据可以实现吗??
当然可以了。但是你的问题是什么呢?
另外,Berlin52里的数据,是你下载的标准文件(除 (x,y) 数据外还有其它特征数据,如 N, no.),还是自己处理后的格式(只有 (x,y) 数据)?处理起来是不同的。
更多详见:Python数模笔记-模拟退火算法(4)旅行商问题 https://blog.csdn.net/youcans/article/details/116396137
例如:
# 子程序:读取TSPLib数据
def read_TSPLib(fileName):
# custom function read_TSPLib(fileName)
# Read datafile *.dat from TSPlib
# return coordinates of each city by YouCans, XUPT
res = []
with open(fileName, 'r') as fid:
for item in fid:
if len(item.strip())!=0:
res.append(item.split())
loadData = np.array(res).astype('int') # 数据格式:i Xi Yi
coordinates = loadData[:,1::]
return coordinates