Questions tagged [knapsack-problem]

The knapsack problem is a problem in combinatorial optimization: Given a set of items with associated weights and values, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and it maximizes the total value. It is an NP-complete problem, but several common simplifications are solved efficiently with dynamic programming.

There are several variants of the knapsack problem, such as 0-1 knapsack problem, bounded and unbounded knapsack problem. The unbounded and 0-1 knapsack are solved efficiently by using divide-and-conquer techniques (dynamic programming).

Other variants, where one can take a non-integer amount of an item, the weights are real numbers (and instances where other constraints become real instead of integer) are NP-complete.

A multiple knapsack problem is often referred to as the bin-packing problem.

1098 questions
14
votes
3 answers

How to ensure Java threads run on different cores

I am writing a multi-threaded application in Java in order to improve performance over the sequential version. It is a parallel version of the dynamic programming solution to the 0/1 knapsack problem. I have an Intel Core 2 Duo with both Ubuntu and…
KBP
  • 1,500
  • 2
  • 14
  • 14
13
votes
3 answers

Printing Items that are in sack in knapsack

Suppose you are a thief and you invaded a house. Inside you found the following items: A vase that weights 3 pounds and is worth 50 dollars. A silver nugget that weights 6 pounds and is worth 30 dollars. A painting that weights 4 pounds and is worth…
T.J.
  • 1,466
  • 3
  • 19
  • 35
13
votes
3 answers

0/1 Knapsack Dynamic Programming Optimization, from 2D matrix to 1D matrix

I need some clarification from wikipedia: Knapsack, on the part This solution will therefore run in O(nW) time and O(nW) space. Additionally, if we use only a 1-dimensional array m[W] to store the current optimal values and pass over this array…
Jack
  • 271
  • 1
  • 7
  • 15
12
votes
2 answers

OpenMP - Nested for-loop becomes faster when having parallel before outer loop. Why?

I'm currently implementing an dynamic programming algorithm for solving knapsack problems. Therefore my code has two for-loops, an outer and an inner loop. From the logical point of view I can parallelize the inner for loop since the calculations…
kevsi
  • 163
  • 1
  • 1
  • 10
12
votes
2 answers

Algorithm design: can you provide a solution to the multiple knapsack problem?

I am looking for a pseudo-code solution to what is effectively the Multiple Knapsack Problem (optimisation statement is halfway down the page). I think this problem is NP Complete so the solution doesn't need to be optimal, rather if it is fairly…
MalcomTucker
  • 7,407
  • 14
  • 72
  • 93
12
votes
1 answer

Knapsack with multiple bags and items having only weight

I am trying to solve this problem and I wanted to know if there are known existing algorithms / solutions to solve this. Problem: I have n bags and n items (which are either equal or different weights) to fill into these bag. Each of these bags…
Jony
  • 6,694
  • 20
  • 61
  • 71
12
votes
3 answers

Strange but practical 2D bin packing optimization

I am trying to write an application that generates drawing for compartmentalized Panel. I have N cubicles (2D rectangles) (N <= 40). For each cubicle there is a minimum height (minHeight[i]) and minimum width (minWidth[i]) associated. The panel…
Abhishek Bansal
  • 12,589
  • 4
  • 31
  • 46
12
votes
1 answer

Any pseudo-polynomial algorithm for bounded 0-1 multi-knapsack?

Suppose that there are n items, e.g i1, i2, .... in, each of them with a known bounded weight w1, w2, ... wn. There are also a set of m knapsacks e.g. k1, k2 and km. Knapsacks are homogeneous, that they all have the same capacity W. The function F…
12
votes
2 answers

Knapsack algorithm with an additional property

When there's 1 property, I do understand what's going on in there. I'm having a problem with understanding knapsack problem when there's more than 1 property. I have to write a program that uses knapsack algorithm with a 2 properties. Teacher told…
Paulina
  • 483
  • 3
  • 13
11
votes
4 answers

Can bottom-up dynamic programming be done in Lisp?

Can a typical Lisp dialect solve problems using the bottom-up "dynamic programming" approach? (Please note: I'm not talking about "memoization" which, as far as I understand, is trivial using any Lisp dialect. I'm really talking about bottom-up…
Cedric Martin
  • 5,945
  • 4
  • 34
  • 66
11
votes
4 answers

Divide people into teams for most satisfaction

Just a curiosity question. Remember when in class groupwork the professor would divide people up into groups of a certain number (n)? Some of my professors would take a list of n people one wants to work with and n people one doesn't want to work…
Jon W
  • 15,480
  • 6
  • 37
  • 47
11
votes
1 answer

Why solving Knapsack problem is not considered as linear programming?

Why isn't the knapsack problem included under the category of linear programming algorithms in spite of the fact that the Knapsack problem statement seems similar to the problems in linear programming?
user1543957
  • 1,758
  • 4
  • 20
  • 30
10
votes
3 answers

Is Dynamic 0/1 Knapsack a Total Joke?

I have obtained a proof that would discredit a generally held idea regarding the 0/1 knapsack problem and I'm really having a hard time convincing my self I am right because I couldn't find any thing any where to support my claims, so I am going to…
Amen
  • 1,524
  • 5
  • 22
  • 41
10
votes
5 answers

divide list in two parts that their sum closest to each other

This is a hard algorithms problem that : Divide the list in 2 parts (sum) that their sum closest to (most) each other list length is 1 <= n <= 100 and their(numbers) weights 1<=w<=250 given in the question. For example : 23 65 134 32 95 123…
user467871
10
votes
2 answers

Knapsack Equation with item groups

Can't call it a problem on Stack Overflow apparently, however I am currently trying to understand how to integrate constraints in the form of item groups within the Knapsack problem. My math skills are proving to be fairly limiting in this…
user470760
1
2
3
73 74