\input CS445Hdr \def\file{CS445N7B.tex of June 22, 1982 1:38 PM} \def\header{7. Decomposition problems} \def\title{Lecture 16} \sect{7.4. Optimal decomposition of a simple polygon in convex pieces.} Algorithms 7.1 and 7.2 allow us to decompose any simple polygon $P$ of $n$ vertices into $n-2$ triangles. For some applications, a decomposition into convex pieces other than triangles may be acceptable, provided that the number of pieces is kept as low as possible. The {\it minimum} number $c(P)$ of convex polygons into which $P$ can be decomposed may be considerably less than $n-2$, being for example 1 when $P$ itself is convex.\par The value of $c(P)$ depends on whether the vertices of the pieces are restricted to be those of $P$, or they are allowed to be interior to it. In the second case, the ``new'' vertices are sometimes called {\it Steiner points}. A polygon for which the introduction of Steiner points results in a decomposition with fewer pieces is shown below:\fig4\par The optimal convex decomposition using Steiner points can be found in $O(n^3)$ time, as was shown by D. Dobkin and B. Chazelle in 1979. For the optimal decomposition without Steiner points, the fastest algorithm known is due to D. Greene (1981), which runs in $O(n^4)$ time in the worst case\foot1{This is a somewhat unusual situation, since several ``easy'' problems (e.g., the determination of a minimum spanning tree in the plane) become much harder, even $NP$-complete, if Steiner points are allowed.}. We will spend the rest of this section discussing Greene's algorithm in some detail.\par Let $p1, p2, \ldotss, pn$ be the vertices of $P$ in counterclockwise order. We will use the ordered pair $(i,j)$ as a synonym for the segment $pipj$, which is assumed to be oriented from $pi$ to $pj$. To simplify the wording of this section, we will extend the meaning of the word {\it edge} so as to include not only the original edges of $P$ but also its diagonals.\par An edge $pipj$ is said to be {\it proper} iff $im$ and $(k,m\pr)$ is a proper edge.\par Suppose that when we computed $\pi{km}$ we concluded that the cheapest among the convex paths $\pi{rk}$ that could be extended by the edge $(k,m)$ was $\pi^*{k}$. Then, in order to compute $\pi{km\pr}$, where $m\pr>m$, we have to consider only $\pi^*{k}$ and the paths $\pi{rk}$ such that $pr$ lies in the angle opposite to $pmpkp{m\pr}$.\fig4 Thanks to this fact, the computation of all paths $\pi{km}$ for a fixed $k$ takes only $O(n)$ operations, instead of $O(n^2)$, bringing the total time down to $O(n^4)$.\par For each pair $(i,j)$, we need $\Theta(n^2)$ space to represent the partial paths $\pi{km}$\foot1{Although there are $\Theta(n^2)$ paths to be stored, with average length $\Theta(n)$, each path can be represented as a vertex and a pointer to some other path in the table, so the total space is still $\Theta(n^2)$.}. After $c{ij}$ has been computed, we can discard all those paths except the cheapest of those ending at $pj$, which defines the optimal decomposition of the ear $P{ij}$; the total space requirement would be then $\Theta(n^3)$.\par By using a two-pass algorithm, the space requirement can be reduced to $\Theta(n^2)$. The first phase, which proceeds ``from the bottom up'', computes all costs $c{ij}$, discarding all paths after processing each edge. The second phase, ``from the top down'', recomputes only those paths that actually define the optimal decomposition. Phase 1 requires $O(n^2)$ storage to compute the cost of each edge $(i,j)$, but that storage can be reused to compute the cost of other edges. Both phases take $O(n^3)$ time.\par Algorithm 7.3 uses two auxiliary procedures, given below as algorithms 7.3B and 7.3D. Both receive as parameters a proper cut $(i,j)$; they assume all edge costs $c{km}$ for $i\leq k< m\leq j$, except perhaps for $c{ij}$ itself, have been previously computed. Algorithm 7.3B computes the cheapest convex path $\beta$ from $pi$ to $pj$, and its cost $b$. If no such path exists (i.e., if $(i,j)$ is not a proper edge), it returns a dummy path $\Lambda$ with infinite cost. Algorithm 7.3D, which is recursive and calls 7.3B, produces a list of the convex polygons that constitute an optimal decomposition of the ear $P{ij}$ into convex pieces.\par \algorithm{7.3}{Optimal convex decomposition of a simple polygon.}{ \step 1. [Initialize.] {For $i=1,2,\ldotss, n-1$, set $c{i,i+1}\gets 0$. Set $d\gets 2$.} \step 2. [Phase 1.] {For $i=1,2,\ldotss,n-d$, set $j\gets i+d$ and perform step 3. Set $d\gets d+1$; if $d0, k>0$; output the polygon $\langle r, a1, a2, \ldotss, a\lscr, s1\rangle$. If $a\lscr$ is below $s1$, then set $a1\gets a\lscr$, $r\gets s1$, $\lscr \gets 1$, delete $s1$ from $S$ and go back to step A1; else set $r\gets a\lscr$ and $\lscr\gets 0$.\fig3} \step A2. [Check angle at $s1$.] {If $k=0$ or the angle at $s1$ is concave, go to step A3. If $k=1$, insert $s1$ at the front of the extension chain $X$, delete it from $S$, and go to step A3. Otherwise, output the triangle $\langle r, s1, s2\rangle$, delete $s1$ from $S$, and repeat step A2.\fig3} \step A3. [Check angle at $pi$.] {If the angle at $pi$ is convex, append $pi$ to the alternate chain $A$. If the angle is concave, and $k=m=\lscr=0$, append $pi$ to the stack $S$. In both cases, return to algorithm 7.4.\fig3} \step A4. [Remove piece from alternate side.] {If $k=0$ then output the piece $\langle r, a1, a2, \ldotss,\penalty-100 a\lscr, pi, \penalty-100 xm, x{m-1}, \ldotss, x1\rangle$, set $r\gets xm$ and $\lscr\gets m\gets 0$. If $k>0$ then output $\langle r, a1, a2, \ldotss, a\lscr, pi, s1\rangle$, set $r\gets s1$, $\lscr\gets 0$ , and delete $s1$ from $S$. Go back to step A3.}}\fig3 It is not hard to check that the chain invariants are satisfied at the beginning of each step of 7.4A, except in step A3 where the angle at $s1$ may be convex. It is also easy to verify that the condition $k=m=\lscr=0$ may happen only once, just before the last execution of step A3, and, therefore, the chains do not switch sides until that moment.\par To prove that the pieces produced by algorithm 7.4A are entirely contained in $P*$, we have to show that the corresponding cuts are proper diagonals of $P*$. For example, let's consider the cut $a\lscr s1$ in step A1, and find out where it may cross the boundary of $P*$. By the convexity of $A$, we see that $a\lscr s1$ cannot cross any edge on the alternate side between $r$ and $a\lscr$. By the concavity of $S$, and the hypothesis that $a\lscr$ can see $r$, we conclude that it cannot cross any edge between $r$ and $x1$ on the stack/extension side. Finally, since the angle at $xm$ is convex, and the next point $pj$ on the stack/extension side has to be below $pi$, we can rule out also the edges between $x1$ and $pj$.\fig3 Similar arguments show that the cuts $rs2$ (in step A2), $pis1$, and $pixm$ (in step A4) are interior to $P*$, and that the pieces defined by them are convex. The other routine, 7.4X, is quite similar to 7.4A and is called when the point $pi$ is on the stack/extension side of $P*$, or when all three chains are empty. \algorithm{7.4X}{Process point on stack/extension side.}{ \step X1. [Check angle at $pi$.] {If the angle at $pi$ is convex, append $pi$ to the extension chain $X$; if the angle is concave and $m=0$, append $pi$ to the stack $S$. In both cases, return to algorithm 7.4.\fig3} \step X2. [Remove piece from extension side.] {If $k=0$, output the polygon $\langle r, a1, a2, \ldotss,\penalty-100 a\lscr, pi,\penalty-100 xm, x{m-1}, \ldotss, x1\rangle$, set $r\gets a\lscr$, $\lscr\gets m\gets 0$, and return to step X1. Otherwise, output the polygon $\langle sk, x1, x2, \ldotss, xm, pi \rangle$ and set $m\gets 0$.\fig3} \step X3. [Check angle at $sk$.] {If the angle at $sk$ is convex, set $m\gets 1$, $xm\gets sk$, and delete $sk$ from $S$. In any case, return to step X1.}} The correctness of 7.4X can be established in essentially the same way as that of the previous routine. The chain invariants hold at the beginning of every step, except that the angle at $sk$ may be convex in step X3. From the convexity of the angle at $a\lscr$ and fact that the next point $pj$ on the alternate side is below $pi$, we concude that $a\lscr pi$ and $pisk$ in step X2 are proper cuts, and the pieces defined by them are convex.\fig3\par It easy to check that each iteration of any loop in Greene's algorithm at least one vertex is either added to or deleted from $\Qscr=S\un A\un X\un \set{r}$. Since each vertex is inserted at most once in $\Qscr$, we conclude that algorithm 7.4 runs in $O(n)$ time.\par To count the number of pieces, let's use an accounting scheme in which every new cut is charged to one of its endpoints. If one of the endpoints is an element $si$ of $S$, and the cut makes the angle at $si$ become convex, the cut is charged to $si$. The cut $a\lscr s1$ in step A1 is charged to $s1$, even though the angle at $s1$ may remain concave; in such case, the cut $a\lscr s1$ is said to be {\it extraordinary}. In all other cases, the cut is incident to the next vertex $pi$ and is charged to it. For example, in the second case of step X2 the cut $pisk$ is charged to $pi$ if the angle at $sk$ remains concave, and to $sk$ if it becomes convex (so that $sk$ is moved to $X$ in step X3).\par A particular vertex of $P$ can be inserted in $S$ at most once (either in step A3 or in step X1), and is deleted from $S$ whenever its angle becomes convex. Therefore, if we do not count extraordinary cuts, every vertex can be charged at most twice: once while it is the next vertex $pi$, and once when it is about to leave $S$.\par In addition, we claim that a vertex can be charged at most one extraordinary cut. For the cut $a\lscr s1$ in step A1 to be extraordinary, $\lscr$ must be above $s1$, so among the vertices of $P*$, $s1$ must be at least third from the top. After the cut is made, $a\lscr$ will be the top vertex, and $s1$ will be second from top, so it cannot receive any other extraordinary charge.\fig4\par A point $p$ is inserted in $S$ only if the current angle at $p$ is concave. Furthermore, when a cut is charged to $pi$ instead of a point of $S$, the current angle at $pi$ is also concave. Since the angles of $P*$ never increase, we conclude that a point is charged only if it was a concave vertex of the original polygon $P$.\par Moreover, we claim that a vertex $v$ can be charged an extraordinary cut only if it is an {\it obnoxious vertex} of $P$, that is, the angle at $v$ is concave, and it cannot be made convex by a single cut. This last condition is equivalent to saying that there is some edge on the boundary of $P$ so close to $v$ that it intercepts all rays out of $v$ that might split that corner in two convex angles.\fig3\par We see that a vertex $s1$ that receives an extraordinary charge is an obnoxious vertex of $P*$ from the fact that the angle at $s1$ remains concave after the cut, and that the latter is performed only if $r pi$ is not inside $P*$. The angle at $s1$ in the original polygon $P$ was at least as narrow as the present one; also, when step A1 is reached, no cuts with endpoint $pi$ have yet been made, so $pi a\lscr$ is on the perimeter of $P$. This implies $s1$ was an obnoxious vertex of the original polygon, too.\par In a convex decomposition of $P$, every concave vertex must be incident to at least one cut, and every obnoxious one to at least two. On the other hand, a cut is incident to exactly two vertices, so, if $P$ has $v$ concave vertices, $x$ of which are obnoxious, the best convex decomposition has at least $(v+x)/2$cuts and $(v+x)/2+1$ pieces.\par By our accounting , algorithm 7.4 will generate at most $2v+x$ cuts. The number of pieces generated will be $$\eqalign{2v+x+1|\leq (2v+2x+4)-3\cr \null|=4((v+x)/2+1)-3\cr \null|\leq 4c(P)-3.\cr}$$ The performance of algorithm 7.4 rarely approaches this upper bound. Actually, the worst case known so far is given by the figure below: The number of cuts generated by the approximate algorithm (a) is only ${3\over2}v-1$, less than three times that of the optimum solution (b).\fig5\par \vfill\eject\end(635)\f5