Presentation is loading. Please wait.

Presentation is loading. Please wait.

UNC Chapel Hill M. C. Lin Linear Programming Reading: Chapter 4 of the Textbook Driving Applications –Casting/Metal Molding –Collision Detection Randomized.

Similar presentations


Presentation on theme: "UNC Chapel Hill M. C. Lin Linear Programming Reading: Chapter 4 of the Textbook Driving Applications –Casting/Metal Molding –Collision Detection Randomized."— Presentation transcript:

1 UNC Chapel Hill M. C. Lin Linear Programming Reading: Chapter 4 of the Textbook Driving Applications –Casting/Metal Molding –Collision Detection Randomized Algorithms –Smallest Enclosing Discs

2 UNC Chapel Hill M. C. Lin Casting Liquid metal is poured into a mold, it solidifies, and then the object shape is formed and the object is removed. Not all objects of different shapes can be removed. Problems: Whether an object can be manufactured by casting; if so, find the suitable mold.

3 UNC Chapel Hill M. C. Lin Transform to a Geometric Problem The shape of cavity in the mold is determined by the shape of the object, but different orientation can be crucial. –The object must have a horizontal top facet Let P, object to be casted, be a 3D polyhedron bounded by planar facets with a designated top facet. Assume: the mold is rectangular block with a cavity that corresponds exactly to P. Problem: Decide whether a direction d exists s.t. P can be translated to infinity in direction d without intersecting interior of of the mold.

4 UNC Chapel Hill M. C. Lin Problem Analysis The polyhedron P can be removed from its mold by a translation in direction d if and only if d makes an angle of at least 90° with the outward normal of all ordinary facets of P. Let n = ( n x, n y, n z ) be the outward normal of an ordinary facet. The direction d = ( d x, d y, 1 ) makes an angle at least 90° with n if and only if the dot product of n and d is non-positive: n x d x + n y d y + n z  0

5 UNC Chapel Hill M. C. Lin Problem Analysis (cont.) n x d x + n y d y + n z  0 This describes a half-plane on the plane z=1, i.e. the area to the left or right of a line on the plane. Casting problem: given a set of half-planes, find a point in their common intersection or decide if the common intersection is empty. Let P be a polyhedron with n facets. In O(n 2 ) expected time and using O(n) storage it can be decided whether P is castable. Moreover, if P is castable, a mold and a valid direction for removing P from it can be computed in the same amount of time.

6 UNC Chapel Hill M. C. Lin Half-Plane Intersection Let H = {h 1, h 2, …, h n } be a set of linear constraints in two variables, i.e. in the form: a i x + b i y  c i where a i, b i and c i are constants, s.t. at least one of a i and b i is non-zero. Problem: Find the set of all points (x,y)  R 2 that satisfy all n constraints at the same time; i.e. find all the points lying in the common intersection of the half-planes in H.

7 UNC Chapel Hill M. C. Lin Type of Intersections Convex regions bounded by at most n edges (half-planes / lines) Unbounded regions Degenerate cases: a line or point Empty

8 UNC Chapel Hill M. C. Lin IntersectHalfPlanes(H) Input: A set H of n half-planes in the plane Output: A convex polygonal region C:=  h  H h 1. if card( H ) = 1 2. then C  the unique half-plane h  H 3. else Split H into sets H 1 and H 2 of the size ( n/2 ) and ( n/2 ) 4. C 1  IntersectHalfPlanes ( H 1 ) 5. C 2  IntersectHalfPlanes ( H 2 ) 6. C  IntersectConvexRegions( C 1, C 2 )

9 UNC Chapel Hill M. C. Lin Run Time Analysis Computing intersections of two overlays takes O( (n+k) log n) time, where k is the number of intersection points between edges of C 1 and edges of C 2 and k  n T(n) = O(1), if n = 1 T(n) = O(n log n) + 2 T(n/2), if n > 1  T(n) = O(n log 2 n)

10 UNC Chapel Hill M. C. Lin Plane-Sweep for Half-Plane Intersection Store left/right boundary of C as sorted lists of half- planes, L left ( C ) & L right ( C ), in order from top to bottom. Plane-Sweep: maintain edges of C 1 & C 2 intersecting the sweep line. There are at most four. Use pointers: l_edge_C 1, r_edge_C 1, l_edge_C 2, r_edge_C 2. Initialization: ( y 1, y 2 ) = y -coordinate of topmost of ( C 1,C 2 ). If y 1 has upward unbounded edge, y 1 = . y start =min ( y 1, y 2 ) Initialize the pointers as ones intersecting y start.

11 UNC Chapel Hill M. C. Lin Plane-Sweep for Half-Plane Intersection Next event to be handled is the highest of the lower end points intersecting the sweep line. Use the pointers to find event points in constant time. At each event point, some new edge e appears on the boundary. To handle edge e, we first check whether e belongs to C 1 or C 2, and whether it is on the left or right boundary, and then call appropriate procedure. According to the handling of each case, we add the appropriate half-planes to the intersection of C 1 & C 2. All cases can be decided in constant time.

12 UNC Chapel Hill M. C. Lin Algorithm Analysis It takes constant time to handle an edge. So, the intersection of two convex polygonal regions in the plane can be computed in O(n) time. So, now …... T(n) = O(n) + 2 T(n/2), if n > 1  T(n) = O(n log n) The common intersection of a set of n half- planes in the plane can be computed in O(nlogn) time and linear storage.

