HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

0/1 Knapsack problem with real-valued weights

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
problemrealwithweightsvaluedknapsack

Problem

Is there a known solution for the 0/1 knapsack problem that allows the weights of the objects to be real numbers? The only algorithm I can think of is a brute force search. I have tried searching for a solution but couldn't come across any. When weights are natural numbers, the most common solution uses dynamic programming by caching solutions $V[i,w]$ to the subproblems in an $N\times W$ table, where $N$ and $W$ are the number of objects and weight limit of the knapsack. When the weights are real numbers, the dynamic programming solution breaks down: how do you define the table now? Granted there will be $N$ rows, but what about the columns?

Solution

Sort the items by density such that $p_1/w_1\geq p_2/w_2\geq\cdots\geq p_n/w_n$ for profits $p$ and weights $w$. Let $W(k)=\sum_{1\leq i\leq k} w_i$ be the total weight of the first $k$ items in this order. Then for capacity $c$ an optimal fractional solution is to choose items $1,\ldots,i^$ where $i^$ is the largest number s.t. $W(i^)\leq c$ , and additionally a fraction of $(c-W(i^))/w_{i+1}$ of item $i^*+1$.

Update: I misread your question. For solving the $0$/$1$ version with real-valued weights you can either round them, or apply branch-and-bound algorithms that were designed for real values, e.g. Martello and Toth's MT1R.

Context

StackExchange Computer Science Q#109716, answer score: 2

Revisions (0)

No revisions yet.