9.2 Knapsack Problem There are many other versions.

Slides:



Advertisements
Similar presentations
MCS 312: NP Completeness and Approximation algorithms Instructor Neelima Gupta
Advertisements

EXAMPLE 1 Standardized Test Practice SOLUTION Substitute several values of h into the equation C = h and solve for C.Then identify the table that.
1-8 Solving Equations Using Inverse Operations Objective: Use inverse operations to solve equations.
Chapter 5 Fundamental Algorithm Design Techniques.
INTEGRALS 5. Indefinite Integrals INTEGRALS The notation ∫ f(x) dx is traditionally used for an antiderivative of f and is called an indefinite integral.
Instructor Neelima Gupta Table of Contents Lp –rounding Dual Fitting LP-Duality.
© 5/7/2002 V.S. Subrahmanian1 Knapsack Problem Notes V.S. Subrahmanian University of Maryland.
© 5/7/2002 V.S. Subrahmanian1 Knapsack Problem Notes V.S. Subrahmanian University of Maryland.
CSC401 – Analysis of Algorithms Lecture Notes 12 Dynamic Programming
Lecture outline Support vector machines. Support Vector Machines Find a linear hyperplane (decision boundary) that will separate the data.
KNAPSACK PROBLEM A dynamic approach. Knapsack Problem  Given a sack, able to hold K kg  Given a list of objects  Each has a weight and a value  Try.
D Nagesh Kumar, IIScOptimization Methods: M3L1 1 Linear Programming Preliminaries.
1 The Greedy Method CSC401 – Analysis of Algorithms Lecture Notes 10 The Greedy Method Objectives Introduce the Greedy Method Use the greedy method to.
Taking a Square Root to Solve an Equation. Solve: In order to solve for x, you have to UNDO the squared first (i.e. square root) What are the number(s)
Direct Variation.
1 Lecture 4 Maximal Flow Problems Set Covering Problems.
LINEAR PROGRAMMING SIMPLEX METHOD.
Linear Programming - Standard Form
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
Approaches to Problem Solving greedy algorithms dynamic programming backtracking divide-and-conquer.
Table of Contents First note this equation has "quadratic form" since the degree of one of the variable terms is twice that of the other. When this occurs,
1 Chapter 8 Sensitivity Analysis  Bottom line:   How does the optimal solution change as some of the elements of the model change?  For obvious reasons.
1.8: Intro to Equations Equation: A mathematical sentence that uses the equal ( = ) sign. Ex: 3x=12, -1(x + 5) = 8, Open Sentence: An equation.
Chapter 1 Partial Differential Equations
Table of Contents Solving Linear Systems of Equations - Dependent Systems The goal in solving a linear system of equations is to find the values of the.
Algebra 1A Vocabulary 1-2 Part 2
Linear Programming Terminology. Contents 1.What is a Mathematical Model? 2.Illustration of LPP: Maximization Case 3.What.
1 1 Slide © 2000 South-Western College Publishing/ITP Slides Prepared by JOHN LOUCKS.
1 Lesson 8: Basic Monte Carlo integration We begin the 2 nd phase of our course: Study of general mathematics of MC We begin the 2 nd phase of our course:
Word Problems that Lead to Inequalities. Word Problem Solving Strategies Read through the entire problem. Highlight the important information and key.
Equations Reducible to Quadratic
Substitution Method: 1. Solve the following system of equations by substitution. Step 1 is already completed. Step 2:Substitute x+3 into 2 nd equation.
MA3264 Mathematical Modelling Lecture 9 Chapter 7 Discrete Optimization Modelling Continued.
The Greedy Method. The Greedy Method Technique The greedy method is a general algorithm design paradigm, built on the following elements: configurations:
Dynamic programming vs Greedy algo – con’t Input: Output: Objective: a number W and a set of n items, the i-th item has a weight w i and a cost c i a subset.
OR Simplex method (algebraic interpretation) Add slack variables( 여유변수 ) to each constraint to convert them to equations. (We may refer it as.
Lecture.6. Table of Contents Lp –rounding Dual Fitting LP-Duality.
CS 3343: Analysis of Algorithms Lecture 19: Introduction to Greedy Algorithms.
1 1 © 2003 Thomson  /South-Western Slide Slides Prepared by JOHN S. LOUCKS St. Edward’s University.
(i) Preliminaries D Nagesh Kumar, IISc Water Resources Planning and Management: M3L1 Linear Programming and Applications.
LINEAR PROGRAMMING 3.4 Learning goals represent constraints by equations or inequalities, and by systems of equations and/or inequalities, and interpret.
1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the famous Knapsack Problem.
CHAPTER 1 – EQUATIONS AND INEQUALITIES 1.4 – SOLVING ABSOLUTE VALUE EQUATIONS Unit 1 – First-Degree Equations and Inequalities.
Discrete Optimization MA2827 Fondements de l’optimisation discrète Material from P. Van Hentenryck’s course.
Part3 Algorithms By example … Overview Shortest Path Knapsack.
Lesson 8: Basic Monte Carlo integration
Section 1-3: Solving Equations 8/29/17
Solving Systems of Equations
7-3 Solving Subtraction and Addition Equations
Solve a system of linear equation in two variables
CS 3343: Analysis of Algorithms
Solving Two-Step Equations
Do Now 1) t + 3 = – 2 2) 18 – 4v = 42.
2 Understanding Variables and Solving Equations.
A new and improved algorithm for online bin packing
Solving Systems of Equation by Substitution
Warm Up Solve for x:
Greedy Algorithms Alexandra Stefan.
Solving 1-Step Integer Equations
Solving systems using substitution
Solving Equations with Variables on Both Sides
Solving Equations with Variables on Both Sides
Lecture 4 Dynamic Programming
Lecture 6 Greedy Algorithms
Part II General Integer Programming
Lecture 19 Linear Program
Lecture 5 Dynamic Programming
Graphical solution A Graphical Solution Procedure (LPs with 2 decision variables can be solved/viewed this way.) 1. Plot each constraint as an equation.
Solving Equations with Absolute Values
6.6 Solve Radical Equations
Presentation transcript:

