From ead5617e445fced2dce40bc9733888cbd90cf3bd Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Wed, 13 Aug 2014 23:09:05 -0700 Subject: [PATCH] Fix for fast_fit visiting the same item multiple times. fast_fit iterates across all items from offset but it wasn't taking this into account when it was determining the sub load. --- tradecalc.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tradecalc.py b/tradecalc.py index 0087935e..e5674d9a 100644 --- a/tradecalc.py +++ b/tradecalc.py @@ -111,18 +111,19 @@ def _fit_combos(offset, cr, cap): def fast_fit(self, items, credits, capacity, maxUnits): def _fit_combos(offset, cr, cap): for item in items[offset:]: + offset += 1 itemCostCr = item.costCr maxQty = min(maxUnits, cap, cr // itemCostCr) if maxQty > 0: loadItems, loadCostCr, loadGainCr = [[item, maxQty]], maxQty * itemCostCr, maxQty * item.gainCr - bestGainCr = 0 + bestGainCr = -1 crLeft, capLeft = cr - loadCostCr, cap - maxQty if crLeft > 0 and capLeft > 0: - for subLoad in _fit_combos(offset + 1, crLeft, capLeft): + for subLoad in _fit_combos(offset, crLeft, capLeft): if subLoad.gainCr >= bestGainCr: yield TradeLoad(subLoad.items + loadItems, subLoad.gainCr + loadGainCr, subLoad.costCr + loadCostCr, subLoad.units + maxQty) bestGainCr = subLoad.gainCr - if not bestGainCr: + if bestGainCr < 0: yield TradeLoad(loadItems, loadGainCr, loadCostCr, maxQty) bestLoad = emptyLoad