简体   繁体   English

尽管具有正确的启发式算法,为什么我的a-star算法会扩展太多节点?

[英]Why does my a-star algorithm expand too many nodes despite having a correct heuristic?

I'm doing an assignment where I have to use a-star to solve a 15-puzzle (in C). 我正在做一项任务,我必须使用一颗星来解决一个15谜题 (在C中)。

The heuristic function is Manhattan distance (aka taxicab distance). 启发函数是曼哈顿距离 (又名出租车距离)。

We are given a sample input/output where the board is solved in 22 moves and after expanding 395 nodes (board states) (ie we had to look at the children of 395 nodes) 我们给出了一个示例输入/输出,其中电路板在22次移动中和扩展395个节点(电路板状态)后解决(即我们必须查看395个节点的子节点)

By 'correct' heuristic I mean my function is the same as the one used to produce the sample outputs and produces the correct distance. 通过'正确'启发式,我的意思是我的功能与用于产生样本输出的功能相同并产生正确的距离。

The problem is my solution expands more than 400 nodes to find the solution ( it is optimal 22 moves but a different one ). 问题是我的解决方案扩展了超过400个节点以找到解决方案( 它是最佳的22个移动而不是另一个 )。

I noticed the number changes depending on the order I generate the children nodes (move the space tile up,left,down,right or other directions). 我注意到数字的变化取决于我生成子节点的顺序 (向上,向左,向下,向右或其他方向移动空间区域)。

There are 24 ways you can move the space tile up,down,left and right to generate the children and I tried all of them but none of them expanded 395 nodes. 有24种方法可以向上,向下,向左和向右移动空间磁贴以生成子项,我尝试了所有这些,但没有一个扩展395个节点。

Why is this happening? 为什么会这样?

Terminology: 术语:

  • node: each node is a configuration of the 15-puzzle board node:每个节点都是15-puzzle board的配置
  • children: the configurations that you can achieve by moving the space tile up,down,left or right from the current node children:通过从当前节点向上,向下,向左或向右移动空间磁贴可以实现的配置

PS: I'm using a binary heap for the open list if that matters PS:如果重要的话,我正在使用二进制堆作为开放列表

Thanks 谢谢

Mmmh... In ideal case the A* does not depend on the order you generate the children. 嗯......在理想的情况下,A *不依赖于你生成孩子的顺序。 Unfortunately if you have in "queue" two or more nodes with the same distance-plus-cost heuristic value, the algorithm may chose "randomly" one of these nodes and find different solution (and explore different search path). 不幸的是,如果您在“队列”中有两个或更多具有相同距离加成本启发式值的节点,则算法可以选择“随机”其中一个节点并找到不同的解决方案(并探索不同的搜索路径)。

I think that you can try: 我想你可以尝试:

  • Check your distance-plus-cost heuristic function. 检查距离加成本启发式功能。 (every action cost 1? You sum the distance of every squares from their right position in the right way?) (每个动作花费1?你以正确的方式将每个方格与正确位置的距离相加?)
  • Check your heap. 检查你的堆。 It returns the right nodes? 它返回正确的节点? How many nodes with the same heuristic value you can have in the same step? 在同一步骤中可以拥有多少具有相同启发式值的节点?

This is the only thing that I can tell you with this information. 这是我能用这些信息告诉你的唯一的事情。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM