position = load('barrier.txt');
plot([0,200],[0,200],'.');
xlabel('km','fontsize',12)
ylabel('km','fontsize',12)
title('二维规划空间','fontsize',12)
plot([S(1),T(1)],[S(2),T(2)],'.');
fill(position(1:4,1),position(1:4,2),[0,0,0]);
fill(position(5:8,1),position(5:8,2),[0,0,0]);
fill(position(9:12,1),position(9:12,2),[0,0,0]);
fill(position(13:15,1),position(13:15,2),[0,0,0]);
plot([position(L(i,1),1),position(L(i,2),1)],[position(L(i,1),2)...
,position(L(i,2),2)],'color','black','LineStyle','--');
v(i,:) = (position(L(i,1),:)+position(L(i,2),:))/2;
text(v(i,1)+2,v(i,2),strcat('v',num2str(i)));
sign = load('matrix.txt');
plot([S(1),v(k-1,1)],[S(2),v(k-1,2)],'color',...
'black','Linewidth',2,'LineStyle','-');
plot([T(1),v(j-1,1)],[T(2),v(j-1,2)],'color',...
'black','Linewidth',2,'LineStyle','-');
plot([v(i-1,1),v(j-1,1)],[v(i-1,2),v(j-1,2)],...
'color','black','Linewidth',2,'LineStyle','-');
path = DijkstraPlan(position,sign);
plot([T(1),v(j-1,1)],[T(2),v(j-1,2)],'color','yellow','LineWidth',3,'LineStyle','-.');
plot([v(i-1,1),v(j-1,1)],[v(i-1,2),v(j-1,2)],'color','yellow','LineWidth',3,'LineStyle','-.');
plot([S(1),v(i-1,1)],[S(2),v(i-1,2)],'color','yellow','LineWidth',3,'LineStyle','-.');
pathtemp(count-i+1) = path(j);
path = [1 9 8 7 13 14 12 22];
pathCount = length(path)-2; %经过线段数量
pheUpPara=[0.1 0.0003]; %信息素更新参数
qfz= zeros(pathCount,10); %启发值
phePara = ones(pathCount,10)*pheUpPara(2); %信息素
qfzPara1 = ones(10,1)*0.5; %启发信息参数
pathk = zeros(pathCount,m); %搜索结果记录
shortestpath = zeros(1,NC); %进化过程记录
dijpathlen = dijpathlen + sqrt((vv(path(i),1)-vv(path(i+1),1))^2+(vv(path(i),2)-vv(path(i+1),2))^2);
lines = zeros(pathCount,4);
lines(i,1:2) = B(L(path(i+1)-1,1),:);
lines(i,3:4) = B(L(path(i+1)-1,2),:);
qfz(i,:) = (qfzPara2-abs((1:10)'/10-qfzPara1))/qfzPara2; %启发信息
arg = phePara(i,:).*(qfz(i,:).^pheCacuPara);
j = find(arg == max(arg));
arg = phePara(i,:).*(qfz(i,:).^pheCacuPara);
qq = (q-pheThres)/(1-pheThres);
qtemp = qtemp + (phePara(i,j)*(qfz(i,j)^pheCacuPara))/sumarg;
phePara(i,j) = (1-pheUpPara(1))*phePara(i,j)+pheUpPara(1)*pheUpPara(2);
Pend = lines(1,1:2) + (lines(1,3:4)-lines(1,1:2))*pathk(1,k)/10;
len(1,k) = len(1,k)+sqrt(sum((Pend-Pstart).^2));
Pend = lines(l+1,1:2) + (lines(l+1,3:4)-lines(l+1,1:2))*pathk(l+1,k)/10;
len(1,k) = len(1,k)+sqrt(sum((Pend-Pstart).^2));
minant = find(len == minlen);
phePara(i,pathk(i,minant)) = (1-pheUpPara(1))* phePara(i,pathk(i,minant))+pheUpPara(1)*(1/minlen);
shortestpath(num) = minlen;
plot(1:NC,shortestpath,'color','blue');
本文分享自微信公众号 - 帮你学MatLab(MatLab_helper)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。
来源:oschina
链接:https://my.oschina.net/u/3137795/blog/4447148