13 UNC Chapel Hill M. C. Lin Linear Programming Linear Programming/Optimization: finding a solution to a set of linear constraints Maximizec 1 x 1 + c 2 x 2 + … + c d x d  c i Subject toa 11 x 1 + a 12 x 2 + … + a 1d x d  b 1 a 21 x 1 + a 22 x 2 + … + a 2d x d  b 2 : a n1 x 1 + a n2 x 2 + … + a nd x d  b n where a ij, b i and c i are real numbers and inputs

14 UNC Chapel Hill M. C. Lin LP Terminology Objective Function: the funct. to be maximized Linear Program: the objective functions and the set of constraints together Dimension: the number of variables, d Feasible Regions: the set of points satisfying all constraints. Points (solns) in this region are called “feasible” & points outside “infeasible”.

15 UNC Chapel Hill M. C. Lin 2D Linear Programming Let H be a set of n linear constraints The vector defining the obj. func. is c = (c x, c y ) The objective function is f c (p) = c x p x + c y p y Problem: find a point p  R 2 s.t. p   H and f c (p) is maximized. Denote the LP by (H, c) and its feasible region by C.

16 UNC Chapel Hill M. C. Lin Types of Solutions to 2D-LP 1. LP is infeasible, i.e. no solution 2. The feasible region is unbounded in direction c. There is a ray p completely contained in feasible region C, s.t. f c takes arbitrary large value along p 3. The feasible region has an edge e whose outward normal points in the direction c. The solution to LP is not unique: any point on e 4. There is a unique solution: a vertex v of C that is extreme in the direction c

17 UNC Chapel Hill M. C. Lin Optimal Vertex In the case where an edge is a soln, there is an unique solution: lexicographically smallest one. With this convention, we define “optimal vertex” as a vertex of the feasible region  Based on this, we can incrementally add one constraint at a time and maintain the optimal vertex of the intermediate feasible regions, except in the case of unbounded LP.

18 UNC Chapel Hill M. C. Lin Incremental LP If LP is unbounded, UnboundedLP() returns a ray. If the LP is not unbounded, then UnboundedLP() returns 2 half-planes, h 1 and h 2 from H, s.t. ({ h 1, h 2 }, c ) is bounded. These half-planes are called certificates that proves ( H, c ) is really bounded. Let C i be the feasible region when the first i half- planes have been added: C i := h 1  h 2  …  hi Denote the optimal vertex of C i by vi, clearly we have: C 2  C 3  C 4 …  C n = C If C i = 0 for some i, then C j = 0 for  j  i & LP infeasible

19 UNC Chapel Hill M. C. Lin How Optimal Vertex Changes Let 2 < i  n, let C i and v i be defined as above. –If v i-1  h i, then v i = v i-1 –If v i-1  h i, then either C i = 0 or v i  l i where l i is the line bounding h i Assume that the current optimal point v i-1 is not contained h i  Restate the problem as: Find the point p on l i that maximizes f c (p), subject to the constraints p  h j, for 1  j  i Assume l i is the x-axis. Let x j denote x-coord. of the intersection point of l i and l j. Depending on whether l i is bounded to left/right, we get a constraint on the x- coord. of the solution of the form x  x j or x  x j

20 UNC Chapel Hill M. C. Lin Simplifying to 1D-LP Maximize f c ((x,0)) Subject to x  x j, 1  j< i and l i  h j bounded to left x  x k, 1  k< i and l i  h k bounded to right This is a 1D-LP. Let x left = max 1  j< i {x j : l i  h j is bounded to the left} and x right = min 1  k< i {x k : l i  h k is bounded to the right} The interval [ x left : x right ] is the feasible region of the 1D-LP. Hence, the LP is infeasible if x left > x right, and otherwise the optimal point is either x left or x right, depending on the objective function. 1D-LP can be solved in linear time. Computing new optimal vertex v i can be done in O(i) time.

21 UNC Chapel Hill M. C. Lin 2DLinearProgramming(H,c) Input: A line program (H, c) where H is set of n half-planes, c  R 2 Output: if (H, c) is unbounded, a ray p completely contained in the feasible region is reported. If (H, c) is infeasible, then this fact is reported. Else, a feasible point p that maximizes f c (p) is reported. 1. if UnboundedLP( H, c ) reports that ( H, c ) is unbounded/infeasible 2. then Report that info and, in the unbounded case, a ray along which ( H, c ) is unbounded 3. else Let h 1, h 2  H be the 2 certificat half-planes returned by Unbounded LP; let v 2 be the intersection point of l 1 & l 2 4. Let h 3, …, h n be the remaining half-planes of H

22 UNC Chapel Hill M. C. Lin 2DLinearProgramming(H,c) 5. for i  3 to n 6. do if v i-1  h i 7. then v i  v i-1 8. else v i  the point p on l i that maximizes f c (p), subject to the constraints, h 1, …, h i-1 9. if p does not exist 10. then Report that LP is infeasible & quit. 11. return v n

23 UNC Chapel Hill M. C. Lin 2D-LP Algorithm Analysis This algorithm computes the solution to a linear program with n constraints and two variables in O(n 2 ) time and linear storage –The time spent in Stage i is dominated by solving 1D-LP in Step 8, which takes O(i) time  3  i  n O(i) = O(n 2 ) Observation: if we could bound the number of times the optimal vertex changes, then we may be able to get better running time.


Download ppt "UNC Chapel Hill M. C. Lin Linear Programming Reading: Chapter 4 of the Textbook Driving Applications –Casting/Metal Molding –Collision Detection Randomized."

Similar presentations


Ads by Google