consistent heuristic 启发的一致性
admissible heuristic 可接受启发
UCS orders by backward cost——g(n)
Greedy orders by forward cost——h(n) (h(n)就是heuristic)A*就是结合g(n)和h(n)
A* orders by backward cost(gn) + forward cost(hn)
g(n)可以看做从start到current所花费的cost,h(n)从current到end的花费。
from heapq import heappush, heappop def aStarTsa(stateSpaceGraph, h, startState, goalState): frontier = [] heappush(frontier, (h[startState], startState)) print('Initial frontier:',list(frontier)); while frontier: node = heappop(frontier) if (node[1].endswith(goalState)): return node print('Exploring:',node[1][-1],'at cost',node[0]) for child in stateSpaceGraph[node[1][-1]]: heappush(frontier, (node[0]+child[0]-h[node[1][-1]]+h[child[1]], node[1]+child[1])) print(list(frontier)); aStarMotivation = { 'S':[(1,'a')],'a':[(1,'b'),(3,'d'),(8,'e')],'b':[(1,'c')],'c':[],'d':[(2,'G')],'e':[(1,'d')]} aStarMotivationH = {'S':6,'a':5,'b':6,'c':7,'d':2,'e':1,'G':0} print('Solution path:',aStarTsa(aStarMotivation, aStarMotivationH, 'S', 'G'))
https://blog.csdn.net/haolexiao/article/details/70302848
启发函数heuristic 与 A*
最新推荐文章于 2024-07-23 13:18:43 发布