Part
Part
ABSTRACT
Two algorithms to partition hole-free rectilinear polygons are developed. One has complexity ∼
O(kn) and the other O(nlogk) where n is the number of vertices in the polygon and k is the smaller
of the number of vertical and horizontal inversions of the polygon. k is a measure of the simpli-
city of a polygon. Since k is small for most practical polygons, our algorithms are fast in prac-
tice. Experimental results comparing our algorithms with that of Imai and Asano [1] are also
presented.
__________________
*This research was supported, in part, by the National Science Foundation under grants MIP 86-17374 and MIP-9103379.
1. Cadence Design Systems, Inc., 555 Riveroaks Parkway, Bldg. 2,, San Jose, CA 95134.
2. Department of CIS, CSE 301, University of Florida, Gainesville, FL 32611.
1
2
1 Introduction
Rectilinear polygons (Figure 1) arise frequently in VLSI layout and artwork analysis, com-
puter graphics, databases, image processing, etc. ([2], [3], [4], [5], [6]). The functions to be per-
formed on rectilinear polygons are often more easily performed using either a rectangle partition
or a rectangle cover. In either case the rectilinear polygon is decomposed into a set of rectangles
whose union is the original rectilinear polygon. If this set of rectangles is disjoint it is a partition .
W
hole
X hole
that contains the fewest possible number of rectangles. Ohtsuki [7] has developed an O(n 5/2 )
algorithm to find the MNC of a rectilinear polygon with n vertices. Imai and Asano [1] have
developed an O(n 3/2 log n) algorithm to find the MNC and Liou, Tan, and Lee [8] have an
O(n loglogn) algorithm for hole-free rectilinear polygons. The algorithm of [8] is not expected to
perform better than that of [1] as it uses finger search trees that are known to be impractical
(‘‘Finger search trees are sufficiently complicated that one would probably not want to use them
Nahar and Sahni [10] introduced a complexity measure for hole-free rectilinear polygons.
They defined the number of horizontal inversions , kH , to be the minimum number of changes in
3
r q r q
..p o p o
..
s. . . . . . . . . ... . . . . . . . . . . . . s
t .. .. t
.. .. m n m n
.. .
.
u. . . . . . ... . . . . . . . . ... . . . . . . . . . . . . l k u l k
v .. .. .. .. v
.. .. ... ..
w . .
..
. ................ .. ............. w
x .. .. i j x i j
.. ..
.. ..
z y .. .. z y
.. ..
.. ..
.. .......... .. ...........h g h g
a´ b´ ... a´ b´
c´. .. c´
d´ .. d´
... ..
.. ..
e´ . .......... .. ..... e´
f´ .. e f f´ e f
c d c d
a b a b
(a) (b) Independent chords
r q
p o
1
s 2
t
m n
u l k
v
3 5
w 4
x i j
z y
6 h g
a´ b´
c´
d´ 8
7
e´
f´ 10 e f
9 c d
a b
(c)
horizontal direction during a walk around the polygon divided by 2. For example if we walk
around the polygon of Figure 1(a) beginning at vertex W such that the interior is to our left, then
we first walk rightwards up to vertex X then the direction is leftwards up to vertex Y and then it it
X, Y, Z. So, kH = 2. For the polygon of Figure 2(a) kH = 5. The number of vertical inversions , kV , is
4
defined analagously. kV = 1 for the polygons of Figures 1(a) and 2(a). The inversion number, k, of
a hole-free rectilinear polygon is defined to be k = min { kH , kV }. The polygon of Figure 1(a) has
inversions number 1 and that of Figure 2(a) has inversion number 1 too. A polygon is simple if it
is hole-free and has a small inversion number. Nahar and Sahni [10] examined 2869 polygons
from VLSI mask data provided by UNISYS and found that 85% of these have k = 1 and 95%
have k ≤ 2 (Figure 3). They took advantage of this observation and developed a fast algorithm to
partition hole-free rectilinear polygons under the restriction that only horizontal cuts are permit-
ted. Their algorithm outperforms the scan line method on simple (and hence practical) polygons.
In this paper we extend the work of Nahar and Sahni [10] and obtain an ∼O(kn) and an
O(n logk) (recall that k = min{kH , kV }) algorithm to find the MNC of a hole-free rectilinear
polygon. Thus our algorithms permit both horizontal and vertical cuts while that of [10] permits
only horizontal cuts. Experiments conducted with randomly generated polygons with low k show
that our algorithms outperform that of [1]. We do not compare our algorithms with that of [10] as
the algorithm of [10] does not obtain MNCs. Rather, it obtains a minimum partitioning under the
assumption that only horizontal (rather than both horizontal and vertical) cuts are permitted.
As noted earlier, most of the polygons that arise in VLSI layout and artwork analysis have a
small k. Hence our algorithms will reduce the run time of current VLSI software that uses rectil-
inear partitioning. Note that our algorithms are not recommended for rectilinear polygons with
high k. In the worst case, k can be Ο(n) and the complexity of our algorithms becomes ∼Ο(n 2 )
and Ο(nlogn), respectively. While the latter is still better than the asymptotic complexity of the
algorithm of [1], it should be noted that Ο(n 3/2 logn) is the only the worst case run time of the
algorithm of Imai and Asano [1] and that there algorithm takes much less time on many
instances. Hence, the algorithm of Imai and Asano can outperform our second algorithm on rec-
Section 2 provides background material necessary for the development of our algorithms.
This section also defines much of the terminology we shall use. In Section 3, we develop the
∼Ο(kn) MNC algorithm. The Ο(nlogk) algorithm is developed in Section 4 and experimental
5
2 Background
We assume that the rectilinear polygon is oriented so that its vertical edges are parallel to
the y-axis and its horizontal edges are parallel to the x-axis. Two vertices (x 1 , y 1 ) and (x 2 , y 2 ) are
cohorizontal (covertical ) iff y 1 = y 2 (x 1 = x 2 ). A vertex is convex (concave ) iff the interior angle
made by the two edges incident at this vertex is 900 (2700 ). A chord is a line segment that lies
wholly within the polygon and joins two cohorizontal or two covertical concave vertices. A set
of chords is independent iff no two chords of the set intersect. Chords are used to generate an
MNC of a rectilinear polygon. Since the MNC is a rectilinear partition, we may restrict our-
Example 1: Consider the hole-free polygon of Figure 2(a). Some of the cohorizontal vertex sets
are (r, q), (p,o), (t, s, m, n), and (v, u, l, k). Some of the covertical vertex sets are (z, a´), (w, v), and
(t, u, x, y). Some of the convex verteices are a, b, d, f, and g. And some of the concave vertices
are c, e, h, and i. The complete set of horizontal chords is {sm, ul, ix, hb´, ef´}, and the complete
set of vertical chords is {ux, sb´, c´f´ , pc, il}. Notice that horizontal chords are always indepen-
dent. So also are vertical chords. The chords sm and sb´ are not independent as they intersect at s.
Step 1: Find a maximum independent set of chords (i.e., a maximum cardinality set of
independent chords).
Step 2: Draw the chords in this maximum independent set. This partitions the polygon
Step 3: From each of the concave vertices from which a chord was not drawn in step 2
draw a maximum length vertical line that is wholly within the smaller rectilinear
In step 3 we may draw horizontal lines or vertical ones. The rectangles formed by the
polygon edges, chords of step 2 and lines of step 3 form an MNC [7].
Example 2: The chord set {ux, li, sm, hb´, ef´} is a maximum independent chord set for the
polygon of Figure 2(a). Figure 2(b) shows the polygon after the chords in this set are drawn.
Figure 2(c) shows the polygon after vertical lines are drawn as in Step 3. The rectangles in the
The complexity of steps 2 and 3 of the algorithm of [7] is Ο(nlogn) where n is the number of
vertices in the rectilinear polygon. A simple sweep line algorithm can be used for this. We con-
centrate on step 1. A maximum independent chord set may be found [7] by first setting up a
bipartite graph G = ( H∪V, E) where each vertex in H represents a horizontal chord and each ver-
tex in V represents a vertical chord. There is an edge between two vertices iff the chords they
represent intersect (i.e., cross or meet). Figure 4 shows the bipartite graph for the polygon of Fig-
ure 2(a). The problem of finding a maximum independent chord set now becomes one of finding
a maximum independent vertex set (MIS) in a bipartite graph (two vertices are independent iff
and let F be the set of free vertices relative to this matching (i.e., F contains all vertices of G that
7
h1 sm ux v1
h2 ul sb´ v2
h3 ix pc v3
h4 hb´ li v4
h5 ef´ c´f´ v5
H V
(b) There is an MIS S of G such that F ⊆ S and for every edge (v, h) ∈ M exactly one of v
and h is in S.
Using the above theorem one may obtain the algorithm of Figure 5 to construct an MIS S
Example 3: Consider the maximum matching M = {(sm, sb´), (ux, ul), (li, ix), (hb´, pc), (c´f´, ef´)}
Iteration 1: F = ∅, S = ∅, and M = {(sm, sb´), (ux, ul), (li, ix), (hb´, pc), (c´f´, ef´)}. (sm, sb´) is
Iteration 2: F = {hb´}, S = {sm}, and M = {(ux, ul), (li, ix), (c´f´, ef´) }. hb´ is added to S and
processed.
8
_______________________________________________________________________________
Procedure MaxInd(G,M,S);
{Given a bipartite graph G = ( H∪V, E) and a maximum matching M ⊆ E. Find an MIS S such that
S ⊆ H∪V}
begin
S := ∅;
F := {u u ∈ H∪V and (u, x) /∈ M for any x}; {Free vertices}
while (F ≠ ∅ ) or (M ≠ ∅) do
begin
if F ≠ ∅ then
begin {add a free vertex to S}
Let u ∈ F; F := F - {u}; S := S ∪ {u};
end
else {add a vertex in M to S}
begin
Let (u, v) ∈ M; M := M - {(u, v)};
E := E - {(u, v)}; S := S ∪ {u};
end;
{ Process vertex u }
for all (u, v) ∈ E do
begin
E := E - {(u, v)};
if there is an h such that (v, h) ∈ M then
begin
M := M - {(v, h)}; F := F ∪ {h}; {h is free}
end;
end; {of for}
end;{of while}
end;{of MaxInd}
_______________________________________________________________________________
Figure 5
Iteration 3: F = ∅, S = {sm, hb´}, and M = {(ux, ul), (li, ix), (c´f´, ef´)}. (ux, ul) is considered; ux
Iteration 4: F = {li}, S = {sm, hb´, ux}, and M = {(c´f´, ef´)}. li is added to S and processed.
Iteration 5: F = ∅, S = {sm, hb´, ux, li}, and M = {(c´f´, ef´)}. (c´f´, ef´) is picked. c´f´ is added
to S.
One may easily verify that procedure MaxInd constructs an independent set of cardinality
H + V - M . From Theorem 1 it follows that this is an MIS. Step 1 of Ohstuki’s algorithm [7] is
implemented as:
Step 1a: Find a maximum matching of the bipartite graph that represents the chords.
9
Step 1b: Find a maximum independent chord set using the maximum matching of Step 1a
Ohtsuki used the O(n 5/2 ) bipartite graph matching algorithm of Hopcroft and Karp [13] for
Step 1a. Since the remaining steps take less time than this, Ohtsuki’s implementation has com-
plexity O(n 5/2 ). Imai and Asano [1] have developed an O(n 3/2 log n) algorithm to find a maximum
matching of the intersection graph of horizontal and vertical line segments. This results in an
The neighborhood, NEB(x), of a vertex x is defined to be the set of vertices adjacent to ver-
tex x. For the bipartite graph of Figure 4, NEB(h 1 ) = {v 2 , v 3 } and NEB(v 1 ) = {h 2 , h 3 }. A bipar-
tite graph G = ( H∪V, E) is convex on V iff the vertices in V can be ordered such that for every h ∈
H, NEB(h) = [FIRST(h), LAST(h)] (i.e. all vertices in the ordering beginning at vertex FIRST(h)
and going on to vertex LAST(h)) or null. Convex on H can be defined similarily. The bipartite
NEB(v 1 ) = {h 2 , h 3 } = [h 2 , h 3 ].
NEB(v 2 ) = {h 1 , h 2 , h 3 , h 4 } = [h 1 , h 4 ].
NEB(v 3 ) = {h 1 , h 2 , h 3 , h 4 , h 5 } = [h 1 , h 5 ].
NEB(v 4 ) = {h 2 , h 3 } = [h 2 , h 3 ].
NEB(v 5 ) = {h 5 } = [h 5 , h 5 ].
A vertex x is matchable iff there is a vertex y ∈ NEB(x) such that NEB(y) ⊆ NEB(z) for all z
all z ∈ NEB(h 1 ). The importance of a matchable vertex x is that we can show that there is a max-
Theorem 2: Let x be a matchable vertex in a graph G. Let y be such that y ∈ NEB(x) and
NEB(y) ⊆ NEB(z) for all z ∈ NEB(x). There is a maximum matching that contains the edge (x, y).
Proof: Let M´ be a maximum matching of G that does not contain the edge (x, y). Since M´ is a
10
maximum matching and (x, y) is an edge of G, both x and y cannot be free relative to M´. If only x
is free then (y, w) ∈ M´ and we can construct M = M´ - {(y, w)} ∪ {(x, y)}. If only y is free then (x,
a) ∈ M´ and we construct the maximum matching M = M´ - {(x, a)} ∪ {(x, y)}. If neither x nor y is
free then (x, a) ∈ M´ and (y, w) ∈ M´. Since a ∈ NEB(x), NEB(y) ⊆ NEB(a). Now since w ∈
NEB(y), w ∈ NEB(a). So, (w, a) is an edge of G. From M´, we may construct the maximum
Step 4: Go to Step 1.
It is evident that a maximum matching is found so long as we do not have a failure termina-
tion in Step 2. Graphs which do not cause the preceding strategy to fail are called matchable
graphs. For a bipartite graph G = (H ∪ V, E) that is convex on V and in which V = {v 1 , v 2 , ..., vnV }
is ordered as required by the convex property the above strategy to find a maximum matching
takes the form given in procedure MaxMatch (Figure 6). This procedure is due to [12]. Step 2
has been eliminated as for any iteration i of the for loop if NEB(vi ) ≠ ∅ then for every h ∈
NEB(vi ), NEB(h) = [vi , LAST(h)]. By the choice of h j , NEB(h j ) ⊆ NEB(h) for every h ∈ NEB(vi ).
Starting with a maximum matching, the MIS of a bipartite graph that is convex on V can be
obtained in O(nH + nV ) time where nH = H and nV = V . For this we use a strategy slightly
different from that used in procedure MaxInd (Figure 4). We assume that the maximum matching
M is obtained by using procedure MaxMatch (Figure 6) and that the vertices in V are ordered as
required by the convexity property and those in H are ordered so that FIRST(hi ) ≤ FIRST(hi+1 ).
The strategy in the new independent set algorithm is to begin by placing all vertices in V
11
_______________________________________________________________________________
Procedure MaxMatch( G,M);
{G = ( H∪V, E) is a bipartite graph that is convex on V. V = {v 1 , ..., vnV } is ordered as required by
the convex property. A maximum matching M is computed.}
begin
M := ∅;
for i := 1 to nV do
if NEB(vi ) ≠ ∅ then
begin
Let h j ∈ H be such that LAST(h j ) = min {LAST(h)}
h ∈ NEB (vi )
M := M ∪ {(h j , vi )};
Delete h j , vi , and incident edges from G;
end
end;{of if & for}
end;{of MaxMatch}
_______________________________________________________________________________
Figure 6 Maximum matching algorithm of [12].
into the MIS S that is being constructed. From Theorem 1 we know that there is an MIS that con-
tains all free vertices and exactly one vertex from each pair of matched vertices in M. To con-
struct such an indenpent set, we examine the free vertices that are also in H (all free vertices in V
are already in S). They are examined in order (i.e. if hi and h j are free and i < j then hi is exam-
ined before h j ). When a free vertex hi is examined, it is added to S. To ensure that the vertices in
S are still independent we need to examine the V vertices in the range [FIRST(hi ), LAST(hi )].
These must be eliminated from S. Further each vertex vk in this range must be in the matching M
tices in the range [FIRST(hq ), LAST(hq )] eliminated from S. Note that LAST(hq ) ≤ LAST(hi ) as
Figure 7 gives an example bipartite graph that is convex on V. Consider the matching M =
tains the single interval [-∞, -∞]. The following describes the progress of the above strategy on
h1
NEB(h 1 ) = [v 1 , v 3 ]
v1
NEB(h 2 ) = [v 2 , v 4 ]
h2
NEB(h 3 ) = [v 2 , v 3 ]
v2 NEB(h 4 ) = [v 3 , v 4 ]
h3
NEB(h 5 ) = [v 3 , v 3 ]
NEB(h 6 ) = [v 4 , v 5 ]
h4 v3
NEB(h 7 ) = [v 4 , v 4 ]
h5 M = {(v 1 , h 1 ), (v 2 , h 3 ),
v4
(v 3 , h 5 ), (v 4 , h 2 ),
h6 (v 5 , h 6 )}
v5
S = {v 1 , v 5 , h 2 , h 3 ,
h7
h4, h5, h7}
Delete v 4 v3 v4
Add h 2 v2 v4
Delete v 3 v2 v3
Add h 5 v2 v3
Delete v 2 v2 v2
Add h 3 v2 v2
[-∞, -∞], [v 2 , v 4 ] v2 v1
[-∞, -∞] v4 v1 v2 v4
[-∞, -∞], [v 2 , v 4 ]
The strategy described above is implemented in procedure MaxInd1 (Figure 8). This pro-
cedure is due to [12]. It uses a stack to keep track of intervals [l, r] of V that have already been
processed. These intervals are in decreasing order as you go down the stack and are disjoint.
bipartite graph G = (H ∪ V, E) can be found in O(nH + nV ) time if we can do the following in this
much time:
3.1 Preliminaries
If the vertices of a polygon edge are both convex (concave) the edge is called a support edge
(reflex edge). A polygon edge is a left, right, top, or bottom edge if the polygon interior is to its
right, left, bottom, or top, respectively. The edges vw, za´, and d´e´ of the polygon of Figure 2(a)
are left support edges and edges xy and b´c´ are left reflex edges.
Theorem 4: Let P be a rectilinear hole-free polygon with horizontal and vertical inversion
(a) kH = number of right support edges plus number of left reflex edges.
(b) kV = number of top support edges plus number of bottom reflex edges.
(c) For each of the four sides left, right, top, and bottom, the number of reflex edges is one
14
_______________________________________________________________________________
Procedure MaxInd1(G,M,S);
{G = ( H∪V, E) is a bipartite graph that is convex on V. M is a matching produced by procedure
MaxMatch. This procedure constructs an MIS S of G. It is assumed that the vertices in V are
ordered as required by the convexity property and that FIRST(hi ) ≤ FIRST(hi+1 ), 1 ≤ i < nH }
begin
Initialize a stack so that it contains the single interval [l, r] = [-∞, -∞];
S := V; {all vertices of V initially in S}
for each free vertex hi in order do
begin
Add hi to S;
if NEB(hi ) ≠ ∅ then
begin
low := FIRST(hi ); high := LAST(hi );
[l, r] := interval at top of stack;
repeat
if l ≤ high ≤ r then
begin
delete [l, r] from top of stack;
high := l − 1; {bypass already processed interval}
low := min {l, low};
set [l, r] to new top of stack interval;
end
else
begin
delete vhigh from V;
if vhigh is a matched vertex in M then
begin
Let hq be the vertex it is matched to;
add hq to S;
low := min {low, FIRST(hq )};
{Note: high is not to be updated as LAST(hq ) ≤ LAST(hi )}
end; {if matched}
high := high - 1;
end; {disjoint from the interval at top of stack}
until (high < low);
Add [low, LAST(hi )] to top of stack;
end; {of if NEB(hi ) ≠ ∅}
end; {of for each free vertex hi }}
end;{of MaxInd1}
_______________________________________________________________________________
Figure 8 Maximum independent set algorithm of [12]
Proof: (a) A walk around the polygon changes from right to left only at a right support edge and
15
at a left reflex edge. Since the number of right to left changes equals the number of left to right
changes, the total horizontal direction changes on a complete walk around the polygon is 2 *
(number of right support edges plus number of left reflex edges). So kH = number of right support
edges plus number of left reflex edges. The equality kH = number of left support edges plus
number of right reflex edges is obtained in a similar way. (b) can be proved analogously.
We shall prove (c) by induction on the number n of vertices in P. Let lse and lre denote the
number of left support edges and left reflex edges. rse, bse, tse, rre, bre, and tre are defined analo-
gously. We explicitly show lse - lre = 1. The proof for the other three sides is similar.
For the induction base, we have n = 4. When n = 4, P has one left support edge and no left
reflex edge. So, lse - lre = 1. Assume lse - lre = 1 for all hole-free rectilinear polygons with n ≤ m
vertices where m is an arbitrary natural number ≥ 4. Let P be any rectilinear hole-free polygon
with n = m + 1 vertices. P has at least one left support edge. Pick any one of P’s left support
edges and move this rightwards until this edge aligns with the first left or right edge encountered.
Figure 9 gives the cases that can arise. For each case the primed quantities represent values for
the polygon that remains following the elimination of the portion of the polygon crossed during
the movement of the left support edge. In cases (j) through (t) cmp´ gives the number of resulting
hole-free polygons. This number is 1 for cases (a) through (i). In case (a) the number of vertices
decreases by 4 as vertices a, b, c, and d are no longer polygon vertices following the movement of
the support edge ab to the position cd. So, n´ = n − 4, lse´ = lse, lre´ = lre. From the induction
hypothesis, lse´ - lre´ = 1. So, lse - lre = 1. As another example, consider case (j). The resulting
h + 1 polygons have a total of n−4 vertices. Applying the induction hypothesis to each and sum-
ming, we get lse´ − lre´ = h + 1. So, lse − lre = lse´ − h − lre´ = 1. Using the induction hypothesis,
we can show that for each of the remaing cases of Figure 9, lse - lre = 1.
= (2rse + 2lse - 2) / 2
= (rse + lse) - 1
16
a
c. c. c
a .. a .. ...
.. .. ..
.. .. ..
.. .. ...
.. .. ..
.. .. .
b b b
d d d
n´ = n - 4 n´ = n - 4 n´ = n - 4
lse´ = lse lse´ = lse - 1 lse´ = lse
lre´ = lre lre´ = lre - 1 lre´ = lre
(a) (b) (c)
c.
a .. a
..
.. c. c
.. a .. ...
.. .. ..
.. .. ..
... ..
.. ...
.. .. ..
b . b b .
d d d
n´ = n - 2 n´ = n - 4 n´ = n - 4
lse´ = lse lse´ = lse - 1 lse´ = lse - 1
lre´ = lre lre´ = lre - 1 lre´ = lre - 1
(d) (e) (f)
c. c.
a .. a a ..
.. ..
..
.. ..c ..
..
.. .. ..
.. .. ..
.. .. ..
.. ... ..
b .. .. ..
d d d
b b
n´ = n - 2 n´ = n - 4 n´ = n - 2
lse´ = lse - 1 lse´ = lse lse´ = lse
lre´ = lre - 1 lre´ = lre lre´ = lre
(g) (h) (i)
a
c c c c
a a a
1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2
.. .. .. .. .. .. .. ..
. . . . . . . .
h h h h h h h h
b b b b
d d d d
n´ = n - 4 n´ = n - 4 n´ = n - 4 n´ = n - 2
lse´ = lse + h lse´ = lse + h - 1 lse´ = lse + h lse´ = lse + h
lre´ = lre lre´ = lre - 1 lre´ = lre lre´ = lre
cmp´ = h + 1 cmp´ = h + 1 cmp´ = h + 1 cmp´ = h + 1
(j) (k) (l) (m)
c
a c
a c a
1 1
1 1
2 2
.. .. ∅ 2 2
. . .. ..
h h . .
h h
d b d b
b d
n´ = n - 4 n´ = n
lse´ = lse + h lse = 1 lse´ = lse + h
lre´ = lre lre = 0 lre´ = lre
cmp´ = h + 1 cmp´ = 0 cmp´ = h + 1
(n) (o) (p)
a a
c c c c
a a
1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2
.. .. .. .. .. .. .. ..
. . . . . . . .
h h h h h h h h
b b b
d d d d
b
n´ = n - 4 n´ = n - 4 n´ = n - 4 n´ = n - 2
lse´ = lse + h lse´ = lse + h - 2 lse´ = lse + h - 1 lse´ = lse + h - 1
lre´ = lre lre´ = lre - 2 lre´ = lre - 1 lre´ = lre - 1
cmp´ = h + 1 cmp´ = h + 1 cmp´ = h + 1 cmp´ = h + 1
(q) (r) (s) (t)
Figure 9: lse - lre = cmp.
3.2 k=1
In this section we develop an O(n) algorithm to find the MNC of a rectilinear hole-free
polygon with inversion number k = 1. We explicitly consider only the case k = kH = 1. The case k
Since every rectilinear polygon has at least one left support edge and one right support
edge, it follows from Theorem 4(a) that when kH = 1 the number of vertical reflex edges is zero.
As a result the polygon cannot have two vertical chords with the same x-coordinate. Conse-
quently there is a unique left to right ordering of the vertical chords. Let the vertical chords, in
this ordering, be v 1 , v 2 , ..., vnV . This ordering may be obtained in O(n) time by starting at the two
vertices of the single left support edge (Thoerem 4) of the polygon and moving rightwards. Dur-
ing this walk we match top vertices with bottom ones to see if a vertical chord can be drawn here.
Since the polygon contains no holes and no vertical reflex edges, NEB(hi ) for every horizontal
chord hi is an interval of the vertical chords. The horizontal chords may be constructed and their
FIRST and LAST values computed by making a left to right pass over the top and bottom boun-
daries of the polygon. During this pass the horizontal chords may also be ordered by their
Procedure MaxMatch examines the vertical chords left to right. Suppose that the neighbor-
hood, NEB, of a vertical chord is maintained as a doubly linked list sorted on the y coordinate.
Since NEB(vi ) cannot contain two horizontal chords with the same y coordinate, this ordering is
well defined. The doubly linked list can be initialized in O(1) time. As we go from one vi to the
next additions and deletions of horizontal chords is localized in the doubly linked list and can be
done in time proportional to the number of affected chords. h j is the horizontal chord in the dou-
bly linked list that has the least right end point. Since the polygon has no right reflex edge, this
must either be the horizontal chord with lowest or highest y coordinate. I.e., it is one of the
chords at the two ends of the doubly linked list that represents NEB. So, h j can be found in O(1)
time and deleted from the list. Figure 10 illustrates this technique. The MIS is now found using
procedure MaxInd1. From the above discussion it follows that the MNC of a hole-free rectilinear
3.3 k=2
Theorem 4(d) it follows that a polygon with kH = 2 satisfies one of the following:
19
.. . h. .6. . .. . . h. .6. . ..
.. .. ..
.. .. ..
.. .. ..
.. . .
.. v..6 v..6
v.5 .. ..
.. .. ..
.. .. ..
. . . . . . . . . . . . . . h. .2. . . . . . . . ... . . . . . .. . . . . . . . . . . . . . . h. .2. . . . . . . . . . . . . . ..
.
. . . . . . . . . h. .4. . . . . . . . . ..
Since (b) is symmertric to (a), we consider only (a) further. From Theorem 4(a) it follows
that lre = 1. If the single left reflex edge is extended in one direction until it meets a horizontal
edge (see Figure 11) then the polygon is divided into two parts P 1 (left of the reflex extension)
and P 2 . Both P 1 and P 2 have k = kH = 1. This partitioning into P 1 and P 2 may be done by begin-
ning at the bottom of the left reflex edge and moving around the polygon until the walk first
reaches the x-coordinate of this left reflex edge. Once P 1 and P 2 have been identified, their verti-
cal chords can be numbered left to right as for the case k = 1 (Section 3.2). In each case, numbers
are assigned beginning with the number 1. Horizontal chords that span both P 1 and P 2 will have
two FIRST and LAST values associated with them; one being the first and last vertical chord of
P 1 they intersect and the other being the first and last vertical chord of P 2 that is intersected.
Since there are no right reflex edges, the FIRST and LAST values associated with the horizontal
(1) Start at the left support edge of P 1 and proceed as for the case k = 1 (Section 3.2). Stop this
algorithm when the right boundary of P 1 is reached. The horizontal segments that continue
(2) Start at the left support edge of P 2 and proceed as for the case k = 1. When the left reflex
(1) Begin at the leftmost vertical chord of P 1 and proceed left to right as for the case k = 1 (Sec-
tion 3.2). A doubly linked list of intersecting horizontal chords ordered by y-coordinate is
maintained as in the case k = 1. When each vertical chord is examined in this order, it is a
matchable chord. This follows from the observation that since P has no right reflex edge,
the neighborhood of the intersecting horizontal chord with smallest right end point is con-
tained in the neighborhood of every other intersecting horizontal chord. Further, the
absence of a right reflex edge implies that the intersecting horizontal chord with the smal-
lest right end point is either at the front or the end of the doubly linked list (i.e., it is either
the one with the highest or the lowest y-coordinate). This matching of vertical chords of P 1
21
to horizontal chords terminates when the right boundary of P 1 is reached. The doubly
(2) Begin with the leftmost vertical chord of P 2 and proceed left to right matching horizontal
and vertical chords as in (1). Stop when the left to right sweep reaches the left reflex edge.
To the doubly linked list of horizontal segments append the doubly linked list saved in (1)
The above two step process results in a maximum matching as when a vertical chord is
P2
..
...
P1 ..
..
..
..
To compute the MIS we use the strategy used in the case k = 1. I.e., we begin with all ver-
tices of V (both in P 1 and P 2 ) in the independent set and then process the free horizontal chords.
The stack scheme of MaxInd1 is replaced by union-find structures [14] for each of P 1 and P 2 .
For each of P 1 and P 2 we maintain a set of equivalence classes of vertical chords in P 1 and P 2 ,
respectively. Each equivalence class represents an interval of processed vertical chords. A free
horizontal chord that is in both P 1 and P 2 needs to be processed in both polygons. The complex-
ity of the resulting scheme is O(n, α(n,n)) where α is the inverse of the Ackermann’s function
22
[14].
3.4 k=3
Since (a) and (c) are symmetric we need only consider (a) and (b). Figure 12(a) gives an
example for lse = 3 and rse = 1 while Figures 12 (b), (c), (d), and (e) are examples for the case lse
= rse = 2. When lse = 3 and rse = 1 the polygon has no right reflex edge and has two left reflex
edges (Theorem 4(a)). By extending the two left reflex edges at one end each we can decompose
the polygon into three polygons with k = 1. Since there is no right reflex edge we can find the
maximum matching by extending the strategy of Section 3.3 to the case when P is partitioned
into three polygons with k = 1 each. We first match the chords in P 1 and then continue to P 2 .
The matching in P 2 commences at its leftmost vertical chord. When the processing reaches the
right boundary of P 1 , the doubly linked list saved from P 1 is appended and we continue till the
right boundary of P 2 is reached. Now we start matching in P 3 . The processing begins at the left-
most vertical chord in P 3 . When the right boundary of P 2 is reached, the doubly linked list saved
at the end of the processing of P 2 is appended and we continue up to the rightmost vertical chord
in P 3 . The correctness of this scheme is established in the same way as we established the
When lse = rse = 2 the polygon has one right reflex edge and one left reflex edge. The parti-
(1) Determine the number of vertical support edges encountered in a walk that begins at the top
of the right reflex edge and ends at the top of the left reflex edge. The walk follows the
polygon edges but does not go over the reflex edges. This latter restriction uniquely
.. ..
.. .. .. P
P 1 .. .. .. 2
.. .. .
.. ..
.. ..
P2 ..
.. P3
..
..
..
. ..
P3 ..
.
P 1 ...
..
.. ..
P1 ..
..
..
.
(a) lse = 3, rse = 1. (b) lse = 2, rse = 2.
P3
..
.. P2 .. P 1 ..
.. .. ..
.. .. P2 ..
.. .. ..
P3 .. . ..
..
(c) lse = 2, rse = 2.
..
.. ..
.. .. P3
.. ..
.. P2 ..
. ..
P1
(2) The number of vertical support edges encountered in the above walk is either 0, 2, or 4. If
the number is 0, then extend both reflex edges downward (Figure 12(d)). If the number is 2,
then extend the right reflex edge upward and the left reflex edge downward in case the bot-
tom of the right reflex edge is at a higher y-coordinate than the top of the left reflex edge
(Figure 12(b)); otherwise extend the right reflex edge downward and the left reflex edge
upward (Figure 12(c)). If the number is 4, then extend both reflex edges upward (Figure
12(e)).
(a) Match chords in P 1 using the strategy of Section 3.2. However, P 1 is processed right
to left. Stop when the left boundary of P 1 is reached. Horizontal chords of P 1 that
extend into P 3 are now processed. If the chord was matched to a vertical chord of P 1 ,
it is marked as matched. If it was not matched, its right end point is changed to be
(b) Match chords in P 2 left to right using the strategy of Section 3.2. Stop when the right
boundary of P 2 is reached and save the doubly linked list of horizontal chords.
(c) Match chords in P 3 left to right. Already matched horizontal chords are ignored from
the processing. When the right boundary of P 2 is reached, the doubly linked list
saved when the processing of P 2 finished is appended to the current doubly linked
list.
The correctness of the above matching strategy follows from the following observations:
(b) If this vertical chord is in P 1 , then it may be matched to the horizontal intersecting chord
with maximum left end point. This is either the bottom most or topmost intersecting chord.
(c) If it is a vertical chord of P 2 , it can be matched to the horizontal intersecting chord with the
yet unmatched and has smallest right end point. Since all vertical chords of P 1 that could
be matched to a horizontal chord have already been matched, the right end points of
unmatched horizontal chords that extend into P 1 may be considered to be the left boundary
of P 1 . This does not affect the set of free vertical chords each such horizontal chord inter-
sects.
(2) [Number of vertical support edges in walk is 2 and the bottom of the right reflex edge is
(a) Match chords in P 1 , left to right, using the strategy of Section 3.2. Stop when the
right boundary of P 1 is reached and save the doubly linked list of free horizontal
(b) Match the chords in P 2 , right to left, using the strategy of Section 3.2. Stop when the
left boundary of P 2 is reached. Mark the matched horizontal chords of P 2 that extend
into P 3 as matched. Change the right end points of the unmatched horizontal chords
(c) Match the chords in P 3 left to right. When the right boundary of P 1 is reached,
The fact that this strategy results in a maximum matching may be established in a manner
analagous to that used for case (1). The strategies for the remaining two cases (Figures 12(c) and
The MIS is now found in O(n, α(n,n)) time using MaxInd1 and union-find structures for
each of P 1 , P 2 , P 3 .
3.5 k>3
We explicitly consider only the case k = kH . The strategy is to decompose the polygon into
2k subpolygons with kH = 1 and then use the matching strategy of Section 3.2 to each of these in a
suitable order. The decomposition is easily done by extending the vertical reflex edges in both
directions (Figure 13(a)). This takes O(nlogk) time if a range search tree [15] is used to store the
end points of the at most k - 1 vertical reflex edges. The resulting polygons have no left or right
reflex edges. From Theorem 4(c) it follows that each polygon has lse = rse = 1. From Theorem
In order to apply the strategy of Section 3.2 (or its modification to a right to left sweep) to a
subpolygon, the following must be true at the time the matching in the subpolygon begins:
(2) Either all subpolygons that abut it on the left or all that abut it on the right must have been
26
..
.. P1
.. .. P6
.. .. e1
.. .
P1 .. P2
.. e3
..
.. .. ..
.. .. .. P3
. .. ..
.. .. P 7 e2
e 1 P4 .. ..
.. .. P4
.. .. ..
.. .. ..
.. .. .
.. .. P5
P2 .. .. e4
.. .. P5 e3
.. .. ..
.. .. .. P6
. .. ..
.. ..
e2 .. .. P 8
.. .. P7
.. .. .
.. .. e4
P 3 .. .
P8
..
.
(a) Original polygon (b) Constraint graph
..
..
..
P1 ..
.. P1
..
.. ..
.. ..
. ..
..
e 1 P4 .. P2
..
.. ..
.. .. e1
.. ..
.. ..
P2 .. .. P4
.. .. P5
.. ..
.. ..
. ..
..
.. P5
..
..
..
.
processed. In case the former is true, the subpolygon is processed left to right; otherwise it
(3) The subpolygon should not contain two unmatched horizontal chords such that one passes
27
on one side of a vertical reflex edge and the other passes on the other side of this reflex
edge. For this test, the current end points of chords are used. Recall from Section 3.4 that
when a subpolygon is processed right to left the right end points of some chords are
updated. Similarly, we assume, that when a subpolygon is processed left to right, the left
end points are updated to become the right boundary of the subpolygon.
Note that since the subpolygons are constructed by extending all vertical reflex edges, all of
them satisfy condition (1). So we need only be concerned with conditions (2) and (3). For condi-
tion (2), we can maintain, with each subpolygon, a count of the number of unprocessed subpo-
lygons that abut it on the left and the number that abut it on the right. Also, with each subpo-
lygon we maintain a list of the subpolygons it abuts on the left as well as on the right. When a
subpolygon is processed, this list is traversed and the left abut and right abut counts of the subpo-
lygons on this list are decremented. For condition (3), we maintain a constraint graph CG. This is
a bipartite graph with one vertex for each subpolygon and one for each vertical reflex edge.
There is an edge between a subpolygon vertex and a reflex edge vertex iff both ends of the reflex
edge can be joined to the interior of the subpolygon by a horizontal line that is wholly within the
polygon. Figure 13(b) gives the constraint graph for Figure 13(a).
Subpolygon vertices with degree zero in the constraint graph and which satisfy condition
(2) above can be processed first in any order. So these are added to the front of the order being
constructed. These subpolygons may be deleted from the original polygon to get the polygon of
Figure 13(c). Since the deletion of each subpolygon reduces the number of vertical reflex edges
by 1, the new polygon has fewer reflex edges than the original one. A new constraint graph for
this polygon is constructed (Figure 13(d)) and the subpolygons with degree zero that also satisfy
condition (2) above are added to the order being constructed. So, so long as the constraint graph
has a subpolygon vertex of degree zero that also satisfies condition (2), we can repeat this pro-
cess to obtain the desired order. For the example of Figure 13(a) we obtain the order P 3 , P 6 , P 7 ,
P 8 , P 1 , P 2 , P 4 , and P 5 . The following theorem shows that every constraint graph has at least one
subpolygon vertex whose degree is zero and for which its current left abut or right abut count is
28
also zero.
Theorem 5: The constraint graph of every rectilinear hole-free polygon (whether original or
updated) has at least one subpolygon vertex with degree zero and such that the corresponding
Proof: Without loss of generality, assume that lse ≥ rse. Since rse = rre + 1 (Theorem 4(c)), it
follows that lse > rre. The number of subpolygons one of whose sides is a left support edge of the
polygon is lse. Each right reflex edge can be connected to at most one of these in the constraint
graph. Since lse > rre, at least one of these left support edge subpolygon vertices is not connected
to a right reflex edge vertex in the constraint graph. Further, no left support edge subpolygon ver-
tex can be connected to a left reflex edge vertex. Hence there is at least one left support edge
subpolygon vertex with degree zero. Every subpolygon, constructed as described above, that has
Using the above strategy and appropriate data structures a maximum matching can be
found in O(kn) time. The MIS can be found in O(knα(n, n)) time using MaxInd1 and union-find
structures.
4 O(nlogk) Algorithm
This algorithm is an adaptation of the O(nloglogn) MNC algorithm of [8]. This latter algo-
Step 1: Decompose the rectilinear polygon P into vertically convex subpolygons. This decom-
position is done in such a way that a maximum matching of chords can be found by pro-
Step 2: Process the subpolygons in the order created to obtain a maximum matching. Free
chords from each subpolygon are added to a queue in the order in which they are deter-
Step 3: Obtain an MIS of chords by processing the maximum matching and free chord queue
obtained in Step 2.
29
Step 4: Draw the independent chords in the independent set of Step 3 to get a set of subpo-
lygons. Draw all vertical chords in the resulting subpolygons to get rectangles.
Step 3 can be done in O(n) time [8] and Step 4 takes O(nlogk) time. We show how steps 1
and 2 can be done in O(nlogk) time. We consider the case k = kV . The case k = kH is similar. The
basic strategy is to start at any horizontal support edge and advance into the polygon (i.e., if we
start at a bottom support edge, then we move upwards and if we start at a top support edge, we
move downwards) until we reach either a vertical or horizontal reflex edge. This is done by mov-
ing along the contour of the polygon beginning at the horizontal support edge. The moving is
done in both directions keeping the y-coordinate of the position in both directions the same (this
is the same as using a horizontal scan line with endpoints on the polygon contour identified by
the above walk). To determine if a horizontal reflex edge is reached, we maintain a range search
tree of horizontal reflex edges. Since the number of such edges is k - 1, the time to determine if
such an edge is reached in O(logk). For vertical reflex edges, we simply see if the current contour
edge is a vertical reflex edge (this test cannot be extended to horizontal reflex edges as the next
such edge to be encountered may not lie on the portion of the contour being traversed currently).
When a vertical reflex edge is reached, it may be extended downwards if we start at a bottom
support edge or upwards if we start at a top support edge to obtain a vertical convex subpolygon.
The situation is more complex when a horizontal reflex edge is reached. We go through a
detailed example to illustrate the various cases that arise. A high level description of the decom-
____
position algorithm is given in Figure 14. In this algorithm next denotes the opposite of next . So, if
_ __ ____
next = top, next = bottom and if next = left, next = right. SP is a list of the subpolygons created.
Consider the polygon of Figure 15(a). Suppose we begin at the horizontal support edge
s 1 s 2 . Since this is a bottom support edge, we set next = top and move a horizontal scan line
upwards from s 1 s 2 . Vertices a, b, and c, the bottom ends of vertical reflex edges, are encountered
in order and subpolygons P 1 , P 2 , and P 3 are added to SP in this order. Next, the scan line reaches
a horizontal reflex edge. We stop processing and resume at another horizontal support edge. Fig-
30
_______________________________________________________________________________
Procedure Decompose( P,SP);
{Decompose the original polygon P with k = kV into SP, a list of vertical convex subpolygons.}
begin
SP := ∅;
repeat
Pick a horizontal support edge hse;
Scanline := hse;
if hse is a bottom edge then next := top else next := bottom;
repeat
Move Scanline along the boundary to the next side until a horizontal edge is
encountered;
if Scanline encloses a horizontal support edge then
begin
Save the last support edge and the remaining polygon P;
Stop;
end
else if Scanline encloses a next reflex edge then
if only one region X on the next side is unvisited then
shift Scanline to the entrance of X and continue
else
Mark all of the next reflex edges visited on this side and exit to outer
loop; _ __
else if Scanline encloses a next reflex
____ edge then
if only one region Y on the next side is unvisited then
turn around to the entrance of Y and reverse next
else
Mark the current region as visited and exit to the outer loop;
else
begin
if a left reflex edge is encountered then
Make a vertical cut on the left side to get P left and add to the end of SP;
if a right reflex edge is encountered then
Make a vertical cut on the right side to get P right and add to the end of
SP;
end;
until false;
until false;
end;{of Decompose}
_______________________________________________________________________________
Figure 14
ure 15(b) shows the current situation. Subpolygons P 1 , P 2 , and P 3 have been eliminated and the
hatched area indicates a region of the polygon that has been scaned. Suppose we pick the bottom
support edge s 3 s 4 . next is set to top and we advance upwards. The vertical reflex edges with ver-
tices d, e, and f at the bottom ends are found. As a result, subpolygons P 4 , P 5 , and P 6 are added to
the queue SP. Processing stops when the next horizontal reflex edge is reached. It resumes at a
31
......
..c
.. P
.. 3
b.
.. a
... ...
P 2 ... ... P 1
s1 s2
(a)
...... . .. . .. .. . .. . . . . . . . . . .
f.
.
P 6 ...
. ..e
..
d. ..P 5
. ..
P 4... .
s3 . s4
(b)
...... . .. . .. .. . .. . . . . . . . . . . . . . . . . . . . . . . . . ..g
..
..P 7
..
.
s5 s6
(c)
Going on to Figure 15(c), the horizontal support edge s 5 s 6 is picked and subpolygon P 7 is
appended to SP. Next, we pick the top support edge s 7 s 8 and set next = bottom (Figure 15(d)). No
subpolygon is generated in this area. Then, another top support edge s 9 s 10 is considered and we
32
move down until a horizontal reflex edge is encountered (Figure 15(e)). Then, we turn the direc-
tion 3 times, down to up, up to down, and down to up, respectively (Figure 15(f)). No subpo-
lygon is added to SP as no vertical reflex edge is encountered. Finally, the top support edge
s 11 s 12 is handled (Figure 15(g)). The subpolygons P 8 and P 9 are added to SP before a horizontal
33
reflex is found.
The subpolygons P 10 and P 11 are appended to SP when we turn around from going down to
up and complete the whole procedure Decompose (Figure 15(h)). The remaining vertical convex
Step 2 can actually be done concurrently with Step 1. The strategy of Section 3.2 can be
used to obtain a maximum matching and the queue of free chords in O(n) time. Step 3 is now
implemented as in [8] and Step 4 is the same as that used for the algorithm of Section 3.
5 Experimental Results
2. ∼ O(kn) ... This uses the algorithms described in Sections 3.2, 3.3, and 3.4 for k = 1, 2, and 3,
respectively. For k > 3, it uses the decomposition scheme of Section 4 and the independent
set strategy of Section 3.5. We did not use the decomposition scheme of Section 3.5 as
All algorithms were programmed in Pascal and run on an Apollo DN3500 workstation.
Tables 1-5 give the average run times, in seconds, of the three programs for the case of randomly
were generated randomly and then classified according to their k value.) The column labeled size
gives the number of vertices in the polygon. For each value of size, 50 random polygons were
generated. The columns labeled improve (%) give the amount by which the run time of the
O(n 1.5 logn) algorithm exceeds this algorithm’s run time. As can be seen, for any fixed k, the
O(nlogk) and ∼ O(kn) programs outperform the O(n 1.5 logn) program for suitably large polygons.
The percentage improvement in run time increases as the polygon size increases. For k = 1, and
2, the ∼ O(kn) program is faster than the O(nlogk) program. For k = 3, these two programs are
Table 6 gives the measured run time for the UNISYS polygon set. The O(nlogk) and ∼
O(kn) programs outperformed the O(n 1.5 logn) one for polygons with no more than 40 vertices.
The O(n 1.5 logn) program was slightly faster for the larger polygons in this test set.
35
6 Conclusions
We have developed two algorithms to obtain the MNC of rectilinear polygons with small k.
Both are significantly faster than the O(n 1.5 logn) algorithm of [1] on polygons whose size is large
relative to k. For k = 1 and 2 the ∼ O(kn) algorithm is recommended while for k > 2 the O(nlogk)
algorithm is recommended.
7 References
[1] H. Imai and T. Asano, "Efficient Algorithms for Geometric Graph Search Problems", SIAM
36
[2] E. Lodi, F. Luccio, C. Mugnai and L. Pagli, "On Two-dimensional Data Organization I",
[4] J. K. Ousterhout, "Corner Stitching: A Data-Structuring Technique for VLSI Layout Tools",
IEEE Trans. on Computer Aided Design of Integrated Circuits and Systems, Vol CAD-3,
University of Virginia.
[6] S. Nahar and S. Sahni, "A Time and Space Efficient Net Extractor", 23rd Design Automa-
[9] R. E. Tarjan and C. J. Van Wyk, "Triangulating a simple polygon", SIAM Jr on Computing,
[10] S. Nahar and S. Sahni, "A Fast Algorithm for Polygon Decomposition", IEEE Trans. on
38
Computer Aided Design of Integrated Circuits and Systems, Vol. CAD-7, No. 4, April
[11] E. L. Lawler, "Combinatiorial Optimization: Networks and Matroids", Holt, Rinehart and
[12] W. Lipski, Jr. and F. P. Preparata, "Efficient Algorithms For Finding Maximum Matching In
Convex Bipartite Graphs And Related Problems", Acta Informatica 15, 1981, pp.329-346.
[13] J. E. Hopcroft and R. M. Karp, "An n 5/2 Algorithm for Maximum matchings in bipartite
[14] E. Horowitz and S. Sahni, "Fundamentals of Data Structures In Pascal", Computer Science
York, 1985.
-- --