2011-10-22 77 views

回答

1

我给你第一次深度优先伪码图

DLS(node, goal, depth, visited) 
{ 
    if (depth >= 0) 
    { 
    if (node == goal) 
     return node 

    visited.insert(node) 

    for each child in expand(node) 
     if (child is not in visited) 
      DLS(child, goal, depth-1, visited) 
    } 
} 

和迭代DLS是

IDDFS(start, goal) 
{ 
    depth = 0 
    while(no solution) 
    { 
    visited = [] // <-- Empty List 
    solution = DLS(start, goal, depth,visited) 
    depth = depth + 1 
    } 
    return solution 
} 

你总是可以通过去除图形循环变换一个图形在树上一个访问列表。 :)

+0

重要的是要注意,迭代加深例程中的每个DLS调用都以**新鲜的关闭列表开始;否则,第二次和以后的呼叫根本不会搜索。 –

+0

答案不是关于迭代缩减,你的描述不符合你给出的代码,或者我错了? – wmax