錯誤的基于遺傳算法的機(jī)器人路徑規(guī)劃MATLAB源碼,求高人指點(diǎn)
《錯誤的基于遺傳算法的機(jī)器人路徑規(guī)劃MATLAB源碼,求高人指點(diǎn)》由會員分享,可在線閱讀,更多相關(guān)《錯誤的基于遺傳算法的機(jī)器人路徑規(guī)劃MATLAB源碼,求高人指點(diǎn)(8頁珍藏版)》請?jiān)谘b配圖網(wǎng)上搜索。
1、基于遺傳算法的機(jī)器人路徑規(guī)劃MATLAB源碼 算法的思路如下:取各障礙物頂點(diǎn)連線的中點(diǎn)為路徑點(diǎn),相互連接各路徑點(diǎn),將機(jī)器人移動的起點(diǎn)和終點(diǎn)限制在各路徑點(diǎn)上,利用Dijkstra算法來求網(wǎng)絡(luò)圖的最短路徑,找到從起點(diǎn)P1到終點(diǎn)Pn的最短路徑,由于上述算法使用了連接線中點(diǎn)的條件,不是整個規(guī)劃空間的最優(yōu)路徑,然后利用遺傳算法對找到的最短路徑各個路徑點(diǎn)Pi?(i=1,2,…n)調(diào)整,讓各路徑點(diǎn)在相應(yīng)障礙物端點(diǎn)連線上滑動,利用Pi=?Pi1+ti×(Pi2-Pi1)(ti∈[0,1]?i=1,2,…n)即可確定相應(yīng)的Pi,即為新的路徑點(diǎn),連接此路徑點(diǎn)為最優(yōu)路徑。 function?[L1,XY
2、1,L2,XY2]=JQRLJGH(XX,YY) %%?基于Dijkstra和遺傳算法的機(jī)器人路徑規(guī)劃演示程序 %輸入?yún)?shù)在函數(shù)體內(nèi)部定義 %輸出參數(shù)為 %??L1????由Dijkstra算法得出的最短路徑長度 %??XY1???由Dijkstra算法得出的最短路徑經(jīng)過節(jié)點(diǎn)的坐標(biāo) %??L2????由遺傳算法得出的最短路徑長度 %??XY2???由遺傳算法得出的最短路徑經(jīng)過節(jié)點(diǎn)的坐標(biāo) %程序輸出的圖片有 %??Fig1??環(huán)境地圖(包括:邊界、障礙物、障礙物頂點(diǎn)之間的連線、Dijkstra的網(wǎng)絡(luò)圖結(jié)構(gòu)) %??Fig2??由Dijkstra算法得到的最短路徑 %??Fi
3、g3??由遺傳算法得到的最短路徑 %??Fig4??遺傳算法的收斂曲線(迄今為止找到的最優(yōu)解、種群平均適應(yīng)值) %%?畫Fig1 figure(1); PlotGraph; title('地形圖及網(wǎng)絡(luò)拓?fù)浣Y(jié)構(gòu)') PD=inf*ones(26,26); for?i=1:26 ????for?j=1:26 ????????if?D(i,j)==1 ????????????x1=XY(i,5); ????????????y1=XY(i,6); ????????????x2=XY(j,5); ????????????y2=XY(j,6); ????????????dist
4、=((x1-x2)^2+(y1-y2)^2)^0.5; ????????????PD(i,j)=dist; ????????end ????end end %%?調(diào)用最短路算法求最短路 s=1;%出發(fā)點(diǎn) t=26;%目標(biāo)點(diǎn) [L,R]=ZuiDuanLu(PD,s,t); L1=L(end); XY1=XY(R,5:6); %%?繪制由最短路算法得到的最短路徑 figure(2); PlotGraph; hold?on for?i=1:(length(R)-1) ????x1=XY1(i,1); ????y1=XY1(i,2); ????x2=XY1(i+1
5、,1); ????y2=XY1(i+1,2); ????plot([x1,x2],[y1,y2],'k'); ????hold?on end title('由Dijkstra算法得到的初始路徑') %%?使用遺傳算法進(jìn)一步尋找最短路 %第一步:變量初始化 M=50;%進(jìn)化代數(shù)設(shè)置 N=20;%種群規(guī)模設(shè)置 Pm=0.3;%變異概率設(shè)置 LC1=zeros(1,M); LC2=zeros(1,M); Yp=L1; %第二步:隨機(jī)產(chǎn)生初始種群 X1=XY(R,1); Y1=XY(R,2); X2=XY(R,3); Y2=XY(R,4); for?i=1:N
6、????farm{i}=rand(1,aaa);
end
%?以下是進(jìn)化迭代過程
counter=0;%設(shè)置迭代計(jì)數(shù)器
while?counter 7、,1:P0),B(:,(P0+1):end)];%產(chǎn)生子代a
????b=[B(:,1:P0),A(:,(P0+1):end)];%產(chǎn)生子代b
????newfarm{2*N-1}=a;%加入子代種群
????newfarm{2*N}=b;
????for?i=1:(N-1)
????????A=farm{Ser(i)};
????????B=farm{Ser(i+1)};
????????newfarm{2*i}=b;
????end
????FARM=[farm,newfarm];%新舊種群合并????
????%%?第四步:選擇復(fù)制
????SER=randperm 8、(2*N);
????FITNESS=zeros(1,2*N);
????fitness=zeros(1,N);
????for?i=1:(2*N)
????????PP=FARM{i};
????????FITNESS(i)=MinFun(PP,X1,X2,Y1,Y2);%調(diào)用目標(biāo)函數(shù)
????end
????for?i=1:N
????????f1=FITNESS(SER(2*i-1));
????????f2=FITNESS(SER(2*i));
????????if?f1<=f2
????????else
????????????farm{i}=FARM{SER 9、(2*i)};
????????????fitness(i)=FITNESS(SER(2*i));
????????end
????end????
????%記錄最佳個體和收斂曲線
????minfitness=min(fitness);
????meanfitness=mean(fitness);
????if?minfitness 10、???????PPP=[0.5,Xp,0.5]';
????????PPPP=1-PPP;
????????X=PPP.*X1+PPPP.*X2;
????????Y=PPP.*Y1+PPPP.*Y2;
????????XY2=[X,Y];
????????figure(3)
????????PlotGraph;
????????hold?on
????????for?i=1:(length(R)-1)
????????????x1=XY2(i,1);
????????????y1=XY2(i,2);
????????????x2=XY2(i+1,1);
??????? 11、?????y2=XY2(i+1,2);
????????????plot([x1,x2],[y1,y2],'k');
????????????hold?on
????????end
????????title('遺傳算法第10代')
????????hold?on
????????for?i=1:(length(R)-1)
????????????x1=XY1(i,1);
????????????y1=XY1(i,2);
????????????x2=XY1(i+1,1);
????????????y2=XY1(i+1,2);
????????????plot([x1,x 12、2],[y1,y2],'k','LineWidth',1);
????????????hold?on
????????end
????end????
????if?counter==20
????????PPP=[0.5,Xp,0.5]';
????????PPPP=1-PPP;
????????X=PPP.*X1+PPPP.*X2;
????????Y=PPP.*Y1+PPPP.*Y2;
????????XY2=[X,Y];
????????figure(4)
????????PlotGraph;
????????hold?on
????????for?i=1:(l 13、ength(R)-1)
????????????x1=XY2(i,1);
????????????y2=XY2(i+1,2);
????????????plot([x1,x2],[y1,y2],'k');
????????????hold?on
????????end
????????title('遺傳算法第20代')
????????hold?on
????????for?i=1:(length(R)-1)
????????????x1=XY1(i,1);
????????????y1=XY1(i,2);
????????????x2=XY1(i+1,1);
???? 14、????????y2=XY1(i+1,2);
????????????plot([x1,x2],[y1,y2],'k','LineWidth',1);
????????????hold?on
????????end
????end
????if?counter==30
????????PPP=[0.5,Xp,0.5]';
????????PPPP=1-PPP;
????????X=PPP.*X1+PPPP.*X2;
????????Y=PPP.*Y1+PPPP.*Y2;
????????XY2=[X,Y];
????????figure(5)
????????PlotG 15、raph;
????????hold?on
????????for?i=1:(length(R)-1)
????????????x1=XY2(i,1);
????????????y1=XY2(i,2);
????????????x2=XY2(i+1,1);
????????????y2=XY2(i+1,2);
????????????plot([x1,x2],[y1,y2],'k');
????????????hold?on
????????end
????????title('遺傳算法第30代')
????????hold?on
????????for?i=1:(le 16、ngth(R)-1)
????????????x1=XY1(i,1);
????????????y2=XY1(i+1,2);
????????????plot([x1,x2],[y1,y2],'k','LineWidth',1);
????????????hold?on
????????end
????end
????if?counter==40
????????PPP=[0.5,Xp,0.5]';
????????PPPP=1-PPP;
????????X=PPP.*X1+PPPP.*X2;
????????Y=PPP.*Y1+PPPP.*Y2;
????????XY 17、2=[X,Y];
????????figure(6)
????????PlotGraph;
????????hold?on
????????for?i=1:(length(R)-1)
????????????x1=XY2(i,1);
????????????y1=XY2(i,2);
????????????x2=XY2(i+1,1);
????????????y2=XY2(i+1,2);
????????????plot([x1,x2],[y1,y2],'k');
????????????hold?on
????????end
????????title('遺傳算法第4 18、0代')
????????hold?on
????????for?i=1:(length(R)-1)
????????????x1=XY1(i,1);
????????????y1=XY1(i,2);
????????????x2=XY1(i+1,1);
????????????y2=XY1(i+1,2);
????????????plot([x1,x2],[y1,y2],'k','LineWidth',1);
????????????hold?on
????????end
????end
????if?counter==50
????????PPP=[0.5,Xp,0 19、.5]';
????????PPPP=1-PPP;
????????X=PPP.*X1+PPPP.*X2;
????????Y=PPP.*Y1+PPPP.*Y2;
????????XY2=[X,Y];
????????figure(7)
????????PlotGraph;
????????hold?on
????????for?i=1:(length(R)-1)
????????????x1=XY2(i,1);
????????????y1=XY2(i,2);
????????????x2=XY2(i+1,1);
????????????y2=XY2(i+1,2);
20、
????????????plot([x1,x2],[y1,y2],'k');
????????????hold?on
????????end
????????title('遺傳算法第50代')
????????hold?on
????????for?i=1:(length(R)-1)
????????????x1=XY1(i,1);
????????????y1=XY1(i,2);
????????????x2=XY1(i+1,1);
????????????y2=XY1(i+1,2);
????????????plot([x1,x2],[y1,y2],'k','Line 21、Width',1);
????????????hold?on
????????end
????end????
????LC2(counter+1)=Yp;
????LC1(counter+1)=meanfitness;????
????%%?第五步:變異
????for?i=1:N
????????if?Pm>rand&&pos(1)~=i
????????????AA=farm{i};
????????????AA(POS)=rand;
????????????farm{i}=AA;
????????end
????end????
????counter=coun 22、ter+1;
????disp(counter);
end
%%?輸出遺傳算法的優(yōu)化結(jié)果
PPP=[0.5,Xp,0.5]';
PPPP=1-PPP;
X=PPP.*X1+PPPP.*X2;
Y=PPP.*Y1+PPPP.*Y2;
XY2=[X,Y];
L2=Yp;
%%?繪制Fig3
figure(8)
PlotGraph;
hold?on
hold?on
for?i=1:(length(R)-1)
????x1=XY1(i,1);
????y1=XY1(i,2);
????x2=XY1(i+1,1);
????y2=XY1(i+1,2);
????p 23、lot([x1,x2],[y1,y2],'k','LineWidth',1);
????hold?on
end
for?i=1:(length(R)-1)
????x1=XY2(i,1);
????y1=XY2(i,2);
????x2=XY2(i+1,1);
????y2=XY2(i+1,2);
????plot([x1,x2],[y1,y2],'k');
????hold?on
end
title('遺傳算法最終結(jié)果')
figure(9)
PlotGraph;
hold?on
for?i=1:(length(R)-1)
????x1=XY1(i,1);
24、????y1=XY1(i,2);
????x2=XY1(i+1,1);
????y2=XY1(i+1,2);
????plot([x1,x2],[y1,y2],'k','LineWidth',1);
????hold?on
end
hold?on
for?i=1:(length(R)-1)
????x1=XY2(i,1);
????y1=XY2(i,2);
????x2=XY2(i+1,1);
????y2=XY2(i+1,2);
????plot([x1,x2],[y1,y2],'k','LineWidth',2);
????hold?on
end
title('遺傳算法優(yōu)化前后結(jié)果比較')
%%?繪制Fig4
figure(10);
plot(LC1);
hold?on
plot(LC2);
xlabel('迭代次數(shù)');
title('收斂曲線');
- 溫馨提示:
1: 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
2: 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
3.本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
5. 裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2020高考化學(xué)熱門專題:原理綜合透題型析課件
- 現(xiàn)代中國的教育說課稿課件
- 蒸餾和熔點(diǎn)沸點(diǎn)的測定和溫度計(jì)的校正
- 臨時起搏器的護(hù)理
- 恒成實(shí)業(yè)網(wǎng)絡(luò)推廣方案
- 勿為小惡優(yōu)秀課件-粵教版
- 人教版初中地理七年級上冊人口與人種課件7
- 誡子書課件文檔
- 軟件測試計(jì)劃書與測試用例編寫課件
- 人教版五年級數(shù)學(xué)上冊課件3小數(shù)除法第2課時除數(shù)是整數(shù)的小數(shù)除法課件
- 太白酒2002年全國推廣營銷企劃案
- 滬教版小學(xué)語文三年級上冊《小狗杜克》課件1
- 我們的情感世界課件7-人教版
- 擔(dān)保產(chǎn)品案例講解及其風(fēng)險控制設(shè)計(jì)(含法律相關(guān)規(guī)范)
- 【部編版】四年級語文上冊《2.走月亮》ppt課件