CS6100: Topics in Design and Analysis of Algorithms Guarding and - - PDF document

cs6100 topics in design and analysis of algorithms
SMART_READER_LITE
LIVE PREVIEW

CS6100: Topics in Design and Analysis of Algorithms Guarding and - - PDF document

CS6100: Topics in Design and Analysis of Algorithms Guarding and Triangulating Polygons John Augustine CS6100 (Even 2012): Guarding and Triangulating Polygons The Art Gallery Problem A simple polygon is a region enclosed by a single closed


slide-1
SLIDE 1

CS6100: Topics in Design and Analysis of Algorithms

Guarding and Triangulating Polygons John Augustine

CS6100 (Even 2012): Guarding and Triangulating Polygons

slide-2
SLIDE 2

The Art Gallery Problem

A simple polygon is a region enclosed by a single closed polygonal chain that does not intersect itself. Models 2D spaces such as floor plans. Given a simple polygon P with n vertices, place a small number of guards inside P so that it is completely

  • monitored. I.e., for any point p inside P, there must

be a guard positioned at g such that line segment pq is completely inside P. Computing the optimum (i.e., minimum) is NP-hard.

CS6100 (Even 2012): Guarding and Triangulating Polygons 1

slide-3
SLIDE 3

Triangulation

A convex polygon only needs one guard! So, if we can decompose P into convex pieces, we need one per convex piece. A diagonal of P is a line segment that connects two vertices of P and is contained in the interior of P. A triangulation is a decomposition of P into triangles be a maximal number of non-intersecting diagonals. Theorem 1. Any simple polygon P with n vertices admits a triangulation and any triangulation has (n − 2) triangles.

CS6100 (Even 2012): Guarding and Triangulating Polygons 2

slide-4
SLIDE 4

v w u v w u v′

Proof Sketch. First we show that a diagonal always

  • exists. (See figures above.) Then, we can always cut

along such a diagonal, thereby decomposing P into two smaller polygons that we can induct on to show both claims. Assume for now that a triangulation of P is given. Do we really need n − 2 guards? Can we do better?

CS6100 (Even 2012): Guarding and Triangulating Polygons 3

slide-5
SLIDE 5

Back to the Art Gallery Problem

A 3-colouring of a triangulated polygon P is an assignment of one of three distinct colours to each vertex such that any two vertices connected by an edge or a diagonal are assigned different colours. Note. The three vertices of any triangle will be assigned different colours. How can we show that ⌊n/3⌋ guards suffice if ∃ 3-colouring?

?

µ ν

The dual graph of a triangulated polygon P is a graph G = (V, E) such that V is the set of (n − 2) triangles and edges connect two triangles that share an edge. We use DFS on the dual graph to 3-colour P.

CS6100 (Even 2012): Guarding and Triangulating Polygons 4

slide-6
SLIDE 6

Invariant. Vertices of all triangles corresponding to dual graph nodes traversed are 3-colored. Start DFS from any node. 3-Colour the vertices of corresponding triangle. Consider any subsequent edge traversed. It goes through a diagonal d and enters a new triangle. The ends of d are already coloured and the third vertex

  • f the newly entered triangle can only be coloured by
  • ne colour.

The good news is that the invariant is maintained. Theorem 2 (Art Gallery Theorem). To guard a simple polygon with n vertices, ⌊n/3⌋ guards are sufficient and sometimes necessary.

⌊n/3⌋ prongs

CS6100 (Even 2012): Guarding and Triangulating Polygons 5

slide-7
SLIDE 7

Overview of Approach

Theorem 3. We can compute the positions of the ⌊n/3⌋ guards for a simple polygon P with n vertices in O(n log n) time. The birds eye view of the algorithm is as follows.

  • 1. Decompose P into y-monotone pieces. (Definition

pending.)

  • 2. Triangulate each y-monotone piece.

This gives a triangulation of P.

  • 3. 3-colour the vertices of P using the triangulation of

P.

  • 4. Find the colour used least and place guards on

vertices of that colour.

CS6100 (Even 2012): Guarding and Triangulating Polygons 6

slide-8
SLIDE 8

Decomposing P into y-monotone pieces

A y-monotone polygon is a simple polygon such that its intersection with any line perpendicular to the y-axis is connected.

y-axis

