Optimization II: Dynamic programming

Similar documents
Computational Methods in IS Research Fall Graph Algorithms Network Flow Problems

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

CSE 21: Mathematics for Algorithms and Systems Analysis

Lesson 1: Complementary and Supplementary Angles

Partha Sarathi Mandal

Math 414 Lecture 30. The greedy algorithm provides the initial transportation matrix.

Problem 1. Which of the following is true of functions =100 +log and = + log? Problem 2. Which of the following is true of functions = 2 and =3?

Grade 7/8 Math Circles Graph Theory - Solutions October 13/14, 2015

CS1 Lecture 31 Apr. 3, 2019

Introduction to Algorithms and Complexity Theory

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

The k-center problem Approximation Algorithms 2009 Petros Potikas

Ideally your algorithms for both parts should run in linear time. You will receive partial credit for a polynomial-time algorithm.

Info 2950, Lecture 16

PATH FINDING AND GRAPH TRAVERSAL

The Shortest Path Problem

Spanning Trees. Lecture 20 CS2110 Spring 2015

CS261: Problem Set #2

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014

Chapter 3 Linear Programming: A Geometric Approach

NP Completeness. Andreas Klappenecker [partially based on slides by Jennifer Welch]

Math 381 Discrete Mathematical Modeling

MCL. (and other clustering algorithms) 858L

