Git Product home page Git Product logo

subsetsum's Introduction

Subsetsum

This sample contains implementations of the algorithms presented in Computing Partitions with Applications to the Knapsack Problem (Available for download here)

Details on how the algorithms function can be found in the paper. Basically all of them present different methods for enumerating all posible combinations. Feel free to add your own algorithm by implementing the SubsetSumStrategy and adding your algorithm to the unit test, you can see how it fares compared to the others.

You can run the the unit test with gradle test which will:

  • Run a series of negative tests, no sum exists in the set.
  • Run a series of positive tests, a sum exists in the set.
  • Solve a specific instance of a puzzle.

It will output the running time in ms. of each algorithm. These algorithms can be very slow, particularly the naive approach, so be patient.

You can also run gradle eclipse and run the unit tests from within eclipse. Note that some of the algorithms require a lot of memory so your mileage may vary.

Notes & Todo's

  • It doesn't include any pseudo polyonomial or approximization strategies.
  • Some algorithms could be improved by making use of heuristics, this is something still open for exploration.

Some results:

Here are the worst case running times (i.e. no sum exists) for the various algorithms:

Algorithm Set size Time in ms
NaiveSubsetSumStrategy 28 18686
NaiveSubsetSumStrategy 29 37831
MultiSubsetSumStrategy2a 28 717
MultiSubsetSumStrategy2a 29 1415
MultiSubsetSumStrategy2b 28 94
MultiSubsetSumStrategy2b 29 189
RecursiveSubsetSumStrategy 28 990
RecursiveSubsetSumStrategy 29 1576

It looks like MultiSubsetSumStrategy2b is the winner here. The only drawback about this one is that it uses O(2^n) space..

subsetsum's People

Contributors

pokowaka avatar

Watchers

James Cloos avatar Humberto "SilverOne" Carvalho avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.