%% 信息素更新
rou=0.2;
cfit=100/bestfitness;
for i=2:PortGrid-1
pheromone(i,bestpath(i*2-1),bestpath(i*2))= ...
(1-rou)*pheromone(i,bestpath(i*2-1),bestpath(i*2))+rou*cfit;
end
%% 適應(yīng)度值計算更新
fitness=CacuFit(path);
[newbestfitness,newbestindex]=min(fitness);
if newbestfitness<bestfitness
bestfitness=newbestfitness;
bestpath=path(newbestindex,:);
end
BestFitness=[BestFitness;bestfitness];
%% 更新信息素
cfit=100/bestfitness;
for i=2:PortGrid-1
pheromone(i,bestpath(i*2-1),bestpath(i*2))=(1-rou)* ...
pheromone(i,bestpath(i*2-1),bestpath(i*2))+rou*cfit;
end
end
%% 最佳路徑
for i=1:21
a(i,1)=bestpath(i*2-1);
a(i,2)=bestpath(i*2);
end
figure(1)
x=1:21;
y=1:21;
[x1,y1]=meshgrid(x,y);
mesh(x1,y1,HeightData)
axis([1,21,1,21,0,2000])
hold on
k=1:21;
plot3(k(1)',a(1,1)',a(1,2)'*200,'--o','LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',10)
plot3(k(21)',a(21,1)',a(21,2)'*200,'--o','LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',10)
text(k(1)',a(1,1)',a(1,2)'*200,'S');
text(k(21)',a(21,1)',a(21,2)'*200,'T');
xlabel('km','fontsize',12);
ylabel('km','fontsize',12);
zlabel('m','fontsize',12);
title('三維路徑規(guī)劃空間','fontsize',12)
set(gcf, 'Renderer', 'ZBuffer')
hold on
plot3(k',a(:,1)',a(:,2)'*200,'--o')