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 * alorgithim,而不是从openset中取出最低的fScore,那么拿最低的gscore甚至不考虑fScore会有效地制作这个dijksta的吗?
答案 0 :(得分:1)
Dijkstra的最短路径算法是A *的一个特例,其中启发式算法为零,尽管Dijkstra算法(1958)是在10年之前构思出来的。 A *根据f(v)
f(v) = h(v) + g(v)
贪婪地选择在搜索期间查找下一个顶点。如果将启发式算法(h(v)
)设置为零,则A *将变为选择仅考虑当前成本(g(v)
)的顶点,并且您可以实现将知情A *转换为未知的Dijkstra。
简而言之,我对你问题的回答是“是”。