Professional Documents
Culture Documents
Code:
graph={
'S':[('1',3,24),('4',4, 22)],
'1':[('2',1,20),('4',5,22)],
'2':[('3',4,18),('5',5,20)],
'3':[],
'4':[('1',5,24),('5',2,20)],
'5':[('2',5,20),('6',4,20)],
'6':[('7',3,0)],
'7':[]}
closedList.append(start)
openList.append(neighbor)
openList.sort(key=lambda neighbor:neighbor[1]+neighbor[2])
if openList[0][0]==stop:
costs+=openList[0][1]+openList[0][2]
closedList.append(openList[0][0])
else:
value=openList[0]
closedList.append(value[0])
costs+=value[1]
openList.remove(value)
astar(value[0],stop,openList,closedList,costs)
astar('S','7')
output: