日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

再译《A *路径搜索入门》之二

發布時間:2023/12/31 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 再译《A *路径搜索入门》之二 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

路徑

Path Scoring

算出的路徑時,確定要使用的方格的關下面的公式

The key to determining which squares to use when figuring out the path is the following equation:

?

F = G + H

?

where

?

G =從起點A沿著生成的路徑到一個定的方形網格上運行成本。

G = the movement cost to move from the starting point A to a given square on the grid, following the path generated to get there.

?

H =格子中方塊到最目的地,B的運行成本。通常稱式,可有點混亂。因是一個猜所以這樣稱呼。找到路徑之前,真的不知道實際的距離,因各種各的事情都在途中,水等)。在本教程中給出一個H的方法,但在網計算H方法其他文章

H = the estimated movement cost to move from that given square on the grid to the final destination, point B. This is often referred to as the heuristic, which can be a bit confusing. The reason why it is called that is because it is a guess. We really don't know the actual distance until we find the path, because all sorts of things can be in the way (walls, water, etc.). You are given one way to calculate H in this tutorial, but there are many others that you can find in other articles on the web.

?

反復遍開啟列表,選擇具有最小F的方塊來生成的路徑。在本文中程將一步更詳細描述。首先來仔看看如何算公式。

Our path is generated by repeatedly going through our open list and choosing the square with the lowest F score. This process will be described in more detail a bit further in the article. First let's look more closely at how we calculate the equation.

?

如上所述,G從起始點移定點所生成路徑的成本。在個例子中,我將指每個移水平或垂直方成本10成本14。們使用這些數字為斜角移動2的平方根(不要害怕),水平或垂直的大1.414倍。我使用1014簡單。比例大致是正確的,又能避免算平方根和小數。這不只是因為我們是愚笨的,不喜歡數學。采用些數字是讓計算機更快,太快了。你很快就會發現,如果你不使用些捷徑路徑搜索能會很慢的。

As described above, G is the movement cost to move from the starting point to the given square using the path generated to get there. In this example, we will assign a cost of 10 to each horizontal or vertical square moved, and a cost of 14 for a diagonal move. We use these numbers because the actual distance to move diagonally is the square root of 2 (don't be scared), or roughly 1.414 times the cost of moving horizontally or vertically. We use 10 and 14 for simplicity's sake. The ratio is about right, and we avoid having to calculate square roots and we avoid decimals. This isn't just because we are dumb and don't like math. Using whole numbers like these is a lot faster for the computer, too. As you will soon find out, pathfinding can be very slow if you don't use short cuts like these.

?

由于我們計G值是沿特定的路徑定的平方,該辦找出那個方的父G,然后加1014取決于它從父方正交(非還是。需要種方法將在本施例一步上得明一點,因得到一個以上的方

Since we are calculating the G cost along a specific path to a given square, the way to figure out the G cost of that square is to take the G cost of its parent, and then add 10 or 14 depending on whether it is diagonal or orthogonal (non-diagonal) from that parent square. The need for this method will become apparent a little further on in this example, as we get more than one square away from the starting square.

?

H各種方式。我里使用的方法被稱曼哈方法,在計算從當前方塊到目標方水平和垂直方向移動方塊的總數忽略角運,忽略可能在程中的任何障礙。然后,我數乘以10,我的成本水平或垂直移一格。是(可能)被稱曼哈方法,因它像算城市街區的數量從一個地方到另一個地方,在那里你不能穿過塊對角。

H can be estimated in a variety of ways. The method we use here is called the Manhattan method, where you calculate the total number of squares moved horizontally and vertically to reach the target square from the current square, ignoring diagonal movement, and ignoring any obstacles that may be in the way. We then multiply the total by 10, our cost for moving one square horizontally or vertically. This is (probably) called the Manhattan method because it is like calculating the number of city blocks from one place to another, where you can't cut across the block diagonally.

?

閱讀明,您可能已猜到了啟僅僅是當前方與目的剩余距離的一個烏鴉飛似的”粗略的估。不是種情況。我們實際試圖沿路徑的剩余距離(通常是更)。越接近我的估實際剩余距離,快的算法。如果我高估了個距離,但是,它不能保證給的最短路徑。在這樣的情況下,我有所的“不可接受啟式”。

Reading this description, you might guess that the heuristic is merely a rough estimate of the remaining distance between the current square and the target "as the crow flies." This isn't the case. We are actually trying to estimate the remaining distance along the path (which is usually farther). The closer our estimate is to the actual remaining distance, the faster the algorithm will be. If we overestimate this distance, however, it is not guaranteed to give us the shortest path. In such cases, we have what is called an "inadmissible heuristic."

?

從技,在個例子中,曼哈方法是不可接受的,因它稍稍高估了剩下的距離。但是我會用也無妨,因它是一個更容易理解我的目的,因它只是一個微的高估。在極少的情況下,得到的路徑不是最短的,這將是近短。想了解更多?你你可以在http://www.policyalmanac.org/games/heuristics.htm找到方程和附加明啟式。

Technically, in this example, the Manhattan method is inadmissible because it slightly overestimates the remaining distance. But we will use it anyway because it is a lot easier to understand for our purposes, and because it is only a slight overestimation. On the rare occasion when the resulting path is not the shortest possible, it will be nearly as short. Want to know more? You can find equations and additional notes on heuristics here.

?

FGH中的和。搜索的第一個步果可以下面的明中看出。在FGH的分數被寫入在每個方格。正如在緊挨著開始方塊右側上,F被打印在左上角,G印在左下方,而H示在右下方。

F is calculated by adding G and H. The results of the first step in our search can be seen in the illustration below. The F, G, and H scores are written in each square. As is indicated in the square to the immediate right of the starting square, F is printed in the top left, G is printed in the bottom left, and H is printed in the bottom right.

?

[3]

[Figure 3]

?

所以,來看看其中的一些方。在字母上,G = 10是因它是在一個水平方向的距離起始方塊僅。正方形緊鄰上方,下方,及在起始的左10相同的G14G

So let's look at some of these squares. In the square with the letters in it, G = 10. This is because it is just one square from the starting square in a horizontal direction. The squares immediately above, below, and to the left of the starting square all have the same G score of 10. The diagonal squares have G scores of 14.

?

H是通計到紅色目的曼哈距離,水平和垂直方向,而忽略上那就是在算方式。使用種方法,方上開始的直接右3格是紅格30。那么高于個方的方塊的H4格距離(住,只能水平移和垂直)的一個H40.你也可以看到其他方塊計H值的方法。

The H scores are calculated by estimating the Manhattan distance to the red target square, moving only horizontally and vertically and ignoring the wall that is in the way. Using this method, the square to the immediate right of the start is 3 squares from the red square, for a H score of 30. The square just above this square is 4 squares away (remember, only move horizontally and vertically) for an H score of 40. You can probably see how the H scores are calculated for the other squares.

?

每個方格的F,再次,只是通GH一起算。

The F score for each square, again, is simply calculated by adding G and H together.

(待續)

轉載于:https://my.oschina.net/dubenju/blog/426134

總結

以上是生活随笔為你收集整理的再译《A *路径搜索入门》之二的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。