Description Usage Arguments Examples
The brute force search (the algorithm that has been used here in this funciton) by going through all possible alternatives and return the maximum value found is the only solution that is guaranteed to give a correct answer in all situations for the knapsack problem. The knapsack problem is a discrete optimization problem where we have a knapsack that can take a limited weight W and we want to fill this knapsack with a number of items i = 1, ..., n, each with a weight wi and a value vi. The goal is to find the knapsack with the largest value of the elements added to the knapsack.This problem is NP-hard. You can see more details about this problem here: https://en.wikipedia.org/wiki/Knapsack_problem
1 | brute_force_knapsack(x, W, parallel = FALSE)
|
x |
data.frame A data.frame that contains the weight and value of each element. |
W |
integer An integer that shows the limit for the weight that can be carried by the knapsack. |
parallel |
boolean deciding if computation should be done in parallel or concurrent |
1 2 3 4 5 | brute_force_knapsack(x = knapsack_objects[1:8,], W = 3500)
# $value
# 16770
# $elements
# 5 8
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.