在尝试实施A *搜索导航时遇到了问题。我的代码在这里:
def shortest_path(M,start,goal):
#def aStar(graph, current, end):
openSet = set()
openHeap = []
closedSet = set()
cameFrom = {}
openSet.add(start)
print("openSet=", openSet)
openHeap.append((0, start))
gScore = {}
gScore[start] = 0
print("gScore: ",gScore)
fScore = {}
#fscore = {start:heuristic(M.intersections[start],
M.intersections[goal])}
fScore[start] = {start:heuristic(M.intersections[start],
M.intersections[goal])}
fscore = fScore[start]
print("fScore: ", fscore)
while openSet:
print("Entered While Loop")
current = heapq.heappop(openHeap)[1]
print("Current: ", current)
if current == goal:
print("current == goal")
return reconstruct_path(cameFrom, current)
openSet.remove(current)
closedSet.add(current)
print("M.intersections[current]: ", M.intersections[start])
for neighbor in M.intersections[current]: #tile = neighbor
print("for neighbor in M.intersections[current]: ", neighbor)
if neighbor in closedSet:
print("neighbor in closedSet")
continue
#neighborH = (abs(goal[0] - neighbor[0])+abs(goal[0]-neighbor[0]))*10
if neighbor not in openSet:
openSet.add(neighbor)
print("OpenSet inside if loop =",openSet )
#if neighbor not in openSet:
#openSet.add(neighbor )
#heapq.heappush(openHeap, (neighborH, neighbor ))
#tile.parent = start
print("Check Point")
print("gscore[current]: ", gScore[current])
print("M.intersections[current]=", M.intersections[current])
print("M.intersections[neighbor]=", neighbor)
tentative_gScore = gScore[current] + distance_to(M.intersections[current],neighbor)
if tentative_gScore >= gScore[neighbor]:
continue
cameFrom[neighbor] = current
gScore[neighbor] = tentative_gScore
fScore[neighbor] = gScore[neighbor] + heuristic(M.intersections[neighbor], M.intersections[goal])
print("shortest path called")
return []
我在这里收到错误:
tentative_gScore = gScore[current] + distance_to(M.intersections[current],neighbor)
'浮动'对象不可订阅。
我应该如何处理它。我知道它给我这个错误的原因,但我需要一些可以帮助我前进的解决方案。任何新的想法都是最受欢迎的。