![](/img/trans.png)
[英]Image Processing in Python- Is there a general solution to this problem?
[英]python- execution time problem
我能够通过第一个功能....但是第二个功能未运行.... getaction
def registerInitialState(self, state):
"""
This is the first time that the agent sees the layout of the game board. Here, we
choose a path to the goal. In this phase, the agent should compute the path to the
goal and store it in a local variable. All of the work is done in this method!
state: a GameState object (pacman.py)
"""
if self.searchFunction == None: raise Exception, "No search function provided for SearchAgent"
starttime = time.time()
problem = self.searchType(state) # Makes a new search problem
self.actions = self.searchFunction(problem) # Find a path
totalCost = problem.getCostOfActions(self.actions)
print('Path found with total cost of %d in %.1f seconds' % (totalCost, time.time() - starttime))
if '_expanded' in dir(problem): print('Search nodes expanded: %d' % problem._expanded)
def getAction(self, state):
"""
Returns the next action in the path chosen earlier (in registerInitialState). Return
Directions.STOP if there is no further action to take.
state: a GameState object (pacman.py)
"""
if 'actionIndex' not in dir(self): self.actionIndex = 0
i = self.actionIndex
self.actionIndex += 1
if i < len(self.actions):
return self.actions[i]
else:
return Directions.STOP
Error: File line 114, in getAction
if i < len(self.actions):
TypeError: len() of unsized object
这是我的功能:执行时,它给了我node的值,但是给了我错误。 在get操作函数中i = 0的值。 我不知道,为什么它没有增加。
while stack.isEmpty()!= 0:
node = stack.pop()
print node
错误:
(5, 5)
Path found with total cost of 999999 in 0.0 seconds
Search nodes expanded: 1
None
按照下面的说明添加打印说明,然后告诉我它说了什么。 self.actions可能是None类型,或者不是类似于列表的对象。 您可能要检查==无,就像另一个。
self.actionIndex += 1
print self.actions
if i < len(self.actions):
return self.actions[i]
else:
return Directions.STOP
所以问题可能出在这里:
problem = self.searchType(state) # Makes a new search problem
self.actions = self.searchFunction(problem) # Find a path
使self.actions ==无
您可以使用以下方法进一步调试:
problem = self.searchType(state) # Makes a new search problem
print problem
self.actions = self.searchFunction(problem) # Find a path
检查问题是否正常..如果是这样,则searchFunction找不到路径或出现问题,并且返回None。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.