greedy_knapsack: Greedy heuristic in knapsack problem

Description Usage Arguments Value References Examples

Description

Greedy heuristic in knapsack problem

Usage

1

Arguments

x

A dataframe with two columns: the values (v) and the weights (w) of each item to put in the knapsack.

W

A positive number representing the knapsack size.

Value

A list of two elements: a positive number with the maximum knapsack value and a vector of all the elements in the knapsack size.

References

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

Examples

1
2
3
4
set.seed(42)
n <- 2000
knapsack_objects <-data.frame(w=sample(1:4000, size = n, replace = TRUE),v=runif(n = n, 0, 10000))
greedy_knapsack(x = knapsack_objects[1:800,], W = 3500)

alede379/lab6 documentation built on May 21, 2019, 2:31 a.m.