xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

資源簡(jiǎn)介

A*算法是從起始點(diǎn)開(kāi)始向目標(biāo)點(diǎn)搜索,而雙向A*是在A*的基礎(chǔ)上由起始點(diǎn)和目標(biāo)點(diǎn)同時(shí)搜索,當(dāng)一方檢測(cè)到另一方的已檢查節(jié)點(diǎn)時(shí),搜索結(jié)束,在搜索時(shí)間效率上,雙向A*更快。

資源截圖

代碼片段和文件信息

function?bidirectional_ASTAR
clc;
clear;
%%?初始化界面
n?=?11;???%?field?size?n?x?n?tiles??20*20的界面
%wallpercent?=?0.3;??%?this?percent?of?field?is?walls???15%的界面作為阻礙物(墻)
cmap?=?[1?1?1;?...%??1?-?white?-?空地
????????0?0?0;?...%?2?-?black?-?障礙?
????????1?0?0;?...%?3?-?red?-?已搜索過(guò)的地方
????????0?0?1;?...%?4?-?blue?-?下次搜索備選中心?
????????0?1?0;?...%?5?-?green?-?起始點(diǎn)
????????1?1?0;...%?6?-?yellow?-??到目?標(biāo)點(diǎn)的路徑?
???????1?0?1];%?7?-?-??目標(biāo)點(diǎn)?
colormap(cmap);?
field?=?ones(n);
startposind?=10;???%sub2ind用來(lái)將行列坐標(biāo)轉(zhuǎn)換為線性坐標(biāo),這里是必要的,因?yàn)槿绻裺tartposind設(shè)置成[xy]的形式,訪問(wèn)field([xy])的時(shí)候
goalposind?=12;????%它并不是訪問(wèn)x行y列元素,而是訪問(wèn)線性坐標(biāo)為x和y的兩個(gè)元素
%?field(ceil(n^2.*rand(floor(n*n*wallpercent)1)?))?=?Inf;
field(1:5?7)?=?2;
field(81:3)?=?2;?
field(2:53:5)=2;
???field(810)=2;
%?startposind?=?sub2ind([nn]ceil(n.*rand)ceil(n.*rand));???%sub2ind用來(lái)將行列坐標(biāo)轉(zhuǎn)換為線性坐標(biāo),這里是必要的,因?yàn)槿绻裺tartposind設(shè)置成[xy]的形式,訪問(wèn)field([xy])的時(shí)候
%goalposind?=?sub2ind([nn]ceil(n.*rand)ceil(n.*rand));????%它并不是訪問(wèn)x行y列元素,而是訪問(wèn)線性坐標(biāo)為x和y的兩個(gè)元素
field(startposind?)=5;
field(goalposind?)=7;
costchart?=?NaN*ones(n);??????%costchart用來(lái)存儲(chǔ)各個(gè)點(diǎn)的實(shí)際代價(jià),NaN代表不是數(shù)據(jù)(不明確的操作)
costchart(startposind)?=?0;?????%起點(diǎn)的實(shí)際代價(jià)
fieldpointers?=?zeros(n);
fieldpointers1?=?zeros(n);
????global?setOpenCosts;
????global?setOpenCosts1;
????global?setOpen;
????global?setOpen1;
????global?setOpenHeuristics;
????global?setOpenHeuristics1;
setOpen?=?(startposind);?setOpenCosts?=?(0);?setOpenHeuristics?=?(Inf);
setClosed?=?[];?setClosedCosts?=?[];%初始化起點(diǎn)的open表和close表
setOpen1?=?(goalposind);?setOpenCosts1?=?(0);?setOpenHeuristics1?=?(Inf);
setClosed1?=?[];?setClosedCosts1?=?[];%初始化目標(biāo)點(diǎn)的open表和close表

[goalpos(1)?goalpos(2)]?=?ind2sub([n?n]goalposind);???????%獲得目標(biāo)點(diǎn)的行列坐標(biāo)
[startpos(1)?startpos(2)]?=?ind2sub([n?n]startposind);
uicontrol(‘style‘‘pushbutton‘‘String‘‘RE-DO‘?‘FontSize‘12?...
?????????‘Position‘?[10?10?60?40]?‘Callback‘‘bidirectional_ASTAR‘);
tic
while?true?%ismember(AB)返回與A同大小的矩陣,其中元素1表示A中相應(yīng)位置的元素在B中也出現(xiàn),0則是沒(méi)有出現(xiàn)
???field(startposind?)=5;
???field(goalposind?)=7;
???image(1.51.5field);?
????grid?on;?
????axis?image;?
????set(gca‘gridline‘‘-‘‘gridcolor‘‘r‘‘linewidth‘2);
????set(gca‘xtick‘1:1:12‘ytick‘1:1:12);
????drawnow;
??if(max(ismember(setOpensetOpen1)))
???????break;
???end;??
???
????[~?ii]?=?min(setOpenCosts?+?setOpenHeuristics);???%從OPEN表中選擇花費(fèi)最低的點(diǎn)tempii是其下標(biāo)(也就是標(biāo)號(hào)索引)
????[~?ii1]?=?min(setOpenCosts1?+?setOpenHeuristics1);
????field(setOpen(ii))=3;
????field(setOpen1(ii1))=6;
????[currentpos(1)?currentpos(2)]?=?ind2sub([n?n]setOpen(ii));
????[currentpos1(1)?currentpos1(2)]?=?ind2sub([n?n]setOpen1(ii1));%獲得以起點(diǎn)擴(kuò)展的當(dāng)前點(diǎn)的行列坐標(biāo),注意currentpos(1)是行坐標(biāo),currentpos(2)是列坐標(biāo)
????%%?獲得當(dāng)前點(diǎn)的鄰居
????[posindsposinds1costcost1heuristicheuristic1]=get_neighbors(niiii1currentpos(1)currentpos(2)currentpos1(1)currentpos1(2)goalpos(1)goalpos(2)startpos(1)startpos(2));
????
?????setClosed?=?[setClosed;?setOpen(ii)];?????%將temp插入CLOSE表中
?????setClosedCosts?=?[setClosedCosts;?setOpenCost

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????14485??2019-04-30?15:44??bidirectional_ASTAR.m

評(píng)論

共有 條評(píng)論

相關(guān)資源