【问题标题】:iterative lengthening pseudo code for traversal of all the nodes遍历所有节点的迭代加长伪代码
【发布时间】:2011-10-22 17:00:01
【问题描述】:

使用迭代延长深度优先方法遍历图中所有节点的算法、伪代码或实际代码是什么?

【问题讨论】:

    标签: algorithm artificial-intelligence robotics


    【解决方案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
    }
    

    您始终可以通过使用已访问列表删除图形循环来转换树中的图形。 :)

    【讨论】:

    • 需要注意的是,在迭代深化例程中对 DLS 的每次调用都以 fresh 封闭列表开始;否则,第二次和以后的调用根本不会搜索。
    • 答案与迭代延长无关,您的描述与您提供的代码不匹配,还是我错了?
    • IDDFS 的重点不是不使用访问节点列表吗?
    猜你喜欢
    • 2012-03-21
    • 2018-01-07
    • 1970-01-01
    • 2018-09-02
    • 2015-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多