Item
This module provides an interface for defining items inside a knapsack problem instance.
Example
Use the Item class to define items for the knapsack problem:
from pykp import Item
items = [
Item(value=10, weight=5),
Item(value=20, weight=10),
Item(value=30, weight=15),
]
-
class pykp.item.Item(value: int, weight: int)
Bases: object
Represents an item for the knapsack problem.
-
value
The value of the item.
- Type:
int
-
weight
The weight of the item.
- Type:
int
-
update_value(new_value: int)
Updates the value of the item.
- Parameters:
new_value (int) – New value of the item.
-
update_weight(new_weight: int)
Updates the weight of the item.
- Parameters:
new_weight (int) – New weight of the item.