搜索,A* IDA* yongmou

A*  

  一般地,节点n的评估函数f(n)可表示如下

        f(n) = h(n) + d(n)

  h(n) 是 启发式函数,与启发信息相关。启发函数h(n)的设计非常重要,它无固定的设计模式,主要取决于面向具体问题结构的知识和求解的技巧。d(n)是开始节点到节点n的深度信息。

  A*算法最为核心的部分,就在评估函数的设计。在A*搜索算法的评估函数中,d(n)表示从起始节点到当前节点的代价,通常用当前节点在搜索树中的深度表示。启发式函数h(n)表示当前节点到目标节点的评估值,是启发式搜索算法最为关键的部分。

  A*搜索算法的评估函数包括两个约束条件:

    (1) h(n)不大于节点n到目标节点t的实际最小代价h*(n),即:h(n) <= h*(n)。

    (2) 任意节点的评估值f必须不小于父节点的f值,即f单调递增。

  满足这两个条件,可以证明A*能够获得问题的最优解。简单证明一下,选择节点x,节点x一定是可扩展节点中的具有最小估计值的节点,如果x是目标节点,则其估计值f(x)就是实际最小代价,不大于其他节点的估计值,又条件(1),所以f(x)不大于其它任意节点的实际最小代价,即为最优解。

一般地,A*搜索算法可以描述如下:
A
* ( )
1 open ← {s};
2 closed ← Ø
3 while open != Ø do
4 remove leftmost state from open, call it x
5 if x is a goal then return success
6 else
7 generate children of x
8 for each child c do
9 if c is already on open list then
10 if c was reached by a shorter path then
11 update f(c)
12 else if c is already on closed list then
13 if c was reached by a shorter path then
14 remove c from closed list
15 add c to open list and update f(c)
16 else
17 assign c a heuristic value f(c)
18 add c to open list
19 put x on closed list and reorder states on open by f
20 return failure

  A*搜索算法采用最小代价优先的策略,即在所有将扩展的节点中,选择具有最小代价的节点作为下一个扩展节点。其终止准则是如果选择的节点是目标节点,即停止A*搜索算法。A*()算法中open表是一个优先队列,保存即将要展开的节点。closed表是一个数据结构,例如数组或者链表,保存展开过的节点。s是开始节点。open表可用最小堆实现。(不能在加入open表之前判断是否是目标节点并返回,这样不能保证是由最优路径到达目标节点的)


IDA*

  IDA* is a variant of the A* search algorithm which uses iterative deepening to keep the memory usage lower than in A*. It is an informed search based on the idea of the uninformed iterative deepening depth-first search.

  The main difference to IDS is that it uses the f-costs (g + h) as the next limit and not just an iterated depth.

 

IDA*
function IDA_star():
cost_limit
= heuristics[rootNode]

while True do
(solution, cost_limit)
= DFS(0, rootNode, cost_limit, [rootNode])
if solution != None then
     return (solution, cost_limit)
if cost_limit ==then
     return None

# returns (solution
-sequence or None, new cost limit)
function DFS(start_cost, node, cost_limit, path_so_far):
minimum_cost
= start_cost + heuristics[node]
if minimum_cost > cost_limit then
   return (None, minimum_cost)
if node in goalNodes then
   return (path_so_
far, cost_limit)

next_cost_limit
=
for succNode in successors[node] do
newStartCost
= start_cost + edgeCosts[(node,succNode)]
(solution, new_cost_limit)
= DFS(newStartCost, succNode, cost_limit, path_so_far + [succNode])
if solution != None then
     return (solution, new_cost_limit)
next_cost_limit
= min(next_cost_limit, new_cost_limit)

return (None, next_cost_limit)
 
  The difference to A* can be seen from this pseudo code: it doesn't remember the current shortest path and costs for all visited nodes like in A* (that is why space-complexity is linear in A* to all visited nodes until it finds the goal) but it only remembers one single path at a time.  
原文地址:https://www.cnblogs.com/liyongmou/p/1778830.html