algorithm - 将 A* 更改为 dijkstra's

标签 algorithm

function A*(start, goal)

closedSet := {}

openSet := {start}

cameFrom := an empty map

gScore := map with default value of Infinity

gScore[start] := 0

fScore := map with default value of Infinity

fScore[start] := heuristic_cost_estimate(start, goal)

while openSet is not empty
    current := the node in openSet having the lowest fScore[] value
    if current = goal
        return reconstruct_path(cameFrom, current)

    openSet.Remove(current)
    closedSet.Add(current)

    for each neighbor of current
        if neighbor in closedSet
            continue    

        if neighbor not in openSet  
            openSet.Add(neighbor)

        tentative_gScore := gScore[current] + dist_between(current, neighbor)
        if tentative_gScore >= gScore[neighbor]
            continue        

        cameFrom[neighbor] := current
        gScore[neighbor] := tentative_gScore
        fScore[neighbor] := gScore[neighbor] + heuristic_cost_estimate(neighbor, goal) 

return failure

function reconstruct_path(cameFrom, current)
total_path := [current]
while current in cameFrom.Keys:
    current := cameFrom[current]
    total_path.append(current)
return total_path

如果我采用这个 A* 算法而不是从 openset 中获取最低的 fScore,而是获取最低的 gscore 甚至不考虑 fScore 是否会有效地使这个 dijksta 的?

最佳答案

Dijkstra 的最短路径算法是 A* 的一个特例,其中启发式为零,尽管 Dijkstra 的算法(1958 年)是在 10 年前构思出来的。 A* 根据 f(v) 贪婪地选择下一个要查找的顶点,其中 f(v) = h(v) + g(v)。如果将启发式 (h(v)) 设置为零,A* 将变为仅考虑当前成本 (g(v)) 选择顶点,并且您可以实现将知情的 A* 转换为非知情的 Dijkstra。

简而言之,我对你的问题的回答是"is"。

关于algorithm - 将 A* 更改为 dijkstra's,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47708889/

相关文章:

python - 是否可以使用快速排序计算计数倒置的次数?

arrays - 排列数组使其在递增和递减之间交替

algorithm - 这种独特排列算法的时间复杂度

c - 使用递归删除链表中所有出现的数字

c - 给定一个 boolean 表达式,决定在何处放置括号使其变为真

秩树特例的算法

java - 如何找到 2 个给定顶点之间的边连接

c - 如果我们从 SAD 算法计算视差值,我们如何使用该值来制作视差图?方法是什么?

python - 特里?在python中匹配带有尾随字符的单词

arrays - 在不使用多个数据结构的情况下,O(n) 时间内数组一侧的负数