为什么我运行Astar算法的代码时没有输出?

2024-06-28 20:34:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试用python实现A-star算法,但是当A完成代码并尝试使用最短路径函数时,没有输出也没有错误,有人能帮我找出原因吗? 这是我的法官代码,抱歉没有权利把所有代码放在这里:

# When meet a point, judge what to do next, the point has a data structure of (name, distance to goal):
# map.intersections[start] is to find the coordinate of the start point in the map. 
def judge(map, point_cur, point_near, point_target, dictionary_ep, dictionary_ft, dictionary_fs):
    for i in dictionary_ep:
        if point_near[0] != i:
            for j in dictionary_ft:
                if point_near[0] != j:
                    dictionary_ft[point_near[0]] = (point_cur[1] + distance(map.intersections[point_cur[0]], map.intersections[point_near[0]]) + distance(map.intersections[point_near[0]], map.intersections[point_target[0]]))
                    dictionary_fs[point_near[0]] = point_cur[0]
                else:
                    if dictionary_ft[j] <= (point_cur[1] + distance(map.intersections[point_cur[0]], map.intersections[point_near[0]]) + distance(map.intersections[point_near[0]], map.intersections[point_target[0]])):
                        dictionary_fs[point_near[0]] = point_cur[0]
                        dictionary_ft[point_near[0]] = (point_cur[1] + distance(map.intersections[point_cur[0]], map.intersections[point_near[0]]) + distance(map.intersections[point_near[0]], map.intersections[point_target[0]]))
    return 0

这就是我的A星计划:

  1. F=G(从当前点到起点的路径长度)+H(从当前点到目标点的假定距离)
  2. 把开头的块放进《边疆词典》。你知道吗
  3. 重复圆圈:

    a)在字典边界中找到F的最小值,该点称为当前点

    b)将当前点切换到当前点

    c)对当前点相邻点的作用:

       If the point is in the explored dictionary, skip over it.  
    
       If the point is in the frontier dictionary, add it into the dictionary and regard the current point as the father point of this point(put them into the Father_Son dictionary).
    
       If the point is already in the frontier point, find the lowest value F, and put the key and value into the dictionary.
    
  4. 当目标点在词典中时停止。你知道吗
  5. 省省吧。你知道吗

Tags: oftheto代码inmaptargetdictionary