Description Usage Arguments Details Value References Examples
View source: R/brute_force_knapsack.R
brute_force_knapsack(x, W)
returns the solution for knapsack problem
using brute force algorithm.
1 | brute_force_knapsack(x, W, parallel = FALSE)
|
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. |
parallel |
If TRUE, the "parallel" package will be implemented to parallelize the function. |
This function solves the Knapsack probem using brute force 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.
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.
http://en.wikipedia.org/wiki/Knapsack_problem
1 2 | brute_force_knapsack(data.frame(w=c(3660,3749,1145,3322),v=c(9899,4384,6999,8890)),W =3500)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.