pykp.knapsack.Knapsack.

remove#

Knapsack.remove(item: Item) list#

Remove a specific item from the knapsack.

Parameters:
itemItem

The item to remove. Must already exist among self.items.

Returns:
list

The updated binary state array after removing the item.

Raises:
ValueError

If item is not of type Item or if it is not present in self.items.

Examples

>>> items = [Item(10, 5), Item(15, 5)]
>>> knapsack = Knapsack(
>>>     items=items,
...     capacity=6
... )
>>> knapsack.add(items[1])
array([0, 1])
>>> knapsack.remove(items[1])
array([0, 0])
>>> knapsack.value
0
>>> knapsack.weight
0