Mat 3770 Bin Packing or

Similar documents
Combinatorial optimization problems

4/12/2011. Chapter 8. NP and Computational Intractability. Directed Hamiltonian Cycle. Traveling Salesman Problem. Directed Hamiltonian Cycle

CSE 421 Dynamic Programming

DAA Unit- II Greedy and Dynamic Programming. By Mrs. B.A. Khivsara Asst. Professor Department of Computer Engineering SNJB s KBJ COE, Chandwad

Dynamic Programming. Cormen et. al. IV 15

In the original knapsack problem, the value of the contents of the knapsack is maximized subject to a single capacity constraint, for example weight.

CSE 421 Weighted Interval Scheduling, Knapsack, RNA Secondary Structure

4. How to prove a problem is NPC

Lecture 18: More NP-Complete Problems

- Well-characterized problems, min-max relations, approximate certificates. - LP problems in the standard form, primal and dual linear programs

MATH 409 LECTURES THE KNAPSACK PROBLEM

TRIPARTITE MATCHING, KNAPSACK, Pseudopolinomial Algorithms, Strong NP-completeness

Data Structures in Java

Operations Research Lecture 6: Integer Programming

6. DYNAMIC PROGRAMMING I

Knapsack. Bag/knapsack of integer capacity B n items item i has size s i and profit/weight w i

CSE 202 Homework 4 Matthias Springer, A

Technische Universität München, Zentrum Mathematik Lehrstuhl für Angewandte Geometrie und Diskrete Mathematik. Combinatorial Optimization (MA 4502)

Greedy Algorithms My T. UF

0-1 Knapsack Problem

Algorithms. NP -Complete Problems. Dong Kyue Kim Hanyang University

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Limitations of Algorithms

(tree searching technique) (Boolean formulas) satisfying assignment: (X 1, X 2 )

Activity selection. Goal: Select the largest possible set of nonoverlapping (mutually compatible) activities.

More NP-Complete Problems

1. Introduction Recap

Unit 1A: Computational Complexity

Introduction to Bin Packing Problems

Polynomial-time Reductions

Aside: Golden Ratio. Golden Ratio: A universal law. Golden ratio φ = lim n = 1+ b n = a n 1. a n+1 = a n + b n, a n+b n a n

Chapter 7. Network Flow. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Exercises NP-completeness

Dynamic Programming: Interval Scheduling and Knapsack

6.046 Recitation 11 Handout

Representations of All Solutions of Boolean Programming Problems

Theory of Computation CS3102 Spring 2014 A tale of computers, math, problem solving, life, love and tragic death

Discrete Optimization 2010 Lecture 10 P, N P, and N PCompleteness

Advanced Analysis of Algorithms - Midterm (Solutions)

12. LOCAL SEARCH. gradient descent Metropolis algorithm Hopfield neural networks maximum cut Nash equilibria

1 The Knapsack Problem

Lecture 13: Dynamic Programming Part 2 10:00 AM, Feb 23, 2018

Lecture 2: Divide and conquer and Dynamic programming

CS 598RM: Algorithmic Game Theory, Spring Practice Exam Solutions

Optimisation and Operations Research

CSE 202 Dynamic Programming II

Dynamic Programming( Weighted Interval Scheduling)

Chapter 11. Approximation Algorithms. Slides by Kevin Wayne Pearson-Addison Wesley. All rights reserved.

CSE 421 NP-Completeness

NP-COMPLETE PROBLEMS. 1. Characterizing NP. Proof

Section Summary. Sequences. Recurrence Relations. Summations Special Integer Sequences (optional)

CS 580: Algorithm Design and Analysis. Jeremiah Blocki Purdue University Spring 2018

What is Dynamic Programming

8 Knapsack Problem 8.1 (Knapsack)

Reductions. Example 1

Easy Problems vs. Hard Problems. CSE 421 Introduction to Algorithms Winter Is P a good definition of efficient? The class P

Dynamic Programming. Credits: Many of these slides were originally authored by Jeff Edmonds, York University. Thanks Jeff!

Greedy vs Dynamic Programming Approach

Ma/CS 6a Class 28: Latin Squares

Reductions. Reduction. Linear Time Reduction: Examples. Linear Time Reductions

On Two Class-Constrained Versions of the Multiple Knapsack Problem

Chapter 8 Dynamic Programming

Weighted Activity Selection

CMPSCI 611 Advanced Algorithms Midterm Exam Fall 2015

The Knapsack Problem. 28. April /44

Limitations of Algorithm Power

Discrete Mathematics. Spring 2017

2001 Dennis L. Bricker Dept. of Industrial Engineering The University of Iowa. Reducing dimensionality of DP page 1

COL351: Analysis and Design of Algorithms (CSE, IITD, Semester-I ) Name: Entry number:

This means that we can assume each list ) is

Written Qualifying Exam. Spring, Friday, May 22, This is nominally a three hour examination, however you will be

Notes for Lecture Notes 2

