java - A*算法返回失败伪代码
问题描述
我试图了解在伪代码末尾使用返回失败的实际作用。它将如何返回计算的路径?
// For each node, the cost of getting from the start node to that node.
gScore := map with default value of Infinity
// The cost of going from start to start is zero.
gScore[start] := 0
// For each node, the total cost of getting from the start node to the goal
// by passing by that node. That value is partly known, partly heuristic.
fScore := map with default value of Infinity
// For the first node, that value is completely heuristic.
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 // Ignore the neighbor which is already evaluated.
// The distance from start to a neighbor
tentative_gScore := gScore[current] + dist_between(current, neighbor)
if neighbor not in openSet // Discover a new node
openSet.Add(neighbor)
else if tentative_gScore >= gScore[neighbor]
continue // This is not a better path.
// This path is the best until now. Record it!
cameFrom[neighbor] := current
gScore[neighbor] := tentative_gScore
fScore[neighbor] := gScore[neighbor] + heuristic_cost_estimate(neighbor, goal)
return failure
解决方案
推荐阅读
- javascript - 我想在 sendinf API 请求中的对象下使用基于条件的对象
- java - 相交功能在第一次相交后停止工作
- javascript - 使用 PasteFromWord 插件时出现 CKEditor 异常
- elasticsearch - 如何使用 Java 高级 REST 客户端 API 编写 elasticsearch-sql 查询
- javascript - ReactJS 组件的引导表 JS 扩展功能
- r - 如何创建一个函数来根据 R 中不同数据框中的值生成新变量
- sql - LEFT OUTER JOIN 的行为类似于 INNER JOIN
- powershell - 如何在powershell中复制zip文件夹
- c# - 在c#中删除文件中的项目
- ruby - 转储:厨师中的节点对象