Your favorite blog : (popularly known as VIJAY JOTANI S BLOG..now in facebook.join ON FB VIJAY

1. The following graph is not Eulerian. Make it into an Eulerian graph by adding as few edges as possible.

Problem set 2. Problem 1. Problem 2. Problem 3. CS261, Winter Instructor: Ashish Goel.

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures

Section The Law of Sines and the Law of Cosines

9 abcd = dcba b + 90c = c + 10b b = 10c.

Lecture: Analysis of Algorithms (CS )

Algorithms for Euclidean TSP

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Student number: Datenstrukturen & Algorithmen page 1

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Shortest Paths Date: 10/13/15

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

LOOK AT THE EXTEMES! Răzvan Gelca Texas Tech University

CMSC 451: Dynamic Programming

How to find a minimum spanning tree

SPANNING TREES. Lecture 21 CS2110 Spring 2016

Algorithm Design Techniques. Hwansoo Han

Artificial Intelligence

Design and Analysis of Algorithms

10/31/18. About A6, Prelim 2. Spanning Trees, greedy algorithms. Facts about trees. Undirected trees

Spanning Trees, greedy algorithms. Lecture 20 CS2110 Fall 2018

L.J. Institute of Engineering & Technology Semester: VIII (2016)

CS61BL. Lecture 5: Graphs Sorting

Graph Algorithms (part 3 of CSC 282),

UNIT 3. Greedy Method. Design and Analysis of Algorithms GENERAL METHOD

Dijkstra's Algorithm

Algorithm Analysis Graph algorithm. Chung-Ang University, Jaesung Lee

Graph Algorithms. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

Module 2: NETWORKS AND DECISION MATHEMATICS

CS161 - Final Exam Computer Science Department, Stanford University August 16, 2008

Math/Stat 2300 Modeling using Graph Theory (March 23/25) from text A First Course in Mathematical Modeling, Giordano, Fox, Horton, Weir, 2009.

MST & Shortest Path -Prim s -Djikstra s

Name: THE SIMPLEX METHOD: STANDARD MAXIMIZATION PROBLEMS

CS2223: Algorithms D-Term, Assignment 5

CS 311 Discrete Math for Computer Science Dr. William C. Bulko. Graphs

CSE 421 Applications of DFS(?) Topological sort

CSC 373 Lecture # 3 Instructor: Milad Eftekhar

CSE 100 Minimum Spanning Trees Prim s and Kruskal

Further Mathematics 2016 Module 2: NETWORKS AND DECISION MATHEMATICS Chapter 9 Undirected Graphs and Networks

Greedy Algorithms and Huffman Coding

Greedy algorithms is another useful way for solving optimization problems.

Lesson 2 7 Graph Partitioning

Note: For all questions, answer (E) NOTA means none of the above answers is correct. Unless otherwise specified, all angles are measured in degrees.

Greedy Algorithms. Algorithms

Graph Algorithms (part 3 of CSC 282),

Examples of P vs NP: More Problems

Graph Algorithms Introduction to Data Structures. Ananda Gunawardena 7/31/2011 1

CS170 Discussion Section 4: 9/18

Name Course Days/Start Time

UNIT Name the different ways of representing a graph? a.adjacencymatrix b. Adjacency list

Chapter 9 Graph Algorithms

Lecture outline. Graph coloring Examples Applications Algorithms

ICS 161 Algorithms Winter 1998 Final Exam. 1: out of 15. 2: out of 15. 3: out of 20. 4: out of 15. 5: out of 20. 6: out of 15.

Solving NP-hard Problems on Special Instances

Linear Programming Terminology

6th Bay Area Mathematical Olympiad

TA: Jade Cheng ICS 241 Recitation Lecture Note #9 October 23, 2009

9 abcd = dcba b + 90c = c + 10b b = 10c.

2006 Fryer Contest. Solutions

Greedy Algorithms. This is such a simple approach that it is what one usually tries first.

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

CS388C: Combinatorics and Graph Theory

Announcements. CSEP 521 Applied Algorithms. Announcements. Polynomial time efficiency. Definitions of efficiency 1/14/2013

NARROW CORRIDOR. Teacher s Guide Getting Started. Lay Chin Tan Singapore

Approximation Techniques for Utilitarian Mechanism Design

END-TERM EXAMINATION

Lecture 3: Totally Unimodularity and Network Flows

Bounds on graphs with high girth and high chromatic number

Outline. CS38 Introduction to Algorithms. Approximation Algorithms. Optimization Problems. Set Cover. Set cover 5/29/2014. coping with intractibility

Dijkstra s algorithm for shortest paths when no edges have negative weight.

Lecture 7. s.t. e = (u,v) E x u + x v 1 (2) v V x v 0 (3)

Pred 8 1. Dist. Pred

FINAL EXAM SOLUTIONS

Spanning Trees, greedy algorithms. Lecture 22 CS2110 Fall 2017

Chapter-6 Backtracking

Lesson 5: Identical Triangles

Linear Programming. Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015

Transcription:

Optimization II: Dynamic programming Ricardo Fukasawa rfukasawa@uwaterloo.ca Department of Combinatorics and Optimization Faculty of Mathematics University of Waterloo Nov 2, 2016 R. Fukasawa (C&O) Optimization II 1 / 21

Picking items Question Suppose you have a list of n items with integer weights (a 1,...,a n ) and with values (c 1,...,c n ) and you can carry at most an integer b amount of weight. Which items would you choose to carry to maximize the total value you carry? Example: n = 5, (a 1,a 2,a 3,a 4,a 5 ) = (5,3,6,4,7) (c 1,c 2,c 3,c 4,c 5 ) = (6,4,5,7,6) b = 11 Examples of feasible solutions: R. Fukasawa (C&O) Optimization II 2 / 21

Picking items Question Suppose you have a list of n items with integer weights (a 1,...,a n ) and with values (c 1,...,c n ) and you can carry at most an integer b amount of weight. Which items would you choose to carry to maximize the total value you carry? Example: n = 5, (a 1,a 2,a 3,a 4,a 5 ) = (5,3,6,4,7) (c 1,c 2,c 3,c 4,c 5 ) = (6,4,5,7,6) b = 11 Examples of feasible solutions: Carry 1 and 3, with value 11 R. Fukasawa (C&O) Optimization II 2 / 21

Picking items Question Suppose you have a list of n items with integer weights (a 1,...,a n ) and with values (c 1,...,c n ) and you can carry at most an integer b amount of weight. Which items would you choose to carry to maximize the total value you carry? Example: n = 5, (a 1,a 2,a 3,a 4,a 5 ) = (5,3,6,4,7) (c 1,c 2,c 3,c 4,c 5 ) = (6,4,5,7,6) b = 11 Examples of feasible solutions: Carry 1 and 3, with value 11 Carry 4 and 5, with value 13 R. Fukasawa (C&O) Optimization II 2 / 21

Picking items Question Suppose you have a list of n items with integer weights (a 1,...,a n ) and with values (c 1,...,c n ) and you can carry at most an integer b amount of weight. Which items would you choose to carry to maximize the total value you carry? Example: n = 5, (a 1,a 2,a 3,a 4,a 5 ) = (5,3,6,4,7) (c 1,c 2,c 3,c 4,c 5 ) = (6,4,5,7,6) b = 11 Examples of feasible solutions: Carry 1 and 3, with value 11 Carry 4 and 5, with value 13 Carry 4 and 6, with value 12 R. Fukasawa (C&O) Optimization II 2 / 21

Picking items Question Suppose you have a list of n items with integer weights (a 1,...,a n ) and with values (c 1,...,c n ) and you can carry at most an integer b amount of weight. Which items would you choose to carry to maximize the total value you carry? Proposed greedy algorithms: R. Fukasawa (C&O) Optimization II 3 / 21

Picking items Question Suppose you have a list of n items with integer weights (a 1,...,a n ) and with values (c 1,...,c n ) and you can carry at most an integer b amount of weight. Which items would you choose to carry to maximize the total value you carry? Proposed greedy algorithms: Pick smallest weight item, until weight limit is exceeded. R. Fukasawa (C&O) Optimization II 3 / 21

Picking items Question Suppose you have a list of n items with integer weights (a 1,...,a n ) and with values (c 1,...,c n ) and you can carry at most an integer b amount of weight. Which items would you choose to carry to maximize the total value you carry? Proposed greedy algorithms: Pick smallest weight item, until weight limit is exceeded. Pick largest value item that does not exceed weight limit. R. Fukasawa (C&O) Optimization II 3 / 21

Picking items Question Suppose you have a list of n items with integer weights (a 1,...,a n ) and with values (c 1,...,c n ) and you can carry at most an integer b amount of weight. Which items would you choose to carry to maximize the total value you carry? Proposed greedy algorithms: Pick smallest weight item, until weight limit is exceeded. Pick largest value item that does not exceed weight limit. Order items from highest to lowest value / weight ratio ( c j a j ). Pick the items in that order if possible. R. Fukasawa (C&O) Optimization II 3 / 21

Picking items Question Suppose you have a list of n items with integer weights (a 1,...,a n ) and with values (c 1,...,c n ) and you can carry at most an integer b amount of weight. Which items would you choose to carry to maximize the total value you carry? Proposed greedy algorithms: Pick smallest weight item, until weight limit is exceeded. Pick largest value item that does not exceed weight limit. Order items from highest to lowest value / weight ratio ( c j a j ). Pick the items in that order if possible. Suggestions? R. Fukasawa (C&O) Optimization II 3 / 21

Alternative approach: Suppose I am considering just the last item (item n). Then either: I pick item n, get a value of c n and reduce my capacity by a n or I don t pick item n and still have capacity b Example: n = 3, (a 1,a 2,a 3 ) = (2,3,1) (c 1,c 2,c 3 ) = (5,7,6) b = 4 If I pick item 3, then I have already a value of 6, with capacity of 3 left for items 1,2. If I don t pick item 3, then I have already a value of 0, with capacity of 4 left for items 1,2. R. Fukasawa (C&O) Optimization II 4 / 21

Example: n = 3, (a 1,a 2,a 3 ) = (2,3,1) (c 1,c 2,c 3 ) = (5,7,6) b = 4 Conclusion: In my example, I should pick the best of: R. Fukasawa (C&O) Optimization II 5 / 21

Example: n = 3, (a 1,a 2,a 3 ) = (2,3,1) (c 1,c 2,c 3 ) = (5,7,6) b = 4 Conclusion: In my example, I should pick the best of: Picking item 3: 6+ optimal value of problem with just items 1,2 and capacity 3 R. Fukasawa (C&O) Optimization II 5 / 21

Example: n = 3, (a 1,a 2,a 3 ) = (2,3,1) (c 1,c 2,c 3 ) = (5,7,6) b = 4 Conclusion: In my example, I should pick the best of: Picking item 3: 6+ optimal value of problem with just items 1,2 and capacity 3 Not picking item 3: 0+ optimal value of problem with just items 1,2 and capacity 4 R. Fukasawa (C&O) Optimization II 5 / 21

Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem R. Fukasawa (C&O) Optimization II 6 / 21

Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem Notation R. Fukasawa (C&O) Optimization II 6 / 21

Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem Notation v(i,d) - Optimal value for problem with items 1,...,i and capacity d R. Fukasawa (C&O) Optimization II 6 / 21

Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem Notation v(i,d) - Optimal value for problem with items 1,...,i and capacity d What we want: v(n,b) R. Fukasawa (C&O) Optimization II 6 / 21

Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem Notation v(i,d) - Optimal value for problem with items 1,...,i and capacity d What we want: v(n,b) Back to example: R. Fukasawa (C&O) Optimization II 6 / 21

Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem Notation v(i,d) - Optimal value for problem with items 1,...,i and capacity d What we want: Back to example: Picking item 3: v(n,b) R. Fukasawa (C&O) Optimization II 6 / 21

Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem Notation v(i,d) - Optimal value for problem with items 1,...,i and capacity d What we want: v(n,b) Back to example: Picking item 3: 6+ optimal value of problem with just items 1,2 and capacity 3 R. Fukasawa (C&O) Optimization II 6 / 21

Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem Notation v(i,d) - Optimal value for problem with items 1,...,i and capacity d What we want: Back to example: Picking item 3: v(n,b) v(3,4) = 6+v(2,3) R. Fukasawa (C&O) Optimization II 6 / 21

Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem Notation v(i,d) - Optimal value for problem with items 1,...,i and capacity d What we want: Back to example: Picking item 3: v(n,b) v(3,4) = 6+v(2,3) Not picking item 3: R. Fukasawa (C&O) Optimization II 6 / 21

Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem Notation v(i,d) - Optimal value for problem with items 1,...,i and capacity d What we want: v(n,b) Back to example: Picking item 3: Not picking item 3: v(3,4) = 6+v(2,3) 0+ optimal value of problem with just items 1,2 and capacity 4 R. Fukasawa (C&O) Optimization II 6 / 21

Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem Notation v(i,d) - Optimal value for problem with items 1,...,i and capacity d What we want: v(n,b) Back to example: Picking item 3: Not picking item 3: v(3,4) = 6+v(2,3) v(3,4) = 0+v(2,4) R. Fukasawa (C&O) Optimization II 6 / 21

Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem Notation v(i,d) - Optimal value for problem with items 1,...,i and capacity d What we want: v(n,b) Back to example: v(3,4) = max{6+v(2,3),0+v(2,4)} R. Fukasawa (C&O) Optimization II 6 / 21

In general, given: integer weights (a 1,...,a n ) values (c 1,...,c n ) integer capacity b v(i,d) = R. Fukasawa (C&O) Optimization II 7 / 21

In general, given: integer weights (a 1,...,a n ) values (c 1,...,c n ) integer capacity b v(i,d) = max{c i +v(i 1,d a i ),0+v(i 1,d)} R. Fukasawa (C&O) Optimization II 7 / 21

In general, given: integer weights (a 1,...,a n ) values (c 1,...,c n ) integer capacity b v(i,d) = max{c i +v(i 1,d a i ),0+v(i 1,d)} (only if i > 1 and d a i ) R. Fukasawa (C&O) Optimization II 7 / 21

In general, given: integer weights (a 1,...,a n ) values (c 1,...,c n ) integer capacity b v(i,d) = max{c i +v(i 1,d a i ),0+v(i 1,d)} (only if i > 1 and d a i ) Otherwise: Easy cases: i = 1 d < a i R. Fukasawa (C&O) Optimization II 7 / 21

Example n = 3, (a 1,a 2,a 3 ) = (2,3,1) (c 1,c 2,c 3 ) = (5,7,6) b = 4 R. Fukasawa (C&O) Optimization II 8 / 21

Dynamic programming Key ingredient: Optimal substructure: Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem R. Fukasawa (C&O) Optimization II 9 / 21

Google maps (shortest path) Suppose circles represent intersections, lines are streets, numbers are distances. Goal: Find shortest path from A E R. Fukasawa (C&O) Optimization II 10 / 21

Google maps (shortest path) Suppose circles represent intersections, lines are streets, numbers are distances. Goal: Find shortest path from A E Nomenclature: Vertices (circles): {A,B,C,D,E,F,G} Edges (lines): {A,B}, {B,F}, {A,F}, {B,C},... Vertices are adjacent if there is an edge connecting them Path is a sequence of adjacent non-repeated vertices Example: (A,B,F,G,E) is an A E path Cost of path is sum of cost of edges Example: Path (A,B,F,G,E) has cost 18 R. Fukasawa (C&O) Optimization II 10 / 21

Shortest path Given G = (V,E) with costs c e > 0 for all e E, and two vertices s and t, find shortest s t path. Key observation Shortest path from A to E is shortest of: 5 + Shortest path from A to D 4 + Shortest path from A to G R. Fukasawa (C&O) Optimization II 11 / 21

Example Dijkstra s algorithm starting with A R. Fukasawa (C&O) Optimization II 12 / 21

Shortest path Given G = (V,E) with costs c e > 0 for all e E, and initial vertex s, find shortest s v path for all v V. Dijkstra s algorithm: Maintain a set S for which we know the shortest s v path. 1 Circle the beginning vertex. 2 List the uncircled vertices that are adjacent to circled ones, the paths, and the total time. 3 Identify the uncircled vertex with shortest total time and circle the corresponding adjacent vertex. 4 Repeat from step 2 until no uncircled vertices exist. R. Fukasawa (C&O) Optimization II 13 / 21