0-1 knapsack with an additional constraint of maximum number of items used.
Project description
extended_knapsack
0-1 knapsack with an additional constraint of maximum number of items used.
Usage
pip3 install extended_knapsack
from extended_knapsack.knapsack import solve
items = [
{'weight': 4, 'value': 5, 'my-custom-field': 1},
{'weight': 3, 'value': 4, 'my-custom-field': 2},
{'weight': 2, 'value': 3, 'my-custom-field': 3},
{'weight': 1, 'value': 2, 'my-custom-field': 4},
]
result_value, result_items = knapsack(items, 6, 2)
print(result_value)
# 8
print(result_items)
# [
# {'weight': 4, 'value': 5, 'my-custom-field': 1},
# {'weight': 2, 'value': 3, 'my-custom-field': 3}
# ]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for extended_knapsack-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b458aced6bc5af26af1917c8f8de0633c26eb9fa6ac0e155f4e91e6c24622539 |
|
MD5 | 79f4cdf4a7e6767cfdc11581af4134a3 |
|
BLAKE2b-256 | 973a28ec28feb07dce1bd629a57dc51330a7aac34dbcca776cf562714c65e5c0 |