Description Usage Arguments Details Value References Examples
View source: R/greedy_knapsack.R
greedy_knapsack(x, W)
returns the solution for knapsack problem
using Greedy approximation algorithm.
1 | greedy_knapsack(x, W)
|
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. |
This function solves the Knapsack probem using Greedy approximation 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.
https://en.wikipedia.org/wiki/Knapsack_problem#Greedy_approximation_algorithm
1 2 | greedy_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.