greedy_knapsack: Greedy heuristic solve for the knapsack problem

View source: R/greedy_knapsack.r

greedy_knapsackR Documentation

Greedy heuristic solve for the knapsack problem

Description

A function that uses greedy heuristic to solve the knapsack problem

Usage

greedy_knapsack(x, W)

Arguments

x

A data frame with two variables w = weight and v = value

W

A numeric scalar with the maximum weight the knapsack is allowed to contain

Value

The function returns a list with the optimum packed value and the corresponding elements

Examples

n <- 10000
knapsack_objects <- data.frame(w = sample(1:4000, size = n, replace = TRUE),
                            v = runif(n = n, 0, 10000))
greedy_knapsack(x = knapsack_objects, W = 3500)


TeaUnn/knapsack documentation built on April 3, 2022, 12:02 a.m.