9.2 Knapsack Problem There are many other versions

Interpretation n = 1,2,..., N - Item-type V = Volume of knapsack v n = Volume of an item of type n w n = Weight of an item of type n x n = Number of items of type n put in the knapsack

Observation If the integrality constraint {x n is in {0,1,2,...}} is ignored, and is replaced by say a nonnegativity constraints, then the problem is trivial (why?) There are many variations on this theme, eg 0-1 knapsack problems.

DP Strategy Let, f(s):= maximum weight of knapsack with available volume of s units, s=0,1,2,...,V. We are interested in f(V). Clearly, f(0)=0 Clearly, f(s) =0 for all s smaller than the smallest item (volume-wise).

Clearly, if f(s)>0, then f(s) = f(s-v n ) + w n for some item-type n. Obvious question: What is the best n ? Answer: The n that maximizes f(s-v n ) + w n.

Hence DP functional Equation

(NILN) V s n f(s) = ?

(NILN) V s n s-v n f(s) = f(s-v n ) + w n V s n f(s) = ?

Minor “Correction ” The functional equation is not valid for s smaller than the smallest v n. Fixes: –Set f(s)=0 for all s <min{v 1,...,v N } –Introduce a dummy item-type, with w n =0 and v n =1. In the Lecture Notes we use the latter.

Notation As we solve the functional equation for s=0,1,2,...,V - in this order (why?) we store the optimal decisions. ie.

Since there is no item-type with v n =1, we introduce a dummy variable n=4, with w 4 =0 and v 4 = Example

V =13

Procedure f(0)=0 N(1)={4} N(2)={4}

N(3)={2}

N(4)={3}

N(5)={3,4}

Recovery of Optimal Solution Using the table we select the optimal items from N(s) and then go to N(s-v n ). x (0) =(0,0,0,0), s=V=13 x (1) =(0,0,1,0) (N(13)={2,3}), next s = s-v 3 = 9 x (2) =(0,1,1,0) (N(9)={2}, next s = s-v 2 = 6 x (3) =(0,2,1,0) (N(6)={2}, next s = s-v 2 = 3 x (4) =(0,3,1,0) (N(3)={2}, next s = s-v 2 = 0 x*=(0,3,1,0)

Important Reminder Do not forget to check the results!