minimum weight triangulation

3
CSC 373 - Algorithm Design, Analysis, and Complexity Summer 2014 Lalla Mouatadid Dynamic Programming: Minimum Weight Triangulation A polygon P is a 2-dimensional closed shape in the plane, made of a set of straight-line segments where consecutive segments intersect at a vertex (point). P is convex if for any two points a, b inside P , the line segment ab lies entirely inside P . Here are some examples of polygons and a more detailed definition. So let P be a polygon on v 1 , ..., v n vertices and let e 1 ,e 2 , ..., e n denote the edges (segments) of P , where e i connects v i v i+1 and e n connects v n v 1 . A chord v i v j is a segment joining two nonadjacent vertices of P . A triangulation is a set of chords that divides P into nonoverlapping triangles. It is easy (?) to see that every polygon on n vertices (called an n-gon) has n - 2 triangles and n - 3 chords. We call the weight of a triangulation the sum of the lengths of its chords, where the length of a chord v i v j is the Euclidean distance between the two points v i (x i ,y i ) and v j (x j ,y j ) in the plane. Recall the Euclidean distance between two points v i (x i ,y i ),v j (x j ,y j ) is d(v i ,v j )= p (x j - x i ) 2 +(y j - y i ) 2 (i.e. just the distance of the straight line connecting v i and v j ). Triangulations of a polygons are not unique, and some weight more than others! Consider the example below with the following coordinates: v 1 (0, 0),v 2 (50, 25),v 3 (80, 30),v 4 (125, 25),v 5 (160, 0) And convince yourself why the greedy approach of selecting the cheapest chords at every step fails. v 1 v 2 v 3 v 4 v 5 v 1 v 2 v 3 v 4 v 5 The algorithmic problem we are interested in is the following: Given a convex polygon P =(v 1 ,v 2 , ..., v n ), determine a triangulation T of P that minimizes: w(T )= X e=(vi,vj )∈T d(v i ,v j ) More formally: Minimum Weight Triangulation: Input: A convex polygon P defined by a set of n points in the plane (v 1 ,v 2 , ..., v n ) and a set of n straight lines (e 1 ,e 2 , ..., e n ) where e i connects v i ,v j and e n connects v n ,v 1 . Output: A minimum weight triangulation T of P . 1

Upload: sagarbolisetti

Post on 20-Feb-2016

6 views

Category:

Documents


3 download

DESCRIPTION

Minimum weight triangulation

TRANSCRIPT

Page 1: Minimum weight triangulation

CSC 373 - Algorithm Design, Analysis, and Complexity Summer 2014

Lalla Mouatadid

Dynamic Programming: Minimum Weight Triangulation

A polygon P is a 2-dimensional closed shape in the plane, made of a set of straight-line segments whereconsecutive segments intersect at a vertex (point). P is convex if for any two points a, b inside P, the linesegment ab lies entirely inside P. Here are some examples of polygons and a more detailed definition.

So let P be a polygon on v1, ..., vn vertices and let e1, e2, ..., en denote the edges (segments) of P, where eiconnects vivi+1 and en connects vnv1. A chord vivj is a segment joining two nonadjacent vertices of P.A triangulation is a set of chords that divides P into nonoverlapping triangles. It is easy (?) to see thatevery polygon on n vertices (called an n-gon) has n− 2 triangles and n− 3 chords.

We call the weight of a triangulation the sum of the lengths of its chords, where the length of a chord vivjis the Euclidean distance between the two points vi(xi, yi) and vj(xj , yj) in the plane. Recall the Euclidean

distance between two points vi(xi, yi), vj(xj , yj) is d(vi, vj) =√

(xj − xi)2 + (yj − yi)2 (i.e. just the distanceof the straight line connecting vi and vj).

Triangulations of a polygons are not unique, and some weight more than others! Consider the example belowwith the following coordinates:

v1(0, 0), v2(50, 25), v3(80, 30), v4(125, 25), v5(160, 0)

And convince yourself why the greedy approach of selecting the cheapest chords at every step fails.

v1

v2

v3 v4

v5

v1

v2

v3 v4

v5

The algorithmic problem we are interested in is the following:

Given a convex polygon P = (v1, v2, ..., vn), determine a triangulation T of P that minimizes:

w(T ) =∑

e=(vi,vj)∈T

d(vi, vj)

More formally: Minimum Weight Triangulation:Input: A convex polygon P defined by a set of n points in the plane (v1, v2, ..., vn) and a set of n straightlines (e1, e2, ..., en) where ei connects vi, vj and en connects vn, v1.Output: A minimum weight triangulation T of P.

1

Page 2: Minimum weight triangulation

2

We once again follow our DP steps to try to break the problem into subproblems.

