だから、私のコードをここに示し、それは次の行で壊れます:
if (suc not in sFrontier) or (suc not in sExplored):
エラーを与える: TypeError: 型 'インスタンス' の引数は反復可能ではありません
"""
The pseudocode I'm following
initialize the frontier using the initial state of the problem
initialize the explored set to be empty
loop do
if the frontier is empty then return failure
choose a leaf node and remove it from the frontier
if the node contains a goal state then return the corresponding solution
add the node to the explored set
expand the chosen node, adding the resulting nodes to the frontier
only if not in the frontier or explored set
"""
sFrontier = util.Stack()
sFrontier.push(problem.getStartState())
sExplored = util.Stack()
lSuccessors = []
while not sFrontier.isEmpty():
leaf = sFrontier.pop()
if problem.isGoalState(leaf):
solution = []
while not sExplored.isEmpty():
solution[:0] = (sExplored.pop())[2]
return solution
sExplored.push(leaf)
lSuccessors = problem.getSuccessors(leaf)
for suc in lSuccessors:
if (suc not in sFrontier) or (suc not in sExplored):
sFrontier.push(suc)
return []
problem.getSuccessors は、後続の状態のリスト、必要なアクション、およびコスト 1 を返します。
だから後
lSuccessors = problem.getSuccessors(leaf)
l後継者の版画
[((5,4), 'South', 1), ((4,5), 'West', 1)]
以降
for suc in lSuccessors:
サックプリント
((5,4), 'South', 1)
なぜ壊れるのですか?sFrontier と sExplored はスタックであり、スタック内を参照できないためでしょうか。
contains() メソッドが必要ですか、それとも代わりにリストを使用するだけですか?
すべての助けに感謝します:)