再譯《A *路徑搜索入門》之四

A *方法總結node

Summary of the A* Methodweb

 

好了,在你通走了,奠基了一步一步的方法,在同一個地方:算法

Okay, now that you have gone through the explanation, let's lay out the step-by-step method all in one place:ide

 

添加開始方(或點)到開啓列表。this

Add the starting square (or node) to the open list.spa

 

重複如下操做code

Repeat the following:orm

 

a) 找開啓列表上最小F方塊。我將此做當前方排序

  1. Look for the lowest F cost square on the open list. We refer to this as the current squareci

 

b) 到關列表。

  1. Switch it to the closed list.

 

c)  當前方塊的8個方塊的...

c) For each of the 8 squares adjacent to this current square …

 

若是不能走,或者若是它是關的名上,忽略它。否請執如下操做。

If it is not walkable or if it is on the closed list, ignore it. Otherwise do the following.

 

若是不在開啓列表中,將其添加到開啓列表。使當前方塊成爲這個方記錄的方FGH

If it isn't on the open list, add it to the open list. Make the current square the parent of this square. Record the F, G, and H costs of the square.

 

若是開啓列表了,檢查,看看個路徑,否是更好的,採用G衡量。更低的G意味着是一個更好的路徑。若是是這樣方格的父改當前方,並從新算方GF。若是你保持開啓列表排序F因爲這個化你可能需重存列表。

If it is on the open list already, check to see if this path to that square is better, using G cost as the measure. A lower G cost means that this is a better path. If so, change the parent of the square to the current square, and recalculate the G and F scores of the square. If you are keeping your open list sorted by F score, you may need to resort the list to account for the change.

 

d)當你中止:

d) Stop when you:

 

添加到關列表,在種狀況下,路徑已發現下面的注),或沒法找到目,而且開啓列表是空的。在種狀況下,不存在路徑。

Add the target square to the closed list, in which case the path has been found (see note below), or Fail to find the target square, and the open list is empty. In this case, there is no path.

 

保存路徑。從目往回走,從每一個方塊移到其父,直到你到達開始是你的路徑。

Save the path. Working backwards from the target square, go from each square to its parent square until you reach the starting square. That is your path.

 

注:在早期版本的文章中,有人建,當目(或點)已添加到開啓列表,而不是關的列表,你能夠停下來。這樣作會更快,它幾乎是會你的最短路徑,但並不是是如此。有些狀況下,這樣作可能產生差別當從第二移到最後一個點到最後的(目成本可能有明顯 -例如,在河流交叉兩個點之的狀況下

Note: In earlier versions of this article, it was suggested that you can stop when the target square (or node) has been added to the open list, rather than the closed list. Doing this will be faster and it will almost always give you the shortest path, but not always. Situations where doing this could make a difference are when the movement cost to move from the second to the last node to the last (target) node can vary significantly -- as in the case of a river crossing between two nodes, for example.

 

小咆哮

Small Rant

 

個人,但得指出的是,當你在網上閱讀A *路徑搜索,並在各類論壇上的各類討論時,你偶會看到有人提到某些代不是A *A *使用方法,你須要包含上面討論到的元素 -- 是開放列表和關列表和路徑採用FGH值。有不少其餘的路徑搜索算法,可是其它的一般被認爲是最好的方法不是A *。在篇文章的末尾布萊恩斯托特討論,包括他的一些利弊引用的文章不少。有替代品在某些狀況下更好,但你應該明白你正在入。好了,爽了。回到話題

Forgive me for digressing, but it is worth pointing out that when you read various discussions of A* pathfinding on the web and in assorted forums, you will occasionally see someone refer to certain code as A* when it isn't. For the A* method to be used, you need to include the elements just discussed above -- specifically open and closed lists and path scoring using F, G, and H. There are lots of other pathfinding algorithms, but those other methods are not A*, which is generally considered to be the best of the lot. Bryan Stout discusses many of them in the article referenced at the end of this article, including some of their pros and cons. Sometimes alternatives are better under certain circumstances, but you should understand what you are getting into. Okay, enough ranting. Back to the article.

 

(待續)

相關文章
相關標籤/搜索