Step 1: Clearly our final goal is a triangulation for the entire polygon, so an optimal solution for the entireproblem is a minimum weight triangulation of P = (v1, v2, ..., vn). Let T denote this optimal triangulation.

Step 2: In this step we are trying to somehow reduce our polygon on n points into smaller polygons, buthow do we come up with these smaller polygons? Well one thing we know for sure is that every two adjacentvertices vi, vi+1 in P must end up in a triangle! Why is this guaranteed in a triangulation?

So this is a good starting point, yeah? Pick two consecutive vertices and find the triangle you can add themto. But how is this helpful in terms of defining subproblems? Consider the polygon below, and suppose westarted with the pair (v3, v4):

v1

v2

v3 v4 v5

v6

v7

We raise two questions at this point: 1. Now what? And 2. Why choose v7 and not another vertex. Well,now we have created two polygons smaller than P, namely (v1, v2, v3, v7) and (v4, v5, v6, v7). So now we canjust recurse on these smaller inputs. And 2. How do we choose v7 (and more generally, how do we choosethe third point of the triangle)? We ask another question, how many possible choices do we have? For thefirst iteration on P we have at most n − 1 vertices to choose from. It suffices to try all of them and pickthe vertex that minimizes the sum of distances of the new chords! And if we have a polygon on the vertices(vi, vi+1, ..., vj), we have at most j − i < n vertices to choose from.

So this is nice :) Start with a pair of adjacent vertices. Try all possible choices for a third point of thetriangle, and select the one that minimizes the total cost of the new chord(s). Then recurse on the newsmaller polygons.

Step 3: Let’s formalize step 2 and create our array: For 1 ≤ i ≤ j, let T [i, j] be The minimum weighttriangulation of the polygon consisting of vertices (vi, vi+1, ..., vj). That is, T [i, j] is the sum of the weightsof the triangulations of the newly created (sub)polygons, plus the sum of any chords added:

T [i, j] = T [i, k] + T [k, j] + d(vi, vk) + d(vk, vj)

And since we don’t know which vertex vk will be the third point of the triangle, we need to try all j − ipossible choices. So:

T [i, j] = mini<k<j

(T [i, k] + T [k, j] + d(vi, vk) + d(vk, vj))

Why isn’t d(vi, vj) included in the formula? Well, because we assume that vi, vj are adjacent from a previoustriangulation! Therefore we don’t need to count d(vi, vj) twice. What’s a base case for our recurrence?T [i, i + 1] = 0 and T [n, 1] = 0.

Notice how this is very similar to what we did in Matrix Chain Multiplication! We’ve split the problem intotwo subproblems, recursed on both and then combined the solutions together! Now, let’s prove that T [i, j]

Page 3: Minimum weight triangulation

3

is indeed a minimum weight triangulation of the polygon consisting of vertices (vi, vi+1, ..., vj). The proof isagain by induction on j − i.

Proof of optimality:

Proof. If j − i = 1 then j = i + 1 and T [i, i + 1] = 0, thus the claim holds for the base case. Suppose T [i, j]is optimal for all j − i < t, and consider j − i = t.

Let Pij denote the polygon on (vi, vi+1, ..., vj) and let T [i, j] be an optimal triangulation for Pij . Since vi, vjare adjacent in Pij , they must belong to a triangle in Tij . So let vk be the third vertex of this triangle inTij . Therefore Tij has two chords (vi, vk) and (vk, vj) but also two smaller polygons Pik and Pkj .

Notice that in Pij , the triangulations Tik, Tkj of Pik and Pkj respectively must be optimal, otherwise we canreplace them by cheaper triangulations and contradict the optimality of Tij . And by induction hypothesis,Tik = T [i, k] and Tkj = T [k, j].

Since our recursive definition of T [i, j] checks all possible vertices vk and picks the minimum out of allpossible choices, it thus must have encounted Tij as a possible solution and by the optimality of Tij , T [i, j]is therefore also optimal.

Below is the final algorithm. What’s x keeping track of? Play with an example and see how the solutions ofthe small polygons are being used to compute solutions to larger ones.

Algorithm 1 Minimum Weight Triangulation

Input: A convex polygon P defined by a set of n points in the plane (v1, v2, ..., vn) and a set of n straightlines (e1, e2, ..., en) where ei connects vi, vj and en connects vn, v1.

Output: A minimum weight triangulation T of P.1: for i=1 ... n-1 do2: T [i, i + 1] = 03: end for4: for x = 1 ... n-1 do5: for i = 1 ... n-x do6: j ← i + x7: T [i, j] = min{T [i, k] + T [k, j] + d(vi, vk) + d(vk, vj)}8: end for9: end for

10: return T [1, n]