博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
启发函数heuristic 与 A*
阅读量:2136 次
发布时间:2019-04-30

本文共 1065 字,大约阅读时间需要 3 分钟。

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, heappopdef 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'))

 

转载地址:http://aoygf.baihongyu.com/

你可能感兴趣的文章
【LEETCODE】7-Reverse Integer
查看>>
【LEETCODE】165-Compare Version Numbers
查看>>
【LEETCODE】299-Bulls and Cows
查看>>
【LEETCODE】223-Rectangle Area
查看>>
【LEETCODE】12-Integer to Roman
查看>>
【学习方法】如何分析源代码
查看>>
【LEETCODE】61- Rotate List [Python]
查看>>
【LEETCODE】143- Reorder List [Python]
查看>>
【LEETCODE】82- Remove Duplicates from Sorted List II [Python]
查看>>
【LEETCODE】86- Partition List [Python]
查看>>
【LEETCODE】147- Insertion Sort List [Python]
查看>>
【算法】- 动态规划的编织艺术
查看>>
用 TensorFlow 让你的机器人唱首原创给你听
查看>>
对比学习用 Keras 搭建 CNN RNN 等常用神经网络
查看>>
深度学习的主要应用举例
查看>>
word2vec 模型思想和代码实现
查看>>
怎样做情感分析
查看>>
用深度神经网络处理NER命名实体识别问题
查看>>
用 RNN 训练语言模型生成文本
查看>>
RNN与机器翻译
查看>>