www.pudn.com > GA.rar > DrawPath.m, change:2014-10-06,size:852b


%% 画路径函数 
%输入 
% Chrom  待画路径    
% X      各城市坐标位置 
function DrawPath(Chrom,X) 
R=[Chrom(1,:) Chrom(1,1)]; %一个随机解(个体) 
figure; 
hold on 
plot(X(:,1),X(:,2),'bo','color',[0.5,0.5,0.5]) 
plot(X(Chrom(1,1),1),X(Chrom(1,1),2),'rv','MarkerSize',20)    %标注起点终点 
% plot(X(:,1),X(:,2),'o','color',[0.5,0.5,0.5]) 
% plot(X(Chrom(1,1),1),X(Chrom(1,1),2),'rv','MarkerSize',20) 
for i=1:size(X,1) 
    text(X(i,1)+0.05,X(i,2)+0.05,num2str(i),'color',[1,0,0]); 
end 
A=X(R,:); 
row=size(A,1); 
for i=2:row 
    [arrowx,arrowy] = dsxy2figxy(gca,A(i-1:i,1),A(i-1:i,2));%坐标转换 
    annotation('textarrow',arrowx,arrowy,'HeadWidth',4,'color',[0,0,1]);   %annotation:注释 
%   annotation('textarrow',arrowx,arrowy,'HeadWidth',8,'color',[0,0,1]); 
end 
hold on 
xlabel('节点距离/m') 
ylabel('节点距离/m') 
title('路径寻优轨迹图') 
box on