Description Details Author(s) References Examples
Solve a test Knapsack problem with different coding methods
The DESCRIPTION file:
This package was not yet installed at build time.
Index: This package was not yet installed at build time.
The package presents three typical ways of resolving Knapsack problem, with brutal force, dynamic programing and approximate solutions. By means of exploring different computing complexities, a better understanding of fast code has been reached.
brute_force_knapsack(x,W)
knapsack_dynamic(x,W)
greedy_knapsack(x,W)
Jun Li
Maintainer: Jun Li <junli559@student.liu.se>
https://en.wikipedia.org/wiki/Knapsack_problem
1 2 3 4 5 6 7 | set.seed(42)
n<- 2000
knapsack_objects<-data.frame(
w=sample(1:4000, size = n, replace = TRUE),
v=runif(n = n, 0, 10000))
system.time(brute_force_knapsack(x = knapsack_objects[1:16,], W = 3500))[2]
system.time(knapsack_dynamic(x = knapsack_objects[1:500,], W = 3500))[2]
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.