再译《A *路径搜索入门》之四
2019獨角獸企業重金招聘Python工程師標準>>>
■在A *方法總結
Summary of the A* Method
?
好了,現在你通過解釋已經走了,讓我們奠定了一步一步的方法,在同一個地方:
Okay, now that you have gone through the explanation, let's lay out the step-by-step method all in one place:
?
添加開始方塊(或節點)到開啟列表。
Add the starting square (or node) to the open list.
?
重復以下操作:
Repeat the following:
?
a) 尋找開啟列表上最小F值的方塊。我們將此作為當前方塊。
Look for the lowest F cost square on the open list. We refer to this as the current square
?
b) 切換到關閉列表。
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.
?
如果不在開啟列表中,將其添加到開啟列表。使當前方塊成為這個方塊的父。記錄的方塊F值,G值和H值。
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值意味著這是一個更好的路徑。如果是這樣,把方格的父改變當前方塊,并重新計算方塊的G值和F值。如果你保持開啟列表排序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 *使用方法,你需要包含上面討論到的元素 -- 特別是開放列表和關閉列表和路徑采用F值,G值和H值。有很多其他的路徑搜索算法,但是其它的通常被認為是最好的方法不是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.
?
(待續)
轉載于:https://my.oschina.net/dubenju/blog/464443
總結
以上是生活随笔為你收集整理的再译《A *路径搜索入门》之四的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MVC捕获数据保存时的具体字段验证错误代
- 下一篇: C字符数组赋值(转)