Skip to content

A simple Java implementation of solver(s) for the Knapsack Problem.

License

Notifications You must be signed in to change notification settings

nieldw/knapsack-solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Knapsack Solver

Build Status

A simple Java implementation of solver(s) for the Knapsack Problem.

The KnapsackSolver interface provides these affordances:

  1. The knapsack's weight limit may be a BigDecimal
  2. The items' weight may be a BigDecimal
  3. The items' value may be a BigDecimal

A solver implementation must cater for these affordances. The affordance allows BigDecimal weights, because BigDecimals allow an exact representation of a number.

0/1 Knapsack Solver

A solution to the 0/1 knapsack problem is provided in the ZeroOneKnapsackSolver.

The 0/1 Knapsack Solver adjusts the weight of all items by multiplying the weight of each item by 10 times the largest number of decimal places among all the weights, thereby reducing the problem to that of integer weighted items.

Constraints

Implementations of KnapsackProblemConstraintSupport can be supplied with a list of Constraints. A number of Constraint implementations are provided:

  • KnapsackWeightConstraint
  • ItemListSizeConstraint
  • ItemValueConstraint
  • ItemWeightConstraint

Constraints are checked at the time of problem parsing to ensure all KnapsackProblems are valid.

Tools

Alongside the knapsack-solver module a collection of tools are provided to simplify dealing with knapsack problems. Please see the knapsack-tools module.

About

A simple Java implementation of solver(s) for the Knapsack Problem.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published