UNC Chapel Hill Lin/Foskey/Manocha Steps in DP: Step 1 Think what decision is the “last piece in the puzzle” –Where to place the outermost parentheses.

Slides:



Advertisements
Similar presentations
Area of Polygons and Circles
Advertisements

Dynamic Programming Introduction Prof. Muhammad Saeed.
CSE 211 Discrete Mathematics
Fibonacci Numbers F n = F n-1 + F n-2 F 0 =0, F 1 =1 – 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 … Straightforward recursive procedure is slow! Why? How slow? Lets.
5.1 Real Vector Spaces.
Computer Graphics- SCC 342
Polygon Triangulation
Interval Graph Test.
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals.
Approximations of points and polygonal chains
Advanced Topics in Algorithms and Data Structures Lecture 7.2, page 1 Merging two upper hulls Suppose, UH ( S 2 ) has s points given in an array according.
Dynamic Planar Convex Hull Operations in Near- Logarithmic Amortized Time TIMOTHY M. CHAN.
2/14/13CMPS 3120 Computational Geometry1 CMPS 3120: Computational Geometry Spring 2013 Planar Subdivisions and Point Location Carola Wenk Based on: Computational.
 Distance Problems: › Post Office Problem › Nearest Neighbors and Closest Pair › Largest Empty and Smallest Enclosing Circle  Sub graphs of Delaunay.
