knapsack_dynamic: Dynamic programming algorithm for solving knapsack problem

Description Usage Arguments Details Value References Examples

View source: R/knapsack_dynamic.R

Description

knapsack_dynamic(x, W) returns the solution for knapsack problem using Dynamic programming algorithm.

Usage

1

Arguments

x

A data.frame with two variables ("w" , "v"). Every observation (row) in this data frame is an item with a weight (w) and a value (v).

W

A numeric scalar which is the maximum capacity of the knapsack.

Details

This function solves the Knapsack probem using Dynamic programming approach. The knapsack problem is a discrete optimization problem where we have a knapsack that can take a limited weight W and we want to fill this knapsack with a number of items i = 1, 2 ,...,n; each with a weight(w) and a value(v). The goal is to find the knapsack with the largest value of the elements added to the knapsack.

Value

A list with names $value, indicating maximum value of the items picked into the the knapsack , and $elements which states which items (rows) in data.frame were selected out to put into the knapsack.

References

https://en.wikipedia.org/wiki/Knapsack_problem#0.2F1_knapsack_problem

Examples

1
 knapsack_dynamic(data.frame(w=c(3660,3749,1145,3322),v=c(9899,4384,6999,8890)),W =3500)

mpirmoradiyan/knapsack documentation built on Nov. 4, 2019, 7:31 p.m.