且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

算法找到最短路径,与障碍

更新时间:2022-12-17 10:39:57

这是一个很好的去处使用 A *搜索算法,启发式搜索算法,发现两点之间的***路径非常快,即使有障碍物present。这样做是为了在网格转换成图表其中在所述网格中的每个单元是一个节点,并且其中有未彼此妨碍任何两个相邻小区之间的边缘。一旦你有了这个图,你要找的答案是从起始节点到目的节点图中的最短路径。

This is an excellent spot to use the A* search algorithm, a heuristic search algorithm that finds optimal paths between points very quickly even when there are obstacles present. The idea is to convert the grid into a graph where each cell in the grid is a node and in which there is an edge between any two adjacent cells that aren't obstructed from one another. Once you have this graph, the answer you're looking for is the shortest path in the graph from the start node to the destination node.

为了使用A *,你需要一个启发函数的猜测,从发车到目的地方任何一点的距离。一个良好的启发式这是使用两点之间的曼哈顿距离

In order to use A*, you'll need a heuristic function that "guesses" the distance from any point on the grid to the destination square. One good heuristic for this would be to use the Manhattan distance between the two points.

如果您正在寻找寻找最短路径更容易,但仍然非常有效的算法,考虑寻找到 Dijkstra算法,它可以被看作是A *简化版本。它比A *慢一点,但仍运行速度非常快,并保证***的答案。

If you're looking for an easier but still extremely efficient algorithm for finding the shortest path, consider looking into Dijkstra's algorithm, which can be thought of as a simpler version of A*. It's a bit slower than A*, but still runs extremely quickly and guarantees an optimal answer.

希望这有助于!