一、部分代码
close all
clear
clc
rng('default');
%% 载入数据
data.S=[50,950,12]; %起点位置 横坐标与纵坐标需为50的倍数
data.E=[950,50,1]; %终点点位置 横坐标与纵坐标需为50的倍数
data.Obstacle=xlsread('data1.xls');
data.numObstacles=length(data.Obstacle(:,1));
%% 画图
figure
hold on
plot(curve,'r','LineWidth',2)
xlabel('迭代次数')
ylabel('路径长度')
legend(str);
[~,result]=fobj(Best_pos);
drawPc(result,option,data,str)
result.path(:,1)=result.path(:,1).*data.unit(1);
result.path(:,2)=result.path(:,2).*data.unit(2);
result.path(:,3)=result.path(:,3).*data.unit(3);
%% 显示路径信息
fprintf("路径坐标:\n");
display(result.path)
fprintf("路径长度:%f\n",result.fit);
二、部分结果
路径坐标:
50 950 12
100 950 12
150 900 12
200 850 12
250 800 12
300 750 12
350 700 11
400 700 11
450 650 10
450 600 9
450 550 9
500 500 8
500 450 7
500 400 6
500 350 6
550 300 5
600 300 5
650 300 5
700 250 5
750 200 4
800 150 3
850 100 2
900 50 1
950 50 1
路径长度:1419.325378
三、完整MATLAB代码