greedy_knapsack: greedy function for knapsack problem

Description Usage Arguments Value See Also Examples

View source: R/greedy_knapsack.R

Description

implement the function using greedy method.

Usage

1

Arguments

x

A data.frame. with weight and value

W

A number. the overall weight

Value

list with maximum value and picked elements

See Also

https://en.wikipedia.org/wiki/Knapsack_problem#Greedy_approximation_algorithm

Examples

1
2
3
4
5
6
  RNGversion(min(as.character(getRversion()),"3.6.1"))
  set.seed(42,kind="Mersenne-Twister",normal.kind = "Inversion")
  n <- 2000
  knapsack_objects <-data.frame(w=sample(1:4000, size = n, replace = TRUE),
                             v=runif(n = n, 0, 10000))
 l1 <- greedy_knapsack(x = knapsack_objects[1:800,], W = 3500)

Oliverckb/LAB6 documentation built on Oct. 17, 2020, 5:53 a.m.