Variation of Knapsack Problem: adding Low bounder - knapsack-problem

Classic variation of 0/1 Knapsack Problem: Only I have to specify low bounder. It means I have to find maximum value and make sure that total weight is equal or higher than some given value but not higher than capacity of a Knapsack. Basically, determine that the solution is between 2 boundries.
I have already code 0/1 Knapsack problem with dynamic programming. And I could test it for low bounder. Something like if the solution is lower than low bounder find second best solution for knapsack and so on. But I believe there is a better way.
Thank you

Related

Which mathematical optimization problem is this?

I have an combinational optimization problem and I do not know its name in literature.
My problem is the following:
I have n sets containing exclusive elements, so each element is present only in a set.
An element is characterized by 2 constraints values, and one profit.
I have to choose an element from each set in order to maximize the sum of the profits, while keeping the sum of each constraint below a a specified limit.
Is this an already studied problem? WHich is its name?
Can I assimilate it to an already studied problem?
Thanks to #Berthur & #mrBen replies, I discovered that this is a multiple-constrained knapsack problem where you have to create an indicator variable to force that only one element will be chosen by each set
The problem you're describing is know as the multiple-choice knapsack problem. In your case, as you have 2 constraints, it's actually a 2-dimentional multiple-choice knapsack problem.
With the keywords multi-dimentional multiple-choice knapsack problem (sometime abbreviated as MMKP) you should be able to find the corresponding literature.

Counter examples for 0-1 knapsack problem with two knapsacks

I came across the following question in this course:
Consider a variation of the Knapsack problem where we have two
knapsacks, with integer capacities ๐‘Š1 and ๐‘Š2. As usual, we are given
๐‘› items with positive values and positive integer weights. We want to
pick subsets ๐‘†1,๐‘†2 with maximum total value such that the total weights of ๐‘†1 and ๐‘†1 are at most ๐‘Š1 and ๐‘Š2, respectively. Assume that every item fits in either knapsack. Consider the following two algorithmic approaches.
(1) Use the algorithm from lecture to pick a max-value feasible solution ๐‘†1 for the first knapsack, and then run it again on the remaining items to pick a max-value feasible solution ๐‘†2 for the second knapsack.
(2) Use the algorithm from lecture to pick a max-value feasible solution for a knapsack with capacity ๐‘Š1+๐‘Š2, and then split the chosen items into
two sets ๐‘†1+๐‘†2 that have size at most ๐‘Š1 and ๐‘Š2, respectively.
Which of the following statements is true?
Algorithm (1) is guaranteed to produce an optimal feasible solution to the original problem provided ๐‘Š1=๐‘Š2.
Algorithm (1) is guaranteed to
produce an optimal feasible solution to the original problem but
algorithm (2) is not.
Algorithm (2) is guaranteed to produce an
optimal feasible solution to the original problem but algorithm (1) is
not.
Neither algorithm is guaranteed to produce an optimal feasible
solution to the original problem.
The "algorithm from lecture" is on YouTube. https://www.youtube.com/watch?v=KX_6OF8X6HQ, which is 0-1 knapsack problem for one bag.
The correct answer to this question is option 4. This, this and this post present solutions to the problem. However, I'm having a hard time finding counterexamples showing that options 1 through 3 are incorrect. Can you cite any?
Edit:
The accepted answer doesn't provide a counterexample for option 1; see 2 knapsacks with same capacity - Why can't we just find the max-value twice for that.
(Weight; Value): (3;10), (3;10), (4;2)
capacities 7, 3
The first method chooses 3+3 into the first sack, remaining items does not fit into the second one
(Weight; Value): (4;10), (4;10), (4;10), (2:1)
capacities 6, 6
The second method chooses (4+4+4) but this set cannot fit into two sacks without loss, while (4+2) and (4) is better

Modification of the 0 1 Knapsack Algorithm

How would we approach to a 0 1 Knapsack Problem if we have items that can be picked multiple times. For example we have 5 items with weights 6, 5, 4, 2, 1 and their respective weights are 6.59, 6.49, 6.39, 6.29, 6.16. Now the allowed weight to pick up is 10.
The variation is we can pick any item any number of time and then maximise the value. How do we approach this.? Any suggestions or articles is really appreciated.
I've already solved 0/1 Knapsack problem using Genetic algorithm, this tutorial will give an introduction to this topic including an example (in C++) that will get you started.
If you want to have an idea on how to solve the mentioned problem, you can give a try to these link:
Solving the Knapsack Problem with a Simple Genetic Algorithm
Genetic Algorithm for Knapsack Problem
You may use other techniques to solve the problem, but I see using GA as a very interesting thing to do.
Good luck.