Applications of Euler’s Formula for Graphs Hannah Stevens.
Brute-Force Triangulation
UNC Chapel Hill M. C. Lin Polygon Triangulation Chapter 3 of the Textbook Driving Applications –Guarding an Art Gallery –3D Morphing.
CSC 252 Algorithms Haniya Aslam
By Groysman Maxim. Let S be a set of sites in the plane. Each point in the plane is influenced by each point of S. We would like to decompose the plane.
Dynamic Programming II Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
Feb Polygon Triangulation Shmuel Wimer Bar Ilan Univ., School of Engineering.
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
Steps in DP: Step 1 Think what decision is the “last piece in the puzzle” –Where to place the outermost parentheses in a matrix chain multiplication (A.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Definition Hamiltonian graph: A graph with a spanning cycle (also called a Hamiltonian cycle). Hamiltonian graph Hamiltonian cycle.
Tucker, Applied Combinatorics, Section 1.4, prepared by Patti Bodkin
Representing Graphs Wade Trappe. Lecture Overview Introduction Some Terminology –Paths Adjacency Matrix.
Dynamic Programming Dynamic Programming algorithms address problems whose solution is recursive in nature, but has the following property: The direct implementation.
UNC Chapel Hill Lin/Manocha/Foskey Optimization Problems In which a set of choices must be made in order to arrive at an optimal (min/max) solution, subject.
Computing the Delaunay Triangulation By Nacha Chavez Math 870 Computational Geometry; Ch.9; de Berg, van Kreveld, Overmars, Schwarzkopf By Nacha Chavez.
Chapter 4: Straight Line Drawing Ronald Kieft. Contents Introduction Algorithm 1: Shift Method Algorithm 2: Realizer Method Other parts of chapter 4 Questions?
1 Separator Theorems for Planar Graphs Presented by Shira Zucker.
Curve Curve: The image of a continous map from [0,1] to R 2. Polygonal curve: A curve composed of finitely many line segments. Polygonal u,v-curve: A polygonal.
The Art Gallery Problem
Dynamic Programming Introduction to Algorithms Dynamic Programming CSE 680 Prof. Roger Crawfis.
Brute-Force Triangulation
The Art Gallery Problem
UNC Chapel Hill M. C. Lin Point Location Chapter 6 of the Textbook –Review –Algorithm Analysis –Dealing with Degeneracies.
GEOMETRY PRE-UNIT 4 VOCABULARY REVIEW ALL ABOUT ANGLES.
GRAPH Learning Outcomes Students should be able to:
Graph Theory Ch6 Planar Graphs. Basic Definitions  curve, polygon curve, drawing  crossing, planar, planar embedding, and plane graph  open set  region,
9/7/06CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Fall 2006 Triangulations and Guarding Art Galleries Carola Wenk.
Graph Theory Chapter 6 Planar Graphs Ch. 6. Planar Graphs.
Dynamic Programming Dynamic programming is a technique for solving problems with a recursive structure with the following characteristics: 1.optimal substructure.
UNC Chapel Hill M. C. Lin Point Location Reading: Chapter 6 of the Textbook Driving Applications –Knowing Where You Are in GIS Related Applications –Triangulation.
Dynamic Programming UNC Chapel Hill Z. Guo.
Planar Graphs: Euler's Formula and Coloring Graphs & Algorithms Lecture 7 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:
COSC 3101A - Design and Analysis of Algorithms 7 Dynamic Programming Assembly-Line Scheduling Matrix-Chain Multiplication Elements of DP Many of these.
CS 8833 Algorithms Algorithms Dynamic Programming.
Ch.6 Phylogenetic Trees 2 Contents Phylogenetic Trees Character State Matrix Perfect Phylogeny Binary Character States Two Characters Distance Matrix.
15-853Page :Algorithms in the Real World Planar Separators I & II – Definitions – Separators of Trees – Planar Separator Theorem.
Graph Theory and Applications
Optimization Problems In which a set of choices must be made in order to arrive at an optimal (min/max) solution, subject to some constraints. (There may.
Dynamic Programming1. 2 Outline and Reading Matrix Chain-Product (§5.3.1) The General Technique (§5.3.2) 0-1 Knapsack Problem (§5.3.3)
15.Dynamic Programming. Computer Theory Lab. Chapter 15P.2 Dynamic programming Dynamic programming is typically applied to optimization problems. In such.
UNC Chapel Hill M. C. Lin Delaunay Triangulations Reading: Chapter 9 of the Textbook Driving Applications –Height Interpolation –Constrained Triangulation.
COMPSCI 102 Introduction to Discrete Mathematics.
Indian Institute of Technology Kharagpur PALLAB DASGUPTA Graph Theory: Planarity Pallab Dasgupta, Professor, Dept. of Computer Sc. and Engineering, IIT.
Common Intersection of Half-Planes in R 2 2 PROBLEM (Common Intersection of half- planes in R 2 ) Given n half-planes H 1, H 2,..., H n in R 2 compute.
Introduction to NP Instructor: Neelima Gupta 1.
GEOMETRY UNIT 3 VOCABULARY ALL ABOUT ANGLES. ANGLE DEFINITION Angle A figure formed by two rays with a common endpoint.
Polygon Triangulation
Dr Nazir A. Zafar Advanced Algorithms Analysis and Design Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar.
Advanced Algorithms Analysis and Design
Parallel Lines & Angles
The Art Gallery Problem
The Art Gallery Problem
Planarity.
Presentation transcript:

UNC Chapel Hill Lin/Foskey/Manocha Steps in DP: Step 1 Think what decision is the “last piece in the puzzle” –Where to place the outermost parentheses in a matrix chain multiplication (A 1 ) (A 2 A 3 A 4 ) (A 1 A 2 ) (A 3 A 4 ) (A 1 A 2 A 3 ) (A 4 )

UNC Chapel Hill Lin/Foskey/Manocha DP Step 2 Ask what subproblem(s) would have to be solved to figure out how good your choice is –How to multiply the two groups of matrices, e.g., this one (A 1 ) (trivial) and this one (A 2 A 3 A 4 )

UNC Chapel Hill Lin/Foskey/Manocha DP Step 3 Write down a formula for the “goodness” of the best choice m[i, j] = min i  k < j (m[i, k] + m[k+1, j] + p i-1 p k p j )

UNC Chapel Hill Lin/Foskey/Manocha DP Step 4 Arrange subproblems in order from small to large and solve each one, keeping track of the solutions for use when needed Need 2 tables –One tells you value of the solution to each subproblem –Other tells you last option you chose for the solution to each subproblem

UNC Chapel Hill Lin/Foskey/Manocha Matrix-Chain-Order(p) 1. n  length[p] for i  1 to n // initialization: O(n) time 3. do m[i, i]  0 4. for L  2 to n // L = length of sub-chain 5. do for i  1 to n - L+1 6. do j  i + L m[i, j]   8. for k  i to j do q  m[i, k] + m[k+1, j] + p i-1 p k p j 10. if q < m[i, j] 11. then m[i, j]  q 12. s[i, j]  k 13. return m and s

UNC Chapel Hill Lin/Foskey/Manocha Assembly-Line Scheduling Two parallel assembly lines in a factory, lines 1 and 2 Each line has n stations S i,1 …S i,n For each j, S 1, j does the same thing as S 2, j, but it may take a different amount of assembly time a i, j Transferring away from line i after stage j costs t i, j Also entry time e i and exit time x i at beginning and end

UNC Chapel Hill Lin/Foskey/Manocha Assembly Lines

UNC Chapel Hill Lin/Foskey/Manocha Finding Subproblem Pick some convenient stage of the process –Say, just before the last station What’s the next decision to make? –Whether the last station should be S 1,n or S 2,n What do you need to know to decide which option is better? –What the fastest times are for S 1,n & S 2,n

UNC Chapel Hill Lin/Foskey/Manocha =min (, Recursive Formula for Subproblem Fastest time to any given station Fastest time through prev station (same line) Fastest time through prev station (other line) Time it takes to switch lines + )

UNC Chapel Hill Lin/Foskey/Manocha Recursive Formula (II) Let f i [ j] denote the fastest possible time to get the chassis through S i, j Have the following formulas: f 1 [ 1] = e 1 + a 1,1 f 1 [ j] = min( f 1 [ j-1] + a 1, j, f 2 [ j-1]+t 2, j-1 + a 1, j ) Total time: f * = min( f 1 [n] + x 1, f 2 [ n]+x 2 )

UNC Chapel Hill Lin/Foskey/Manocha

UNC Chapel Hill Lin/Foskey/Manocha Analysis Only loop is lines 3-13 which iterate n-1 times: Algorithm is O(n). The array l records which line is used for each station number

UNC Chapel Hill Lin/Foskey/Manocha Example

UNC Chapel Hill Lin/Foskey/Manocha Polygons A polygon is a piecewise linear closed curve in the plane. We form a cycle by joining line segments end to end. The line segments are called the sides of the polygon and the endpoints are called the vertices. A polygon is simple if it does not cross itself, i.e. if the edges do not intersect one another except for two consecutive edges sharing a common vertex. A simple polygon defines a region consisting of points it encloses. The points strictly within this region are in the interior of this region, the points strictly on the outside are in its exterior, and the polygon itself is the boundary of this region.

UNC Chapel Hill Lin/Foskey/Manocha Convex Polygons A simple polygon is said to be convex if given any two points on its boundary, the line segment between them lies entirely in the union of the polygon and its interior. Convexity can also be defined by the interior angles. The interior angles of vertices of a convex polygon are at most 180 degrees.

UNC Chapel Hill Lin/Foskey/Manocha Triangulations Given a convex polygon, assume that its vertices are labeled in counterclockwise order P=. Assume that indexing of vertices is done modulo n, so v 0 = v n. This polygon has n sides, ( v i-1,v i ). Given two nonadjacent v j, where i < j, the line segment ( v i,v j ) is a chord. (If the polygon is simple but not convex, a segment must also lie entirely in the interior of P for it to be a chord.) Any chord subdivides the polygon into two polygons. A triangulation of a convex polygon is a maximal set T of chords. Every chord that is not in T intersects the interior of some chord in T. Such a set of chords subdivides interior of a polygon into set of triangles.

UNC Chapel Hill Lin/Foskey/Manocha Example: Polygon Triangulation Dual graph of the triangulation is a graph whose vertices are the triangles, and in which two vertices share an edge if the triangles share a common chord. NOTE: the dual graph is a free tree. In general, there are many possible triangulations.

UNC Chapel Hill Lin/Foskey/Manocha Minimum-Weight Convex Polygon Triangulation The number of possible triangulations is exponential in n, the number of sides. The “best” triangulation depends on the applications. Our problem: Given a convex polygon, determine the triangulation that minimizes the sum of the perimeters of its triangles. Given three distinct vertices, v i, v j and v k, we define the weight of the associated triangle by the weight function w( v i, v j, v k ) = | v i v j | + | v j v k | + | v k v i |, where |v i v j | denotes length of the line segment (v i, v j ).

UNC Chapel Hill Lin/Foskey/Manocha Correspondence to Binary Trees In MCM, the associated binary tree is the evaluation tree for the multiplication, where the leaves of the tree correspond to the matrices, and each node of the tree is associated with a product of a sequence of two or more matrices. Consider an ( n+1 )-sided convex polygon, P= and fix one side of the polygon, (v 0,v n ). Consider a rooted binary tree whose root node is the triangle containing side (v 0,v n ), whose internal nodes are the nodes of the dual tree, and whose leaves correspond to the remaining sides of the tree. The partitioning of a polygon into triangles is equivalent to a binary tree with n-1 leaves, and vice versa.

UNC Chapel Hill Lin/Foskey/Manocha Binary Tree for Triangulation The associated binary tree has n leaves, and hence n-1 internal nodes. Since each internal node other than the root has one edge entering it, there are n-2 edges between the internal nodes.

UNC Chapel Hill Lin/Foskey/Manocha Lemma A triangulation of a simple polygon has n-2 triangles and n-3 chords. (Proof) The result follows directly from the previous figure. Each internal node corresponds to one triangle and each edge between internal nodes corresponds to one chord of triangulation. If we consider an n-vertex polygon, then we’ll have n-1 leaves, and thus n-2 internal nodes (triangles) and n-3 edges (chords).

UNC Chapel Hill Lin/Foskey/Manocha Another Example of Binary Tree for Triangulation

UNC Chapel Hill Lin/Foskey/Manocha DP Solution (I) For 1  i  j  n, let t[i, j] denote the minimum weight triangulation for the subpolygon. v0v0 v5v5 v4v4 v3v3 v2v2 v1v1 v6v6 Min. weight triangulation = t[2, 5] We start with v i-1 rather than v i, to keep the structure as similar as possible to the matrix chain multiplication problem.

UNC Chapel Hill Lin/Foskey/Manocha DP Solution (II) Observe: if we can compute t[i, j] for all i and j ( 1  i  j  n ), then the weight of minimum weight triangulation of the entire polygon will be t[1, n]. For the basis case, the weight of the trivial 2-sided polygon is zero, implying that t[i, i] = 0 (line (v i-1, v i ) ).

UNC Chapel Hill Lin/Foskey/Manocha DP Solution (III) In general, to compute t[i, j], consider the subpolygon, where i  j. One of the chords of this polygon is the side (v i-1, v j ). We may split this subpolygon by introducting a triangle whose base is this chord, and whose third vertex is any vertex v k, where i  k  j-1. This subdivides the polygon into 2 subpolygons &, whose minimum weights are t[i, k] and t[k+1, j]. We have following recursive rule for computing t[i, j] : t[i, i] = 0 t[i, j] = min i  k  j-1 (t[i, k] + t[k+1, j] + w(v i-1 v k v j )) for i < k

UNC Chapel Hill Lin/Foskey/Manocha Weighted-Polygon- Triangulation(V) 1. n  length[V] - 1 // V = 2. for i  1 to n // initialization: O(n) time 3. do t[i, i]  0 4. for L  2 to n // L = length of sub-chain 5. do for i  1 to n-L+1 6. do j  i + L t[i, j]   8. for k  i to j do q  t[i, k] + t[k+1, j] + w(v i-1, v k, v j ) 10. if q < t[i, j] 11. then t[i, j]  q 12. s[i, j]  k 13. return t and s