Description Usage Arguments Value Examples
View source: R/knapsack_dynamic.R
Given data frame x
, max weight W
, give the best solution with dynamic programing of O(n*W)
1 | knapsack_dynamic(x, W)
|
x, |
a data frame of items with different values and weights |
W, |
the capacity of knapsack |
a list with best value and selected elements
1 2 3 4 5 6 | set.seed(42)
n<- 1000000
knapsack_objects <-data.frame(
w=sample(1:4000, size = n, replace = TRUE),
v=runif(n = n, 0, 10000))
knapsack_dynamic(x = knapsack_objects[1:8,], W = 3500)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.