while openSet: current = extract_minCost_of_openSet(openSet) # 从openset中获取开销最小的节点(从源点到当前点n的距离最短的) if current == end: # 成功找到最短路径 return reconstruct_path(cameFrom, current) openSet.remove(current) closeSet.add(current)
for neighbor in get_all_neighbors(graph, current): if neighbor in closeSet: continue if neighbor_can_pass(neighbor): gScore[neighbor] = gScore[current] + distance(current, neighbor) cameFrom[neighbor] = current # f(n) = g(n) + h(n) fScore[neighbor] = gScore[neighbor] + heuristic_cost_estimate(neighbor, end) openSet.add(neighbor)
while openSet: current = extract_minCost_of_openSet(openSet) # 从openset中获取开销最小的节点(从源点到当前点n的距离最短的) if current == end: # 成功找到最短路径 return reconstruct_path(cameFrom, current) openSet.remove(current) closeSet.add(current)
for neighbor in get_all_neighbors(graph, current): if neighbor in closeSet: continue if neighbor_can_pass(neighbor): gScore[neighbor] = gScore[current] + distance(current, neighbor) cameFrom[neighbor] = current # f(n) = g(n) + h(n) fScore[neighbor] = gScore[neighbor] + heuristic_cost_estimate(neighbor, end) openSet.add(neighbor)