/KnapsackProblemSolver

An algorithm to solve the "Knapsack Problem"

Primary LanguageRuby

Knapsack Problem Solver

This code allows you to solve the knapsack problem by initialising a KnapsackProblemSolver object with an array of items and calling the max_value_items method passing in the maximum capacity (weight) as a parameter.

The items will need to be in the following format:

{
    item: <String>,
    weight: <Integer>,
    value: <Integer>"
}

The definition of the Knapsack Problem by Wikipedia is as follows:

The knapsack problem or rucksack problem is a problem in combinatorial optimization: Given a set of items, each with a weight and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible.

The example.rb file shows the Knapsack Problem Solver in action.