22 lines
606 B
Matlab
22 lines
606 B
Matlab
% 加载数据
|
||
load('postion_att48.mat');
|
||
% 假设加载的变量名为positions,如果实际变量名不同,请相应调整
|
||
|
||
% 计算城市间距离矩阵
|
||
distMatrix = calculateDistanceMatrix(postion);
|
||
|
||
% 输出距离矩阵
|
||
disp('城市间距离矩阵:');
|
||
disp(distMatrix);
|
||
|
||
% 选择起始城市(这里选择城市1)
|
||
startCity = 1;
|
||
|
||
% 生成遍历路径并计算总距离
|
||
[route, totalDistance] = calculateTourDistance(distMatrix, startCity);
|
||
|
||
% 输出总距离
|
||
fprintf('从城市%d出发的遍历路径总距离: %.2f\n', startCity, totalDistance);
|
||
|
||
% 绘制遍历路径
|
||
plotTour(postion, route); |