Skip to main content

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}
# ]

Metadata

Release files for extended-knapsack 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for extended-knapsack 0.0.1
File Size Uploaded
extended_knapsack-0.0.1.tar.gz 2.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for extended-knapsack 0.0.1
File Interpreter ABI Platform
extended_knapsack-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 6.4 kB

Release files / extended_knapsack-0.0.1.tar.gz

Download URL extended_knapsack-0.0.1.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
796b2dc27a9bd90fb68d29a6d6b2bc4af07df2cd5ea05f7d44913a9a4448523a
BLAKE2b-256 checksum
How to use checksums
65638583bc4eacc77ceef88d41004cdedf768e6cdf336e6d20a2c65debffb75e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

Release files / extended_knapsack-0.0.1-py3-none-any.whl

Download URL extended_knapsack-0.0.1-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b458aced6bc5af26af1917c8f8de0633c26eb9fa6ac0e155f4e91e6c24622539
BLAKE2b-256 checksum
How to use checksums
973a28ec28feb07dce1bd629a57dc51330a7aac34dbcca776cf562714c65e5c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page