|
|
| Line 1: |
Line 1: |
| The '''[[knapsack problem]]''' is one of the most studied problems in [[combinatorial optimization]], with many real-life applications. For this reason, many special cases and generalizations have been examined.
| | I would like to introduce myself to you, I am Andrew and my wife doesn't like it at all. I've usually cherished residing in Mississippi. One of the issues she enjoys most is canoeing and she's been performing it for quite a whilst. Invoicing is my occupation.<br><br>My website :: [http://203.250.78.160/zbxe/?document_srl=1792908 good psychic] |
| | |
| Common to all versions are a set of ''n'' items, with each item <math>1 \leq j \leq n</math> having an associated profit ''p<sub>j</sub>'' ,weight ''w<sub>j</sub>''. The binary decision variable ''x<sub>j</sub>'' is used to select the item. The objective is to pick some of the items, with maximal total profit, while obeying that the maximum total weight of the chosen items must not exceed ''W''. Generally, these coefficients are scaled to become integers, and they are almost always assumed to be positive.
| |
| | |
| The '''knapsack problem''' in its most basic form:
| |
| {|
| |
| |colspan="2"|maximize <math>\sum_{j=1}^n p_j x_j</math>
| |
| |
| |
| |-
| |
| |subject to
| |
| |<math>\sum_{j=1}^n w_j x_j \leq W,</math>
| |
| |
| |
| |-
| |
| |
| |
| |<math> x_j \in \{0,1\}</math>
| |
| |<math>\forall j \in \{1,\ldots, n\}</math>
| |
| |}
| |
| | |
| __TOC__
| |
| | |
| ==Direct generalizations==
| |
| One common variant is that each item can be chosen multiple times. The '''bounded knapsack problem''' specifies, for each item ''j'', an upper bound ''u<sub>j</sub>'' (which may be a positive integer, or infinity) on the number of times item ''j'' can be selected:
| |
| | |
| {|
| |
| |colspan="2"|maximize <math>\sum_{j=1}^n p_j x_j</math>
| |
| |
| |
| |-
| |
| | subject to
| |
| |<math>\sum_{j=1}^n w_j x_j \leq W,</math>
| |
| |
| |
| |-
| |
| |
| |
| |<math> u_j \geq x_j \geq 0, x_j</math> integral for all ''j''
| |
| |}
| |
| | |
| The '''unbounded knapsack problem''' (sometimes called the '''integer knapsack problem''') does not put any upper bounds on the number of times an item may be selected:
| |
| | |
| {|
| |
| |colspan="2"|maximize <math>\sum_{j=1}^n p_j x_j</math>
| |
| |
| |
| |-
| |
| | subject to
| |
| |<math>\sum_{j=1}^n w_j x_j \leq W,</math>
| |
| |
| |
| |-
| |
| |
| |
| |<math> x_j \geq 0, x_j</math> integral for all ''j''
| |
| |}
| |
| | |
| The unbounded variant was shown to be [[NP-complete]] in 1975 by Lueker.<ref>{{Cite journal
| |
| | first = G.S.
| |
| | last = Lueker
| |
| | contribution = Two NP-complete problems in nonnegative integer programming
| |
| | title = Report No. 178, Computer Science Laboratory, Princeton
| |
| | year = 1975}}</ref> Both the bounded and unbounded variants admit an [[Polynomial-time approximation scheme|FPTAS]] (essentially the same as the one used in the 0-1 knapsack problem).
| |
| | |
| If the items are subdivided into ''k'' classes denoted <math>N_i</math>, and exactly one item must be taken from each class, we get the '''multiple-choice knapsack problem''':
| |
| | |
| {|
| |
| |colspan="2"|maximize <math>\sum_{i=1}^k\sum_{j\in N_i} p_{ij} x_{ij}</math>
| |
| |
| |
| |-
| |
| |subject to
| |
| |<math>\sum_{i=1}^k\sum_{j\in N_i} w_{ij} x_{ij} \leq W,</math>
| |
| |
| |
| |-
| |
| |
| |
| |<math>\sum_{j \in N_i}x_{ij} = 1,</math>
| |
| |for all <math>1 \leq i \leq k</math>
| |
| |-
| |
| |
| |
| |<math> x_{ij} \in \{0,1\}</math>
| |
| |for all <math>1 \leq i \leq k</math> and all <math>j \in N_i</math>
| |
| |}
| |
| | |
| If for each item the profits and weights are identical, we get the '''[[subset sum problem]]''' (often the corresponding [[decision problem]] is given instead):
| |
| | |
| {|
| |
| |colspan="2"|maximize <math>\sum_{j=1}^n p_j x_j</math>
| |
| |
| |
| |-
| |
| |subject to
| |
| |<math>\sum_{j=1}^n p_j x_j \leq W,</math>
| |
| |
| |
| |-
| |
| |
| |
| |<math> x_j \in \{0,1\}</math>
| |
| |
| |
| |}
| |
| | |
| If we have ''n'' items and ''m'' knapsacks with capacities <math>W_i</math>, we get the '''multiple knapsack problem''':
| |
| | |
| {|
| |
| |colspan="2"|maximize <math>\sum_{i=1}^m\sum_{j=1}^n p_j x_{ij}</math>
| |
| |
| |
| |-
| |
| |subject to
| |
| |<math>\sum_{j=1}^n w_j x_{ij} \leq W_i,</math>
| |
| |for all <math>1 \leq i \leq m</math>
| |
| |-
| |
| |
| |
| |<math>\sum_{i=1}^m x_{ij} \leq 1,</math>
| |
| |for all <math>1 \leq j \leq n</math>
| |
| |-
| |
| |
| |
| |<math> x_{ij} \in \{0,1\}</math>
| |
| |for all <math>1 \leq j \leq n</math> and all <math>1 \leq i \leq m</math>
| |
| |}
| |
| | |
| As a special case of the multiple knapsack problem, when the profits are equal to weights and all bins have the same capacity, we can have '''multiple subset sum problem''':
| |
| | |
| '''Quadratic knapsack problem''':
| |
| | |
| {|
| |
| |colspan="2"|maximize <math>\sum_{j=1}^n p_j x_j+\sum_{i=1}^{n-1}\sum_{j=i+1}^n p_{ij} x_i x_j</math>
| |
| |
| |
| |-
| |
| |subject to
| |
| |<math>\sum_{j=1}^n w_j x_j \leq W,</math>
| |
| |
| |
| |-
| |
| |
| |
| |<math> x_j \in \{0,1\}</math>
| |
| |for all <math>1 \leq j \leq n</math>
| |
| |
| |
| |}
| |
| | |
| '''Set-Union Knapsack Problem''':
| |
| | |
| SUKP is defined by Kellerer et al<ref name = KP-KPP>{{cite book
| |
| | author= Kellerer, Hans and Pferschy, Ulrich and Pisinger, David
| |
| | year = 2004
| |
| | title = Knapsack Problems
| |
| | publisher = [[Springer Verlag]]
| |
| | isbn = 3-540-40286-1
| |
| | unused_data = Kellerer
| |
| }}</ref> (on page 423) as follows:
| |
| <blockquote>
| |
| Given a set of <math>n</math> items <math>N = \{1, \ldots, n\}</math> and a set of <math>m</math> so-called elements <math>P = \{1, \ldots, m\}</math>, each item <math>j</math> corresponds to a subset <math>P_j</math> of the element set <math>P</math>. The items <math>j</math> have non-negative profits <math>p_j</math>, <math>j = 1, \ldots, n</math>, and the elements <math>i</math> have non-negative weights <math>w_i</math>, <math>i = 1, \ldots, m</math>. The total weight of a set of items is given by the total weight of the elements of the union of the corresponding element sets. The objective is to find a subset of the items with total weight not exceeding the knapsack capacity and maximal profit.
| |
| </blockquote>
| |
| | |
| ==Multiple constraints==
| |
| If there is more than one constraint (for example, both a volume limit and a weight limit, where the volume and weight of each item are not related), we get the '''multiply constrained knapsack problem''', '''multidimensional knapsack problem''', or ''m''-'''dimensional knapsack problem'''. (Note, "dimension" here does not refer to the shape of any items.) This has 0-1, bounded, and unbounded variants; the unbounded one is shown below.
| |
| | |
| {|
| |
| |colspan="2"|maximize <math>\sum_{j=1}^n p_j x_j</math>
| |
| |
| |
| |-
| |
| |subject to
| |
| |<math>\sum_{j=1}^n w_{ij} x_j \leq W_i,</math>
| |
| |for all <math>1 \leq i \leq m </math>
| |
| |-
| |
| |
| |
| |<math>x_j \geq 0</math>, <math>x_j</math> integer
| |
| |for all <math> 1\leq j \leq n</math>
| |
| |}
| |
| | |
| The 0-1 variant (for any fixed <math>m \ge 2</math>) was shown to be [[NP-complete]] around 1980 and more strongly, has no FPTAS unless P=NP.<ref>{{cite news|authors = Gens, G. V. and Levner, E. V.|year=1979|title=Complexity and Approximation Algorithms for Combinatorial Problems: A Survey|publisher = Central Economic and Mathematical Institute, Academy of Sciences of the USSR, Moscow}}</ref><ref>{{cite journal|author8 = Korte, B. and Schrader, R. | year = 1980 | title = On the Existence of Fast Approximation Schemes| journal = Nonlinear Programming | volume = 4 | publisher = Academic Press | pages = 415–437}}</ref>
| |
| | |
| The bounded and unbounded variants (for any fixed <math>m \ge 2</math>) also exhibit the same hardness.<ref>{{cite journal|doi = 10.1287/moor.9.2.244|last1 = Magazine|title = A Note on Approximation Schemes for Multidimensional Knapsack Problems|first1 = M. J.|last2 = Chern|first2 = M.-S.|
| |
| author8 = Magazine, Michael J. and Chern, Maw-Sheng |
| |
| journal = Mathematics of Operations Research |
| |
| volume = 9|
| |
| issue = 2|
| |
| pages = 244–247|year = 1984}}</ref>
| |
| | |
| For any fixed <math>m \ge 2</math>, these problems do admit a [[pseudo-polynomial time]] algorithm (similar to the one for basic knapsack) and a [[Polynomial-time approximation scheme|PTAS]].<ref name = KP-KPP />
| |
| | |
| ==Knapsack-like problems==
| |
| If all the profits are 1, we can try to minimize the number of items which exactly fill the knapsack:
| |
| | |
| {|
| |
| |colspan="2"|minimize <math>\sum_{j=1}^n x_j</math>
| |
| |
| |
| |-
| |
| |subject to
| |
| |<math>\sum_{j=1}^n w_j x_j = W,</math>
| |
| |
| |
| |-
| |
| |
| |
| |<math> x_j \in \{0,1\},</math>
| |
| |<math> \forall j \in \{1,\ldots,n\}</math>
| |
| |}
| |
| | |
| If we have a number of containers (of the same size), and we wish to pack all ''n'' items in as few containers as possible, we get the '''[[bin packing problem]]''', which is modelled by having indicator variables <math>y_i=1 \Leftrightarrow</math> container ''i'' is being used:
| |
| | |
| {|
| |
| |colspan="2"|minimize <math>\sum_{i=1}^n y_i</math>
| |
| |
| |
| |-
| |
| |subject to
| |
| |<math>\sum_{j=1}^n w_j x_{ij} \leq Wy_i,</math>
| |
| |<math>\forall i \in \{1,\ldots,n\}</math>
| |
| |-
| |
| |
| |
| |<math>\sum_{i=1}^n x_{ij} = 1</math>
| |
| |<math>\forall j \in \{1,\ldots,n\}</math>
| |
| |-
| |
| |
| |
| |<math> y_i \in \{0,1\}</math>
| |
| |<math>\forall i \in \{1,\ldots,n\}</math>
| |
| |-
| |
| |
| |
| |<math> x_{ij} \in \{0,1\}</math>
| |
| |<math>\forall i \in \{1,\ldots,n\} \wedge \forall j \in \{1,\ldots,n\}</math>
| |
| |}
| |
| | |
| The '''[[cutting stock problem]]''' is identical to the [[bin packing problem]], but since practical instances usually have far fewer types of items, another formulation is often used. Item ''j'' is needed ''B<sub>j</sub>'' times, each "pattern" of items which fit into a single knapsack have a variable, ''x<sub>i</sub>'' (there are ''m'' patterns), and pattern ''i'' uses item ''j'' ''b<sub>ij</sub>'' times:
| |
| | |
| {|
| |
| |colspan="2"|minimize <math>\sum_{i=1}^m x_i</math>
| |
| |
| |
| |-
| |
| |subject to
| |
| |<math>\sum_{i=1}^m b_{ij} x_i \leq B_j,</math>
| |
| |for all <math>1 \leq j \leq n</math>
| |
| |-
| |
| |
| |
| |<math>x_i \in \{0,1,\ldots ,n\}</math>
| |
| |for all <math>1\leq i \leq m</math>
| |
| |}
| |
| | |
| If, to the multiple choice knapsack problem, we add the constraint that each subset is of size ''n'' and remove the restriction on total weight, we get the '''[[assignment problem]]''', which is also the problem of finding a maximal '''[[bipartite matching]]''':
| |
| | |
| {|
| |
| |colspan="2"|maximize <math>\sum_{i=1}^k\sum_{j=1}^n p_{ij} x_{ij}</math>
| |
| |
| |
| |-
| |
| |subject to
| |
| |<math>\sum_{i=1}^n x_{ij} = 1,</math>
| |
| |for all <math>1 \leq j \leq n</math>
| |
| |-
| |
| |
| |
| |<math>\sum_{j=1}^n x_{ij} = 1,</math>
| |
| |for all <math>1 \leq i \leq n</math>
| |
| |-
| |
| |
| |
| |<math> x_{ij} \in \{0,1\}</math>
| |
| |for all <math>1 \leq i \leq k</math> and all <math>j \in N_i</math>
| |
| |}
| |
| | |
| In the '''Maximum Density Knapsack''' variant there is an initial weight <math>w_0</math>,
| |
| and we maximize the density of selected of items which do not violate the capacity constraint:
| |
| <ref>Cohen, R. and Katzir, L. 2008. [http://dx.doi.org/10.1016/j.ipl.2008.03.017 The Generalized Maximum Coverage Problem]. ''Inf. Process. Lett''. 108, 1 (Sep. 2008), 15-22.</ref>
| |
| | |
| {|
| |
| |colspan="2"|maximize <math>\frac{\sum_{j=1}^n x_j p_j}{w_0 +\sum_{j=1}^n x_j w_j}</math>
| |
| |
| |
| |-
| |
| |subject to
| |
| |<math>\sum_{j=1}^n w_j x_j \leq W,</math>
| |
| |
| |
| |-
| |
| |
| |
| |<math> x_j \in \{0,1\},</math>
| |
| |<math> \forall j \in \{1,\ldots,n\}</math>
| |
| |}
| |
| | |
| Although less common than those above, several other knapsack-like problems exist, including:
| |
| | |
| * Nested knapsack problem
| |
| * Collapsing knapsack problem
| |
| * Nonlinear knapsack problem
| |
| * Inverse-parametric knapsack problem
| |
| | |
| The last three of these are discussed in Kellerer et al's reference work, ''Knapsack Problems''.<ref name=KP-KPP />
| |
| | |
| ==References== | |
| <references/>
| |
| * [http://www.diku.dk/users/pisinger/95-1.pdf "Algorithms for Knapsack Problems"], D. Pisinger. Ph.D. thesis, DIKU, University of Copenhagen, Report 95/1 (1995).
| |
| | |
| [[Category:Combinatorial optimization]]
| |