【发布时间】:2015-02-22 06:28:29
【问题描述】:
给定以下迷宫:
|||||||||||||||||||||||||||||||||||||
| | | | | | | |
| ||||||| | ||| | ||| ||| ||||||| | |
| | | | | | | |
||||| ||||| ||| | | | ||| ||||| | |||
| | | | | | | | | | | | | |
| ||| | | | ||| ||||| ||| | ||| ||| |
| | | | | | | | |
||| ||||||||| ||||||| ||| ||| | | | |
| | | | | | |
| | ||||| | ||| | | ||| | ||| ||| | |
| | | | | | | | | | | | | |
| | | ||||||| | ||||||||| ||| | ||| |
| | | | | | | | | |
||| ||| | ||||| ||||| ||| ||| ||||| |
| | | | | | | | | | | |
| | | | | ||| ||| ||| ||| | | | | | |
| | | | | | | | |
||| ||||||| | | ||||| ||| | ||| |||||
| | | | | | | | | |
||||| | | ||||||||| ||||||||||| | |||
| | | | | | | | |
| ||| ||||| ||||||||| ||||| | | ||| |
| | | | | | |
| | | ||||| ||| | | | | |||||||||||||
| | | | | | | | | | | |
| | ||| ||| | | | ||||||||| ||| | | |
| | | | | | | | | | | | |
| ||| ||| ||||| ||| | | ||||| | |||||
| | | | | | | | |
||| | ||||| ||||| ||| ||| | ||| | |||
| | | | | | | | | | | | | | |
| | ||| | | | | ||||||||| | | | | | |
| | | | | |
| | | | ||| ||| ||||||| ||| ||| ||| |
|+| | | | | | | | P|
|||||||||||||||||||||||||||||||||||||
我有来自两种不同算法的两个结果(其中,我希望是 A* 和 Greedy First 的正确实现):
#nodes searched; hops to goal
large maze - a* - expanded: 1120 (cost: 209)
large maze - greedy - expanded: 916 (cost: 209)
这是正常行为吗?在给定单一路径的情况下,A* 并不总是最优和比其他算法更有效吗?我知道这取决于问题设置,但这也通过更大的测试进行了复制:
mega maze - a* - expanded: 8964 (837)
mega maze - greedy (mh heur) - expanded: 5455 (837)
我认为 A* 应该在这里优于 Greedy First 是不是错了? 以下是我的启发式方法...也许我的启发式值设置错误?:
#greedy
self.heuristic = abs(goalNodeXY[0] - self.xy[0]) + abs(goalNodeXY[1] - self.xy[1])
#A* --- costFromStart == path length from starting point
self.heuristic = math.hypot(self.xy[1]-goalNodeXY[1],self.xy[0]-goalNodeXY[0]) + costFromStart
【问题讨论】:
-
这些数字是什么单位?秒? MB 内存?
-
对不起.. 这只是节点/路径长度。 1 跳 = 1。我会在问题中澄清
标签: python artificial-intelligence path-finding heuristics