Lecture 10. The Bin Packing Problem The one dimensional bin packing problem is defined as follows. Given a set ๐ฟ = {1, … , ๐} of items and theirs weights ๐ค๐ ๏(0,1), ๐๏๐ฟ. We wish to partition the set ๐ฟ into minimal number ๐ of subsets ๐ต1 , ๐ต2 , … , ๐ต๐ in such a way that ∑ ๐ค๐ ≤ 1, 1 ≤ ๐ ≤ ๐. ๐ฯต๐ต๐ The sets ๐ต๐ we will call bins. In other words, we wish to pack all items in a minimal number of bins. It is NP-hard problem in the strong sense. Lecture 10 1 Mathematical Model Decision variables: 1 if bin ๐ is used ๐ฆ๐ = { ; 0 otherwise ๐ฅ๐๐ = { ๐ 1 if item ๐ is in bin ๐ 0 otherwise min ∑ ๐ฆ๐ ๐=1 ๐ s.t. ∑ ๐ค๐ ๐ฅ๐๐ ≤ ๐ฆ๐ , ๐ = 1, … , ๐; ๐=1 ๐ ∑ ๐ฅ๐๐ = 1, ๐ = 1, … , ๐; ๐=1 ๐ฆ๐ , ๐ฅ๐๐ ฯต{0,1}, ๐, ๐ = 1, … , ๐. Can we find the optimal solution for the linear programming relaxation in polynomial time? Lecture 10 2 Bad News ๏ท There is much symmetry in the model. ๏ท The problem is hard to approximate. 3 Theorem 1. The existence of a polynomial time ( − ๐)-approximation algorithm 2 for any positive ๏ฅ implies P = NP. Proof. Let us consider the following NP-complete problem. Given ๐ positive numbers ๐1 , … , ๐๐ . Is it possible to partition this set into two subsets ๐ด1 , ๐ด2 in such a way that ∑๐∈๐ด1 ๐๐ = ∑๐∈๐ด2 ๐๐ ? 1 ๐๐ 2 ๐ We put ๐ถ = ∑๐ ๐=1 ๐๐ , ๐ค๐ = 3 , ๐ = 1, … , ๐, and apply our (2 − ๐)- approximation algorithm. If we get 2 bins, then answer is Yes, otherwise No. It is exact answer! ๏ฎ Lecture 10 3 Strong Heuristic (FFD) Rank the items by the weights: ๐ค1 ๏ณ ๐ค2 ๏ณ … ๏ณ ๐ค๐ and apply the First Fit strategy: ๏ญ put the first item in the first bin; ๏ญ at the step ๐, we try to put item ๐ into the used bins and, if it is not possible, we put item ๐ into a new bin. Theorem 2. ๐น๐น๐ท(๐ฟ) ๏ฃ 11 ๐๐๐(๐ฟ) + 4 for all ๐ฟ and there exist some instances 9 for the bin packing problem with ๐น๐น๐ท(๐ฟ) ๏ณ 11 ๐๐๐(๐ฟ). 9 Lecture 10 4 1 Hard Example ๐ฟ = {1, … , 30 ๐} 2 1 ๐ค๐ = 4 1 4 1 + ๐, 1 ≤ ๐ ≤ 6๐ + 2๐, 6๐ < ๐ ≤ 12๐ + ๐, 12๐ < ๐ ≤ 18๐ { 4 − 2๐, 18๐ < ๐ ≤ 30๐ ¼ – 2๏ฅ ¼ – 2๏ฅ ¼ + ๏ฅ ¼ – 2๏ฅ ½ +๏ฅ ¼ + 2๏ฅ ¼ + 2๏ฅ ¼ + ๏ฅ ½ +๏ฅ ¼ + ๏ฅ ¼ + 2๏ฅ 6๐ 3๐ ๐๐๐(๐ฟ) = 9๐ Lecture 10 ¼ + ๏ฅ 6m ¼ – 2๏ฅ ¼ – 2๏ฅ ¼ – 2๏ฅ ¼ – 2๏ฅ 2m 3m FFD(L) = 11m 5 Huge Reformulation Given ๐ฟ = {1, … , ๐} is the set of items; ๐ค๐ > 0 is the weight of item ๐; ๐๐ > 0, integer, is the number of identical items ๐ ๐๐๐ is the number of identical items ๐ in packing pattern ๐. Find a partition of all items into a minimal number of bins. Variables: ๐ฅ๐ ≥ 0, integer, is the number of bins for the pattern ๐ min ∑ ๐ฅ๐ ๐∈๐ฝ s.t. ∑ ๐๐๐ ๐ฅ๐ ≥ ๐๐ , ๐ ∈ ๐ฟ; ๐∈๐ฝ ๐ฅ๐ ≥ 0, integer, ๐ ∈ ๐ฝ. ๐ฝ is the set of all possible patterns. Lecture 10 6 LP-Based Heuristic Solve the linear programming relaxation min ∑ ๐ฅ๐ ๐∈๐ฝ s.t. ∑ ๐๐๐ ๐ฅ๐ ≥ ๐๐ , ๐ ∈ ๐ฟ; ๐∈๐ฝ ๐ฅ๐ ≥ 0, ๐ ∈ ๐ฝ. Put ๐ฅ๐ = ⌈๐ฅ๐∗ ⌉, ๐ ∈ ๐ฝ. It is a feasible solution with deviation from the optimum at most ๐= ∑๐∈๐ฝ(⌈๐ฅ๐∗ ⌉ − ๐ฅ๐∗ ) ∑๐∈๐ฝ ๐ฅ๐∗ where ๐ฅ๐∗ is the optimal solution for the LP model. Can we solve LP? Lecture 10 7 The Column Generation Method Let us consider a subset ๐ฝ๏ข๏ ๐ฝ of patterns and assume that the following subproblem min ∑ ๐ฅ๐ ๐∈๐ฝ′ s.t. ∑ ๐๐๐ ๐ฅ๐ ≥ ๐๐ , ๐ ∈ ๐ฟ; ๐∈๐ฝ′ ๐ฅ๐ ๏ณ 0, ๐๏๐ฝ′ ; has at least one feasible solution. Denote by ๐ฅ๐∗ the optimal solution to this subproblem. Lecture 10 8 The Dual Problem max ∑ ๐๐ ๐๐ ๐∈๐ฟ ∑ ๐๐๐ ๐๐ ≤ 1, ๐ ∈ ๐ฝ′ ; ๐∈๐ฟ ๐๐ ≥ 0, ๐ ∈ ๐ฟ. Denote by ๐∗๐ ≥ 0 its optimal solution. If ∑ ๐๐๐ ๐∗๐ ≤ 1, for ๐ ∈ ๐ฝ \ ๐ฝ′ ; (๏ช) ๐∈๐ฟ then ๐ฅ๐∗ , ๐ ∈ ๐ฝ′; ๐ฅฬ ๐ = { 0, ๐ ∈ ๐ฝ \ ๐ฝ′ is the optimal solution for the LP problem. Lecture 10 9 How to Check (๏ช)? Let us consider the following knapsack problem: ๐ผ = max ∑ ๐∗๐ ๐ฆ๐ ๐∈๐ฟ s.t. ∑ ๐ค๐ ๐ฆ๐ ≤ 1 ; (capacity of bin) ๐∈๐ฟ ๐ฆ๐ ≥ 0, integer, ๐ ∈ ๐ฟ. If ๐ผ ≤ 1 then (๏ช) is satisfied. If ๐ผ > 1 then we have got a new pattern and include it in ๐ฝ′ . Lecture 10 10 The Framework of the Method 1. Select an initial subset ๐ฝ′ ⊂ ๐ฝ. 2. Solve the subproblem for ๐ฝ′ and its dual one, get ๐ฅ๐∗ , ๐∗๐ . 3. Solve the knapsack problem for ๐∗ and compute ๐ผ. 4. If ๐ผ ≤ 1 then STOP. 5. Include new pattern ๐0 : ๐๐๐0 = ๐ฆ๐∗ , ๐ ∈ ๐ฟ, into subset ๐ฝ′ and goto 2. Surprise: As a rule, solution ๐ฅ๐ = ⌈๐ฅ๐∗ ⌉, ๐ ∈ ๐ฝ is optimal for the bin packing problem. If it is not true, we have at most one additional bin only! Lecture 10 11 Two-Dimensional Packing Problem Given: ๐ rectangles with size ๐ค๐ ๏ด ๐๐ , ๐ = 1, … , ๐. Find: a packing of the rectangles into a rectangle area with minimal square. Rotations are forbidden ๐ฆ ๐ฟ ๏ด ๐ ๏ฎ min 6 2 ๐ 1 It is guillotine solution. 5 3 4 ๐ฟ Lecture 10 12 The Strip Packing Problem ะะฐะฝะพ: ๐ rectangles with size ๐ค๐ ๏ด๐๐ , ๐ ∈ ๐ฟ, and large strip with width ๐. Find: a packing of rectangles into the strip with minimal length. ๐ฆ 2 4 ๐ 1 For ๐๐ = 1 we have one-dimentional bin packing problem (NP-hard) 5 3 ๐ฅ Hometask. Design a linear integer programming model for the strip packing problem (with and without 90° rotations). Lecture 10 13 The Two-Dimensional Knapsack Problem Given: ๐ rectangles with size ๐ค๐ ๏ด ๐๐ , profit ๐๐ for each rectangle, and the size of a vehicle ๐ ๏ด ๐ฟ. Find: a subset of rectangles with maximal total profit which can be packed into the vehicle. 5 For ๐๐ = ๐ฟ, we have 6 4 the classical knapsack problem 9 7 ๐ 10 1 2 3 8 ๐ฟ Hometask. Design a linear integer programming model for the two-dimensional knapsack problem. Lecture 10 14 The Two-Dimensional Bin Packing Problem Given: ๐ rectangles with size ๐ค๐ ๏ด ๐๐ and the size of a vehicle ๐ ๏ด ๐ฟ. Find: a packing all rectangles into the minimal number of vehicles. 4 6 7 3 1 ๐– 1 5 ๐ 2 ... Hometask. Design LP-based heuristic for the two-dimensional bin packing problem. Lecture 10 15