Skip to content

Commit

Permalink
Fix for fast_fit visiting the same item multiple times.
Browse files Browse the repository at this point in the history
fast_fit iterates across all items from offset but it wasn't taking this into account when it was determining the sub load.
  • Loading branch information
kfsone committed Aug 14, 2014
1 parent a096590 commit ead5617
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tradecalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ead5617

Please sign in to comment.