資源簡介
用 MATLAB 實現基于柵格地圖的A-星算法路徑規劃,代碼中障礙物是隨機的。

代碼片段和文件信息
function?shangeaxingdaima?
%ASTARDEMO?Demonstration?of?ASTAR?algorithm?
n?=?20;?%?field?size?n?x?n?tiles?20*20的界面?
wallpercent?=?0.35;?%?this?percent?of?field?is?walls?35%的界面作為阻礙物(墻)?
%?create?the?n?x?n?FIELD?with?wallpercent?walls?containing?movement?costs?創建包含移動成本的wallpercent墻
%?a?starting?position?STARTPOSIND?a?goal?position?GOALPOSIND?the?costs?起始位置startposind?目標位置goalposind成本
%?A?star?will?compute?movement?cost?for?each?tile?COSTCHART?星號將計算每個方格的移動開銷
%?and?a?matrix?in?which?to?store?the?pointers?FIELDPOINTERS?存儲指針fieldpointers的矩陣
[field?startposind?goalposind?costchart?fieldpointers]?=?...
????initializeField(nwallpercent);?%初始化界面?
%?initialize?the?OPEN?and?CLOSED?sets?and?their?costs?,初始化開集和閉集及其代價
setOpen?=?startposind;?setOpenCosts?=?0;?setOpenHeuristics?=?Inf;?%Heuristics??啟發式
setClosed?=?[];?setClosedCosts?=?[];?
movementdirections?=?{‘R‘‘L‘‘D‘‘U‘};?
%?keep?track?of?the?number?of?iterations?to?exit?gracefully?if?no?solution?counterIterations?=?1;如果沒有解決方案counteriterations?=?1?請跟蹤要正常退出的迭代次數;
axishandle?=?createFigure(fieldcostchartstartposindgoalposind);?
%?as?long?as?we?have?not?found?the?goal?or?run?out?of?spaces?to?explore?只要我們沒有找到目標或跑出空間去探索
while?~max(ismember(setOpengoalposind))?&&?~isempty(setOpen)?%ismember(AB)返回與A同大小的矩陣,其中元素1表示A中相應位置的元素在B中也出現,0則是沒有出現?
%?for?the?element?in?OPEN?with?the?smallest?cost?
[tempii]?=?min(setOpenCosts?+?setOpenHeuristics);?%從OPEN表中選擇花費最低的點tempii是其下標(也就是標號索引)?temp改為~
%?find?costs?and?heuristic?of?moving?to?neighbor?spaces?to?goal?
%?in?order?‘R‘‘L‘‘D‘‘U‘?
[costsheuristicsposinds]?=?findFValue(setOpen(ii)setOpenCosts(ii)?...
????fieldgoalposind‘euclidean‘);?%擴展temp的四個方向點,獲得其坐標posinds,各個方向點的實際代價costs,啟發代價heuristics?
%?put?node?in?CLOSED?and?record?its?cost?
setClosed?=?[setClosed;?setOpen(ii)];?%將temp插入CLOSE表中?
setClosedCosts?=?[setClosedCosts;?setOpenCosts(ii)];?%將temp的花費計入ClosedCosts?
%?update?OPEN?and?their?associated?costs?更新OPEN表?分為三種情況?
if?(ii?>?1?&&?ii?setOpen?=?[setOpen(1:ii-1);?setOpen(ii+1:end)];?
setOpenCosts?=?[setOpenCosts(1:ii-1);?setOpenCosts(ii+1:end)];?
setOpenHeuristics?=?[setOpenHeuristics(1:ii-1);?setOpenHeuristics(ii+1:end)];?
elseif?(ii?==?1)?
setOpen?=?setOpen(2:end);?%temp是OPEN表的第一個元素,刪除temp?
setOpenCosts?=?setOpenCosts(2:end);?
setOpenHeuristics?=?setOpenHeuristics(2:end);?
else?%temp是OPEN表的最后一個元素,刪除temp?
setOpen?=?setOpen(1:end-1);?
setOpenCosts?=?setOpenCosts(1:end-1);?
setOpenHeuristics?=?setOpenHeuristics(1:end-1);?
end?
%?for?each?of?these?neighbor?spaces?assign?costs?and?pointers;?對于每個鄰居空間分配成本和指針;
%?and?if?some?are?in?the?CLOSED?set?and?their?costs?are?smaller?如果一些是在封閉集合他們的成本較小
%?update?their?costs?and?pointers?更新他們的成本和指針
for?jj=1:length(posinds)?%對于擴展的四個方向的坐標?
%?if?cost?infinite?then?it‘s?a?wall?so?ignore?如果成本無限那么它就是一堵墻所以忽略
if?~isinf(costs(jj))?%如果此點的實際代價不為Inf(無窮)也就是沒有遇到墻?
%?if?node?is?not?in?OPEN?or?CLOSED?then?insert?into?costcha
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-01-19?09:28??A星代碼(任意)+文檔\
?????文件?????????372??2007-01-07?13:57??A星代碼(任意)+文檔\A.caa
?????文件?????????372??2007-01-07?13:59??A星代碼(任意)+文檔\A1.caa
?????文件??????280122??2007-01-07?13:58??A星代碼(任意)+文檔\A_算法在矢量地圖最優路徑搜索中的應用_劉浩?(1).caj
?????文件??????280122??2007-01-07?13:58??A星代碼(任意)+文檔\A_算法在矢量地圖最優路徑搜索中的應用_劉浩.caj
?????文件??????244875??2007-01-07?13:59??A星代碼(任意)+文檔\A_算法改進算法及其應用_張仁平.caj
?????目錄???????????0??2018-01-19?09:28??A星代碼(任意)+文檔\A星算法障礙任意\
?????文件???????15167??2017-04-26?20:31??A星代碼(任意)+文檔\A星算法障礙任意\shangeaxingdaima.m
?????文件??????231797??2007-01-07?13:59??A星代碼(任意)+文檔\基于加權A_算法的服務型機器人路徑規劃_趙真明.caj
?????文件??????686043??2007-01-07?13:58??A星代碼(任意)+文檔\基于平滑A_算法的移動機器人路徑規劃_王紅衛.caj
- 上一篇:基于柵格地圖的A星算法路徑規劃
- 下一篇:matlab反距離權重插值
評論
共有 條評論