【发布时间】:2011-10-22 17:00:01
【问题描述】:
使用迭代延长深度优先方法遍历图中所有节点的算法、伪代码或实际代码是什么?
【问题讨论】:
标签: algorithm artificial-intelligence robotics
使用迭代延长深度优先方法遍历图中所有节点的算法、伪代码或实际代码是什么?
【问题讨论】:
标签: algorithm artificial-intelligence robotics
我先给你图的深度优先伪代码
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
}
您始终可以通过使用已访问列表删除图形循环来转换树中的图形。 :)
【讨论】: