启发函数heuristic 与 A*

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

https://www.jianshu.com/p/c728bb269116

https://www.zhihu.com/question/23052955

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值