【发布时间】: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