1 Last time: row reduction to (reduced) echelon form

Introduction to Integer Programming

ACO Comprehensive Exam October 18 and 19, Analysis of Algorithms

0-1 Knapsack Problem in parallel Progetto del corso di Calcolo Parallelo AA

6. DYNAMIC PROGRAMMING I

Stochastic processes. MAS275 Probability Modelling. Introduction and Markov chains. Continuous time. Markov property

1 T 1 = where 1 is the all-ones vector. For the upper bound, let v 1 be the eigenvector corresponding. u:(u,v) E v 1(u)

The P versus NP Problem. Ker-I Ko. Stony Brook, New York

Topics in Approximation Algorithms Solution for Homework 3

Chapter 11. Approximation Algorithms. Slides by Kevin Wayne Pearson-Addison Wesley. All rights reserved.

Part V. Intractable Problems

Flows and Cuts. 1 Concepts. CS 787: Advanced Algorithms. Instructor: Dieter van Melkebeek

CS325: Analysis of Algorithms, Fall Final Exam

Lecture 27: Theory of Computation. Marvin Zhang 08/08/2016

Essential facts about NP-completeness:

Intractable Problems Part Two

CPSC 320 Sample Final Examination December 2013

Consecutive ones matrices for multi-dimensional orthogonal packing problems

Algorithm Design and Analysis

Computational Complexity. IE 496 Lecture 6. Dr. Ted Ralphs

CSE 421 Introduction to Algorithms Final Exam Winter 2005

Knapsack and Scheduling Problems. The Greedy Method

Chapter 8 Dynamic Programming

Topics in Theoretical Computer Science April 08, Lecture 8

What is an integer program? Modelling with Integer Variables. Mixed Integer Program. Let us start with a linear program: max cx s.t.

Lecture 18: P & NP. Revised, May 1, CLRS, pp

RECAP How to find a maximum matching?

Week 5: Quicksort, Lower bound, Greedy

CHAPTER 1. Relations. 1. Relations and Their Properties. Discussion

Transcription:

Basic Algithm Spring 2014

Used when a problem can be partitioned into non independent sub problems Basic Algithm Solve each sub problem once; solution is saved f use in other sub problems Combine solutions of sub problems into a solution f the iginal problem Effective when a given sub problem may arise from me than one partial set of choices

Approach structure of an optimal solution is recursively defined. Basic Algithm value of an optimal solution is computed in a bottom up fashion. An example: Fibonacci numbers F 1 = 1, F 2 = 1, F n = F n 2 + F n 1

Definition Basic Algithm Generally: Given a knapsack with weight capacity K and n objects of weights w 1, w 2,..., w n, is it possible to find a collection of objects such that their weights add up to K, i.e. find w i1, w i2,..., w im, such that K = m w ij? F example, given a list: { 12, 10, 40, 3, 11, 26, 37, 28, 9, 18 }, does any subset add up to 72? j=1 yes: { 12, 3, 22, 37, 9 }

This Has Many s Basic Algithm Allow same weights to be used multiple times Ask: how close to full (without going over) can we get? I.e., if W = {w 1, w 2,..., w n }, we want to minimize K w W w over all W W subject to the constraint that K w 0 w W Assume there s a cresponding value v i f each w i (e.g., gold s value & its weight). Maximize the total value given that the weight must be at most K: Maximize over I {1,..., n}, i I v i, given i I w i K