maximize profit with n products satisfying certain constraints

I am given a list of n products with associated profits and costs per unit. The aim is to maximize the profits while keeping the total cost below some threshold. For each product either one or zero are produced.
Now suppose we have three products and Suppose we label these products 1,2 and 3. Then all possible combinations of productions can be given as the binary numbers 111,110,101,011,100,010,001 and 000, where a 1 in the i^th position denotes a production of one of product i and similarly for zero. We could then easily check which of these combinations has a production cost under the threshold and has the maximum profit. This algorithm would then be of order O(2^n) because for n products we have to check 2^n binary numbers. We can probably make this a little faster by recognizing that if 100 is above the threshold already we need not check 110 and 111 and some stuff like this but the order will not change because of this. How can I make a smarter algorithm maybe that has a better time complexity. The n can be as large as 100 in which case checking 2^100 numbers is not possible. Thanks in advance
If your costs are integers that are not too big, you can use the dynamic programming solution for the knapsack problem, which is listed in the link mentioned in David Eisenstat's comment. If your costs are either big integers or fractional, then your best bet is using one of the existing knapsack solvers that e.g. reduce to an integer linear programming problem and then do something like branch and bound in order to solve. At any rate, your problem IS the knapsack problem, with the only slight modification that you don't have to fill the knapsack completely, you can fill it partially as long as you don't overfill it. However this variant is also studied along with the original formulation, and there are solvers for it. Also it is easy to modify the dynamic programming solution to handle this, let me know if it's unclear how and I'll update my answer with an explanation.

Suggestions for fragment proposal algorithm

I'm currently trying to solve the following problem, but am unsure which algorithm I should be using. Its in the area of mass identification.
I have a series of "weights", *w_i*, which can sum up to a total weight. The as-measured total weight has an error associated with it, so is thus inexact.
I need to find, given the total weight T, the closest k possible combinations of weights that can sum up to the total, where k is an input from the user. Each weight can be used multiple times.
Now, this sounds suspiciously like the bounded-integer multiple knapsack problem, however
it is possible to go over the weight, and
I also want all of the ranked solutions in terms of error
I can probably solve it using multiple sweeps of the knapsack problem, from weight-error->weight+error, by stepping in small enough increments, however it is possible if the increment is too large to miss certain weight combinations that could be used.
The number of weights is usually small (4 ->10 weights) and the ratio of the total weight to the mean weight is usually around 2 or 3
Does anyone know the names of an algorithm that might be suitable here?
Your problem effectively resembles the knapsack problem which is a NP-complete problem.
For really limited number of weights, you could run over every combinations with repetition followed by a sorting which gives you a quite high number of manipulations; at best: (n + k - 1)! / ((n - 1)! ยท k!) for the combination and nยทlog(n) for the sorting part.
Solving this kind of problem in a reasonable amount of time is best done by evolutionary algorithms nowadays.
If you take the following example from deap, an evolutionary algorithm framework in Python:
ga_knapsack.py, you realise that by modifying lines 58-59 that automatically discards an overweight solution for something smoother (a linear relation, for instance), it will give you solutions close to the optimal one in a shorter time than brute force. Solutions are already sorted for you at the end, as you requested.
As a first attempt I'd go for constraint programming (but then I almost always do, so take the suggestion with a pinch of salt):
Given W=w_1, ..., w_i for weights and E=e_1,.., e_i for the error (you can also make it asymmetric), and T.
Find all sets S (if the weights are unique, or a list) st sum w_1+e_1,..., w_k+e_k (where w_1, .., w_k \elem and e_1, ..., e_k \elem E) \approx T within some delta which you derive from k. Or just set it to some reasonably large value and decrease it as you are solving the constraints.
I just realise that you also want to parametrise the expression w_n op e_m over op \elem +, - (any combination of weights and error terms) and off the top of my head I don't know which constraint solver would allow you to do that. In any case, you can always fall back to prolog. It may not fly, especially if you have a lot of weights, but it will give you solutions quickly.

Resources