greedyKnapsackSolver: Solves a knapsack problem by using a greedy strategy.

Description Usage Arguments Value See Also Examples

View source: R/greedyKnapsackSolver.R

Description

This function takes a data frame with items and a knapsack capacity and returns a solution that maximises (or closely maximises) the total value.

Usage

1

Arguments

x

A data frame containing items

W

The weight capacity of the knapsack

Value

A list describing the solution

See Also

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

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

Examples

1
2
3
4
5
6
## Not run: 
if(interactive()){
 greedyKnapsackSolver(data.frame(w = c(1,2,3), v = c(1,9,4)), W=5)
 }

## End(Not run)

paerx/knapsackph documentation built on Dec. 31, 2020, 1:11 a.m.