def apply(self, kp: Knapsack, items: List[Item]):
     if self.name == None:
         return None
     if self.onKP:
         # Choice the item that will be unpacked from the knapsack
         idx = None
         kp_packed = kp.getPackedItems()
         for i, item in enumerate(kp_packed):
             if idx == None or heuristicComparison[self.name](
                     kp_packed[idx], item):
                 idx = i
         if idx != None:
             items.append(kp.unpack(idx))
         return idx
     else:
         # Choice the item that will be packed
         idx = None
         for i, item in enumerate(items):
             if kp.canPack(item):
                 if idx == None or heuristicComparison[self.name](
                         items[idx], item):
                     idx = i
         if idx != None:
             kp.pack(items.pop(idx))
         return idx
 def nextItem(self, kp: Knapsack, items: List[Item]):
     # Choice the next packable item
     if self.onKP:
         return None
     idx = None
     for i, item in enumerate(items):
         if kp.canPack(item):
             if idx == None or heuristicComparison[self.name](items[idx],
                                                              item):
                 idx = i
     return idx