Description Usage Arguments Value
View source: R/greedy_knapsack.R
This is a greedy approach to knapsack problem. Here unit value per weight is calculated for each item.
After calculating unit per weight, the items with maximum values are selected in an order.
Total value of all selected items must be below knapsack weight W
.
This approach does not give an exact value but returns at least 50% of the true maximum value.
It reduces computational complexity due to O(n*log n).
1 | greedy_knapsack(x, W)
|
x |
Data frame with two numeric columns: weights and values |
W |
Total weight of the knapsack |
List with numbers of items that can be put into knapsack and approximate maximum obtained value
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.