Skip to main content

A PyPI package for subsetsumdfs with a Markdown README

Project description

Dynamic Subset Sum Solver

Description

This repository houses a versatile implementation of the subset sum algorithm utilizing dynamic programming with a depth-first search (DFS) approach. The algorithm efficiently computes all possible combinations with unique keys provided in the output. It is capable of handling both positive and negative float and integer numbers, offering robust functionality across a wide range of numerical scenarios.

Authors

Key Features:

  • Dynamic Programming with DFS: Utilizes a dynamic programming paradigm with depth-first search for efficient subset sum computation.

  • Supports Positive and Negative Numbers: Handles both positive and negative float and integer numbers, ensuring versatility in solving various problem instances.

  • Customizable Constraints: Users can specify constraints such as time limits, accuracy thresholds, and maximum combinations to tailor the algorithm's behavior to specific requirements.

Time Complexity:

The time complexity of the algorithm is O(2^n), where n is the size of the input set.

Space Complexity:

The space complexity of the algorithm is O(n), where n is the size of the input set.

This dynamic subset sum solver empowers users with a flexible and powerful tool for tackling subset sum problems across diverse use cases.

Installation

Install subsetsumdfs with pip

  pip install subsetsumdfs

Please carefully read below info

  • Follow Data structure : Please follow provided data structure in example to avoid errors
  • Default values : By Default this are the values for algorithm arguments [max_time = 60 seconds accuracy = 0.01 max_combinations = 100]
  • Warning : Please choose max_time wisely otherwise it will run for longer period of time.If you have large list as an input and it may cause high RAM utilization.

Example usage

For a case user has to make a code like this:

from subsetsumdfs import subsetsum

data =[
        {
            "value": 40806839.37,
            "unique_key": "1"
        },
        {
            "value": -23995624.33,
            "unique_key": "2"
        },
        {
            "value": -58386586.35,
            "unique_key": "3"
        },
        {
            "value": 93705577.71,
            "unique_key": "4"
        },
        {
            "value": 56065510.55,
            "unique_key": "5"
        },
        {
            "value": -16366515,
            "unique_key": "6"
        },
        {
            "value": -19421385,
            "unique_key": "7"
        },
        {
            "value": -254331.86,
            "unique_key": "8"
        },
        {
            "value": -57561556.47,
            "unique_key": "9"
        },
        {
            "value": 2609628022,
            "unique_key": "10"
        },
        {
            "value": 1104.92,
            "unique_key": "11"
        },
        {
            "value": -980.88,
            "unique_key": "12"
        },
        {
            "value": 745847.81,
            "unique_key": "13"
        },
        {
            "value": 231520.34,
            "unique_key": "14"
        },
        {
            "value": 6438.48,
            "unique_key": "15"
        },
        {
            "value": 2860.77,
            "unique_key": "16"
        },
        {
            "value": 81026.7,
            "unique_key": "17"
        },
        {
            "value": 497896.57,
            "unique_key": "18"
        },
        {
            "value": 3223.43,
            "unique_key": "19"
        },
        {
            "value": -575095.08,
            "unique_key": "20"
        },
        {
            "value": 342730.6,
            "unique_key": "21"
        },
        {
            "value": 26119.62,
            "unique_key": "22"
        },
        {
            "value": 17127.86,
            "unique_key": "23"
        },
        {
            "value": 309.19,
            "unique_key": "24"
        },
        {
            "value": 4086683.03,
            "unique_key": "25"
        }
        # Add more data entries as needed
    ]
]

result = subset_sum(items=data, target=4086683.03, max_time=300, accuracy=1, max_combinations=2)

Example Output :

[
    [{'value': -254331.86, 'unique_key': '8'}, {'value': -980.88, 'unique_key': '12'}, {'value': 745847.81, 'unique_key': '13'}, {'value': 81026.7, 'unique_key': '17'}, {'value': 3223.43, 'unique_key': '19'}, {'value': -575095.08, 'unique_key': '20'}, {'value': 309.19, 'unique_key': '24'}, {'value': 4086683.03, 'unique_key': '25'}],
    [{'value': 4086683.03, 'unique_key': '25'}]
]

Here's what the arguments represent in the above code:

  • items: a list of dictionaries according to the provided data structure, each containing "value" and "unique_key" for identifying combinations.
  • target: a float number for which the user wants to find all possible combinations that sum to that target.
  • max_time: the maximum time for the subset sum algorithm to run (in seconds). Useful when dealing with large list.
  • accuracy: an accuracy parameter indicating the precision for which the target can be achieved.
  • max_combinations: the maximum number of combinations the user wants to find.

Support

Use it! Write about it! Star it! If you love this.

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

subsetsumdfs-0.0.2.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

subsetsumdfs-0.0.2-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file subsetsumdfs-0.0.2.tar.gz.

File metadata

  • Download URL: subsetsumdfs-0.0.2.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for subsetsumdfs-0.0.2.tar.gz
Algorithm Hash digest
SHA256 07a8268696e7d864725e33529842cd0db48c135cce2242f5fc9c6b102c22739b
MD5 d53855a3d25723e096a8a3d836ff3190
BLAKE2b-256 0fca375ca97e6cb1f5ba527e0e99298dfcc43d8a269d895e868fe6f436b2bcc9

See more details on using hashes here.

File details

Details for the file subsetsumdfs-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: subsetsumdfs-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for subsetsumdfs-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c2b4ef1a135b9dd24c6018f983f44305d541eb3a4e1a83ad15c720635d0a21f1
MD5 56c3bd3e20794ca9e2f60d2d1ccf0fae
BLAKE2b-256 cf43ad440c63c4ad006835cb6d034b58cc8fb092b84de06e5e34a6c9db5091b2

See more details on using hashes here.

Supported by

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