錯(cuò)誤的基于遺傳算法的機(jī)器人路徑規(guī)劃MATLAB源碼,求高人指點(diǎn)
《錯(cuò)誤的基于遺傳算法的機(jī)器人路徑規(guī)劃MATLAB源碼,求高人指點(diǎn)》由會(huì)員分享,可在線閱讀,更多相關(guān)《錯(cuò)誤的基于遺傳算法的機(jī)器人路徑規(guī)劃MATLAB源碼,求高人指點(diǎn)(8頁(yè)珍藏版)》請(qǐng)?jiān)谘b配圖網(wǎng)上搜索。
1、基于遺傳算法的機(jī)器人路徑規(guī)劃MATLAB源碼 算法的思路如下:取各障礙物頂點(diǎn)連線的中點(diǎn)為路徑點(diǎn),相互連接各路徑點(diǎn),將機(jī)器人移動(dòng)的起點(diǎn)和終點(diǎn)限制在各路徑點(diǎn)上,利用Dijkstra算法來(lái)求網(wǎng)絡(luò)圖的最短路徑,找到從起點(diǎn)P1到終點(diǎn)Pn的最短路徑,由于上述算法使用了連接線中點(diǎn)的條件,不是整個(gè)規(guī)劃空間的最優(yōu)路徑,然后利用遺傳算法對(duì)找到的最短路徑各個(gè)路徑點(diǎn)Pi?(i=1,2,…n)調(diào)整,讓各路徑點(diǎn)在相應(yīng)障礙物端點(diǎn)連線上滑動(dòng),利用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算法得出的最短路徑長(zhǎng)度 %??XY1???由Dijkstra算法得出的最短路徑經(jīng)過(guò)節(jié)點(diǎn)的坐標(biāo) %??L2????由遺傳算法得出的最短路徑長(zhǎng)度 %??XY2???由遺傳算法得出的最短路徑經(jīng)過(guò)節(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)化迭代過(guò)程
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????
????%記錄最佳個(gè)體和收斂曲線
????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: 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
2: 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
3.本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
5. 裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 110中國(guó)人民警察節(jié)(筑牢忠誠(chéng)警魂感受別樣警彩)
- 2025正字當(dāng)頭廉字入心爭(zhēng)當(dāng)公安隊(duì)伍鐵軍
- XX國(guó)企干部警示教育片觀后感筑牢信仰之基堅(jiān)守廉潔底線
- 2025做擔(dān)當(dāng)時(shí)代大任的中國(guó)青年P(guān)PT青年思想教育微黨課
- 2025新年工作部署會(huì)圍繞六個(gè)干字提要求
- XX地區(qū)中小學(xué)期末考試經(jīng)驗(yàn)總結(jié)(認(rèn)真復(fù)習(xí)輕松應(yīng)考)
- 支部書(shū)記上黨課筑牢清廉信念為高質(zhì)量發(fā)展?fàn)I造風(fēng)清氣正的環(huán)境
- 冬季消防安全知識(shí)培訓(xùn)冬季用電防火安全
- 2025加強(qiáng)政治引領(lǐng)(政治引領(lǐng)是現(xiàn)代政黨的重要功能)
- 主播直播培訓(xùn)直播技巧與方法
- 2025六廉六進(jìn)持續(xù)涵養(yǎng)良好政治生態(tài)
- 員工職業(yè)生涯規(guī)劃方案制定個(gè)人職業(yè)生涯規(guī)劃
- 2024年XX地區(qū)黨建引領(lǐng)鄉(xiāng)村振興工作總結(jié)
- XX中小學(xué)期末考試經(jīng)驗(yàn)總結(jié)(認(rèn)真復(fù)習(xí)輕松應(yīng)考)
- 幼兒園期末家長(zhǎng)會(huì)長(zhǎng)長(zhǎng)的路慢慢地走