Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

extended_knapsack-0.0.1.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

extended_knapsack-0.0.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file extended_knapsack-0.0.1.tar.gz.

File metadata

  • Download URL: extended_knapsack-0.0.1.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for extended_knapsack-0.0.1.tar.gz
Algorithm Hash digest
SHA256 796b2dc27a9bd90fb68d29a6d6b2bc4af07df2cd5ea05f7d44913a9a4448523a
MD5 92d90ef10eb4c0ae5da90b97586d3f03
BLAKE2b-256 65638583bc4eacc77ceef88d41004cdedf768e6cdf336e6d20a2c65debffb75e

See more details on using hashes here.

File details

Details for the file extended_knapsack-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: extended_knapsack-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for extended_knapsack-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b458aced6bc5af26af1917c8f8de0633c26eb9fa6ac0e155f4e91e6c24622539
MD5 79f4cdf4a7e6767cfdc11581af4134a3
BLAKE2b-256 973a28ec28feb07dce1bd629a57dc51330a7aac34dbcca776cf562714c65e5c0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page