【问题标题】:What's wrong with this iterative deepening search code?(python)这个迭代加深搜索代码有什么问题?(python)
【发布时间】:2015-12-22 07:26:07
【问题描述】:

我在项目(Pacman)中实现了这个,但它根本不动,它似乎进入了一个无限循环或什么的......有人能告诉我它有什么问题吗???我已经被困在这里好几天了.....

def depthLimitedSearch(problem, limit ):

    explored = set()                                         
    node = problem.getStartState()
    path = []

    def recursive_DLS(node, problem, limit, path):

        if node not in explored :    
            explored.add(node)      
            if problem.goalTest(node):      
                return path     
            elif limit == 0 :       
                return 'cutoff'
            else:            
                cutoff_occurred = False
                for successor in problem.getActions(node):   
                    child = problem.getResult(node,successor) #next state
                    result = recursive_DLS(child ,problem, limit - 1, path)  
                    if result == 'cutoff':
                    cutoff_occurred = True
                    elif result != None:
                    path.append(successor)
                if cutoff_occurred:
                    return 'cutoff'
                else:
                    return None

    return recursive_DLS(node, problem, limit, path)    


def iterativeDeepeningSearch(problem):

    for depth in xrange(sys.maxint):
        result = depthLimitedSearch(problem, 1)
        if result is not 'cutoff':
            return result

【问题讨论】:

  • 您能举例说明输入和结果吗?
  • 这很抽象..问题是指一个特定的问题,结果应该是一个动作列表
  • 基本上,如果您提供一个我们可以实际运行的示例,然后看看发生了什么,就更容易找出问题所在。大概你有这样的东西,或者你不会知道它不起作用。

标签: python search recursion graph iteration


【解决方案1】:

你总是通过1depthLimitedSearch 的限制:

for depth in xrange(sys.maxint):
    result = depthLimitedSearch(problem, 1)

depth 未使用。如果限制为 1 的搜索导致截止,这将迭代很长时间而不会产生结果。

【讨论】:

  • 但是这里又出现了一个问题...successor这里指的是一个动作,但是当我运行程序时,吃豆子只是不动,相反,颜色指的是道路变化.. . 怎么会这样?.....
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-14
  • 1970-01-01
  • 1970-01-01
  • 2013-04-07
  • 1970-01-01
相关资源
最近更新 更多