Basic Basic Algithm Is there I {1,..., n} such that i I w i = K Let predicate { true : if I {1,..., i} P[i, k] = j I w j = k. false : otherwise and we want the value of P[n, K]

Observation Basic Algithm P[i, k] = { P[i 1, k] : if wi is not used P[i 1, k w i ] : if w i is used Furtherme: P[i, k] is false if k < 0 P[i, k] is true f k = 0 P[1, k] is true IFF k = w 1 So, we can build a table to solve this type of problem.

Algithm Basic Algithm // initialize first row P[0, 0] = true f currentweight := 1 to K P[0, currentweight] = false // calculate rest of rows 1 through n f i := 1 to n f currentweight := 0 to K P[i, currentweight] = false if P[i - 1, currentweight] then P[i, currentweight] = true else if currentweight - wi >= 0 then if P[i - 1, currentweight - wi] then P[i, currentweight] = true

Basic Algithm Wksheet

Time Complexity Basic Algithm idea behind dynamic programming is to build a table iteratively, where we solve a problem by sting solutions to subproblems efficiently. What is our complexity f finding P[n, K]? We have to fill in the table out to the K th column f n 1 rows, then consider the n th row at column K if P[n 1, K] true. Thus: O((n 1)K + 1) = O(nk) which could be bad if K = 2 n.

Follow up Basic Algithm To make it easier to know which objects were used, we could mark P[i, currentweight] if w i was used (i.e., if P[i 1, k w i ] = true) we can trace back through the table to find which w i were used. Note that recapturing the subset would take O(n) time.

A On Basic Algithm Given a collection of items, T = {t 1,..., t n } where t i has (integer) size s i and a set B of bins each with a fixed (integer) capacity b. A subset of the items can be packed in one bin as long as the sum of the sizes of the items is less than equal to b. goal is to pack all items, minimizing the number of bins used.

An Example Basic Algithm Suppose there are 7 items with sizes 1, 4, 2, 1, 2, 3, 5, and the bin capacity b = 6. One (optimal) solution: Bin 1 : 1 and 5 = 6 Bin 2 : 4 and 2 = 6 Bin 3 : 1, 2, and 3 = 6

Solution Methods Basic Algithm Approach Divide and Conquer Mathematical

Many Possibilities One is: Basic Algithm Find all partitions of the items from all in a single set, to all items in separate sets. Determine the feasible partitions, and choose one of the feasible solutions that uses a minimum number of bins.

Approach Optionally, can st items in increasing der by size: 1, 1, 2, 2, 3, 4, 5 Basic Algithm Pack a b in with the items given in der until the bin is full get another (empty bin) and keep packing until all items are in bins. Results: Bin 1 : 1, 1, 2, 2 Bin 2 : 3 Bin 3 : 4 Bin 4 : 5 Suboptimal since it uses 4 bins instead of 3

Basic Algithm Strategy: solve the problem f the first k items, then consider the (k + 1) st iteration and determine the best way to place the (k + 1) st item in previous ( a new) bins.

Basic Algithm Items: 1, 4, 2, 1, 2, 3, 5 Bin capacity: 6 Step 1 : place 1 1 Step 2 : place 4 1, 4 Step 3 : place 2 1, 4 2 Step 4 : place 1 1, 1, 4 2 Step 5 : place 2 1, 1, 4 2, 2 Step 6 : place 3 1, 1, 4 2, 2 3 Step 7 : place 5 1, 1, 4 2, 2 3 5

Basic Algithm Note: der makes a difference in this algithm. If they are sted in descending der, 5, 4, 3, 2, 2, 1, 1, we happen to get an optimal solution, but this isn t guaranteed in all cases. 5, 1 4, 2 3, 2, 1

Divide and Conquer Basic Algithm Partition the problem into 2 subproblems F example: 1, 4, 2, 1, 2, 3, 5 1, 4, 2, 1 and 2, 3, 5 Recursively partition each subproblem until each subset can fit into a bin. 1, 4, 2, 1 1, 4 and 2, 1 bins 1 & 2 2, 3, 5 2, 3 and 5 bins 3 & 4 Uses four bins suboptimal

Linear Basic Algithm A linear programming problem may be stated as follows: Given real numbers b 1,..., b m, c 1,..., c n, and a ij (f 1 i m and 1 j n), minimize ( maximize) the function: subject to the conditions: Z(X 1,..., X n ) = c 1 X 1 + + c n X n a 11 X 1 + a 12 X 2 + + a 1n X n {, =, } b 1 a 21 X 1 + a 22 X 2 + + a 2n X n {, =, } b 2......... a m1 X 1 + a m2 X 2 + + a mn X n {, =, } b m

Vocabulary Basic Algithm X i are called decision variables Z is the objective function conditions are called constraints

Vocabulary Basic Algithm A solution is any specification of values f the decision variable A feasible solution is one in which all the constraints are satisfied An infeasible solution leaves one me of the constraints unsatisfied An optimal solution is a feasible solution which minimizes (maximizes) Z solution (search) space is the set of all possible configurations of the decision variables.

Mathematical Basic Algithm We can fmulate the decision problem in general fm as follows: Let U be the set of items, U = {u 1, u 2,..., u n } Let B be the set of bins, B = {b 1, b 2,..., b k } F our particular problem, all our b i = 6 Fm a complete bipartite graph G = (U, B, E), with the goal of assigning an item to one and only one bin weight w ij (the i th item in the j th bin) of an edge connecting one vertex u i in U and one vertex b j in B, is set to s(u i ), the size of item u i.

χ Function Basic Algithm { 0 : if i χ ij = th item not in j th bin 1 : otherwise

objective is to maximize (i, j) E (w ij χ ij ) Basic Algithm Subject to the following four constraints: 1. [0, 1] Constraint: cannot have part of an item in a bin χ ij {0, 1} 2. Capacity Constraint: the sum of the sizes of the items in each bin cannot exceed its capacity (wij χ ij ) i U b j j B 3. Assignment Constraint: each item can only be assigned to one bin (χij ) j B = 1 i U 4. Completeness Constraint: the total number of χ ij whose value is 1 is equal to n every item gets put in some bin. χ ij = n (i, j)

A Possible Solution Basic Algithm Step 1: Set the number of bins B to a lower bound found by dividing the sum of the item sizes by the bin capacity. Step 2: Fmulate the linear programming problem and use it to find a feasible solution satisfying the set of constraints. Step 3: If a solution exists f B bins, we re done! Step 4: Otherwise, set B to B + 1 and repeat steps 1 4.