I got this working using your code as a starting point. I defined my class Nodeas:
class Node:
def __init__(self, level, profit, weight, bound, contains):
self.level = level
self.profit = profit
self.weight = weight
self.bound = bound
self.contains = contains
, root = Node(0, 0, 0, 0.0, []). root.bound float, 0.0, ( , ) . node , . , , node ( , ) contains, :
u.contains = v.contains[:]
u.contains.append(uLevel)
, contains " " node. , if bound > maxProfit:. contains if: , maxProfit:
if u.weight <= knapsackSize and u.value > maxProfit:
maxProfit = u.profit
bestList = u.contains
, , bestList. if v.bound > maxProfit and v.level < items-1 v = queue.get(), , , , .
, , , , :
taken = [0]*numItems
for item in bestList:
taken[item] = 1
print str(taken)
, .