第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

[JAVA} A-Star 代碼沒(méi)有找到最優(yōu)路徑

[JAVA} A-Star 代碼沒(méi)有找到最優(yōu)路徑

汪汪一只貓 2021-11-17 15:09:35
我正在嘗試編寫(xiě) A* 搜索算法,但似乎無(wú)法使其正常工作。我正在從維基百科復(fù)制偽代碼。我的代碼似乎只是搜索每個(gè)可能的節(jié)點(diǎn)。這是我的 showPath() 函數(shù):public void showPath() {Nodes current = end;while(current.cameFrom!=null) {    current.isPath = true;    current = current.cameFrom;}}起始節(jié)點(diǎn)的 comeFrom 為 null,因?yàn)檫@是默認(rèn)值。public void A_Star() {PriorityQueue<Nodes> closedSet = new PriorityQueue<Nodes>();PriorityQueue<Nodes> openSet = new PriorityQueue<Nodes>();closedSet.clear();openSet.clear();start.gScore = 0;openSet.add(start);start.fScore = getDist(start,end);while(!(openSet.size() ==0)) {    Nodes curr = openSet.poll();    if(curr.x == end.x && curr.y == end.y) {        showPath();    }    closedSet.add(curr);    for(int i=0;i<curr.getNeighbourCount();i++) {        Nodes neighbour = curr.getNeighbour(i);        if(closedSet.contains(neighbour)) {            continue;        }        //isPassable is a boolean that is false if the Nodes is an obstacle        if(!openSet.contains(neighbour) && neighbour.isPassable) {            openSet.add(neighbour);        }        //It's a grid so every point is a distance of 1 from it's neighbours        else if((curr.gScore+1)>= neighbour.gScore){            continue;        }        neighbour.cameFrom = curr;        neighbour.gScore = curr.gScore+1;        neighbour.fScore = neighbour.gScore + getDist(neighbour,end);    }}}編輯:我的 getDist 函數(shù)public int getDist(Nodes node1, Nodes node2) {    return ( Math.abs(node1.x - node2.x) + Math.abs(node1.y - node2.y));}
查看完整描述

1 回答

?
慕妹3146593

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超9個(gè)贊

如果你看一下這個(gè)picure,你要的是,與曼哈頓距離,一切從起點(diǎn)至終點(diǎn)的路徑具有相等的距離通知。這將導(dǎo)致,您將訪問(wèn)所有。

將距離更改為歐幾里得距離。



查看完整回答
反對(duì) 回復(fù) 2021-11-17
  • 1 回答
  • 0 關(guān)注
  • 208 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)