简体   繁体   English

难题中a *搜索算法的深度

[英]depth of a* search algorithm in puzzle problem

I am trying to implement a 4*4 puzzle solver using A* search algorithm. 我正在尝试使用A *搜索算法实现4 * 4难题求解器。 I understand that the totalDistance f(n) = g(n) + h(n), whera g(n)is the path cost from root to the current node. 我知道totalDistance f(n)= g(n)+ h(n),而g(n)是从根到当前节点的路径成本。 However, I am confused about how to calculate the depth for each level when setting the totalcost to each node. 但是,当为每个节点设置总成本时,如何为每个级别计算深度感到困惑。 Hope someone could explain. 希望有人能解释。

The A* algorithm doesn't really have a concept of 'depth'. A *算法实际上没有“深度”的概念。 Instead, the idea is to keep a record of the cost of getting from the start to all visited nodes. 取而代之的是,该想法是记录从头到所有访问节点的成本。 When a new node is visited, the cost to get to the new node is cost to current node + cost to go from current to new node. 当访问新节点时,到达新节点的成本是当前节点的成本+从当前节点到新节点的成本。

The total cost heuristic is used for only 1 purpose: choosing the next node to consider. 总成本启发式方法仅用于1个目的:选择要考虑的下一个节点。 As you say it is generally the cost to the node + estimated cost to destination. 如您所说,通常是节点成本+到目的地的估计成本。

With respect to changes to your code, I suggest you either store the 'score' as the cost to the node (ignoring the estimate) and calculate the heuristic in your sorting comparator, or store both the cost and the estimate separately (if calculating the estimation is expensive for any reason). 关于代码更改,我建议您要么将“得分”作为成本存储到节点(忽略估算值),然后在排序比较器中计算启发式算法,要么分别存储成本和估算值(如果计算出估算由于任何原因都是昂贵的)。

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

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