基于改进遗传算法的路径规划MATLAB实现
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
基于遗传算法的路径规划MATLAB实现
主程序:
clear all;
close all;
t=23; %过程点个数=t-1
s=500; %种群规模
pc=0.90; %交叉概率
pm=0.20; %变异概率
pop=zeros(s,t);
for i=1:s
pop(i,1:t-1)=randperm(t-1);
end
for k=1:1:2000 %进化代次数k
if mod(k,10)==1
k
end
pop=lujingdis(pop);
c=15;%选择淘汰个数
pop=lujingselect(pop,c);
p=rand;
if p>=pc
pop=lujingcross(pop);
end
if p>=pm
pop=lujingmutate(pop);
End
end
pop
min(pop(:,t))
J=pop(:,t);
fi=1./J;
[Oderfi,Indexfi]=sort(fi); %安排fi从小到大
BestS=pop(Indexfi(s),:); %使BestS=E(m),m即是属于max(fi)的Indexfi I=BestS;
x=[2 3 6 10 14 17 22 20 23 25 30 28 25 21 29 16 18 15 9 11 6 5 ];
y=[5 26 14 29 27 24 28 22 26 30 30 17 13 15 4 13 3 1 6 2 2 7];
%过程点坐标
% x=[1 2 3 4 6 9 11 10 8 9 6 4]; %12个过程点的坐标
% y=[1 2 3 4 8 10 11 9 5 2 1 2];
for i=1:1:t-1
x1(i)=x(I(i));
y1(i)=y(I(i));
end
x(t)=x(I(1));
y(t)=y(I(1));
a = [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1
1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1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 1 1 1 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1
1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1];%31*31栅格%a = [1 1 1 1 1 1 1 1 1 1
1 1 1 0 0 1 1 1 0 0
1 0 1 0 0 1 1 1 1 1
0 0 1 1 1 1 0 1 1 0
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 0 0 1 1 0 1 1 1 1
1 1 1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 1 1 1
0 1 1 1 1 1 0 0 1 1];%11*11栅格
b = a;
b(end+1,end+1) = 0;
colormap([0 0 0;1 1 1]),pcolor(b)
axis image xy;%绘制栅格图
hold on;
figure(1);
plot(x,y,'-or');
适应度函数程序:lujingdis.m
function [pop]=qiujuli(pop)
[s,t]=size(pop);
for i=1:1:s
dd=0;
for j=1:1:t-2
dd=dd+lujingcalculate(pop(i,j),pop(i,j+1));
end