問題
関数のどこかで、返すべきものを返していないことを認識しています。
再帰呼び出しを返していますが、「ずっと」返していないようです
環境
リスト内のすべての組み合わせの深さ優先検索を行っています。条件に合う組み合わせにたどり着いたら、戻りたい。
私は自分のコンビネーションの「状態」を維持しており、あるべき場所に戻っています (私はそう思います)。
私は何を間違っていますか?
class Combo:
def __init__(self, list):
self.staples = list
コンボには、ステープル クラスのリストで構成される「ステープル」と呼ばれるプロパティがあります。最適な数を見つけるために、ディシジョン ツリーのステープルのリストを反復処理したいと考えています。
この場合、リスト内の各ステープル インスタンスの数量全体で最適な数が合計され、Combo インスタンスのプロパティとして保存/再計算されます。
def IterateStaples(combo, target):
#Exit condition for combo dictionary
if all(combo.diff[macro] < 2 for macro in combo.diff):
return combo;
#iterate through all items in list
for staple in combo.staples:
#Increment and calc conditions
staple.increment()
combo.calcTotals()
combo.findDiff(target)
#If exceeds target value, backtrack
if combo.findConflict(target):
staple.decrement()
combo.calcTotals()
combo.findDiff(target)
#Redundant exit condition to try and return
elif all(combo.diff[macro] < 2 for macro in combo.diff):
return combo
#Recursive call
else:
return IterateStaples(combo, target)
staple.decrement()
combo.calcTotals()
combo.findDiff(target)