Files
MATLAB3/main.m
2025-03-26 20:08:20 +08:00

22 lines
606 B
Matlab
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

% 加载数据
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);