To triangulate P, we first partition P into y-monotone sub-polygons (in O(n log n) time and then triangulate the y-monotone pieces (again, in O(n log n) time.

CS6100 (Even 2012): Guarding and Triangulating Polygons 7

slide-9
SLIDE 9

Classification of Vertices

A vertex at which, as we walk along the edges, the direction of the edges change from downward to upward

  • r vice versa is called a turn vertex. A vertex at which

the direction does not change is called a regular vertex. The following figure illustrates 4 types of turn vertices.

v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 e1 e2 e3 e4 e5 e6 e7 e8 e9 e10 e11 e13 e14 e15 e12 = merge vertex = regular vertex = end vertex = start vertex = split vertex

Lemma 1. A simple polygon is y-monotone if it does not contain any split or merge vertex. The proof is left as an exercise. While this lemma is easy to “see,” a formal proof needs a bit of care.

CS6100 (Even 2012): Guarding and Triangulating Polygons 8

slide-10
SLIDE 10

Plane Sweep Method

Let v1 be the rightmost vertex in P. Traverse the edges of P starting from v1 so that the polygon is always to your left. In so doing, denote the ith vertex you encounter as vi for all 1 < i ≤ n. Denote edge vivi+1 as ei for 1 ≤ i < n. Denote edge vnv1 as en. Let Left be the set of edges of P such that the polygon lies to its right. We sweep a line ℓ from top to bottom. The status of the sweep line ℓ at any given time is the edges in Left that ℓ intersects. They are stored in L → R order in a balanced binary tree. The events are the vertices of P and since they are known up front, they can be stored in an array sorted according to the descending order of y coordinates.

CS6100 (Even 2012): Guarding and Triangulating Polygons 9

slide-11
SLIDE 11

Let e be an edge in the status of ℓ. We define the helper

  • f e, denoted helper(e), as the lowest vertex above ℓ

such that the horizontal line segment connecting the vertex to e lies inside P. Note: helper(e) may be the upper endpoint of e. (The figure below shows the helper of an edge ej.)

ej ek vi ℓ ei−1 ei helper(ej)

Given Lemma 1, we can focus our efforts on eliminating merge and split vertices.

CS6100 (Even 2012): Guarding and Triangulating Polygons 10

slide-12
SLIDE 12

Pseudocode from BCKO1

Algorithm MAKEMONOTONE(P)

  • Input. A simple polygon P stored in a doubly-connected edge list D.
  • Output. A partitioning of P into monotone subpolygons, stored in D.

1. Construct a priority queue Q on the vertices of P, using their y-coordinates as priority. If two points have the same y-coordinate, the one with smaller x-coordinate has higher priority. 2. Initialize an empty binary search tree T. 3. while Q is not empty 4. do Remove the vertex vi with the highest priority from Q. 5. Call the appropriate procedure to handle the vertex, depending on its type. HANDLESTARTVERTEX(vi) 1. Insert ei in T and set helper(ei) to vi. HANDLEENDVERTEX(vi) 1. if helper(ei−1) is a merge vertex 2. then Insert the diagonal connecting vi to helper(ei−1) in D. 3. Delete ei−1 from T. HANDLESPLITVERTEX(vi) 1. Search in T to find the edge e j directly left of vi. 2. Insert the diagonal connecting vi to helper(e j) in D. 3. helper(ej) ← vi 4. Insert ei in T and set helper(ei) to vi.

1Computational Geometry:

Algorithms and Applications, by de Berg, Cheong, van Krevald, and Overmars.

CS6100 (Even 2012): Guarding and Triangulating Polygons 11

slide-13
SLIDE 13

HANDLEMERGEVERTEX(vi) 1. if helper(ei−1) is a merge vertex 2. then Insert the diagonal connecting vi to helper(ei−1) in D. 3. Delete ei−1 from T. 4. Search in T to find the edge e j directly left of vi. 5. if helper(ej) is a merge vertex 6. then Insert the diagonal connecting vi to helper(ej) in D. 7. helper(ej) ← vi HANDLEREGULARVERTEX(vi) 1. if the interior of P lies to the right of vi 2. then if helper(ei−1) is a merge vertex 3. then Insert the diagonal connecting vi to helper(ei−1) in D. 4. Delete ei−1 from T. 5. Insert ei in T and set helper(ei) to vi. 6. else Search in T to find the edge e j directly left of vi. 7. if helper(ej) is a merge vertex 8. then Insert the diagonal connecting vi to helper(e j) in D. 9. helper(ej) ← vi

Lemma

  • 2. Algorithm MakeMonotone correctly

adds a set

  • f

non-intersecting diagonals that partitions P into monotone subpolygons. Theorem 4. A simple polygon with n vertices can be partioned into y-monotone polygons in O(n log n) time with an algorithm that uses O(n) storage. Proofs are left as exercises.

CS6100 (Even 2012): Guarding and Triangulating Polygons 12

slide-14
SLIDE 14

ej vi ek vm diagonal will be added when the sweep line reaches vm v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 e1 e2 e3 e4 e5 e6 e7 e8 e9 e10e11 e13 e14 e15 e12

CS6100 (Even 2012): Guarding and Triangulating Polygons 13

slide-15
SLIDE 15

Triangulating a Monotone Polygon

Given a y-monotone polygon P, we want to triangulate

  • it. We assume that P is given as a sequence of vertices
  • rdered anticlockwise.

From the given sequence, we can order the vertices in decreasing order of their y-coordinates. How? Once ordered, we pass through the vertices top → bottom. As the algorithm progresses, a (connected) portion of P will be untriangulated, while the rest is triangulated. Even though we might have passed some of the vertices, they may still be on the boundary of the untriangulated part of P.

CS6100 (Even 2012): Guarding and Triangulating Polygons 14

slide-16
SLIDE 16

not yet triangulated triangles split off

As can be seen above, the untriangulated, but passed vertices form a geometric shape that has an inverted funnel-like structure with the following properties. Straight side. This is a “part” of an edge. Concave side. The other side forms a sequence of reflex vertices (i.e., vertices whose internal angle is > 180◦). This side might have triangulated pieces sticking to it.

CS6100 (Even 2012): Guarding and Triangulating Polygons 15

slide-17
SLIDE 17

We will need a stack S, which is initially empty. At any time, it stores the vertices of the untriangulated

  • part. The vertices are stored in S such that if popped
  • ne after another, we will get the lowest → hightest

sequence. If next vertex vj is on the straight side: We pop vertices one-by-one and add diagonals from each popped vertex to v. The last vertex popped will be the other side of the straight edge, so we don’t add a diagonal between the last vertex and v.

vj popped pushed popped and pushed e

CS6100 (Even 2012): Guarding and Triangulating Polygons 16

slide-18
SLIDE 18

If next vertex vj is on the concave side: We again pop vertices from the stack and add diagonals as long as (i) we can add diagonals that don’t intersect2 edges of P and (ii) S is not empty. If the diagonal to top vertex v′ in S intersects edges

  • f P, then do not pop v′. Furthermore, push the

vertex that was popped immediately prior to v′ (if it exists) back into the stack. Finally, push vj into the stack as well.

pushed vj popped pushed vj popped and pushed popped and pushed

2How can this be tested in O(1) time? CS6100 (Even 2012): Guarding and Triangulating Polygons 17

slide-19
SLIDE 19

Algorithm TRIANGULATEMONOTONEPOLYGON(P)

  • Input. A strictly y-monotone polygon P stored in a doubly-connected edge list D.
  • Output. A triangulation of P stored in the doubly-connected edge list D.

1. Merge the vertices on the left chain and the vertices on the right chain of P into one sequence, sorted on decreasing y-coordinate. If two vertices have the same y-coordinate, then the leftmost one comes first. Let u1,...,un denote the sorted sequence. 2. Initialize an empty stack S, and push u1 and u2 onto it. 3. for j ← 3 to n−1 4. do if u j and the vertex on top of S are on different chains 5. then Pop all vertices from S. 6. Insert into D a diagonal from u j to each popped vertex, except the last one. 7. Push uj−1 and uj onto S. 8. else Pop one vertex from S. 9. Pop the other vertices from S as long as the diagonals from u j to them are inside P. Insert these diagonals into D. Push the last vertex that has been popped back onto S. 10. Push uj onto S.

  • 11. Add diagonals from un to all stack vertices except the first and the last one.

Theorem 5. A strictly y-monotone polygon with n vertices can be triangulated in O(n) time. Theorem 6. A simple polygon with n vertices can be triangulated in O(n log n) time. Theorem 7. A planar subdivision with n vertices can be triangulated in O(n log n) time.

CS6100 (Even 2012): Guarding and Triangulating Polygons 18