This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site. Start by pressing the button below!
0) { if (index%2) crosscount += tree[index+1]; index = (index - 1)/2; tree[index]++; } } printf("Number of crossings: %d\n",crosscount); free(tree); Fig. 5. C program fragment for simple bilayer cross counting
Simple and Efficient Bilayer Cross Counting
4
137
Computational Experiments
In order to obtain an impression of how old and the new algorithms for bilayer cross counting perform in direct comparison, we made an empirical study. We implemented the following algorithms in the C programming language as functions and used them in various computational experiments: SAN is the algorithm by Sander [10] that runs in O(|E| + |C|) time and O(|E|) space, WAM is the algorithm by Waddle and Malhotra [12] that runs in O(|E| log |V |) time and O(|E|) space, MER is a merge sorting algorithm (Section 2) that runs in O(|E| log RUN (π)) time and O(|E|) space, INS is a plain insertion sorting algorithm (Section 3, step 1) that runs in O(|E|+ |C|) time and O(|E|) space, BJM is the algorithm of Section 3, step 2, that runs in O(|E| log |Vsmall |) time and O(|E|) space. In order to make the comparison as fair as possible, all C-functions have the same parameters: int p: p is the number of nodes in the northern layer, int q: q is the number of nodes in the southern layer (q ≤ p), int r : r is the number of edges, int∗ NorthNodePos: NorthNodePos[k] ∈ {0, 1, . . . , p − 1} is the position of the northern end node of edge k ∈ {0, 1, . . . , r − 1} in the northern permutation πN , int∗ SouthNodePos: SouthNodePos[k] ∈ {0, 1, . . . , q − 1} is the position of the southern end node of edge k ∈ {0, 1, . . . , r − 1} in the southern permutation πS . No assumption is made about the ordering of the edges, e.g., MER and BJM start by computing southsequence by a two phase radix sort. Likewise, the other algorithms compute the internally needed information from the given data that should be readily available in any reasonable implementation of a Sugiyama-style layout algorithm. Furthermore, the functions are responsible for allocating and freeing temporarily needed space. We made an effort in implementing all five algorithms as well as we could. All experiments were performed under Linux on a SONY VAIO PCG-R600 notebook with an 850 MHz INTEL Mobile Pentium III processor and 256 MB of main memory. The software was compiled by the GNU gcc compiler with optimization option O3. All uniformly distributed random numbers needed in our experiments were generated by the C-function gb unif rand of Donald Knuth’s Stanford GraphBase [7]. In all subsequent plots, data points are averages for 100 instances each. The crossing minimization phase of a Sugiyama-style layout algorithm typically starts with random permutations of the nodes on each layer, and in the
138
Wilhelm Barth, Michael J¨ unger, and Petra Mutzel
course of the computation, the edges become more and more untangled. This means that a bilayer cross counting algorithm is likely to be initially confronted with random permutations πN and πS and later with permutations that induce significantly less crossings. In our experiments, we take this phenomenon into account by running each layer pair twice – first with random permutations and then with permutations generated by a crossing minimization algorithm. The fastest method with good practical results we know is the so-called MEDIAN crossing minimization algorithm [4]. While the node permutation in one of the two layers is temporarily fixed, the nodes of the other layer are reordered according to the median positions of their neighbors in the fixed layer. The MEDIAN heuristic can be implemented to run in O(|E|) time and space. After some experimentation, we decided that four iterations (reorder southern, then northern, then southern, and finally northern layer) give reasonable results. The second run is performed after such a reordering. In our first experiment, we consider sparse graphs with 1,000 to 30,000 nodes on each layer and 2,000 to 60,000 randomly drawn edges. The average running times are plotted in Fig. 6. Here and in the subsequent figures, the suffix “RAN” indicates that the running times are for the instances with random permutations of the two layers and the suffix “MED” indicates that the running times are for the MEDIAN-ordered instances.
Fig. 6. Running time for sparse graphs
The first observation is that SAN and INS are unpractical for large instances while all other procedures have very reasonable running times. This behavior extends to very large graphs as can be seen in Fig. 7 for instances up to 500,000 nodes on each layer and 1,000,000 randomly drawn edges. BJM dominates all other methods for up to about 50,000 nodes both for the “RAN” and for the “MED” instances, for larger instances BJM leads in the “MED” case and MER leads in the “RAN” case. However, the differences are so small that they can
Simple and Efficient Bilayer Cross Counting
139
Fig. 7. Running time for large sparse graphs
possibly be attributed to system or implementation peculiarities, just like the slight peak for 350,000 nodes in Fig. 7. Now we study the behavior of the algorithms for instances of increasing density with 1,000 nodes on each layer. The number of edges grows from 1,000 to 100,000. Fig. 8 shows the results. As before, SAN and INS are not competitive. Up to about 30,000 edges, BJM is the best method and beyond, WAM is slightly better. Finally, we ran the algorithms on a selection of real-world graphs compiled from the AT&T directed graph collection by Michael Kr¨ uger of the Max-PlanckInstitut f¨ ur Informatik in Saarbr¨ ucken. We used the first phase of the AGD Sugiyama implementation in order to obtain layerings with the Longest-Path
Fig. 8. Running time for graphs with increasing density
140
Wilhelm Barth, Michael J¨ unger, and Petra Mutzel
and Coffman-Graham options from which we extracted the resulting layer pairs as test instances. Thus, we compiled two collections of 30,061 instances and 57,300 instances, respectively. For each instance, we applied 10 random shuffles of the northern and southern layers, each followed by a MEDIAN-ordered run as explained above. So we ran a total of 601,220 and 1,146,000 instances of the Longest-Path generated layer pairs and the Coffman-Graham generated layer pairs, respectively. In the Longest-Path case, the number of northern nodes varies between 1 and 6,566, with 63 on the average, the number of southern nodes varies between 1 and 5,755, with 57 on the average, and the number of edges varies between 1 and 6,566, with 64 on the average. For the random shuffles, the number of crossings varies between 0 and 10,155,835, with 24,472 on the average and for the MEDIAN ordered layers, the number of crossings varies between 0 and 780,017, with 182 on the average. In the Coffman-Graham case, the number of northern nodes varies between 1 and 3,278, with 142 on the average, the number of southern nodes varies between 1 and 3,278, with 137 on the average, and the number of edges varies between 1 and 3,276, with 141 on the average. For the random shuffles, the number of crossings varies between 0 and 2,760,466, with 47,559 on the average and for the MEDIAN ordered layers, the number of crossings varies between 0 and 2,872, with 4 on the average.
Fig. 9. Running time for AT&T graphs
The total running times are reported in Fig. 9. The low crossing numbers in the MEDIAN case explain why INS and MER are the clear winners. With very few inversions and very few runs, INS and MER have almost nothing to do while the other methods do not profit much from this fact. We doubt, however, that we picked “typical real world data”. Further experiments may lead to hybrid methods that choose the algorithm according to the problem characteristics. Nevertheless, our experiments indicate that WAM, MER, and BJM are safe choices. It should be kept in mind that the running times of a MEDIAN step and a bilayer cross counting step with one of the fast algorithms are similar, in
Simple and Efficient Bilayer Cross Counting
141
fact, the latter is asymptotically slower. Therefore, bilayer cross counting may dominate the work in the second phase of a Sugiyama-style layout algorithm significantly, unless WAM, MER, BJM, or a method of comparable performance is used.
References 1. B. Chazelle, Reporting and counting segment intersections. Journal of Computer and System Sciences 32 (1986) 156–182. 2. B. Chazelle and H. Edelsbrunner, An optimal algorithm for intersecting line segments in the plane. Journal of the ACM 39 (1992) 1–54. 3. T. H. Cormen, C. E. Leiserson, and R. L. Rivest, Introduction to algorithms. MIT Press, Cambridge, MA, 1990. 4. P. Eades and N. Wormald, Edge crossings in drawings of bipartite graphs. Algorithmica 11 (1994) 379–403. 5. C. Gutwenger, M. J¨ unger, G. W. Klau, S. Leipert, and P. Mutzel, Graph Drawing Algorithm Engineering with AGD. in: S. Diehl (ed.), Software Visualization, International Dagstuhl Seminar on Software Visualization 2001, Lecture Notes in Computer Science 2269, Springer, 2002, pp. 307–323, see also: http://www.mpi-sb.mpg.de/AGD/ 6. M. J¨ unger and P. Mutzel, 2-layer straight line crossing minimization: performance of exact and heuristic algorithms. Journal of Graph Algorithms and Applications 1 (1997) 1–25. 7. D. E. Knuth, The Stanford GraphBase: A platform for combinatorial computing. Addison-Wesley, Reading, Massachusetts, 1993 8. G. S. Lueker, A data structure for orthogonal range queries. Proceedings of the 19th IEEE Symposium on Foundations of Computer Science, 1978, pp. 28–34. 9. G. Sander, Graph Layout through the VCG Tool. in: R. Tamassia and I. G. Tollis (eds): Graph Drawing 1994, Lecture Notes in Computer Science 894, Springer, 1995, pp. 194-205, see also: http://rw4.cs.uni-sb.de/users/sander/html/gsvcg1.html 10. G. Sander, Visualisierungstechniken f¨ ur den Compilerbau. Pirrot Verlag & Druck, Saarbr¨ ucken, 1996. 11. K. Sugiyama, S. Tagawa, and M. Toda, Methods for visual understanding of hierarchical system structures. IEEE Transactions on Systems, Man, and Cybernetics 11 (1981) 109–125. 12. V. Waddle and A. Malhotra, An E log E line crossing algorithm for levelled graphs. in: J. Kratochv´ıl (ed.) Graph Drawing 1999, Lecture Notes in Computer Science 1731, Springer, 1999, pp. 59–70.
Orthogonal 3D Shapes of Theta Graphs Emilio Di Giacomo1 , Giuseppe Liotta1 , and Maurizio Patrignani2 1 Universit` a di Perugia, Italy {digiacomo,liotta}@diei.unipg.it 2 Universit` a di Roma Tre, Italy [email protected]
Abstract. The recent interest in three dimensional graph drawing has been motivating studies on how to extend two dimensional techniques to higher dimensions. A common approach for computing a 2D orthogonal drawing of a graph separates the task of defining the shape of the drawing from the task of computing its coordinates. First results towards finding a three-dimensional counterpart of this approach are presented in [8,9], where characterizations of orthogonal representations of paths and cycles are studied. In this note we show that the known characterization for cycles does not immediately extend to even seemingly simple graphs such as theta graphs. A sufficient condition for recognizing three-dimensional orthogonal representations of theta graphs is also presented.
1
Introduction
The recent interest in three-dimensional graph drawing has been motivating studies on how to extend two dimensional techniques to 3D space. Work in this direction includes extensions of simulated annealing techniques, spring embedder techniques, and incremental techniques (see e.g., [3,5,11,15]). However, while a rich body of literature is devoted to three-dimensional orthogonal drawings, little is known on the challenging task of extending to 3D the well-known topologyshape-metrics approach [18]. In order to reach such an ambitious research target, a crucial step is to find a three-dimensional counterpart of the well-known two-dimensional characterization of orthogonal representations (see, e.g. [18,19]). More precisely, a solution to the following problem has to be found. Let G be a graph such that each edge is directed and labeled with a label in the set {U p, Down, East, W est, N orth, South}. Does a three-dimensional orthogonal drawing of G exist such that no two edges intersect and each edge has a direction consistent with its associated label? This question has been addressed by Di Battista et al. [7,8,9] for simple classes of graphs, namely paths and cycles. The goal of this note is to shed some more light on the above basic question. Namely, we show that the known
Work partially supported by European Commission - Fet Open project COSIN IST2001-33555 and by “Progetto Giovani Ricercatori: Algoritmi per la Visualizzazione di Grafi di Grandi Dimensioni” of the University of Perugia, Italy.
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 142–149, 2002. c Springer-Verlag Berlin Heidelberg 2002
Orthogonal 3D Shapes of Theta Graphs
143
characterization for cycles does not immediately extend to even seemingly simple graphs such as theta graphs, that is, graphs composed by two nodes of degree three and three disjoint paths, of length at least two, joining them. Also, we give a sufficient condition for recognizing three-dimensional orthogonal representations of theta graphs. We remark that theta graphs have been studied extensively in the literature. For example, they arise in problems concerning graph planarity (see, e.g., [1,4,17]), graph bandwidth (see, e.g., [12,14,16]), and chromatic polynomials (see, e.g., [2]).
2
Preliminaries
We assume familiarity with basic graph drawing terminology (see, e.g. [6]). A direction label is a label in the set {U, D, E, W, N, S} specifying the directions Up, Down, East, West, North, South, respectively. Three distinct labels are also used to identify an octant of the reference system, which is assumed to be open. Let e be an undirected edge of a graph whose end-vertices are u and v. We use the term darts for the two possible orientations (u, v) and (v, u) of edge e. A 3D shape graph γ is an undirected labeled graph such that (i) each dart is associated with one direction label; (ii) the two darts of the same edge have opposite labels; and (iii) each label in the set {U, D, E, W, N, S} appears at least once in γ. A three dimensional orthogonal drawing of a graph is such that vertices are mapped to grid points of an integer three dimensional grid and edges are segments along the integer grid lines connecting the end points. An intersection in a three dimensional orthogonal drawing is a pair of edges that overlap in at least a point that does not correspond to a common end-vertex. A 3D shape graph γ is simple if there exists an orthogonal drawing Γ of γ such that no two edges of Γ intersect and each oriented edge satisfies the direction constraint defined by the direction labels associated with its darts. The simplicity testing problem for a 3D shape graph γ is to decide whether γ is simple. Obviously, if γ is simple, no vertex of γ has two entering (or leaving) darts with the same label. For example, this implies that no vertex of γ can have degree greater than six. Also, we restrict our attention to the class of shape graphs that do not have vertices of degree two whose entering darts are given opposite direction labels, since it can be shown (we omit the details for the sake of brevity) that each instance for which this property does not hold has an equivalent instance in this class. Let γ be a 3D shape graph. A flat F ⊂ γ is a connected subgraph of γ that is maximal with respect to the property that in every orthogonal drawing with the shape of γ all edges in F are co-planar. Observe that the labels of γ come from the union of two oppositely directed pairs of directions. Also, the definition above extends the analogous definitions given in [7,8,9].
144
Emilio Di Giacomo, Giuseppe Liotta, and Maurizio Patrignani
Let π be a 3D shape path with vertices p1 , p2 , . . . , pk and suppose to walk along π from p1 to pk . The label path of π, denoted by σπ , is the sequence of labels associated with darts (p1 , p2 ), . . . , (pi , pi+1 ), . . . ,(pk−1 , pk ). Similarly, let C be a 3D shape cycle with vertices p1 , p2 , . . . , pk and suppose to walk along C from p1 to pk . The label cycle of C, denoted by σC , is the sequence of label associated with darts (p1 , p2 ), . . . , (pi , pi+1 ), . . . , (pk−1 , pk ), (pk , p1 ). Given a label path or cycle σ, a not necessarily consecutive subsequence τ ⊆ σ, where τ consists of k elements, is a canonical sequence [9,8] provided that: (i) 1 ≤ k ≤ 6; (ii) the labels of τ are distinct; (iii) no flat of σ contains more than three labels of τ ; and (iv) if a flat F of σ contains one or more labels of τ , then τ ∩ F form a consecutive subsequence of σ. The following basic result for paths is given in [9]: Theorem 1. [9] Let π be a 3D shape path with vertices p1 , p2 , . . . , pk and let σπ be the label path associated with the sequence of darts (p1 , p2 ), . . . , (pi , pi+1 ), . . . , (pk−1 , pk ). Shape path π admits an intersection free orthogonal drawing with p1 at the origin and pk in the UNE octant if and only if σπ contains a canonical sequence of three labels in the set {U, N, E}. A characterization of simple shape cycles is given in [8]: Theorem 2. [8] A 3D shape cycle C described by a sequence of direction labels σC is simple if and only if it contains a canonical sequence of length six. A theta graph is a graph with two non adjacent nodes of degree three and all other nodes of degree two [13]. Thus, a theta graph consists of two nodes of degree three and three disjoint paths, of length at least two, joining them. We will call 3D theta shape a 3D shape for a theta graph. In the following we will denote by p and q the two degree-three nodes of a theta shape. Also, given a shape path πx from p to q, and a shape path πy from q to p, we denote Cx,y the shape cycle obtained by joining πx and πy . Observe that given a theta shape, three paths πx , πy , and πz , and three cycles Cx,y , Cx,z , and Cy,z , are defined.
3
A Forbidden Theta Shape
In this section we show that the simplicity of the cycles composing a theta shape does not imply the simplicity of the theta shape itself. We use the following notation: given a shape path π (say DW U N E) we will denote by π (DW U N E in the example) the shape path obtained by orienting each edge in the opposite direction and changing its label with the opposite one (DW U N E = W SDEU ). Also, we will use a dot to denote a series composition of paths (for example π1 = π2 · π 3 ). Given two distinct vertices v and w of a shape path (shape cycle, theta shape, respectively) γ, we say that v is Y with respect to w, where Y ∈ {U, D, E, W, N, S}, if in any drawing of γ, denoted Πv and Πw the two planes orthogonal to Y containing v and w respectively, the two planes may be joined by a segment oriented from Πw to Πv which has direction Y . Observe that, if v is Y with respect to w, w is Y with respect to v.
Orthogonal 3D Shapes of Theta Graphs
145
Ez D
❄
U✻
a
N ✒
b
Ez
q
N ✒
Ez
B
N ✒
δ (B,e,W)
U✻
✛W p U✻ ✛ W
N ✒ D
δ (B,e,U) δ (B,e,E)
e
❄
(a)
δ (B,e,D)
(b)
Fig. 1. (a) A not simple theta shape and (b) the definition of δ(B, e, X).
Theorem 3. There exists a 3D shape graph that is not simple even if all its induced cycles are simple. Proof. Let ϑ be the theta shape composed by the three paths: π1 = W N U ED, π2 = DW U N E, and π3 = N U EN (see Fig. 1.a). The three cycles C1,2 , C1,3 , and C2,3 defined by ϑ are simple. Namely, we have: C1,2 = W N U ED · DW U N E = W N U EDW SDEU C1,3 = W N U ED · N U EN = W N U EDSW DS C2,3 = DW U N E · N U EN = DW U N ESW DS and each of them satisfies the hypotheses of Theorem 2. In fact, C1,2 contains, for example, the canonical sequence identified by the checked labels in the ˇ U ED ˇW ˇ SD ˇ E ˇU ˇ ; C1,3 contains, for example, the canonical sequence sequence W N ˇU ˇ ED ˇ SˇW ˇ DS; ˇ and C2,3 conidentified by the checked labels in the sequence W N tains, for example, the canonical sequence identified by the checked labels in the ˇU ˇN ˇ ESW ˇ ˇ S. ˇ sequence DW D Suppose for a contradiction that ϑ is simple. Consider a non intersecting orthogonal drawing Γ of ϑ. Let σ be the label path EN U EN W from a to b. By Theorem 1, since the only canonical sequences of length three contained in σ are of type NUW or NUE, then b is NUW or NUE with respect to a in each non intersecting drawing of σ. Let σ be the label path N U EDW from a to b. By Theorem 1, since the only canonical sequences of length three contained in σ are of type NUE, NDE, or NDW, then b is NUE, NDE, or NDW with respect to a in each non intersecting drawing of σ . Let σ be the label path EDW U N from a to b. By Theorem 1, since the only canonical sequences of length three contained in σ are of type NUW, NDE, or NDW, then b is NUW, NDE, or NDW with respect to a in each non intersecting drawing of σ . We have a contradiction, the three conditions above can not be simultaneously verified and thus one intersection necessarily occurs.
146
4
Emilio Di Giacomo, Giuseppe Liotta, and Maurizio Patrignani
Triply Expanding Drawings
Let π1 , π2 , . . . , πn be n shape paths starting from a common point p. Denote by mi the number of edges of πi , and by ei,h , with h = 1, . . . , mi , the h-th edge of πi starting from p. An expanding drawing of π1 , π2 , . . . , πn is a simple 3D orthogonal drawing for which edges e1,m1 , e2,m2 , . . . , en,mn can be replaced by arbitrarily long segments without creating any intersection with the drawing. The bounding box of an expanding drawing is the bounding box of the drawing when edges e1,m1 , e2,m2 , . . . , en,mn are removed. In [8] Di Battista et al. showed the following sufficient condition for the existence of an expanding drawing of two paths (doubly expanding drawing). Theorem 4. [8] A shape path π with n edges admits a doubly expanding drawing if it either consists of exactly two edges or contains at least two flats. A triply expanding drawing is an expanding drawing of three paths. The next theorem extends Theorem 4 to triply expanding drawings. Theorem 5. Let πx , πy , and πz be three shape paths starting from a common point p. If the paths πx · πy , πx · πz , and πy · πz consist of exactly two edges or contain at least two flats, then πx , πy , and πz admit a triply expanding drawing. Due to space limitations we omit the proof of Theorem 5 and refer to [10] the interested reader. Roughly, the theorem can be proved by construction, after a suitable case analysis, and by using the following lemma. Lemma 1. A shape graph γ that admits a three dimensional orthogonal drawing such that no intersection occurs between two edges of the same flat is simple. Proof. The statement can be proved by construction. Namely, given a three dimensional orthogonal drawing Γ such that no intersection occurs between two edges of the same flat, an iterative process can be used to produce an orthogonal drawing Γ without intersections. Consider an intersection between two edges e1 and e2 that do not belong to the same flat. The following technique eliminates the intersection, without introducing a new one. Consider a plane p common to e1 and e2 and a direction d orthogonal to p. Move one unit in the d direction all the nodes in the open half-space determined by p and d, the end-points of e1 , and the end-points of all the edges of the flat F of e1 perpendicular to d, if any. It can be shown that the obtained drawing is a 3D orthogonal drawing of γ, that the intersection between e1 and e2 has been removed, and that no other intersection has been introduced (see [10] for details). By virtue of the preceding lemma, intersections occurring between edges (and nodes) that do not share a flat can be neglected, assuming that they could be easily eliminated in a post processing step.
Orthogonal 3D Shapes of Theta Graphs
5
147
A Sufficient Condition for Theta Shapes Simplicity
Let Θ be a theta shape composed by three shape paths π1 , π2 , and π3 from point p to point q. Let eij , with j = 1, . . . , mi , the j-th edge of πi . In the following we denote by lij the label associated with eij when directed according to πi . Recall that when πi is reversed, as in Ck,i = πk · πi , the label associated with eij is the opposite of lij , that is lij . Theorem 6. Let Θ be a theta shape composed by three shape paths π1 , π2 , and π3 from point p to point q. If for each πi there exist three edges ei1 , ei2 , and ei3 , such that for each pair of paths πi and πj , i, j = 1, 2, 3, i = j, the six labels li1 , li2 , li3 , lj1 , lj2 , and lj3 form a canonical sequence τi,j for the shape cycle Ci,j = πi · πj , then Θ is simple . Proof. By using the canonicity of τ1,2 , τ1,3 , and τ2,3 , the following properties for labels lij can be verified: 1. The labels lij of the same path are different, i.e., lij = lik , i, j, k = 1, 2, 3, j = k. 2. No two labels lij of the same path are opposite, i.e., lij = lik , i, j, k = 1, 2, 3, j = k. 3. No two labels lij of different paths are opposite, i.e., lij = lhk , i, j, h, k = 1, 2, 3, i = h. It follows that, for each i = 1, 2, 3, labels li1 li2 li3 are a permutation of the same three labels, one for each oppositely directed pair. We assume, without loss of generality, that lij ∈ {U, N, E} with i, j = 1, 2, 3. The nine edges eij (i, j = 1, 2, 3) bound eight connected subgraphs of the theta graph. We call Gi,j the subpath of πi from eij to ei(j+1) , (i = 1, 2, 3, j = 1, 2). Further, we call Gp the subgraph composed by the three paths from p to ei1 with i = 1, 2, 3, and Gq the subgraph composed by the three paths from ei3 with i = 1, 2, 3 to q. Observe that Gi,j , with i = 1, 2, 3, and j = 1, 2 admits a doubly expanding drawing. In fact, since the labels associated with eij and ei(j+1) are canonical, it follows that, if they are not consecutive, they do not share a flat, and Theorem 4 applies. Also, observe that Gp admits a triply expanding drawing. In fact, since, for each pair i, j, ei1 and ej1 are canonical in Ci,j , it follows that, if they are not consecutive, they do not share a flat, and Theorem 5 applies. Analogously, Gq admits a triply expanding drawing. We draw a doubly expanding drawing Γi,j for each Gi,j , with i = 1, 2, 3, and j = 1, 2.Theorem 4. Let L be the maximum length of a side of a bounding box of the drawings obtained above. We draw a triply expanding drawing Γp of Gp and a triply expanding drawing Γq of Gq . Now we show how to set the lengths λij , i, j = 1, 2, 3, of the part of each edge eij that is not contained in the bounding box of any expanding drawing, since the actual lengths of the edges can be easily computed from it. Denote by Bp , Bq , and Bi,j , with i = 1, 2, 3 and j = 1, 2, the bounding boxes of Γp , Γq , and Γi,j , respectively. Since edges ei1 , with i = 1, 2, 3, have labels in
148
Emilio Di Giacomo, Giuseppe Liotta, and Maurizio Patrignani
{U, N, E}, there are three pairwise orthogonal sides of Bp from which edges ei1 may come out. Denote by vBp the only point common to these sides. Denote by vBq the point common to the analogous sides of Bq . Place the drawings Γp and Γq in such a way that vBp has coordinates (−2L − 1, −2L − 1, −2L − 1) and vBq has coordinates (2L + 1, 2L + 1, 2L + 1). Now we show how to add the drawing of Γi,1 and Γi,2 , for i = 1, 2, 3. Given a bounding box B, an edge e protruding from it, and a direction label X orthogonal to e, we denote by δ(B, e, X) the distance of e from the side of B in the X direction (see Figure 1.b). We determine λij , with i, j = 1, 2, 3, by considering the following equalities. λi,1 = 4L + 2 + δ(Bq , ei3 , li1 ) − δ(Bi,2 , ei3 , li1 )+ +δ(Bi,2 , ei2 , li1 ) − δ(Bi,1 , ei2 , li1 )
(1)
λi,2 = 4L + 2 + δ(Bp , ei1 , li2 ) + δ(Bq , ei3 , li2 )− −δ(Bi,1 , ei1 , li2 ) − δ(Bi,2 , ei3 , li2 )
(2)
λi,3 = 4L + 2 + δ(Bp , ei1 , li3 ) − δ(Bi,1 , ei1 , li3 )+ +δ(Bi,1 , ei2 , li3 ) − δ(Bi,2 , ei2 , li3 )
(3)
Now we show that no intersection between edges sharing a flat has been introduced in the drawing. By Theorems 4 and 5 no intersection occurs in each (doubly or triply) expanding drawing. There is no intersection between two edges of the same πi . In fact, since 0 ≤ δ(Bi,j , e, X) ≤ L, and by equations 1, 2, and 3, each λij , with i, j = 1, 2, 3 is at least 2L + 2 and each one of Bp , Bq , Bi,1 , and Bi,2 is in a different octant. Intersections between edges belonging to different paths involve edges that do not share a flat, and thus, by Lemma 1, can be removed. Indeed, suppose for a contradiction that ex and ey are two intersecting edges belonging to two different paths πx and πy and that ex and ey are on the same flat F . Edges ex and ey do not belong to the same expanding drawing, since otherwise they could not intersect. There must exist a path π ∗ joining ex and ey , entirely contained in F , and containing p or q. In π ∗ there can be at most three of the edges eij , with i = x, y, and j = 1, 2, 3, since otherwise there would be more than three canonical labels on the same flat for the cycle Cx,y , contradicting the hypothesis that τx,y is a canonical sequence. Since edges eij in π ∗ are on the same flat F and are canonical, they are necessarily adjacent, and thus if they are consecutive they are orthogonal with each other. If ex and ey coincide with two edges eij , then they can not intersect since they are parallel or adjacent and orthogonal. Otherwise, since edges eij are the only ones to transition between octants, then ex and ey belong to two different octants and they can not intersect.
Orthogonal 3D Shapes of Theta Graphs
149
References ˇ an 1. D. S. Archdeacon and J. Sir´ ˇ. Characterizing planarity using theta graphs. J. Graph Theory, 27:17–20, 1998. 2. J. Brown, C. Hickman, A. Sokal, and D. Wagner. On the chromatic roots of generalized theta graphs. J. of Combinatorial Theory, Series B, to appear. 3. I. Bruß and A. Frick. Fast interactive 3-D graph visualization. In F. J. Brandenburg, editor, Graph Drawing (Proc. GD ’95), volume 1027 of Lecture Notes Comput. Sci., pages 99–110. Springer-Verlag, 1996. 4. G. Chartrand and F. Harary. Planar permutation graphs. Ann. Inst. H. Poincar´e, Sect B, 3:433–438, 1967. 5. I. F. Cruz and J. P. Twarog. 3D graph drawing with simulated annealing. In F. J. Brandenburg, editor, Graph Drawing (Proc. GD ’95), volume 1027 of Lecture Notes Comput. Sci., pages 162–165. Springer-Verlag, 1996. 6. G. Di Battista, P. Eades, R. Tamassia, and I. G. Tollis. Graph Drawing. Prentice Hall, Upper Saddle River, NJ, 1999. 7. G. Di Battista, G. Liotta, A. Lubiw, and S. Whitesides. Embedding problems for paths with direction constrained edges. In Annual International Computing and Combinatorics Conference, (COCOON 2000), volume 1858 of Lecture Notes Comput. Sci., pages 64–73. Springer-Verlag, 2000. 8. G. Di Battista, G. Liotta, A. Lubiw, and S. Whitesides. Orthogonal drawings of cycles in 3d space. In J. Marks, editor, Graph Drawing (Proc. GD ’00), volume 1984 of Lecture Notes Comput. Sci. Springer-Verlag, 2001. 9. G. Di Battista, G. Liotta, A. Lubiw, and S. Whitesides. Embedding problems for paths with direction constrained edges. J. of Theor. Comp. Sci., 2002. to appear. 10. E. Di Giacomo, G. Liotta, and M. Patrignani. On orthogonal 3d shapes of theta graphs. Tech. Report RT-DIA-71-2002, Dept. of Computer Sci., Univ. di Roma Tre, 2002. http://web.dia.uniroma3.it/research/. 11. D. Dodson. COMAIDE: Information visualization using cooperative 3D diagram layout. In F. J. Brandenburg, editor, Graph Drawing (Proc. GD ’95), volume 1027 of Lecture Notes Comput. Sci., pages 190–201. Springer-Verlag, 1996. 12. D. Eichhorn, D. Mubayi, K. O’Bryant, and D. B. West. Edge-bandwidth of theta graphs. J. Graph Theory, 35:89–98, 2000. 13. F. Harary. Graph Theory. Addison-Wesley, Reading, Mass., 1969. 14. T. Jiang, D. Mubayi, A. Shastri, and D. B. West. Edge-bandwidth of graphs. SIAM Journal on Discrete Mathematics, 12(3):307–316, 1999. 15. A. Papakostas and I. G. Tollis. Algorithms for incremental orthogonal graph drawing in three dimensions. Journal of Graph Algorithms and Applications, 3(4):81– 115, 1999. 16. G. Peck and A. Shastri. Bandwidth of theta graphs with short paths. Discrete Mathematics, 103, 1992. 17. I. Sciriha and S. Fiorini. On the characteristic polynomial of homeomorphic images of a graph. Discrete Mathematics, 174:293–308, 1997. 18. R. Tamassia. On embedding a graph in the grid with the minimum number of bends. SIAM J. Comput., 16(3):421–444, 1987. 19. G. Vijayan and A. Wigderson. Rectilinear graphs and their embeddings. SIAM J. Comput., 14:355–372, 1985.
Separating Thickness from Geometric Thickness David Eppstein Dept. of Information and Computer Science University of California, Irvine Irvine, CA 92697-3425, USA [email protected]
Abstract. We show that graph-theoretic thickness and geometric thickness are not asymptotically equivalent: for every t, there exists a graph with thickness three and geometric thickness ≥ t.
1
Introduction
The graph-theoretic property of thickness and its variants formalize the concept of layered graph drawing, in which a graph must be drawn in multiple layers (or with multiple colors) so that each edge belongs to a single layer and no two edges in the same layer cross. The vertices of the graph should be represented as points and should exist in the same positions in each layer. There are three important variants of thickness: – The thickness of a graph G, denoted θ(G), is the minimum number of layers for which a drawing of G exists, without restriction on the number of bends per edge [11]. ¯ – The geometric thickness of a graph G, denoted θ(G), also known as real linear thickness, is the minimum number of layers for which a drawing exists without any bends in the edges: each edge must be represented as a straight line segment [5, 11]. – The book thickness of a graph G, denoted bt(G), is the minimum number of layers for which a drawing exists without any bends in the edges and with all vertices placed in convex position [4]. Since each variant imposes additional constraints on the previous one, these ¯ parameters are always ordered: θ(G) ≤ θ(G) ≤ bt(G), and it is of interest to determine how tight these inequalities are. Due to F´ ary’s theorem [7], the graphs with thickness one and geometric thickness one coincide (both are just the planar graphs), and are a strict superset of the graphs with book thickness one (the outerplanar graphs). Thickness and geometric thickness were known to differ for infinitely many graphs: in particular, complete graphs on n vertices have thickness n/6 + O(1) [1, 2, 3, 13, 14] but have geometric thickness ≥ n/5.646 [5]. In previous work [6] we showed that book thickness can not be bounded by any function of the geometric thickness: for any t there exists a graph with geometric M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 150–162, 2002. c Springer-Verlag Berlin Heidelberg 2002
Separating Thickness from Geometric Thickness
151
Fig. 1. Graph Gz (8) drawn with geometric thickness two.
>
thickness two and book thickness t . Therefore, one can not hope to find nearoptimal bend-free layered drawings by placing all vertices in convex position. In this paper, we prove a similar separation between thickness and geometric thickness: for any t there exists a graph with thickness three and geometric thickness t . This implies that known strategies for approximating thickness (layered drawing with bends) will not lead to good approximation algorithms for layered drawing without bends.
>
2
Proof Outline
The overall outline of our proof is very similar t o our previous result, separating geometric thickness from book thickness, so as a warmup we review that result.
Theorem 1 (Eppstein [6]). For every t , a graph exists ,with geometric thickness two and book thickness > t .
+
Proof. For any 7% > 0, define a graph G 2 ( n ) having as its n )(; vertices the singleton and doubleton subsets of an n-element set, with an edge between two subsets when one is contained in the other. G 2 ( n )can be drawn with geometric thicksless two using a construction related t o a one-bend drawing algorithm of Wood [15]; a two-layer drawing of G2(8) is shown in Figure 1. However, G2(5) is nonplanar (it is formed by subdividing each edge of the nonplanar complete graph K 5 ) so it has book thickness greater than two. By Ramsey theory (Lemma I ) , there exists an no such that, if the edges of G 2 ( n o )are given t - 1 colors, one can find a two-colored G2(5) subgraph. If the (t - 1)-coloring is determined by a book embedding with t - 1 layers, the subgraph would have a twelayer book embedding. Since no such two-layer embedding exists, G2(no)does not have a (t - 1)-layer book embedding.
152
David Eppstein
Fig. 2. Graph G3 (5). The circular vertices represent singleton subsets, and the triangular vertices represent tripleton subsets.
Our main result is the following theorem. Theorem 2. For every t, a graph exists with thickness three and geometric thickness ≥ t. Proof. For any n > 0, define a graph G3 (n) having as its n + n3 vertices the singleton and tripleton subsets of an n-element set, with an edge between two subsets when one is contained in the other. G3 (4) forms the vertices and edges of a cube; G3 (5) is depicted in Figure 2. If we assign the edges of G3 (n) to three layers, in such a way that the three edges incident to each tripleton are assigned to different layers, then each layer will form a forest of stars, which is a planar graph, so G3 (n) has thickness at most three. We show that there exists an n1 such that G3 (n1 ) has geometric thickness more than three (Lemma 19). By Ramsey theory (Lemma 1), there exists n2 such that, if the edges of G3 (n2 ) are given t − 1 colors, it has a three-colored G3 (n1 ) subgraph. If the (t − 1)-coloring is determined by a (t − 1)-layer geometric embedding, the subgraph would have a three-layer geometric embedding. Since no such three-layer embedding exists, G3 (n2 ) does not have a (t − 1)-layer geometric embedding. The difficult part of our proof is Lemma 19, showing that some G3 (n) has geometric thickness greater than three. The proof involves a complicated case analysis, with Ramsey theory used again at several stages in order to show that, if a thickness-three drawing existed, one could find a drawing with a simplified form that can be shown not to exist.
3
Ramsey Theory
We use the following classical result from Ramsey theory [?, Theorem 2]: Lemma 1. For every three positive integers c, e, and there is an integer Re ( ; c) with the following property: if |S| ≥ Re ( ; c) and the e-element subsets of S are partitioned into c classes, then there exists a set T ⊂ S with |T | ≥ so that all e-element subsets of T belong to the same class.
Separating Thickness from Geometric Thickness
153
+ t − 1, e = 2, For instance, in the proof of Theorem 1, we choose c = t−1 2 and = 5. The set S is the set of singletons in G2 (n0 ), and the doubletons in G2 (n0 ) are partitioned into c classes by the colors of their two incident edges. The Lemma tells us that we can find a two-colored G2 (5) subgraph of G2 (n0 ). Similarly, in Theorem 2 we can find a three-colored G3 (n1 ) subgraph of G3 (n2 ). We also use another well-known Ramsey-theoretic result [?, pp. 24–25]: Lemma 2. For every integer k there is an integer N (k) with the following property: if N (k) points are placed in the plane with no three points colinear, then some subset of k points form the vertices of a convex polygon.
4
Coherent Drawings
Define a convex drawing of G3 (n) to be a drawing with geometric thickness three in which all singletons are in convex position. We do not restrict the positions of the tripletons. Lemma 3. If every graph G3 (n) has geometric thickness three, then every G3 (n) has a convex drawing. Proof. Small perturbations of the vertex locations in a layered drawing will not create or remove crossings, so we can assume no three vertices are colinear. To form a convex drawing of G3 (n), apply Lemma 2 to the singletons of G3 (N (n)), and form a G3 (n) subgraph from the resulting convex set of n singletons and their adjacent tripletons. We number the singleton vertices of a convex drawing in clockwise order from 0 to n − 1, starting from an arbitrarily chosen vertex. Using this numbering, we can partition the edges of G3 (n) into three classes: a low edge connects a tripleton to the adjacent singleton with the smallest number, a high edge connects a tripleton to the adjacent singleton with the largest number, and a middle edge connects a tripleton to the remaining adjacent singleton. Define a coherent drawing of G3 (n) to be a convex drawing in which these three classes form the three layers of the drawing. Lemma 4. If every graph G3 (n) has geometric thickness three, then every G3 (n) has a coherent drawing. Proof. By Lemma 3 we can assume G3 (n) has a convex drawing. Partition the tripletons of such a drawing into 27 classes according to the layers to which the incident low, middle, and high edges belong. By Lemma 1 with c = 27 and e = 3, we can find a drawing in which each of the three sets of edges belongs to a single layer. If this results in more than one set belonging to the same layer, we can move sets to distinct layers without introducing any crossings. In a coherent drawing, we will denote tripletons by triples of symbols abc, where each letter denotes the position of an adjacent singleton in the clockwise ordering of the drawing, and a < b < c according to the clockwise ordering.
154
David Eppstein
Fig. 3. Five tripletons crossing each other convexly (left) or concavely (right), from Lemma 6.
5
Restriction t o Outer Drawings
Define an inner drawing of G3(n) to be a coherent drawing such that some strictly convex curve C passes through all singletons and contains all tripletons. Similarly, define an outer drawing to be a coherent drawing such that some strictly convex curve C passes through all singletons and contains no tripletons. A drawing can be both inner and outer, for instance if all vertices are in convex position. In an inner drawing, all edges are contained in C; however an edge in an outer drawing may have portions inside C and portions outside C .
Lemma 5. Suppose two tripletons abc and def are part of a n inner drawing, with a < d < c < f . T h e n either the low edge of abc crosses the high edge of de f , or the high edge of abc crosses the low edge of de f . However, both types of crossing can not occur simultaneously. Proof. Consider the two paths formed by the low and high edges of each tripleton. These paths cross C and each path separates the endpoints of the other path; therefore the paths cross an odd number of times. However, each pair of edges can cross only once, and the only types of crossing permitted are those described in the lemma, so exactly one of these crossings occurs.
We say that the two tripletons cross convexly if the low edge of abc crosses the high edge of de f , and that they cross concavely in the other case of Lemma 5.
Lemma 6. There exists a n n3 such that G3(n3) does not have a n inner drawing. Proof. Let n be sufficiently large, and assume for convenience that n = 2 (mod 4). Consider the sequence of tripletons 2i, n/2, n/2 2i 2 for 0 i < n/2 - 2; each pair of tripletons meets the conditions of Lemma 5. By applying Lemma 1 with c = 2, e = 2, and t = 5, for sufficiently large n , we can obtain a set of five such triples that all cross convexly or all cross concavely. As Figure 3 shows, in either case, the low and high edges of these crossing triples form a grid
+ +
<
Separating Thickness from Geometric Thickness
155
Fig. 4. Forced crossings in an inner drawing, from Lemma 6.
graph, containing a complete 2 × 2 subgrid. (The quadrilaterals of this grid need not always be convex, but this does not affect our argument.) Because we chose tripletons using only every other singleton from the ordering, it is now possible to find singletons a and b that lie between the three low edges forming the 2 × 2 subgrid, and e and f that lie between the three high edges forming the subgrid (Figure 4). Therefore, any tripleton with a low edge to a or b and a high edge to e or f must be forced to lie within a particular square of the subgrid. Extend the two middle line segments of the subgrid into lines across curve C (the thin dotted lines of the figure), partitioning C into three curves: the curve clockwise of both extended lines, the curve counterclockwise of the extended lines, and the curve between the two lines. The four points n/2 − 2, n/2 − 1, n/2, n/2 + 1 lie between b and e, and by the pigeonhole principle we can find two of these points c < d that are both within the same one of these three curves. If c and d are both in the center curve of the three curves (shown in the left side of the figure) then tripletons ace and bdf must have crossing middle edges. If c and d are both in the counterclockwise curve (shown on the right side of the figure), then tripletons adf and bce must have crossing middle edges; the case in which c and d belong to the clockwise curve is symmetric. Thus, in all cases two tripletons have crossing middle edges, contradicting the assumption that we have a three-layer drawing with no crossings. Lemma 7. If every graph G3 (n) has geometric thickness three, then every G3 (n) has an outer drawing. Proof. Assume without loss of generality that n is sufficiently large that, by Lemma 6, no inner drawing of G3 (n) exists. Let r = R3 (n; 2), as shown to exist in Lemma 1. By Lemma 4, we can assume G3 (r) has a coherent drawing. Let C be the convex hull of the singletons of this drawing, and perturb C if necessary so that it remains convex and does not pass through any tripletons. Partition the tripletons of the drawing into two classes according to whether they are inside or outside C, and apply Lemma 1 with c = 2 and e = 3 to find a drawing
156
David Eppstein
Fig. 5. Left: Forced crossing in an outer drawing of type 201, from Lemma 9. Right: Sharp angles in an outer drawing of type 021, from Lemma 10.
of G3 (n) in which all triples are inside C or all triples are outside C. Since no inner drawing exists, all triples are outside C, and we have an outer drawing of G3 (n).
6
Classification of Outer Drawings
In an outer drawing, the three angles formed by the three edges incident to a tripleton must include an angle greater than 180◦ , and we can order the three edges clockwise starting at this large angle. Define the type of a tripleton to be a symbol xyz, where x, y, and z form a permutation of 0, 1, and 2, and where the positions of the low, middle, and high number in the symbol are the same as the positions of the low, middle, and high edge in the clockwise ordering at the tripleton. There are six possible types: 012, 021, 102, 120, 201, and 210. If all tripletons in a drawing have the same type xyz, we say that the drawing is of type xyz. Lemma 8. If every graph G3 (n) has geometric thickness three, then every G3 (n) has an outer drawing in which all tripletons have the same type. Proof. By the previous lemma, we can assume that we have an outer drawing with sufficiently many vertices, to which we can apply Lemma 1 with c = 6 and e = 3. We now successively analyze each type of outer drawing and show that, for sufficiently large n, each type must lead to a crossing. Lemma 9. For n ≥ 4, G3 (n) has no outer drawing of type 201 or 120. Proof. In a drawing of type 201, each low edge of a tripleton must cross the convex curve C between the middle and high sigletons adjacent to the tripleton. Therefore, in a drawing of G3 (4), the low edge from tripleton 012 would cross the low edge from tripleton 123, as shown in Figure 5. Type 120 is equivalent
Separating Thickness from Geometric Thickness
157
to type 201 under mirror reversal of the drawing and reversal of the clockwise ordering of the singletons. Lemma 10. In any outer drawing of G3 (4) of type 021, let θi denote the angle at singleton i on the convex hull of the singletons. Then θ1 + θ2 < 180◦ . Proof. In order to be of type 021, tripleton 012 must lie in a wedge outside C bounded by lines 02 and 12 (the shaded area on the upper right of Figure 5). The low edge e0 from 0 to 012 crosses line 12 on the boundary of this wedge. Similarly, the low edge e1 from 1 to tripleton 123 crosses line 23. In order for e1 to reach this line without crossing e0 , tripleton 123 must be clockwise from singleton 0 as viewed from singleton 1, so angle 123-1-2 must be greater than θ1 . But in order for the crossing of e1 with line 23 to be on the boundary of the wedge containing 123 (shown as the lower shaded area in the figure), angle 123-1-2 must be less than 180◦ − θ2 . Combining these two inequalities gives the result. Lemma 11. For n ≥ 6, G3 (n) has no outer drawing of type 021 or 102. Proof. By applying Lemma 10 twice, θ1 + θ2 + θ3 + θ4 < 360◦ , but this is not possible in a convex polygon. Type 102 is equivalent to type 021 under mirror reversal. Lemma 12. In an outer drawing of G3 (n) of type 012, the middle edges adjacent to singletons 2, 3, . . ., n − 3 all pass across line segment 0-(n − 1). Proof. By the assumption that the drawing is of type 012, the middle edges of the tripletons 0i(n − 1) all pass across this segment (Figure 6, left). In any other singleton abc, the middle edge must pass from b across line segment ac within the convex curve C. Unless b = 1 or b = n − 2, this crossing with ac must occur within a strip bounded by two of the middle edges of tripletons 0i(n − 1), and the only way for the middle edge from b to exit C is at the end of this strip, where it meets segment 0-(n − 1). Lemma 13. Suppose we have an outer drawing of G3 (n) of type 012, in which all middle edges cross segment 0-(n − 1). Draw a tangent line to convex curve C parallel to line 0-(n − 1), on the opposite side of C from that line, and let h be a point where the tangent line touches C. Then, for every tripleton ijk where i is clockwise from h, the low edge from i to ijk crosses C either at a point counterclockwise from h or between singletons 0 and n − 1. Proof. By the assumption of the drawing type, all low edges must cross line 0n − 1 to the left of the crossing point of the middle edge, which is between points 0 and n − 1. If the low edge’s crossing is not also between points 0 and n − 1, it must be to the left of point 0. But, within the strip between line 0-(n − 1) and the parallel tangent line, the portion of C between 0 and h separates the rest of C (containing i) from the points left of point 0 (as shown in Figure 6, right), so the low edge most cross C before it reaches its crossing with line 0-(n − 1).
158
David Eppstein
Fig. 6. Analysis of outer drawings of type 012. Left, the middle edges of the tripletons 0i(n − 1) form tracks that force the remaining middle edges to cross segment 0-(n − 1) (Lemma 12). Right, low edges from clockwise of the tangent point h cross C counterclockwise of the tangent point (Lemma 13).
Symmetrically, the high edges from counterclockwise of h must cross C clockwise of h. Lemma 14. For sufficiently large n, G3 (n) has no outer drawing of type 012. Proof. Start with an outer drawing of type 012, and remove singletons 1 and n−2 if necessary so that (by Lemma 12) all middle edges cross segment 0-(n−1). Form the tangent point h described in Lemma 13, and assume without loss of generality that at least half of the remaining singletons lie clockwise of h on convex curve C. (The case that at least half the singletons lie counterclockwise of h is symmetric.) Remove from the drawing all points counterclockwise of h. The result is an outer drawing of type 012 of a graph G3 (m), with at least m ≥ (n − 2)/2 singletons, in which all low and middle edges cross segment 0(m − 1). We can now apply the same reasoning as in Lemma 6: by choosing an appropriate set of tripletons, we can find a set of low and middle edges forming a grid that contains a complete 2 × 2 subgrid, and use the subgrid to constrain the locations of two more tripletons, forcing two high edges to cross. Lemma 15. In an outer drawing of G3 (n) of type 210, each middle edge is completely exterior to convex curve C. Proof. Suppose to the contrary that a middle edge for tripleton ijk crosses C at point x. If x is clockwise of j, an edge from ijk to C clockwise of the middle edge can only reach singletons in the range from j to x, contradicting the requirement (from the assumption of the drawing type) that the low edge i-ijk must be clockwise of the middle edge. Symmetrically, if x is counterclockwise of j, an edge counterclockwise of the middle edge can only reach singletons in the range
Separating Thickness from Geometric Thickness
159
Fig. 7. In an outer drawing of type 210, low edges from singletons 0 and 1 cross disjoint ranges of the convex curve C (Lemma 17).
from x to j, contradicting the requirement that the high edge must be clockwise of the middle edge. The same reasoning as above also proves the following lemma: Lemma 16. In an outer drawing of G3 (n) of type 210, suppose that the low edge of tripleton ijk crosses the convex curve C. Then the crossing point is clockwise of singleton i. Lemma 17. Suppose that G3 (n) has a convex drawing of type 210, and let n = 2k − 2 Then we can select a subset S of the singletons, with |S| = k, such that no member of S is incident to a low edge that crosses the convex hull of S. Proof. We use induction on k. As a base case, for k = n = 2, G3 (2) has no edges. Otherwise, consider the sets of low edges incident to singletons 0 and 1 that cross convex curve C. Since these two sets of low edges do not cross each other (Figure 7), we can partition the portion of C clockwise of 1 into two parts, where the clockwise part of C is crossed only by low edges from 0 and the counterclockwise part of C is crossed only by low edges from 1. One of these two parts contains at least (n − 2)/2 singletons. If the clockwise part contains many singletons, we apply the induction hypothesis to these singletons, and form S by adding singleton 1 to the resulting set. On the other hand, if the counterclockwise part contains many singletons, we add singleton 0 to the set formed by applying the induction hypothesis to the singletons in this part. In either case, we get a set S of (k − 1) + 1 = k singletons. The low edges from 0 or 1 (whichever was included in the set) can not cross the hull, because of how we chose which part of C to apply the induction hypothesis to. The low edges from the remaining members of S can not cross the hull between 0 or 1 and the rest of S, by Lemma 16, and they can not cross the hull elsewhere by induction. Therefore S fulfills the conditions of the lemma. Lemma 18. Not every graph G3 (n) has an outer drawing of type 210. Proof. By Lemma 17, if G3 (n) has such a drawing, then we can find a set of k singletons, and a convex curve C (the hull of this set), forming an outer drawing
160
David Eppstein
Fig. 8. Schematic view of drawing of G3 (8) with geometric thickness three.
of G3 (k) in which all low and middle edges avoid the interior of convex curve C; here k = log2 (n + 2) . We can now apply the same reasoning as in Lemmas 6 and 14: by choosing an appropriate set of tripletons, we can find a set of low and middle edges forming a grid that contains a complete 2 × 2 subgrid, and use the subgrid to constrain the locations of two more tripletons, forcing two high edges to cross.
7
Completion of the Proof
Lemma 19. Not every graph G3 (n) has geometric thickness at most three. Proof. This follows from Lemma 8 (showing that we can restrict our attention to outer drawings of fixed type) and Lemmas 9, 11, 14, and 18 (showing that each fixed type leads to a forced crossing). The largest n for which G3 (n) has no thickness-three drawing must be at least nine, as G3 (8) has geometric thickness at most three: draw four singleton subsets in a large square, with the remaining four singletons and all tripletons clustered near the center of the square. The edges incident to the inner four singletons form a planar graph, consisting of a cube G3 (4), 24 two-edge paths across the faces of the cube, and 24 tripletons with only a single edge to one of the inner singletons. By choosing an appropriate F´ ary embedding of this planar graph, we can draw it in a single layer, and use an additional layer for the edges incident to each pair of opposite outer singletons. Figure 8 shows this drawing in a schematic view, with the outer four vertices and inner cube visible but omitting the remaining tripletons.
8
Conclusions
We have shown that thickness and geometric thickness are not asymptotically equivalent. Some interesting open questions remain:
Separating Thickness from Geometric Thickness
161
– What can be said about two-layer drawings? It is known that there exist ¯ ¯ graphs, for instance K6,8 , for which θ(G) = 2 and θ(G) > 2 [12,5]. Can θ(G) be unbounded when θ(G) = 2? – Four-regular graphs have thickness at most two. Do random four-regular graphs have bounded expected geometric thickness? More generally, can one bound the geometric thickness of a graph as some function of its degree? – Due to our use of Ramsey theory, our lower bounds on geometric thickness grow only very slowly as a function of the number of vertices. Can we find good upper bounds for geometric thickness as a combination of the graphtheoretic thickness and a slowly growing function of the graph size? ¯ – What is the complexity of computing θ(G) for a given graph G [5]? – Thickness is NP-hard [12] but not difficult to approximate to within a constant factor; e.g., it is within a factor of three of the graph’s arboricity. Our new results imply that these approximations do not directly extend to geometric thickness. Is there an efficient algorithm for layered drawing of graphs without bends, using a number of layers within a constant factor of optimal? Acknowledgements This work was supported in part by NSF grant CCR-9912338.
References 1. V. B. Alekseev and V. S. Gonˇcakov. The thickness of an arbitrary complete graph. Math USSR Sbornik 30(2):187–202, 1976. 2. L. W. Beineke. The decomposition of complete graphs into planar subgraphs. Graph Theory and Theoretical Physics, chapter 4, pp. 139–153. Academic Press, 1967. 3. L. W. Beineke and F. Harary. The thickness of the complete graph. Canad. J. Math. 17:850–859, 1965. 4. F. Bernhart and P. C. Kainen. The book thickness of a graph. J. Combinatorial Theory, Ser. B 27(3):320–331, 1979. 5. M. B. Dillencourt, D. Eppstein, and D. S. Hirschberg. Geometric thickness of complete graphs. J. Graph Algorithms & Applications 4(3):5–17, 2000, arXiv:math.CO/9910185. 6. D. Eppstein. Separating geometric thickness from book thickness. arXiv.org, September 2001, arXiv:math.CO/0109195. 7. I. F´ ary. On straight line representation of planar graphs. Acta Sci. Math. Szeged. 11:229–233, 1948. 8. R. L. Graham, B. L. Rothschild, and J. H. Spencer. Ramsey Theory. Wiley, 1980. 9. N. Hartsfield and G. Ringel. Pearls in Graph Theory. Academic Press, Boston, MA, 1990. 10. B. Jackson and G. Ringel. Plane constructions for graphs, networks, and maps: Measurements of planarity. Selected Topics in Operations Research and Mathematical Economics: Proc. 8th Symp. Operations Research, pp. 315–324. Springer-Verlag, Lecture Notes in Economics and Mathematical Systems 226, August 1983. 11. P. C. Kainen. Thickness and coarseness of graphs. Abh. Math. Sem. Univ. Hamburg 39:88–95, 1973.
162
David Eppstein
12. A. Mansfield. Determining the thickness of a graph is NP-hard. Math. Proc. Cambridge Philos. Soc. 93(9):9–23, 1983. 13. J. Mayer. Decomposition de K16 en trois graphes planaires. J. Comb. Th., Ser. B 13:71, 1972. 14. J. Vasak. The thickness of the complete graph having 6m + 4 points. Manuscript, cited in [9] and [10]. 15. D. R. Wood. Geometric thickness in a grid of linear area. Proc. Euroconf. Combinatorics, Graph Theory, and Applications, pp. 310–315. Univ. Aut` onoma de Barcelona, Centre de Recerca Matem` atica, September 2001, http://www.cs.usyd.edu.au/∼davidw/papers/Wood-COMB01.ps.
Book Embeddings and Point-Set Embeddings of Series-Parallel Digraphs Emilio Di Giacomo1 , Walter Didimo1 , Giuseppe Liotta1 , and Stephen K. Wismath2 1
Dipartimento di Ingegneria Elettronica e dell’Informazione, Universit` a degli Studi di Perugia, Perugia, Italy. {digiacomo,didimo,liotta}@diei.unipg.it 2 Department of Mathematics and Computer Science, University of Lethbridge, Lethbridge, Alberta, Canada. [email protected]
Abstract. An optimal O(n)-time algorithm to compute an upward twopage book embedding of a series-parallel digraph with n vertices is presented. A previous algorithm of Alzohairi and Rival [1] runs in O(n3 ) time and assumes that the input series-parallel digraph does not have transitive edges. One consequence of our result is that series-parallel (undirected) graphs are necessarily sub-hamiltonian. This extends a previous result by Chung, Leighton, and Rosenberg [5] who proved subhamiltonicity for a subset of planar series-parallel graphs. Also, this paper investigates the problem of mapping planar digraphs onto a given set of points in the plane, so that the edges are drawn upward planar. This problem is called the upward point-set embedding problem. The equivalence between the problem of computing an upward two-page book embedding and an upward point-set embedding with at most one bend per edge on any given set of points is proved. An O(n log n)-time algorithm for computing an upward point-set embedding with at most one bend per edge on any given set of points for planar series-parallel digraphs is presented.
1
Introduction
A book consists of a line in Euclidean 3D space called the spine and some number of half-planes, called pages, having the spine as a boundary. A book embedding of a graph G is a linear ordering of the vertices along the spine of a book and an assignment of edges to pages such that edges assigned to the same page can be drawn as simple Jordan curves on that page without intersecting each other. The problem of computing a book embedding of a graph that uses the minimum number of pages has been the subject of intense research activities. (see e.g., [2,5,17]). In their seminal paper [2], Bernhart and Kainen prove that a planar
Research supported in part by the Natural Sciences and Engineering Research Council of Canada, and by “Progetto Giovani Ricercatori: Algoritmi per la Visualizzazione di Grafi di Grandi Dimensioni” of the University of Perugia, Italy.
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 162–173, 2002. c Springer-Verlag Berlin Heidelberg 2002
Book Embeddings and Point-Set Embeddings of Series-Parallel Digraphs
163
graph has a book embedding on two pages if and only if it is sub-hamiltonian. Yannakakis [17] shows that all planar graphs have a book embedding on four pages and that four pages are necessary for some planar graphs. Also upward book embeddings of directed acyclic graphs and of posets have been widely investigated (see e.g., [1,11,12,13,15]). An upward book embedding of a digraph G is a book embedding of G such that the ordering of the vertices along the spine is a topological ordering of G. In contrast to the result by Yannakakis [17] concerning the book embeddability of undirected planar graphs, the minimum number of pages required by an upward book embedding of an upward planar digraph is not known [1,15]. Heath, Pemmaraju, and Trenk [13] show that oriented trees have a two-page upward book embedding. Alzohairi and Rival [1] show that a planar series-parallel ordered set has a two-page upward book embedding and that such an embedding can be computed in O(n3 ) time if the poset is a series-parallel planar lattice with n elements (note that the covering graph of a planar ordered set is an upward planar digraph). In this paper we study upward book embeddings and find relations between book-embeddability and another relevant graph drawing question, the point-set embeddability problem. Before giving an overview of our main results, we briefly digress on this second topic to better clarify our contributions. Let P be a set of n distinct points in the plane and let G be a planar graph with n vertices. A point-set embedding of G on P is a planar drawing of G such that each vertex is mapped to a distinct point of P and each edge is drawn as a polygonal chain connecting its endpoints (note that the mapping of the vertices to the points is not specified as part of the input). The problem of computing a point-set embedding of a graph while minimizing the number of bends per edge has been widely investigated (see e.g.[4,3,10,14]). Since outerplanar graphs are the largest class of graphs admitting a straight-line point-set embedding on any set of points [10], Kaufmann and Wiese [14] investigate the point-set embeddability problem for planar graphs allowing few bends per edge. They show that if a graph has a hamiltonian cycle with an edge on the external face then it admits a point-set embedding with at most one bend per edge on any set of points on the plane and present an O(n log n) time algorithm to compute it. Also, they show that for a planar graph G with n vertices and for any set of n points on the plane, a point-set embedding of G with at most three bends per edge can be computed in O(n log n) time and that the number of bends per edge can be reduced to be at most two at the expense of increasing the time complexity to O(n2 ). The research of Kaufmann and Wiese is extended in this paper to upward point-set embeddings. An upward point-set embeddings of an upward planar digraph G on a set P of points in the plane is a point-set embedding of G onto P such that the edges are drawn monotonically increasing in a common direction. An overview of our results follows. – An optimal O(n) time algorithm to compute a two-page upward book embedding of a planar series-parallel digraph with n vertices is presented. The best previously known algorithm runs in O(n3 ) time and assumes that the input graph does not have transitive edges [1].
164
Emilio Di Giacomo et al.
– The equivalence between the problem of computing a two-page upward book embedding and an upward point-set embedding with at most one bend per edge on any given set of points is proved. – The investigation is extended to the undirected book-embeddability and the point set embeddability problem. One consequence of our result is that seriesparallel (undirected) graphs are necessarily sub-hamiltonian.
2 2.1
Preliminaries Series-Parallel Digraphs and Their Decomposition Tree
Let u and v be two vertices of a digraph. We use the notation u → v to say that there is a directed path from u to v in the digraph. A two terminal series-parallel digraph (also called TTSP-digraph in the following) is a planar digraph recursively defined as follows [6,16]: – An edge joining two vertices is a TTSP-digraph. – Let G and G be two TTSP-digraphs; the digraph obtained by identifying the sink of G with the source of G (Series Composition) is also a TTSPdigraph. – Let G and G be two TTSP-digraphs; the digraph obtained by identifying the source of G with the source of G and the sink of G with the sink of G (Parallel Composition) is also a TTSP-digraph. A TTSP-digraph has one source and one sink that are called its poles. The undirected underlying graph of a TTSP-digraph is called a two terminal seriesparallel graph or TTSP-graph for short. We recall the definition of the SPQR-tree of an st-graph G, also called the decomposition tree of G [7]. A split pair of G is either a separation pair or a pair of adjacent vertices. A split component of a split pair {u, v} is either an edge (u, v) or a maximal subgraph C of G such that C is an uv-graph and {u, v} is not a split pair of C. A maximal split pair {u, v} of G is such that there is no other split pair {u , v } in G such that {u, v} is contained in a split component of {u , v }. The SP QR-tree T of an st-graph G is a rooted ordered tree whose nodes are of four types: S,P ,Q, and R. Each node µ of T has an associated planar st-graph (possibly with multiple edges), called the skeleton of µ and denoted by skeleton(µ). Also it is associated with an edge of the skeleton of the parent ν of µ, called the virtual edge of µ in skeleton(ν). Tree T is recursively defined as follows (see Figure 3(b)): Trivial case: If G consists of a single edge from s to t, then T consists of a single Q-node whose skeleton is G itself. Series case: If G is not biconnected, let c1 , . . . , ck−1 (k ≥ 2) be the cutvertices of G. Since G is planarly biconnectible, each cutvertex ci is contained in exactly two blocks Gi and Gi+1 such that s is in G1 and t is in Gk . The root of T is an S-node µ. Graph skeleton(µ) consists of the chain e1 , . . . , ek , where edge ei goes from ci−1 to ci , c0 = s, and ck = t.
Book Embeddings and Point-Set Embeddings of Series-Parallel Digraphs
165
Parallel case: If s and t are a split pair for G with split components G1 , . . . Gk (k ≥ 2), the root of T is a P -node µ. Graph skeleton(µ) consists of k parallel edges from s to t, denoted e1 , . . . , ek . Rigid case: If none of the above cases applies, let {s1 , t1 }, . . . , {sk , tk } be the maximal split pairs of G (k ≥ 1), and for i = 1, . . . , k, let Gi be the union of all the split components of {si , ti }. The root of T is an R-node µ. Graph skeleton(µ) is obtained from G by replacing each subgraph Gi with edge ei from si to ti . Note that for a TTSP-graph, the Rigid case never applies and thus the decomposition tree of a TTSP-graph does not contain any R-node. 2.2
Two Page Book Embeddings
Let G be a graph. Without loss of generality, we assume that in each drawing of a two-page book embedding of G, the spine is always vertical, and we call the half-plane to the left and to the right of the spine, the left page and the right page respectively. Also, we denote by LG the linear ordering of the vertices of G on the spine, and, for each edge e of G, we denote by de the page (left or right) to which e is assigned. The following theorem gives a simple characterization of two-page upward book embeddings of planar digraphs, that will be useful in the following. Theorem 1. Let G be a planar digraph. The linear ordering LG and the assignment de for every edge e of G define a two-page upward book embedding of G if and only if the following two properties hold: UBE1: If (u, v) is a directed edge of G then u precedes v in LG . UBE2: There are no two edges e1 = (u, v) and e2 = (w, z) (with u, v, w, z all distinct) for which de1 = de2 and u, w, v, z occur in this order in LG . Proof. Given an upward book embedding of G, the ordering LG of the vertices of G along the spine is a topological ordering of the vertices of G, hence Property UBE1 is verified. Also, suppose for a contradiction that Property UBE2 is not satisfied. This implies that there exist two edges e1 = (u, v) and e2 = (w, z) (with u, v, w, z all distinct) for which de1 = de2 and u, w, v, z occur in this order in LG . In this case, however, e1 and e2 can not be drawn on the same page without intersecting each other (see Figure 1(a)), which is a contradiction. Hence, also Property UBE2 is verified. Suppose that LG and the assignment de (for every edge e of G) are such that Properties UBE1 and UBE2 hold. Property UBE1 implies that LG defines a topological ordering of the vertices on the spine. Also, consider any two edges e1 = (u, v) and e2 = (w, z) of G. From Property UBE1, u precedes v, and w precedes z in LG . – If de1 = de2 , that is, the two edges are assigned to different pages, then it is always possible to draw e1 and e2 without intersecting each other (see for example Figure 1(b)).
166
Emilio Di Giacomo et al.
– If de1 = de2 , from Property UBE2, only the following sub-cases are possible (we do not examine symmetric sub-cases): (i) Edges e1 and e2 have no common vertex, and u, v, w, z occur in this order in LG . Edge e2 can be drawn completely above e1 (see Figure 1(c)). (ii) Edges e1 and e2 have no common vertex, and u, w, z, v occur in this order in LG . Edge e2 can be drawn nested into e1 (see Figure 1(d)). (iii) Edges e1 and e2 have one common vertex. The two edges can be drawn either nesting one edge into another (see Figure 1(e)) or putting one edge completely above the other (see Figure 1(f)).
z
z
v
v
w
z
z
v
w
u
u
u
(b)
(c)
z
v
w
u
(a)
v
w
(d)
z
v=w
u=w
(e)
u
(f)
Fig. 1. Illustration of the cases of Theorem 1
Given a two-page book embedding of G, a drawing of this book embedding can be easily computed mapping the vertices of G at consecutive points on a vertical line (the spine of the book), according to the ordering LG , and drawing each edge e as a semi-circle between its end-vertices on page de with a diameter chosen as the distance between the end-vertices of e (see Figure 3(d)).
3
Two-Page Upward Book Embeddings of Series-Parallel Digraphs in Linear Time
In this section we describe a linear time algorithm for computing a two-page upward book embedding of a TTSP-digraph G. We can assume that edge (s, t) exists in G. If it does not exist, we temporarily add such an edge and then remove it at the end of the algorithm. Finally, since s and t are on the external face, edge (s, t) can always be embedded on the external face. Algorithm SP-Book Embedder Input: A TTSP-digraph G with edge (s, t) on the external face. Output: A two-page upward book embedding of G, defined by a linear ordering LG and by a page assignment de for each edge e of G. Step 1: Compute the SP QR-tree T of G. Since G is a TTSP-digraph, T has no R nodes.
Book Embeddings and Point-Set Embeddings of Series-Parallel Digraphs
167
– For each node µ of T denote by Gµ the pertinent digraph of µ, and let Lµ be a linear list used to define a linear ordering of the vertices of Gµ . – Define the following merge operation ◦ between two ordered vertex lists Lµ =< u1 , u2 , . . . , uk > and Lν =< v1 , v2 , . . . , vh >: • Lµ ◦ Lν =< u1 , u2 , . . . , uk , v1 , v2 , . . . , vh >, if uk = v1 . • Lµ ◦ Lν =< u1 , u2 , . . . , uk , v2 , . . . , vh >, if uk = v1 . Step 2: Denote by {µ1 , µ2 , . . . , µh } the nodes of T ordered according to a postorder visit. Step 3: For i = 1, . . . , h do: Case 1 µi is a Q-node (see Figure 2(a)). Let e = (u, v) be the directed edge represented by µi . – Set Lµi =< u, v >. – Set de = lef t. Case 2 µi is an S-node (see Figure 2(b)). Let (u = u1 , u2 ), (u2 , u3 ), . . . , (uk , uk+1 = v) be the edges of the skeleton of µi where u → v in G, and let νj , (j = 1, . . . , k) be the child of µi in T corresponding to edge (uj , uj+1 ). Node νk will be called the top child of µi in the following. – Set Lµi = Lν1 ◦ Lν2 ◦ . . . ◦ Lνk . – If νk is a Q-node representing an edge ek of G, then set dek = right. Case 3 µi is a P -node (see Figure 2(c)). Let u, v be the poles of the skeleton of µi , such that u → v. Let ν1 , ν2 , . . . , νk be the children of µ in T and assume that if the edge (u, v) exists in Gµi , the corresponding Q-node is νk . Also, denote by L− νj the list Lνj without the first vertex u and the last vertex v, (j = 1, . . . , k). − − – Set Lµi =< u > ◦L− νk ◦ Lνk−1 ◦ . . . ◦ Lν1 ◦ < v >. – If νk is a Q-node representing an edge ek and if µi is the top child of an S-node in T , set dek = right. Step 4: Set LG = Lµh .
v
u k+1= v 111 000 νk 000 111 000 111 000 111 uk
00 ν2 11 003 11 00 11 00 11 u2 111 000 ν1 000 111 000 111 000 111 u= u u
u
(a) Case Q
1
(b) Case S
1111 0000 v 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 0000 1111 νk ν1 1111 ν2 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 0000 1111 u
(c) Case P
Fig. 2. Illustration of the cases of Algorithm SP-Book Embedder
In order to prove the correctness of Algorithm SP-Book Embedder, we need the following preliminary lemma.
168
Emilio Di Giacomo et al.
8
14 P−NODE
l =left r =right
1
7
(1,2)
Q−NODE
34 15
14 6
12
5
35
15 S−NODE
15
1
13
9
8
(1,2)
14
(5,6)
l
11
(1,8)
33 22
31
(15,8)
r
l 10
4
3
4
9
30
(6,8)
7
13
18
21
25
29
r
10
2 1
(11,15)
l
2
3
5
6
11
12
16
(2,3)
(3,5)
(2,4)
(4,5)
(6,7)
(7,8)
(1,9)
l
r
l
r
l
r
l
(a)
l
32
17
19
20
23
24
(9,11) (1,10) (10,11) (11,12) (12,15)
r
l
r
l
r
26
27
28
(11,13) (13,14) (14,15)
l
l
r
(b)
L 1={1,2}
L 13={6,7,8}
L 25={11,12,15}
L 2={2,3}
L 14={6,7,8}
L 26={11,13}
7
L 3={3,5}
L 15={1,2,4,3,5,6,7,8} L ={13,14} 27
6
L 4={2,3,5} L 16={1,9}
L 28={14,15}
L 5={2,4}
L 17={9,11}
L 29={11,13,14,15}
L 6={4,5}
L 18={1,9,11}
L 30={11,15}
L 7={2,4,5} L 19={1,10}
L 31={11,13,14,12,15}
L 8={2,4,3,5} L 20={10,11}
L 32={15,8}
L 9={5,6}
L 21={1,10,11}
L 33={1,10,9,11,13,14,12,15,8}
L 10={6,8}
L 22={1,10,9,11}
L 34={1,10,9,11,13,14,12,15,2,4,3,5,6,7,8}
L 11={6,7}
L 23={11,12}
L 35={1,10,9,11,13,14,12,15,2,4,3,5,6,7,8}
L 12={7,8}
L 24={12,15}
8
5 3 4 2 15 12 14 13
(c)
11
9 10 1
(d)
Fig. 3. (a) A TTSP-digraph G. The dashed edges are dummy egdes that form an augmented hamiltonian cycle along with the bold edges.(b) The SP QR-tree of G. For each node the number given by the post order visit is shown. For each Q-node the edge associated and the page assigned are also shown. (c) The lists Lµ for each node µ. (d) The final book embedding.
Lemma 1. Let G be a TTSP-digraph, let T be its SP QR-tree, and let µ be an S-node of T . Let Gµ be the pertinent digraph of µ and let u and v be the poles of µ such that u → v. Algorithm SP-Book Embedder assigns the edges of Gµ to the pages in such a way that each edge incident on u is assigned to the left page and each edge incident on v is assigned to the right page. Proof. We prove the statement by induction on the height hµ of the subtree Tµ ⊂ T rooted at µ (note that hµ is always an odd number). If hµ = 1, then all children ν1 , . . . , νk of µ are Q-nodes. Let e1 , . . . , ek be the edges associated with ν1 , . . . , νk , respectively; vertex u is the starting vertex of e1 and v is the end vertex of ek . Algorithm SP-Book Embedder sets dei = lef t for 1 ≤ i ≤ (k − 1)
Book Embeddings and Point-Set Embeddings of Series-Parallel Digraphs
169
(Case 1 of Step 3) and dek = right (Case 2 of Step 3). Hence, the lemma holds when hµ = 1. Let us assume that the lemma is true for hµ = k ≥ 1 and consider the case hµ = k + 2. The children ν1 , . . . , νk of µ are either P -nodes or Q-nodes. In particular, in order to verify that the lemma is true, we only need to verify the assignment on the edges incident on u and v, that is, the edges of the pertinent digraphs of ν1 and νk . – Consider node ν1 : If it is a Q-node representing an edge e, then the algorithm sets de = lef t (Case 1 of Step 3); if ν1 is a P -node then the children of ν1 are all S-nodes except at most one which is a Q-node. For each child which is an S-node, the statement is true by the inductive hypothesis. For the edge e associated with the only child (if present) which is Q-node the algorithm sets de = lef t (Case 1 of Step 3). – Consider node νk : If it is a Q-node representing an edge e, then the algorithm sets de = right, since it is the top child of µ (Case 2 of Step 3); if νk is a P -node then the children of νk are all S-nodes except at most one, which is a Q-node. For each child which is an S-node the statement is true by the inductive hypothesis. For the edge e associated with the only child (if present) which is a Q-node the algorithm sets de = right, since νk is the top child of µ (Case 3 of Step 3). Theorem 2. Let G be a TTSP-digraph with n vertices. There exists an algorithm that computes a two-page upward book embedding of G in O(n) time and space. Proof. Let T be the SP QR-tree of G, and denote by Gµ the pertinent digraph of a node µ of T . We prove by induction that, after the i-th iteration of Step 3 has been executed, a two-page upward book embedding of Gµi is correctly given by list Lµi and by variable de , for each edge e of Gµi . Namely, based on Theorem 1 we prove that Properties UBE1 and UBE2 hold for Gµi . We adopt the same notation used for describing Algorithm SP-Book Embedder. Since Step 3 iterates on the nodes of T in post-order, µ1 is a leaf of T , that is, a Q-node. Hence Gµ1 is a single edge e = (u, v), and Case 1 applies. In this case the proof is trivial. Suppose the statement is true for i ≥ 1; we prove that it is true for i + 1. There are three possible cases: 1. µi+1 is a Q-node. In this case Gµi+1 is a single edge and the proof is trivial. 2. µi+1 is an S-node. Let ν1 . . . νk be the children of µi+1 . For each edge e = (w, z) of Gµi+1 , w and z belong to the same list Lνj for some 1 ≤ j ≤ k. Since Property UBE1 is verified for Lνj and since the merge operation keeps unchanged the ordering of the vertices in Lνj , Property UBE1 holds for Lµi+1 . Let e1 = (w1 , z1 ) and e2 = (w2 , z2 ) be two edges of Gµi+1 such that w1 , z1 , w2 , z2 are all different. If w1 , z1 , w2 , z2 belong to the same list Lνj for some 1 ≤ j ≤ k then Property UBE2 follows from the inductive hypothesis. Otherwise, w1 , z1 ∈ Lνj1 and w2 , z2 ∈ Lνj2 with j1 = j2 . Assume, without
170
Emilio Di Giacomo et al.
loss of generality, that j1 < j2 . Since Lµi+1 = Lν1 ◦ Lν2 ◦ . . . ◦ Lνk , all the vertices in Lνj1 precede all the vertices in Lνj2 . Thus Property UBE2 holds. 3. µi+1 is a P -node. Let ν1 . . . νk be the children of µi+1 , and let u and v be the poles of µi+1 where u → v. We prove first that Property UBE1 is satisfied. Let e = (w, z) be a directed edge of Gµi+1 . There are three cases to consider: – if w = u then w is the first vertex in Lµi+1 and so Property UBE1 holds; – if z = v then z is the last vertex in Lµi+1 and so Property UBE1 holds; – If w = u and z = v then w, z ∈ L− νj for some 1 ≤ j ≤ k. Since the merge operation keeps unchanged the ordering of the vertices in L− νj Property UBE1 follows from the inductive hypothesis. We now show that Property UBE2 is true. Let e1 = (w1 , z1 ) and e2 = (w2 , z2 ) be two directed edges of Gµi+1 such that w1 , z1 , w2 , z2 are all different. Also in this case we have three cases: – wj = u j = 1, 2 and zj = v j = 1, 2. In this case w1 , z1 ∈ L− νj1 for some − 1 ≤ j1 ≤ k and w2 , z2 ∈ Lνj2 for some 1 ≤ j2 ≤ k. • If j1 = j2 = j then the ordering of w1 , z1 , w2 , z2 in Lµi+1 is the same as in L− νj and Property UBE2 follows from the inductive hypothesis. • If j1 = j2 (assume without loss of generality j1 < j2 ). Since Lµi+1 =< − u > ◦L− νk ◦ . . . ◦ Lν1 < v > all the vertices in Lνj2 precedes all the vertices in Lνj1 . Thus the ordering of w1 , z1 , w2 , z2 in Lµi+1 is w2 , z2 , w1 , z1 , and Property UBE2 holds. – One of w1 , z1 , w2 , z2 is equal to u or v (without loss of generality assume that w1 = u, other cases are similar). Let w1 , z1 ∈ Lνj1 and w2 , z2 ∈ Lνj2 . • If j1 = j2 = j then the ordering of w1 , z1 , w2 , z2 in Lµi+1 is the same as in L− νj since the merge operation keeps unchanged the ordering of the vertices z1 , w2 , z2 ∈ L− νj and the vertex w1 = u which precedes all z1 , w2 , z2 in Lνj also precedes all z1 , w2 , z2 in Lµi+1 . Thus Property UBE2 follows from the inductive hypothesis. − • If j1 < j2 then all the vertices in L− νj2 precede all the vertices in Lνj1 , and w1 = u precedes all other vertices in Lµi+1 . Thus the ordering of w1 , z1 , w2 , z2 in Lµi+1 is w1 = u, w2 , z2 , z1 , and Property UBE2 holds. − • If j1 > j2 then all the vertices in L− νj1 precede all the vertices in Lνj2 , and w1 = u precedes all other vertices in Lµi+1 . Thus the ordering of w1 , z1 , w2 , z2 in Lµi+1 is w1 = u, z1 , w2 , z2 , and Property UBE2 holds. – Two of w1 , z1 , w2 , z2 are equal to u or v. • If w1 = u and z1 = v (or symmetrically w2 = u and z2 = v) w1 = u (w2 = u) is the first vertex in Lµi+1 , and z1 = v (z2 = v) is the last vertex in Lµi+1 . Thus the ordering of w1 , z1 , w2 , z2 in Lµi+1 is w1 = u, w2 , z2 , z1 = v (symmetrically w2 = u, w1 , z1 , z2 = v), and Property UBE2 holds. • If w1 = u and z2 = v (or symmetrically w2 = u and z1 = v) then one among e1 and e2 is incident on u and the other is incident on v. By Lemma 1 they are on different pages and Property UBE2 holds. Proofs about time and space complexity are omitted for reasons of space.
Book Embeddings and Point-Set Embeddings of Series-Parallel Digraphs
4
171
Hamiltonicity, Book and Point-Set Embeddability
In their investigation of book-embeddings, Bernhart and Kainen [2] show that an undirected planar graph admits a book embedding on two pages if and only if it is sub-hamiltonian, i.e. it can be augmented with edges to create a hamiltonian cycle while still remaining planar. In a subsequent paper, Chung, Leighton, and Rosenberg [5] show that a family of planar graphs that they call series-parallel graphs have a book embedding on two pages and therefore are sub-hamiltonian. However, it must be noted that the definition of Chung, Leighton, and Rosenberg appears somewhat restrictive if compared to the one commonly used for seriesparallel graphs by the vast majority of researchers (see e.g. [6,16]). In particular, in [5] the series composition is the usual one, but the parallel composition is defined as follows: Let G1 , . . . , Gn be series-parallel graphs with source vertices s1 , . . . sn and sink vertices t1 , . . . tn ; the parallel composition of G1 , . . . , Gn is obtained by taking a new source s and a new sink t and by adding edges between each si and s and between each ti and t. Clearly the family of series-parallel graphs defined by Chung, Leighton, and Rosenberg is a proper subset of the class of TTSP-graphs. For example, a threecycle is a TTSP-graph, but is not a series-parallel graph as defined by Chung et al. Furthermore, it is not obvious how to extend the proof of sub-hamiltonicity given in [5] to all TTSP-graphs. On the other hand, we observe that, since each TTSP undirected graph can be st-oriented in linear time with s and t on the external face [8], Algorithm SP-Book Embedder can also be used for computing a two-page book embedding of a two terminal series-parallel graph. This observation, together with the result by Bernhart and Kainen [2] leads to the following. We recall that he problem of determining if a graph is subhamiltonian is NP-Complete [5] Theorem 3. Let G be a TTSP-graph with n vertices. Then G admits a twopage book embedding and therefore it is sub-hamiltonian. Also there exists an O(n)-time algorithm that computes an augmented hamiltonian cycle of G. In a recent paper, Ganley and Heath [9] conjecture that every k-tree has a book-embedding on exactly k pages. Since every 2-tree is a TTSP-graph, a consequence of Theorem 3 is to prove their conjecture for k = 2. Corollary 1. Every 2-tree has a book embedding on two pages. As a second application of the results in Section 3, we consider the upward point-set embeddability problem, that is the problem of computing a point-set embedding of an upward planar digraph on a given set of points by minimizing the number of bends along the edges and by drawing all edges monotonically increasing in a common direction. We remark that the upward point-set embeddability problem is, in general, different from the non-upward problem. For example, let G be the upward planar graph of Figure 4. Graph G does not admit an upward point set embedding if the points of P are collinear as in Figure 4(b). Conversely, Figure 4(c) shows a non upward point-set embedding of G on P with at most one bend per edge.
172
Emilio Di Giacomo et al. e
e
e
d c
d c d
b
c a
(a)
b
b
a
a
(b)
(c)
Fig. 4. (a) An upward planar graph G. (b) There is no upward point-set embeddings of G on P . (c) A (non-upward) point-set embedding of G on a set of points P on the same line.
Theorem 4. An upward planar digraph G with n vertices has an upward pointset embedding with at most one bend per edge on every set of n points if and only if G has a two-page upward book embedding. Also, from a two-page upward book embedding of G it is possible to construct in O(n log n) time an upward point-set embedding of G with at most one bend per edge on every set of n points. Proof. If G has an upward point-set embedding with at most one bend per edge on every set of n points then it has an upward point-set embedding on consecutive points of a straight line l. In this upward point-set embedding the edges of G are drawn either on the half-plane to the left of l (assuming l to be a vertical line), or on the half-plane to the right of l. The ordering of the vertices of G along l and the assignment of the edges of G to the left or right half-plane define the two-page upward book embedding of G. Consider now a two-page upward book embedding of G and let vi , i = 1, . . . , n be the vertices of G in the order they appear along the spine. Since G has a two-page upward book embedding, G is sub-hamiltonian, and so we can add a certain number of edges in order to create a hamiltonian cycle C. Let C = (v1 , v2 )(v2 , v3 ) . . . (vn−1 , vn )(vn , v1 ), i.e., the ordering of the vertices in C is set to be the ordering of the vertices along the spine. In order to compute an upward point-set embedding of G on P with at most one bend per edge, we apply the algorithm described by Kaufmann and Wiese [14]. Namely, given a planar graph G with a hamiltonian cycle (v1 , v2 , . . . , vn , v1 ), the algorithm in [14] computes a point-set embedding of G on P with at most one bend per edge such that vi is mapped to pi (i = 1, . . . , n). About time complexity, we just observe that the algorithm in [14] takes O(n log n) time and that the operations of ordering the points of P according to their y-coordinates and possibly rotating the plane can be performed in O(n log n) time. The equivalence shown above is also valid for the non-upward case. Thus combining Theorem 4, Theorem 3 and, Theorem 2, we have the following. Corollary 2. Let G be a TTSP-(di)graph with n vertices. There exists an O(n log n)-time algorithm that computes an (upward) point-set embedding of G with at most one bend per edge on every set of n distinct points on the plane.
Book Embeddings and Point-Set Embeddings of Series-Parallel Digraphs
173
References 1. M. Alzohairi and I. Rival. Series-parallel ordered sets have pagenumber two. In S. North, editor, Graph Drawing (Proc. GD ’96), volume 1190 of Lecture Notes Comput. Sci., pages 11–24. Springer-Verlag, 1996. 2. F. Bernhart and P. C. Kainen. The book thickness of a graph. J. Combin. Theory, Ser. B 27:320–331, 1979. 3. P. Bose. On embedding an outer-planar graph on a point set. In G. Di Battista, editor, Graph Drawing (Proc. GD ’97), volume 1353 of Lecture Notes Comput. Sci., pages 25–36. Springer-Verlag, 1997. 4. P. Bose, M. McAllister, and J. Snoeyink. Optimal algorithms to embed trees in a point set. Journal of Graph Algorithms and Applications, 2(1):1–15, 1997. 5. F. R. K. Chung, F. T. Leighton, and A. Rosenberg. Embedding graphs in books: A layout problem with applications to VLSI design. SIAM Journal on Algebraic and Discrete Methods, 8:33–58, 1987. 6. G. Di Battista, P. Eades, R. Tamassia, and I. G. Tollis. Graph Drawing. Prentice Hall, Upper Saddle River, NJ, 1999. 7. G. Di Battista and R. Tamassia. On-line planarity testing. SIAM Journal on Computing, 25(5):956–997, October 1996. 8. S. Even and R. E. Tarjan. Computing an st-numbering. Theoret. Comput. Sci., 2:339–344, 1976. 9. J. Ganley and L. Heath. The pagenumber of k-trees is O(k). Discrete Applied Mathematics, 109:215–221, 2001. 10. P. Gritzmann, B. Mohar, J. Pach, and R. Pollack. Embedding a planar triangulation with vertices at specified poi nts. Amer. Math. Monthly, 98(2):165–166, 1991. 11. L. S. Heath and S. V. Pemmaraju. Stack and queue layouts of posets. SIAM Journal on Discrete Mathematics, 10:599–625, 1997. 12. L. S. Heath and S. V. Pemmaraju. Stack and queue layouts of directed acyclic graphs: Part II. SIAM Journal on Computing, 28:1588–1626, 1999. 13. L. S. Heath, S. V. Pemmaraju, and A. Trenk. Stack and queue layouts of directed acyclic graphs: Part I. SIAM Journal on Computing, 28:1510–1539, 1999. 14. M. Kaufmann and R. Wiese. Embedding vertices at points: Few bends suffice for planar graphs. Journal of Graph Algorithms and Applications, 6(1):115–129, 2002. 15. R. Nowakowski and A. Parker. Ordered sets, pagenumbers and planarity. Order, 6:209–218, 1989. 16. J. Valdes, R. E. Tarjan, and E. Lawler. The recognition of series-parallel digraphs. SIAM J. Comput., 11(2):298–313, 1982. 17. M. Yannakakis. Embedding planar graphs in four pages. Journal of Computer and System Sciences, 38:36–67, 1989.
Compact Encodings of Planar Orthogonal Drawings Amrita Chanda and Ashim Garg Department of Computer Science and Engineering University at Buffalo Buffalo, NY 14260 {achanda,agarg}@cse.buffalo.edu Abstract. We present time-efficient algorithms for encoding (and decoding) planar orthogonal drawings of degree-4 and degree-3 biconnected and triconnected planar graphs using small number of bits. We also present time-efficient algorithms for encoding (and decoding) turn-monotone planar orthogonal drawings.
1
Introduction
It is important to compress the representation of planar orthogonal drawings to reduce their storage requirements and transmission times over a network, like Internet. The encoding problem is also interesting from a theoretical viewpoint. A degree-d graph is one, where each vertex has at most d edges incident on it. A planar drawing is one with no edge-crossings. An orthogonal drawing is one, where each edge is drawn as an alternating sequence of horizontal and vertical line-segments. A bend (turn) is defined as the meeting point of two consecutive line-segments of an edge in a drawing. In this paper, we investigate the problem of encoding planar orthogonal drawings of degree-4 and degree-3 biconnected and triconnected planar graphs using small number of bits, and present several results. Let d be a planar orthogonal drawing, with b turns (bends), of a planar graph G with n vertices, m edges, and f internal faces. Suppose each line-segment of d has length at most W . Through out the paper, to avoid triviality, we will assume that n ≥ 3. A simple drawing-description format that stores the underlying graph using adjacency-list representation, and stores the coordinates of the vertices and edge-bends would require Ω(n + m log2 n + n log2 (b + n)W + b log2 (b + n)W ) bits in the worst case. More complex formats may require even more bits. We are not aware of any work focusing explicitly on encoding planar orthogonal drawings. In Sections 2, 3, and 4, respectively, we give our result, previous work, and some definitions. In Sections 5, 6, and 7, respectively, we show how to encode (and decode) degree-3 and degree-4 plane graphs, orthogonal representations, and lengths of the line-segments of a planar orthogonal drawing. In Section 8, we give our overall algorithm for encoding (and decoding) a planar orthogonal drawing.
Research supported by NSF CAREER Award IIS-9985136 and NSF CISE Research Infrastructure Award No. 0101244.
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 174–186, 2002. c Springer-Verlag Berlin Heidelberg 2002
Compact Encodings of Planar Orthogonal Drawings
2
175
Our Result
Our results can be summarized as follows (with G, n, m, f , d, W , and b as defined above): Let p = (2 + b + m − f ) log2 (W + 1). Let q = n + b. – If G is a degree-4 biconnected graph, then we can encode (and decode) d using at most 4.74m+2.42n+1.58b+p+O(log q) bits in O((n+b+p)2 ) time, and using at most 5.01m + 2.33n + 1.67b + p + O(log q) bits in O(n+b+p) time. – If G is a degree-4 triconnected graph, then we can encode (and decode) d using at most 3.58m+2.59n+1.58b+p+O(log q) bits in O((n+b+p)2 ) time, and using at most 3.67m + 2.67n + 1.67b + p + O(log q) bits in O(n+b+p) time. – If G is a degree-3 biconnected graph, then we can encode (and decode) d using at most 4.74m+1.23n+1.58b+p+O(log q) bits in O((n+b+p)2 ) time, and using at most 5.01m + 1.33n + 1.67b + p + O(log q) bits in O(n+b+p) time. – If G is a degree-3 triconnected graph, then we can encode (and decode) d using at most 3.58m + n + 1.58b + p + O(log q) bits in O((n + b + p)2 ) time, and using at most 3.67m + n + 1.67b + p + O(log q) bits in O(n + b + p) time. Several drawing algorithms [7,8], that try to minimize the number of bends, produce turn-monotone planar orthogonal drawings, i.e., where for each edge e = (u, v), if we travel from u to v along e, then we will either make left turns or right turns, but not both (see Figure 1(a)). Turn-monotone planar orthogonal drawings are very common in practice. We show that a turn-monotone planar orthogonal drawing d can be encoded even more succinctly: – If G is a degree-4 biconnected graph, then we can encode (and decode) d using at most 3.16m+4n+1.58b+p+O(log q) bits in O((n+b+p)2 ) time, and using at most 3.34m + 4n + 1.67b + p + O(log q) bits in O(n + b + p) time. – If G is a degree-4 triconnected graph, then we can encode (and decode) d using at most 2m+4.17n+1.58b+p+O(log q) bits in O((n+b+p)2 ) time, and using at most 2m + 4.34n + 1.67b + p + O(log q) bits in O(n + b + p) time. – If G is a degree-3 biconnected graph, then we can encode (and decode) d using at most 3.16m+2.81n+1.58b+p+O(log q) bits in O((n+b+p)2 ) time, and using at most 3.34m + 3n + 1.67b + p + O(log q) bits in O(n + b + p) time. – If G is a degree-3 triconnected graph, then we can encode (and decode) d using at most 2m+2.58n+1.58b+p+O(log q) bits in O((n+b+p)2 ) time,, and using at most 2m + 2.67n + 1.67b + p + O(log q) bits in O(n + b + p) time. As a by-product, our technique also encodes orthogonal representations, which are important intermediate constructs used by several drawing algorithms [7,4].
3
Related Work
As mentioned above, we are not aware of any previous work focusing explicitly on encoding planar orthogonal drawings. However, a lot of work has been done on encoding planar graphs. Let G be a planar graph with n vertices and m edges. If G is biconnected (triconnected, triangulated, respectively), then it can be
176
Amrita Chanda and Ashim Garg
+
encoded using at most 2n 1.58m bits [I] (1.58(n+ m ) bits [I], 1.33m bits [I]). If G is a triangulated graph, then any encoding of G requires at least 1.08m bits [9]. [5] presents a technique for encoding G in asymptotically the minimum number of bits in O(n1ogn) time. For more results on graph encoding, see [I]. Our encoding technique is based on the graph encoding technique of [I], and on the concept of canonical orderings of planar graphs [2,6,1].
4
Preliminaries
We use standard definitions of graph-theoretic terms. A plane graph G is a planar graph equipped with an embedding. Two vertices of G are neighbors if they are connected by an edge. Let u l , u2,. . . , uk be some vertices of G. The plane graph induced by u l , u2, . . . , uk is the maximal subgraph of G that consists of these vertices and their incident edges. Suppose G has n vertices. An ordering vl, v2, . . . , v, of the vertices of G is an assignment of unique integers in the range [I,n] to the vertices, such that the ith vertex vi in the order is assigned number i . Let G be a degree-4 plane graph. Two planar orthogonal drawings TI and r2 of G are shape equivalent if: (1) for each vertex v, consecutive edges incident to v form the same angle at v in TI and r2, and (2) for each edge (u, v), the sequence of left and right turns encountered while walking from u to v along the polygonal An orthogonal representation r chain representing (u, v) is the same in TI and r2. of G defines an equivalence class of shape equivalent planar orthogonal drawings of G. r is a t u r n m o n o t o n e representation if each edge is represented as a polygonal chain consisting of only left or right turns, but not both (see Figure l ( a ) ) . An important concept used by our encoding technique is that of a canonical ordering of a plane graph (see Figure 1(b)).This concept has been defined and used in [2,6,1].Let G = (V, E) be a simple biconnected plane graph with n vertices,
Fig. 1. (a) A turn-monotone planar orthogonal drawing. (b) corresponding plane graph G, a rightmost canonical ordering c of G and the canonical spanning tree T, corresponding to c. Here, each vertex is labeled by its number in c , the edges of T, are shown as dark lines. Each face is also labeled by its number in corresponding ordering of faces.
Compact Encodings of Planar Orthogonal Drawings
177
and m edges. Let v1 , v2 , . . . , vn be an ordering of the vertices of G. Let Gi be the plane graph induced by vertices v1 , v2 , . . . , vi . Let Hi be the external face of Gi . Definition 1 ([1]). Let v1 , v2 , . . . , vn be an ordering of the vertices of a biconnected plane graph G = (V, E), where v1 and v2 are two arbitrary vertices on the external face of G with (v1 , v2 ) ∈ E. The ordering is canonical if there exist ordered partitions I1 , I2 , . . . , IK of the interval [3, n] such that the following properties hold for every 1 ≤ j ≤ K: Suppose Ij = [k, k + q]. Let Cj be the path (vk , vk+1 , . . . , vk+q ) (Note, Cj is a single vertex if q = 0). Suppose we say that a vertex u of Gk−1 is a neighbor of Cj if a vertex of Cj is a neighbor of u. Then: – The graph Gk+q is biconnected. Its external face Hk+q contains the edge (v1 , v2 ), and the path Cj . Cj has no chord in G, i.e., G does not contain any edge (vs , vt ) with |s − t| > 1 and k ≤ s, t ≤ k + q. – Cj has at least two neighbors in Gk−1 , all of which are vertices of Hk−1 . The leftmost neighbor is a neighbor of vk and the rightmost neighbor is a neighbor of vk+q . Moreover, if q > 0, then vl and vr are the only neighbors of Cj in Gk−1 . Here, the leftmost and rightmost neighbors of Cj in Gk−1 are defined as follows: Vertices v1 and v2 divide Hk−1 into two paths: a path consisting only of edge (v1 , v2 ), and another path v1 (= u1 )u2 . . . us (= v2 ) that connect v1 and v2 , and that does not contain the edge (v1 , v2 ). We say that a vertex ui is left (right) of another vertex uz , if i < z (i > z). The leftmost (rightmost) neighbor of Cj in Gk−1 is the vertex ub such that ub is a neighbor of Cj , and there is no other vertex ut such that ut is a neighbor of Cj and ut is left (right) of ub . A canonical ordering for a triconnected plane graph is defined the same as for a biconnected plane graph, except that it has the following additional property: Property 1 ([1]). Every vertex vk , where 1 ≤ k ≤ n − 1 has at least one neighbor vp with k < p. A rightmost canonical (rmc) ordering for a biconnected plane graph G is defined as follows (see Figure 1(b)): Definition 2 ([1]). Let v1 , v2 , . . . , vn be a canonical ordering for G, where I1 , I2 , . . . , IK are its corresponding interval partitions. We say that v1 , v2 , . . . , vn is a rightmost canonical (rmc) ordering for G if the following property holds for every interval Ij , where 1 ≤ j ≤ K: Suppose Ij = [k, k + q]. Let v1 , v2 , . . . , vk−1 , uk , uk+1 , . . . , un be any canonical ordering for G whose first j − 1 interval partitions are exactly I1 , I2 , . . . , Ij−1 (Clearly, the Gk−1 and Hk−1 with respect to both canonical orderings are the same). Let vl be the leftmost neighbor of vk on Hk−1 . Let ul be the leftmost neighbor of uk on Hk−1 . Then, vl is to the right of ul on Hk−1 . Theorem 1. [1] Every biconnected plane graph G with n vertices admits a rightmost canonical (rmc) ordering, which can be constructed in O(n) time.
178
Amrita Chanda and Ashim Garg
Any canonical ordering c = v1 , v2 , . . . , vn of a biconnected plane graph G and its corresponding interval partitions I1 , I2 , . . . , IK defines a canonical spanning tree Tc that consists of the edge (v1 , v2 ) plus the union of the paths vl vk vk+1 ...vk+q over all intervals Ij = [vk , vk+q ], where 1 ≤ j ≤ K and vl is the leftmost neighbor of vk on Hk−1 (see Figure 1(b)). Suppose we root Tc at v1 . A tree edge of a vertex v is one that also belongs to Tc , and a non-tree edge is one that does not. The incoming tree edge of v is the edge that connects v to its parent in Tc , and an outgoing tree edge is one that connects v to a child in Tc . Suppose vertex v belongs to interval Ij = [vk , vk+q ]. The incoming non-tree edges of v are those that connect v to neighbors in Gk−1 , and the outgoing non-tree edges are the remaining non-tree edges. Note that by the definition of canonical ordering, each outgoing non-tree edge of v will be of the form (v, vs ), where s > k + q. Also, note that for each incoming non-tree edge (u, v) of v, u will be on Hk−1 . For example, in Figure 1(b), Vertex 12 has incoming tree edge (10, 12), no outgoing tree edge, incoming non-tree edges (11, 12) and (9, 12), and outgoing non-tree edge (12, 14). Properties 2 and 3 follow easily from the definition of canonical ordering: Property 2. Let v = v1 be a vertex of G. Then, v has exactly one incoming tree edge, and at least one outgoing tree-edge or incoming non-tree edge. Vertex v1 has only outgoing tree edges. Property 3. If G is a triconnected graph, then for every vertex v = v1 , vn of G, v has Property 2. Also, it has either at least one outgoing tree-edge, or at least one outgoing non-tree edge. Vertex v1 has only outgoing tree edges. Vertex vn has exactly one incoming tree edge and all its other edges are incoming non-tree edges. Theorem 2. Let G be a biconnected plane graph with n vertices. Suppose, we are given a rightmost canonical ordering c = v1 , v2 , . . . , vn of the vertices of G, along with the number of outgoing tree edges, incoming non-tree edges, and outgoing non-tree edges of each vertex as defined by c. Then, we can determine in O(n) time, all the edges in G, as well as its embedding. In other words, given this information, we can determine the entire structure of graph G. Sketch of Proof. Starting from the empty graph G0 , we reconstruct G iteratively by constructing a sequence of plane graphs G0 , G1 , G2 , . . . , Gp = G, where in each iterative step i, we obtain Gi from Gi−1 by inserting some vertices and edges into it. This is done as follows: For each vertex vk , where 1 ≤ k ≤ n, maintain two counters, T Count(vk ) and N count(vk ), that initially store the number of outgoing tree edges and outgoing non-tree edges, respectively, of vk . In the first iterative step, insert into G0 , vertices v1 , v2 , . . . , vr , where vr is the lowest numbered vertex in c with an incoming non-tree edge. Also, insert the edges (v1 , v2 ), (v1 , v3 ), (v3 , v4 ), . . . , (vr−1 , vr ), (vr , v2 ). Note that these edges will form a single simple cycle. Reduce N count(v2 ) by 1. For each j, where 1 ≤ j ≤ r − 1 and j = 2, reduce T Count(vj ) by 1. In a general iterative step i, we obtain Gi from Gi−1 as follows: Suppose Gi−1 consists of vertices v1 , v2 , . . . , vk−1 . Let vk , vk+1 , . . . , vk+q be the sequence
Compact Encodings of Planar Orthogonal Drawings
179
of consecutive vertices in c such that vertices vk , vk+1 , . . . , vk+q−1 do not have any incoming non-tree edge, but vk+q does. Let Hk−1 be the external face of Gk−1 . Let u be the rightmost vertex on Hk−1 with T Count(u) > 0. We have 2 cases: – q = 0 : Suppose vk has t incoming non-tree edges. Let u1 , u2 , . . . , ut be the first t vertices to the right of u on Hk−1 , such that, for each ui , N Count(ui ) > 0. Insert vertex vk and the edges (u, vk ), (vk , u1 ), (vk , u2 ), . . . , (vk , ut ) into Gk−1 to obtain Gk . For each i, where 1 ≤ i ≤ t, reduce N Count(ui ) by 1 (Note that except for ut , N Count(ui ) for each ui will become 0 now). Reduce T Count(u) by 1. – q > 0 : In this case, vk+q will have only one neighbor u on Hk−1 , where u is the first vertex right of u with N Count(u ) > 0. Insert vertices vk , vk+1 , . . . , vk+q and edges (u, vk ), (vk , vk+1 ), (vk+1 , vk+2 ), . . . , (vk+q−1 , vk+q ), (vk+q , u ), into Gk−1 to obtain Gk . Reduce N Count(u ) by 1. Reduce T Count(u) by 1. Also, for each i, where k ≤ i ≤ k + q − 1, reduce T Count(vi ) by 1.
5
Encoding Degree-3 And Degree-4 Plane Graphs
The algorithms of [1] will encode a biconnected (triconnected) degree-4 plane graph using 5.17n bits (4.74n bits), and a degree-3 biconnected (triconnected) plane graph using 4.37n (3.95n) bits. But, these algorithms do not consider the degrees of vertices while encoding a graph. (The algorithm of [5] will construct an asymptotically bit-minimum encoding of these graphs, but it is practical only for very large graphs.) Here, we show that we can get a better encoding for degree-3 and degree-4 plane graphs by considering the degrees of their vertices. The basic idea is simple. Suppose we construct a rightmost canonical ordering c = v1 , v2 , . . . , vn of the vertices of a biconnected plane graph G. Then, to encode G, from Theorem 2, it is sufficient to encode, for each vertex, how many outgoing tree edges, incoming non-tree edges, and outgoing non-tree edges the vertex has. Suppose G is a degree-3 graph. From Property 2, a vertex v = v1 can only be of one of the 7 types, A to G, based on its degree, and the number and types of its edges. v is of one of types A to F , if it has degree 3, and of type F or G if it has degree 2. v is of (a) Type A: if it has two outgoing tree edges, (b) Type B: if it has one outgoing tree edge and one incoming non-tree edge, (c) Type C: if it has one outgoing tree edge and one outgoing non-tree edge, (d) Type D: if it has one incoming and one outgoing non-tree edge, (e) Type E: if it has two incoming non-tree edges, (f) Type F: if it has one incoming non-tree edge, and (g) Type G: if it has one outgoing tree edge. Note that vertex v1 will have either two or three outgoing tree edges. Thus, we encode G by a string S = s1 s2 . . . sn , where – s1 represents the number of outgoing tree edges of v1 , and is equal to 0 if v1 has two outgoing edges, and is equal to 1 if v1 has three outgoing edges. – Each symbol si , 2 ≤ i ≤ n, represents the type of vertex vi , and is equal to A, B, C, D, E, F , or G. Since each si , where 2 ≤ i ≤ n, can have 7 possible values, we can encode the substring S = s2 . . . sn using (n − 1) log2 7 ≈ 2.81(n − 1) bits by converting the
180
Amrita Chanda and Ashim Garg
corresponding Base-7 number into binary representation in O(n2 ) time. Using Huffman encoding, we can encode S using at most 3(n − 1) bits in O(n) time. This, combined with Theorems 1 and 2, gives us the following lemma: Lemma 1. Given a degree-3 biconnected plane graph G with n vertices, we can encode it using less than 2.81n bits in O(n2 ) time and decode the encoding to reconstruct G in O(n2 ) time. We can also encode G using at most 3n − 2 bits and decode the encoding to reconstruct G in O(n) time. If G is a degree-3 triconnected graph, then, using Property 3, we can show that each vertex v = v1 , vn can only be of 4 types. This gives a shorter encoding for G: Lemma 2. Given a degree-3 triconnected plane graph G with n vertices, we can encode it using at most 2n−2 bits in O(n) time (using Huffman Encoding). This encoding can be decoded in O(n) time to reconstruct G. If G is a degree-4 biconnected (triconnected) graph, then each vertex v, where v = v1 (v = v1 , vn ), can be of 16 (12) types. This gives Lemma 3 (Lemma 4): Lemma 3. Given a degree-4 biconnected plane graph G with n vertices, we can encode it using at most 4n − 2 bits in O(n) time (using Huffman Encoding) and decode the encoding to reconstruct G in O(n) time. Lemma 4. Given a degree-4 triconnected plane graph G with n vertices, we can encode it using 2 + (n − 2) log2 12 + 1 < 3.59n bits in O(n2 ) time and decode the encoding to reconstruct G in O(n2 ) time. We can also encode G using at most 2 + 3.67(n − 1) + 1 < 3.67n bits (using Huffman encoding) and decode the encoding to reconstruct G in O(n) time.
6
Encoding an Orthogonal Representation
We will use the following properties of an orthogonal representation: Property 4. The sum of angles around any vertex is equal to 360◦ . Property 5. The sum of interior angles of the polygon p representing any internal face is equal to (k − 2)180◦ , where k is the total number of line-segments in p. We can encode an orthogonal representation Γ of a biconnected plane graph G by: – encoding structure: encoding the structure of graph G, – encoding angles: for each vertex, encoding the angles between consecutive edges incident on it, and – encoding turns: for each edge e = (u, v), encoding the sequence of left and right turns encountered while walking from u to v along e.
Compact Encodings of Planar Orthogonal Drawings
181
To encode angles, suppose G has n vertices and m edges. Each angle of Γ can be either 90◦ , 180◦ , or 270◦ . Suppose we have already constructed a rightmost canonical ordering c = v1 , v2 , . . . , vn of the vertices of G. Let vi be a vertex of G. Let e1 e2 . . . ek , where k ≤ 4 be the counterclockwise order of edges incident on vi , where, if vi = v1 , then e1 is the incoming tree edge of v, and if vi = v1 , then e1 is the edge (v1 , v2 ). Let s∗i be the string a1 a2 . . . ak , where aj represents the counterclockwise angle between edges ej and ej+1 at vertex vi . aj is equal to A, B, or C, respectively, if the magnitude of the corresponding angle is equal to 90◦ , 180◦ , or 270◦ , respectively. Then, we can construct a string S ∗ = s∗1 s∗2 . . . s∗n , that encodes all the angles of G. Total number of symbols in S ∗ is equal to number of angles in Γ , which is equal to 2m. Using Property 4, we can encode S ∗ using even fewer bits. Property 4 implies that, for each vertex vi , it is sufficient to encode angles a1 , a2 , . . . , ak−1 since the value of angle ak can be obtained from them. Thus, for vi , it is sufficient to construct the string s∗i = a1 a2 . . . ak−1 . So, the overall number of symbols in string S ∗ can be reduced to 2m − n. We therefore have the following lemma: Lemma 5. Given an orthogonal representation of a degree-4 biconnected graph G with n vertices, we can encode its angles using (2m−n) log2 3 ≈ 1.58(2m−n) ≤ 4.74n bits in O(n2 ) time and at most 1.67(2m − n) ≤ 5.01n bits in O(n) time (using Huffman Encoding). Moreover, during decoding, if we already knew the degree of each vertex, then we can decode these encodings to obtain the angles in O(n2 ) and O(n) time, respectively. If G is a triconnected graph, then each vertex has at least 3 angles around it, and so each angle can be either 90◦ , or 180◦ . Therefore: Lemma 6. Given an orthogonal representation of a degree-4 triconnected graph G with n vertices, we can encode its angles using 2m − n bits in O(n) time. Moreover, during decoding, if we already knew the degree of each vertex, then we can decode the encoding to obtain the angles in O(n) time. Now consider the problem of encoding the turns of Γ . Given a rightmost canonical ordering c = v1 , v2 , . . . , vn of G, and the associated canonical tree Tc , we first construct an ordering o = e1 , e2 , . . . , em of the edges of G by putting the incoming tree and non-tree edges of the vertices v1 , v2 , . . . , vn into o, such that the edges of vi precede those of vj if i < j, and for each vertex vi , we first put its incoming tree edge, and then its incoming non-tree edges in the same order as their counter-clockwise order around vi . Next, for each edge ei = (vj , vk ) in o, where j < k, we construct a (possibly empty) string s+ i consisting of symbols L and R, where a symbol L (R) denotes a left (right) turn encountered while walking from vj to vk along ei . These symbols are placed in s+ i in the order the corresponding turns are encountered while walking from vj to vk . Finally, we construct a string + + + S + = s+ 1 #s2 # . . . #sn consisting of all the si ’s separated by a symbol #. Lemma 7. Given an orthogonal representation Γ with b turns (bends) of a degree-4 biconnected graph G with n vertices, we can encode its turns using (b + m−1) log2 3 ≈ 1.58(b+m−1) bits in O((b+m)2 ) time, and at most 1.67(b+m−1)
182
Amrita Chanda and Ashim Garg
bits in O(b+m) time (using Huffman Encoding). These encodings can be decoded in O((b + m)2 ) and O(b + m) time, respectively, to obtain the turns of Γ . If Γ is a turn-monotone orthogonal representation, then we can reduce the length of S + by using Property 5 as follows: c induces an ordering f1 , f2 , . . . , fp of the internal faces of G, such that when we reconstruct G using c, as in the proof of Theorem 2, starting from an initially empty graph, the faces will get inserted into it in the same order. Let I1 , I2 , . . . , IK be the corresponding intervals of c. The ordering f1 , f2 , . . . , fp is defined as follows (see Figure 1(b)): Let I1 = [v3 , v3+q ], where q ≥ 0. Face f1 is the face consisting of the vertices v1 , v3 , . . . , v3+q , v2 . In general, suppose we have already constructed the partial ordering f1 , f2 , . . . , fs of the faces, using intervals I1 , I2 , . . . , Ik−1 . Let Ik = [vk , vk+q ], where q ≥ 0. Let P = v1 (= u1 )u2 . . . us (= v2 ) be the subpath of Hk−1 that we obtain by removing the edge (v1 , v2 ) from Hk−1 . Let Cj be the path vk vk+1 . . . vk+q . We have 2 cases: – q > 0: Then, Cj has exactly two neighbors vl and vr in Hk−1 . Let x1 = (vl )x2 , . . . , xt (= vr ) be the subpath of P that connects vl and vr . Then, fs+1 is the internal face of G consisting of the vertices vl (= x1 ), vk , . . . , vk+q , vr (= xt ), xt−1 , xt−2 , . . . , x2 . We say that face fs+1 belongs to Interval Ik . – q = 0: Then Cj consists of exactly one vertex vk . Let u1 (= vl ), u2 , . . . , ut (= vr ) be the left-to-right order of the neighbors of vk in Hk−1 . Let Pi , where 1 ≤ i ≤ t − 1, be the subpath of P that connects ui and ui+1 . Then, each face fs+i , where 1 ≤ i ≤ t − 1, is the internal face that consists of the vertex vk and the vertices of path Pi . We say that face fs+i belongs to Interval Ik . (Figure 1(b) also shows the ordering of the faces given by the rightmost canonical ordering shown in Figure 1(b).) Let Tc be the canonical spanning tree associated with c. For each face fi , a tree edge of fi is one that is also an edge of Tc . Fact 1. Except for one non-tree edge e, all the non-tree edges of each face fi are already contained in the faces f1 , f2 , . . . , fi−1 . We will call edge e as the non-tree completion edge of fi . Intuitively, we call the edge non-tree completion edge because, while reconstructing G using c, this is the only non-tree edge that we need to add to the already constructed graph to add face fi to it (of course, we will need to add the tree edges of fi also). For example, in Figure 1, edge (14, 12) is the non-tree completion edge of face f10 . For the face fs , in the case q > 0 given above, the non-tree completion edge is the edge (vk+q , vr ). For each face fs+i , in the case q = 0 given above, the non-tree completion edge is the edge (vk , ui+1 ). Since each edge of a turn-monotone orthogonal representation Γ has same kinds of turns only (left or right, but not both), Property 5 implies that for any face of Γ , it is sufficient to encode the turns of all but one edge, namely its non-tree completion edge e, since the turns of e can be deduced from the turns of the other edges. Infact, Lemma 8 says that it is sufficient to encode turns of tree edges:
Compact Encodings of Planar Orthogonal Drawings
183
Lemma 8. Let Γ be a turn-monotone orthogonal representation of a degree-4 biconnected plane graph G. let c be a rightmost canonical ordering of G. Suppose we construct a string S + encoding the turns of Γ as in Lemma 7 using c, except that S + encodes the turns of only the tree edges of G. Then, by decoding S + we can obtain the turns of all the edges of Γ . Proof. Let f1 , f2 , . . . , fp be the ordering of faces that corresponds to c, as defined above. We can easily prove this lemma can using induction: Base Case: Consider face f1 . Decoding S + will give us the turns of all the tree edges of f1 . f1 has exactly one non-tree edge e (which is its non-tree completion edge). From Property 5, we can determine the turns of e also. Induction: Suppose we have already determined the turns of all the edges of faces f1 , f2 , . . . , fi−1 . Consider face fi . From Fact 1, except for its non-tree completion edge e, all the other non-tree of fi are already contained in the faces f1 , f2 , . . . , fi−1 . Decoding S + will give us the turns of all the tree edges of f1 . Hence, except for e, we would know the turns of all the edges of fi . From Property 5, we can determine the turns of e also. Since, Tc has exactly n − 1 edges, we have: Lemma 9. Given a turn-monotone orthogonal representation with b turns(bends) of a degree-4 biconnected graph with n vertices, we can encode its turns using at most (b + n − 2) log2 3 ≈ 1.58(b + n − 2) bits in O((b + n)2 ) time, and at most 1.67(b + n − 2) bits in O(b + n) time (using Huffman Encoding). These encodings can be decoded in O((b+n)2 ) and O(b+n) time, respectively, to obtain the turns. To encode an orthogonal representation Γ , we construct a string S1 = A L A∗ L∗ S S ∗ S + , where S , S ∗ , S + are strings encoding structure, angles, and turns, respectively, of Γ , as given by Lemmas 1 (or 2, 3, or 4), 5 (or 6), and 7 (or 9), respectively, L (L∗ ) is length of S (S ∗ ) in binary notation, and A (A∗ ) encodes the length of L (L∗ ) in unary notation, and consists of |L | (|L∗ |) 0’s followed by a 1. Note that lengths of A , L , A∗ , and L∗ are O(log n) each.
7
Encoding Lengths of Line-Segments
Let d be a planar orthogonal drawing with b turns of a degree-4 biconnected plane graph G with n vertices and m edges. Suppose each line-segment of d has length at most W . Just as we constructed a string S + in Section 6 to encode turns, we can construct a string S = s1 s2 . . . sm , where each si contains the lengths of all the line-segments of edge ei = (vj , vk ), placed in the order the corresponding linesegments are encountered while traveling along ei from vj to vk , where j < k. We can reduce the length of S by using the following property of d: Suppose we orient each horizontal line-segment of d as going “East” or “West”, and each vertical line-segment as going “North” or “South”, assuming that the linesegment of the edge (v1 , v2 ) incident on v1 goes East. (We can easily do this in O(n+m+b) = O(n+b) time using the angle and turn information contained in d.)
184
Amrita Chanda and Ashim Garg
Property 6. In d, for each face of G: 1. The sum of the lengths of all the line-segments going East = the sum of the lengths of all the line-segments going West, and 2. The sum of the lengths of all the line-segments going North = the sum of the lengths of all the line-segments going South. Property 6 implies that we can omit encoding the length of one horizontal and one vertical line-segment of fi , and still be able to obtain the lengths of all the line-segments of fi from an encoding of the lengths of its other line-segments. To decide which line-segments to omit, consider the ordering f1 , f2 , . . . , fm of the faces of G that we can obtain from a rightmost ordering c of G, as described in Section 6. Let Ik = [vk , vk+q ] be the interval of c, such that fi belongs to Ik . Let Ei be the set of all the edges of fi that are not in the faces f1 , f2 , . . . , fi−1 . Note that Ei contains at least one edge, namely, the non-tree completion edge e = (u, v) of fi . Moreover, the edges of Ei form a connected path p, which connects u with a vertex u , where u is the end-vertex of e that belongs to Hk−1 , and u is a vertex common to both fi and fi−1 . The free horizontal (vertical) line-segment of fi is defined as the first horizontal (vertical) line-segment encountered while traveling along p from u to u . Note that fi will have at least one free line-segment (which can be horizontal or vertical). While encoding the lengths of the linesegments of d, we can omit from S all the free line-segments of the faces of G. Having constructed S , we can construct a string S2 = A T S , where T stores the value of W in binary using exactly log2 (W + 1) bits, and A contains a sequence of |T | 0’s followed by a 1. String A basically encodes the length of T in unary notation. We have the following lemma: Lemma 10. We can encode the lengths of the line-segments of d using a string S2 consisting of 1+(2+b+m−fH −fV ) log2 (W +1) ≤ 1+(2+b+m−f ) log2 (W +1) bits in O(|S2 |) time, where fH and fV are the number of horizontal and vertical free line-segments, respectively, of d. Assuming that, while decoding, we already know all the angles and turns of d, we can decode S2 to obtain the lengths of all the line-segments of d in O(|S2 |) time.
8
Encoding a Planar Orthogonal Drawing
Let d be a planar orthogonal drawing of a degree-4 biconnected planar graph G. Let Γ be the orthogonal representation of G that corresponds to d. We can encode d by constructing a string S = BLS1 S2 , where S1 is the string constructed in Section 6 that encodes Γ , S2 is the string constructed using Lemma 10 that encodes the free lengths of the line-segments of d, L is a string, with length log2 (|S1 | + 1), that encodes in binary notation the length of string S1 , and B is a string that contains a sequence of |L| 0’s followed by a 1. B encodes the length of L in unary notation. We can obtain d by decoding S, by first extracting B from it and obtaining the length of L, then extracting L and obtaining the length of S1 , then extracting
Compact Encodings of Planar Orthogonal Drawings
185
S1 and decoding it to obtain Γ , and finally, extracting S2 and decoding it to obtain the lengths of the line-segments of d. This is summarized in Theorem 3: Theorem 3. Let d be a planar orthogonal drawing, with b turns (bends) of a plane graph G with n vertices, m edges, and f internal faces. Suppose each linesegment of d has length at most W . Let p = (2 + b + m − f ) log2 (W + 1). Let q = n + b. – If G is a degree-4 biconnected graph, then we can encode (and decode) d using at most 4.74m+2.42n+1.58b+p+O(log q) bits in O((n+b+p)2 ) time, and using at most 5.01m + 2.33n + 1.67b + p + O(log q) bits in O(n + b + p) time. – If G is a degree-4 triconnected graph, then we can encode (and decode) d using at most 3.58m+2.59n+1.58b+p+O(log q) bits in O((n+b+p)2 ) time, and using at most 3.67m + 2.67n + 1.67b + p + O(log q) bits in O(n + b + p) time. – If G is a degree-3 biconnected graph, then we can encode (and decode) d using at most 4.74m+1.23n+1.58b+p+O(log q) bits in O((n+b+p)2 ) time, and using at most 5.01m + 1.33n + 1.67b + p + O(log q) bits in O(n + b + p) time. – If G is a degree-3 triconnected graph, then we can encode (and decode) d using at most 3.58m + n + 1.58b + p + O(log q) bits in O((n + b + p)2 ) time, and using at most 3.67m + n + 1.67b + p + O(log q) bits in O(n + b + p) time. Moreover, if d is turn-monotone, then we can encode it using fewer bits, as follows: – If G is a degree-4 biconnected graph, then we can encode (and decode) d using at most 3.16m + 4n + 1.58b + p + O(log q) bits in O((n + b + p)2 ) time, and using at most 3.34m + 4n + 1.67b + p + O(log q) bits in O(n + b + p) time. – If G is a degree-4 triconnected graph, then we can encode (and decode) d using at most 2m + 4.17n + 1.58b + p + O(log q) bits in O((n + b + p)2 ) time, and using at most 2m + 4.34n + 1.67b + p + O(log q) bits in O(n + b + p) time. – If G is a degree-3 biconnected graph, then we can encode (and decode) d using at most 3.16m + 2.81n + 1.58b + p + O(log q) bits in O((n + b + p)2 ) time, and using at most 3.34m + 3n + 1.67b + p + O(log q) bits in O(n + b + p) time. – If G is a degree-3 triconnected graph, then we can encode (and decode) d using at most 2m + 2.58n + 1.58b + p + O(log q) bits in O((n + b + p)2 ) time,, and using at most 2m + 2.67n + 1.67b + p + O(log q) bits in O(n + b + p) time.
References 1. R. C. Chuang, A. Garg, X. He, M. Y. Kao, and H. Lu. Compact encoding of planar graphs via canonical ordering and multiple parenthesis. In Proc. International Colloqium on Automata, Languages and Programming (ICALP), pp. 118–129, 1998. 2. H. de Fraysseix, J. Pach, and R. Pollack. How to draw a planar graph on a grid. Combinatorica, 10(1):41–51, 1990. 3. G. Di Battista, G. Liotta, and F. Vargiu. Diagram Server. J. Visual Lang. Comput., 6(3):275–298, 1995.
186
Amrita Chanda and Ashim Garg
4. G. Di Battista, G. Liotta, and F. Vargiu. Spirality and optimal orthogonal drawings. SIAM J. Comput., 27(6):1764–1811, 1998. 5. Xin He, M.-Y. Kao, and H. Lu. A fast general methodology for informationtheoretically optimal encodings of graphs. SIAM J. Comput., 30(3):838–846, 2000. 6. G. Kant. Drawing planar graphs using the lmc-ordering. In Proc. 33th Annu. IEEE Sympos. Found. Comput. Sci., pages 101–110, 1992. 7. R. Tamassia. On embedding a graph in the grid with the minimum number of bends. SIAM J. Comput., 16(3):421–444, 1987. 8. R. Tamassia and I. G. Tollis. Planar grid embedding in linear time. IEEE Trans. Circuits Syst., CAS-36(9):1230–1234, 1989. 9. W. T. Tutte. A census of planar triangulation. Canad. J. Math., 14:21–38, 1962.
Fractional Lengths and Crossing Numbers Ondrej S´ ykora1 , L´ aszl´o A. Sz´ekely2 , and Imrich Vrt’o3 1 Department of Computer Science, Loughborough University Loughborough, Leicestershire LE11 3TU, The United Kingdom 2 Department of Mathematics, University of South Carolina Columbia, SC 29208, USA 3 Institute of Mathematics, Slovak Academy of Sciences D´ ubravsk´ a 9, 842 35 Bratislava, Slovak Republic
Abstract. Adamec and Neˇsetˇril [1] proposed a new the so called fractional length criterion for measuring the aesthetics of (artistic) drawings. They proposed to apply the criterion to the aesthetic drawing of graphs. In the graph drawing community, it is widely believed and even experimentally confirmed that the number of crossings is one of the most important aesthetic measures for nice drawings of graphs [6]. The aim of this note is to demonstrate on two standard graph drawing models that in provably good drawings, with respect to the crossing number measure, the fractional length criterion is closely related to the crossing number criterion.
1
Introduction
Adamec and Neˇsetˇril [1] proposed a new the so called fractional length criterion for measuring the aesthetics of (artistic) drawings. A drawing D is a finite set of continuous rectifiable curves in the Euclidean plane. The fractional length of the drawing D, is defined as follows. For a line l denote by i(l, D) the number of intersections of the line l and the drawing D. The fractional length fl(D) of the drawing D is the expected value of i(l, D), where the expectation relates to the random selection of l such that l has a nonempty intersection with the convex hull of D. See Fig. 1 and Fig. 2. The fractional length of the second drawing is roughly 4.81. The fractional length is invariant under transposition, rotation and scaling. The criterion is also applicable to aesthetic graph drawings. See Fig. 2. In the graph drawing community, it is widely believed and even experimentally confirmed that the number of crossings is one of the most important aesthetic measures for nice drawing of graphs [3,6]. The aim of this note is to demonstrate on two standard graph drawing models that in provably good drawings, with respect to the crossing number measure, the fractional length criterion is closely related to the crossing number criterion. Under provably good drawing we understand a drawing in which the number of crossings differs from the minimum
This research was supported in part by the EPSRC grant GR/R37395/01, NSF contract 007 2187 and the VEGA grant 2/7007/20.
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 186–192, 2002. c Springer-Verlag Berlin Heidelberg 2002
Fractional Lengths and Crossing Numbers
187
Fig. 1. A prehistoric drawing - the Uffington white horse.
Fig. 2. A drawing of the 2-dimensional ordinary Butterfly graph inspired by the web page http://www.uni-paderborn.de/cs/ag-madh/.
by a polylogarithmic factor. More precisely, in the orthogonal model of drawing the relation between both parameters is almost quadratical while in the 2-layer drawing model is linear.
188
2
Ondrej S´ ykora, L´ aszl´ o A. Sz´ekely, and Imrich Vrt’o
Definitions
Let G = (V, E) be a graph. Let cr(D) denote the number of crossings of edges in a drawing D of G in the plane. The crossing number of the graph G, denoted by cr(G), is the minumum of cr(D) over all drawings of G. Let G be a connected graph of maximum degree of at most 4. Consider an infinite grid of horizontal and vertical lines with unit distances between any two parallel neighbouring lines. The VLSI layout for the graph G is an injective mapping of vertices of G into nodes of the grid and a mapping of the edges of G into paths of the grid such that two paths can cross or touch at the grid nodes but can not overlap. See Fig. 3. The area A of G is the area of the smallest rectangle covering the layout, where the minumum is taken over all VLSI layouts of G in the grid [9]. Note that any VLSI layout of G produces the so called orthogonal layout.
Fig. 3. A VLSI layout of a graph within area 49.
Let G = (V0 , V1 , E) be a bipartite graph. Place the vertices of V0 and V1 into distinct points on horizontal lines y = 0 and y = 1, in the standard coordinate systems, respectively. Draw the edges by straight line segments producing a 2layer drawing D of G. See Fig. 4. Let bcr(D) denote the number of crossings of edges of D. The bipartite crossing number of G is the minimum of bcr(D) over all drawings D of G.
Fractional Lengths and Crossing Numbers
189
For a graph G = (V, E), let f : |V | → {1, 2, ..., |V |} be a bijection. The optimal linear arrangement problem for G is to find Length(G) = min |f (u) − f (v)|. f
uv∈E
Now we introduce the main tool for estimating fractional lengths of drawings. Steinhaus’ paper [8] implies the following lemma: Lemma 1. Consider a finite system of rectifiable curves in the plane of total length L. Let P be the perimeter of the convex hull of the corresponding drawing D. Then 2L fl(D) = . P
Fig. 4. A 2-layer drawing of the 3-dimensional hypercube.
3
VLSI Model
Our first drawing model with provably good crossing numbers is the orthogonal graph drawing based on the VLSI layout of graphs. 3.1
Basic Result
Theorem 1. Let G = (V, E) be an n-vertex graph with the maximum degree of at most 4. Consider a VLSI layout of G with the area A. Then there exists an orthogonal drawing D of G with a provably good number of crossings cr(D) and positive constants c1 and c2 satisfying cr(D) + n c1 ≤ fl(D) ≤ c2 cr(D) + n log n. log n Proof. As we do not care about the constant factors we may assume that the optimal VLSI layout of G lies in a square. In fact, Leiserson [5] proved that any
190
Ondrej S´ ykora, L´ aszl´ o A. Sz´ekely, and Imrich Vrt’o
layout lying in a rectagle of the area A can be redrawn by “folding” in such a way that it occupies a square of the area A ≤ 3A. The optimal VLSI layout of G produces in a natural way an orthogonal drawing D of G. The results of Leighton [4], Leiserson [5] and Valiant [10] implies: cr(G) + n ≤ cr(D) + n ≤ A ≤ c3 (cr(G) + n) log2 n ≤ c3 (cr(D) + n) log2 n, (1) for some constant c3 . This means that the drawing induced by the optimal VLSI layout produces a provably good drawing as it provides a polylogarithmic approximation of the crossing number of G. Let L be the sum of lengths of all edges of G in the layout. Observe that 1 (cr(D) + n) ≤ L ≤ 2A. (2) 2 In fact, horizontal or vertical straightline segments of lenght 1/2 starting at a single vertex or crossing in the drawing contribute to L by at least 1/2. To see the second inequality, take a unit square and move its center along all edges in the drawing. The total area of covered points is no greater then A, but every point is covered at most twice. Now consider our drawing as a union of curves in the plane of total length L with a square convex hall of the area A. According to the Lemma 1 we have L fl(D) = √ . 2 A
(3)
From (1) and (2) we get √ √ cr(D) + n L √ ≤ √ ≤ A ≤ c3 cr(D) + n log n. 4 A 2 A Hence
cr(D) + n √ L ≤ √ ≤ c3 cr(D) + n log n. (4) log n 2 A Finally, substituting (3) into (4) we get the result. ✷ Our results roughly say that the fractional length of a provably good drawing, with respect to crossing number measure, is proportional to the square root of the number of crossings plus the number of vertices. It suggests that the fractional length expresses for orthogonal drawings the same “beauty” as the crossing number but measured in different units. √ Note √ that it is impossible to remove the n term in cr(D) + n, because an n ×√ n mesh graph has crossing number zero but the fractional lenght is of order n. This suggests that the aesthetic measure cr(G) + n is more suitable than just a sole cr(G). We compared the fractional length measure with the number of crossings in “good” drawings with small number of crossings. A comparison to any drawing would be more desirable but one can easily see that if we consider a general drawing model in the plane then any drawing of a graph can be redrawn keeping the number of crossings same but increasing the fractional length arbitrarily. So without putting “reasonable” assumption on the drawing the both measures are incoparable. 1 √ c3
Fractional Lengths and Crossing Numbers
4
191
Two-Layer Model
Our second model of provably good graph drawing is the 2-layer model with the bipartite crossing number measure. Consider an n-vertex bipartite graph V = (V0 , V1 , E). As the bipartite crossing number depends on the orderings of vertices on the lines y = 0 and y = 1 only, we may assume that the vertices are placed into points with integer coordinates such that the whole drawing fits into an (n − 1) × 1 rectangle. 4.1
General Graphs
Theorem 2. Let G = (V0 , V1 , E) be an n-vertex bipartite graph of minimum and maximum degree δ and d. Let δ ≥ 2 and d = O(δ). Then there exists a 2-layer drawing D of G with a provably good number of crossings bcr(D) and positive constants c1 , c2 and c3 satisfying c1
1 1 bcr(D ≤ fl(D) ≤ c2 bcr(D) + c3 d. dn dn
Proof. Consider an optimal linear arrangement of G. We may assume that the vertices of G are placed on the line y = 0 into points {1, 2, ..., n}. Projecting orthogonally the vertices of V1 on the line y = 1 and drawing the edges of G as straight line segments we obtain a 2-layer drawing D of G. The results of Shahrokhi et al. [7] implies bcr(G) ≤ bcr(D) ≤ 5dLength(G)
(5)
and
1 2 1 (6) nd ≤ bcr(D) + nd2 , 12 12 for some positive constant c4 . The above inequalities immediately imply that the bipartite crossing number of the drawing D is approximately the same as the optimal value bcr(G). Now consider our drawing D as a union of curves in the plane of total length L with a rectangular convex hall of the perimeter 2n. Clearly √ Length(G) ≤ L ≤ 2Length(G). (7) c4 dLength(G) ≤ bcr(G) +
Finally, combining (5),(6) and (7) and noting that fl(D) = L/n, we get √ √ bcr(D) 2bcr(D) 2 d, ≤ fl(D) ≤ + 5dn c4 dn c4 which implies the claim. 4.2
✷
Trees
A more precise relation between the fractional length and the bipartite crossing number holds in the case of trees.
192
Ondrej S´ ykora, L´ aszl´ o A. Sz´ekely, and Imrich Vrt’o
Theorem 3. Let T be an n-vertex tree and dv denote the degree of any vertex v. Then there exist a 2-layer optimal drawing D of T satisfying dv dv 1 bcr(D) + n − 1 + fl(D) ≥ n 2 2 v∈T
√ dv dv 2 fl(D) ≤ bcr(D) + n − 1 + n 2 2 v∈T
Proof. Shahrokhi et al. [7] proved that an optimal 2-layer drawing D of a tree T can be obtained from an optimal linear arrangemment of T by the above projection and moreover dv dv . bcr(T ) = bcr(D) = Length(T ) + 1 − n − 2 2 v∈T
The rest of the proof is similar as above.
✷
References 1. Adamec, J., Neˇsetˇril, J.: Towards an Aesthetic Invariant for Graph Drawing. In: 9th Intl. Symp. on Graph Drawing. LNCS 2265. Springer. Berlin (2001) 287-296 2. Bhatt, S., Leighton, F.T.: A Framework for Solving VLSI Graph Layout Problems. J. Computer and System Science 28 (1984) 300-334 3. DiBattista, G., Eades, P., Tollis, I., Tamassia, R.: Graph Drawing: Algorithms for the Visualization of Graphs. Prentice Hall (1999) 4. Leighton, F.T.: New Lower Bound Techniques for VLSI. Mathematical Systems Theory 17 (1984) 47-70 5. Leiserson, C.E.: Area Efficient Graph Layouts (for VLSI). In: 21st Annual Symposium on Foundations of Computer Science. IEEE Press (1980) 270-281 6. Purchase, H.: Which aestethic has the greatest effect on Human Understanding? In: 5th Intl. Symp. on Draph Drawing. LNCS 1353. Springer. Berlin (1997) 248-261 7. Shahrokhi, F., S´ ykora, O., Sz´ekely, L.A., Vrt’o, I.: On Bipartite Drawings and the Linear Arrangement Problem. SIAM J. Computing 30 (2000), 1773-1789. 8. Steinhaus, H.: Length, Shape and Area. Colloquium Math. III (1954) 1-13 9. Thompson, C.D.: Area-Time Complexity for VLSI. In: 11th Annual ACM Symposium on Theory of Computing. ACM Press (1979) 81-89 10. Valiant, L.G.: Universality Considerations in VLSI Circuits. IEEE Transactions on Computers 30 (1981) 135-140
Drawing Directed Graphs Using One-Dimensional Optimization Liran Carmel, David Harel, and Yehuda Koren Dept. of Computer Science and Applied Mathematics The Weizmann Institute of Science, Rehovot, Israel {liran, harel, yehuda}@wisdom.weizmann.ac.il
Abstract. We present an algorithm for drawing directed graphs, which is based on rapidly solving a unique one-dimensional optimization problem for each of the axes. The algorithm results in a clear description of the hierarchy structure of the graph. Nodes are not restricted to lie on fixed horizontal layers, resulting in layouts that convey the symmetries of the graph very naturally. The algorithm can be applied without change to cyclic or acyclic digraphs, and even to graphs containing both directed and undirected edges. We also derive a hierarchy index from the input digraph, which quantitatively measures its amount of hierarchy.
1
Introduction
Visualizing digraphs is a challenging task, requiring algorithms that faithfully represent the relative similarities of the nodes, and give some sense of the overall directionality. The latter requirement renders algorithms designed for undirected graphs inappropriate for digraphs. Consequently, algorithms for digraph drawing usually adopt different strategies from their undirected counterparts. The dominant strategy, rooted in the work of Sugiyama et. al. [11], is based on separating the axes, where the y-axis represents the directional information, or hierarchy, and the x-axis allows for additional aesthetic considerations, such as shortening edge lengths or minimizing the number of edge crossings. In these algorithms, the y-coordinates are computed by dividing the y-axis into a finite number of layers and associating each node with exactly one layer — a process called layering. Edges are allowed only between consecutive layers, and they all point in the same direction. To make this feasible, dummy nodes are sometimes inserted. When dealing with cyclic digraphs, no layout can place all edges in the same direction, and what is traditionally done in this case is to apply a preliminary stage, in which a minimal number of edges is sought, whose reversal will make the digraph acyclic. This is actually an NP-hard problem. Assigning the x-coordinates is normally done in two stages. The first determines the order of the nodes within each layer, in an iterative process called ordering. In a single iteration, the order of the nodes in all layers but one is fixed, and the order of the mobile nodes is determined, so as to minimize the number of edge crossings. This too is an NP-hard problem. The second stage determines the exact locations of the nodes along the x-axis, taking into account various parameters, such as the finite size of the nodes and the smoothness of the edges. For more details see [2,6].
For a full version see [1]
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 193–206, 2002. c Springer-Verlag Berlin Heidelberg 2002
194
Liran Carmel, David Harel, and Yehuda Koren
Such digraph drawing algorithms have evolved to produce nice and useful layouts for many different types of digraphs. Nevertheless, we would like to point out two inherent properties of the standard strategy, which, despite being treated in various ways by the many algorithms, are in many cases still undesirable: – Finding a layering for cyclic digraphs requires transforming them into acyclic ones, thus introducing a certain distortion of the original problem. – The layering is strict, in the sense that the y-axis is quantized into a finite number of layers. This constraint may sometimes be advisable for acyclic digraphs, but we show that allowing for more flexibility turns out to be advantageous to the drawing. In this paper we present a new algorithm for digraph drawing. It embraces the idea of axis separation, but uses novel approaches to the drawing of both axes. These approaches, apart from the fact that they produce nice drawings and have fast implementations, also successfully deal with the two aforementioned points — the distortion and the discrete layering. We associate with the nodes continuous y-coordinates, in a way that suggests a natural unified framework that can be applied to any kind of digraph, whether cyclic or acyclic, and which requires no graph modification or preprocessing. In particular, dummy nodes are not required, and cyclic digraphs do not have to go through the process of edge inversion. For some digraphs, the continuous layering produces the usual quantization of the y-axis. But, for many other digraphs the quantization is broken, in order to better represent the hierarchy. We define the vector of y-coordinates as the unique minimizer of a simple energy function, and show that the minimization problem is equivalent to a system of linear equations. The simple form of the energy function enables rigorous analysis, giving rise to many interesting results, the most important of which appears to be the definition of an index for measuring the amount of hierarchy in a digraph. As to the x-coordinates, they are assigned using the minimizer of another energy function that is suitable for the one-dimensional case. By definition, a force is the inverse gradient of the energy. Thus, the strategy of energy minimization is equivalent to a force directed model. Therefore, had we been asked to categorize our algorithm, we would have said that it is purely energy minimization oriented, as all of its parts use energy minimization procedures, each part with its own specially tailored energy function. Force directed models are much more popular in undirected graph drawing than in digraph drawing. We are aware of only one other occasion where a force directed model was suggested for digraph drawing, [10], forcing directionality by applying a homogeneous magnetic field and favoring edges that are parallel to its field lines. Yet, we are under the impression that the inferred energy function is complicated, rich in local minima, and rather difficult to minimize.
2
The Algorithm
A digraph is usually written G(V, E), where V = {1, . . . , n} is a set of n nodes and E ⊆ V × V is a set of directed edges, (i, j) being the edge pointing from node i to node j. Each edge is associated with two magnitudes: (1) symmetric weights, wij = wji , and
Drawing Directed Graphs Using One-Dimensional Optimization
195
(2) target height differences, which express the relative hierarchy of nodes i and j by the number δij , measuring their desired height difference along the y-axis. Thus, in the drawing we would like to place nodes i and j such that yi − yj = δij = −δji . A digraph with δij = 0 for every (i, j) ∈ E is really an undirected graph. A digraph is called unweighted if for every edge (i, j), δij = wij = 1. Henceforth, we assume wij = 0 for any non-adjacent pair of nodes. By the conventional definition, the Laplacian is the symmetric n × n matrix n k=1 wik i = j Lij = i, j = 1, . . . , n. i = j −wij For later use, we introduce another important magnitude associated with a digraph: Definition 1. Let G(V, E) be a digraph. The balance of node i is def
bi =
n
wij δij .
j=1
The balance of G is the vector b = (b1 , . . . , bn )T . A node whose balance is zero will be called a balanced node. The balance of i measures the difference between how much i pushes away other nodes (those nodes j for which δij > 0), and how much it is pushed away from them. 2.1
Assigning the y-Coordinates
Here is our energy function: Definition 2. Let G(V, E) be a digraph, and let y = (y1 , . . . , yn )T be any vector of coordinates. The hierarchy energy is EH (G, y) =
n 1 wij (yi − yj − δij )2 = wij (yi − yj − δij )2 . 2 i,j=1
(1)
(i,j)∈E
Clearly, EH ≥ 0 for any digraph and any vector of coordinates. We define an optimal arrangement of a digraph, y , as a minimizer of the hierarchy energy, y = arg miny EH (G, y). An optimal arrangement will try to place the nodes such that the height difference yi − yj for any adjacent pair will be close to δij . The weight wij indicates how ‘important’ it is that (yi − yj − δij )2 be small. The larger this quantity, the smaller (yi − yj − δij )2 should be, in order to keep the contribution to the energy small. Using the previously defined notions of Laplacian and balance, the hierarchy energy in the compact form EH = E0 + y T Ly − 2y T b, where E0 = ncan be written 1 2 i,j=1 wij δij . For a proof see the full version of this paper [1]. Differentiating this 2 simple form, we find an explicit formula for an optimal arrangement. As the next result shows, y is the solution of a system of linear equations. Proposition 1. Let G(V, E) be a digraph, with Laplacian L and balance b. An optimal arrangement y is a solution of Ly = b.
196
Liran Carmel, David Harel, and Yehuda Koren
The proof appears in [1], where we also show that the system Ly = b is compatible with an infinite number of solutions that differ from each other only by a translation. The uniqueness (up to a translation) suggests that y carries some essential information, as we show in Section 3. We are now in a position to define the optimal arrangement in a completely unique fashion. We require that the center of mass of the optimal arrangement is at the origin of coordinates, i.e., i yi = 0. This choice of y enables its fast computation using the Conjugate Gradient method, see [1]. Therefore: Definition 3. Let G(V, E) be a digraph with Laplacian L and balance b. Its optimal arrangement, y , is the solution of Ly = b, subject to the constraint i yi = 0. Let us see how this algorithm works by applying it to some very small-scale examples. More examples appear in later sections. Figure 1(a) shows an unweighted acyclic digraph. Its optimal arrangement is the solution of the system
2 −1 −1 −1 1 0 −1 0 1
y =
2 −1 −1
=⇒
y =
2/3 −1/3 −1/3
,
under the constraint i yi = 0. This is just the expected two-layer solution. The height difference between the layers is 1, thus δij = yi − yj , ∀(i, j) ∈ E, giving EH (y ) = 0. Figure 1(b) shows another example of an unweighted acyclic digraph. In this case,
2 −1 −1 −1 2 −1 −1 −1 2
y =
2 0 −2
=⇒
y =
2/3 0 −2/3
.
Aesthetically, this vector of coordinates nicely captures the structure of the digraph, where, in contrast to the first example, nodes 2 and 3 can no longer have the same y-coordinate since they push each other in opposite directions. The result reflects a compromise of sorts, pushing node 2 upwards and node 3 downwards, thus decreasing the height difference y1 − y2 to 23 and increasing y1 − y3 to 43 . The height differences cannot achieve their targets, resulting in a strictly positive hierarchy energy EH (y ) = ( 32 − 1)2 + ( 23 − 1)2 + ( 43 − 1)2 = 13 . 1
1
2
3
(a)
2
3
(b)
Fig. 1. Two very small examples of unweighted acyclic digraphs.
Drawing Directed Graphs Using One-Dimensional Optimization
197
Figure 2(a) shows an example of an unweighted cyclic digraph. In this case, 2 −1 0 −1
0
−1 3 −1 −1 1 0 −1 2 −1 y = 0 −1 −1 −1 3
0
=⇒
−1
1/4 y = , 0
−1/4
which is schematically plotted in Fig. 2(b). Here we see the naturalness of the way our algorithm deals with cyclic digraphs. The result is aesthetically convincing, putting node 2, whose balance is the largest, at the top, and node 4, whose balance is the smallest, at the bottom. As is always the case with cyclic digraphs, the height differences cannot all achieve their targets, resulting in strictly positive hierarchy energy. Indeed, EH (y ) = 4 · ( 14 − 1)2 + ( 12 − 1)2 = 2.5. y 2
1
2
4
3
(a)
1
1
4
3
4
1
4
(b)
Fig. 2. (a) A small example of an unweighted cyclic digraph; (b) its optimal arrangement.
The idea of using energy minimization to determine a vector of coordinates on one axis was already exploited in undirected graph drawing by Tutte [12] and Hall [5], both n utilizing the same quadratic energy function, ET H = 12 i,j=1 wij (yi − yj )2 = y T Ly. Comparing this energy with the hierarchy energy (1), it is clear that they become identical for a digraph with δij = 0, ∀(i, j) ∈ E, which is really an undirected graph. It is instructive to adopt a different viewpoint in explaining a fundamental difference between the minimizer of ET H , and the optimal arrangement y . The former is obtained from the equation ∂ET H /∂yi = 0 which gives n j=1 wij yj yi = n . (2) j=1 wij This equation tells us to put node i in the barycenter of its neighbors. Clearly, the zero vector is a solution of (2), a situation that both Tutte and Hall avoid by using various constraints. In analogy, y satisfies the following important property n j=1 wij (yj + δij ) n yi = , j=1 wij
198
Liran Carmel, David Harel, and Yehuda Koren
which is substantially different from (2). Here we take a ‘balanced’ weighted average instead of the barycenter. The introduction of nonzero δij ’s prevents the collapse of all the nodes to the same location, yielding a meaningful solution. 2.2
Assigning the x-Coordinates
In principle, we would like to use a classical force directed model for the x-axis. Directional information should not be considered any longer, since it is assumed to be exhaustively taken care of by the y-axis. However, when trying to modify the customary two-dimensional gradient descent optimization algorithm, for use in our one-dimensional case, convergence was rarely achieved. The reason for this is what we call the ‘swapping problem’. Recall that the y-coordinates of the nodes are already fixed, and now the nodes are allowed to move only along the x-axis. However, if two nodes have close y-coordinates, swapping places along the x-axis is almost always impossible, even if it is energetically favorable, due to the repulsive forces that form an “energy barrier”; see [1] for a demonstration of this. It would be the best, then, to employ an alternative optimization technique for our one-dimensional case, which skirts the swapping problem We suggest to find a vector x = (x1 , . . . , xn )T representing the x-coordinates of the nodes in a way that minimizes edge (squared) lengths. This enables us to use simple energy functions that can be minimized by powerful global techniques. Besides the aesthetical reasoning, minimizing edge lengths is known to reduce edge crossings. We present two alternative variants of the method: – Minimizing edge-squared lengths: This nmeans minimizing the already familiar Tutte-Hall energy function, ET H = 12 i,j=1 wij (xi − xj )2 = xT Lx. As suggested by Hall [5,7], the non-trivial minimizer of this energy function is the Fiedler vector, which is the eigenvector of the Laplacian associated with the smallest positive eigenvalue. We find the minimizer of ET H using ACE [8] — an extremely fast multiscale algorithm for undirected graph drawing. – Minimizing edge lengths: This is the well known problem of minimum linear arrangement [3]. The solution is obtained by minimizing the energy function ELA = n 1 i,j=1 wij |xi − xj |, where (x1 , . . . , xn ) is a permutation of (1, . . . , n). This is 2 an NP-hard problem, and hence we should work with heuristics. In practice, we find a local minimizer of ELA using another fast multiscale algorithm [9], designed especially for this problem. In some of the cases we have studied (most notably, trees), the Fiedler vector was inferior with respect to the final result. The reason for this is that nothing in the Tutte-Hall energy function prevents two nodes from having the same x-coordinate. Therefore, locally dense regions could very well appear. In contrast, the minimum linear arrangement incorporates some kind of ‘repulsive force’, by not letting two nodes have the same x-coordinate. For example, see Fig. 4(a,b). However the Fiedler vector has advantages that make it very attractive in some cases. First, it is guaranteed to be an optimal global minimizer, and second, it can be computed extremely rapidly; see Table 1. In practice, for many graphs the Fiedler vector yields better results (see Section 4).
Drawing Directed Graphs Using One-Dimensional Optimization
199
Final beautification. So far, we have found the vector x using a very simple energy function and have ignored the information about the y-coordinates. As a result, there are cases where local smoothing can improve the drawing; see for example Fig. 4(c). We do this using a richer one-dimensional force directed model, which incorporates the information about the y-coordinates in order to refine the x-coordinates. Specifically, we have chosen to work with the Fruchterman-Reingold model [4]. In practice we do not use forces, but rather the energy they induce. This results in a modified optimization process, more suitable for the one-dimensional case; see [1].
3
Further Implications of the y-Axis Arrangement
Regular Digraphs A regular graph is one in which all nodes have the same degree. In analogy, a regular digraph is one in which all nodes have the same in-degree and the same out-degree. A regular digraph exhibits a high level of symmetry, so that we do not expect to find much hierarchy in it. It can be proved that in a regular digraph each node is balanced, having equal in-degree and out-degree. The optimal arrangement for a regular digraph is the solution of Ly = 0; hence y = (0, . . . , 0)T . In other words, a regular digraph is a hierarchy-free digraph. A simple example is a directed cycle. Symmetric Nodes A regular digraph is hierarchy-free. Thus, when the nodes are all symmetric, they are all assigned the same y-coordinate. Interestingly, this observation can be extended. Actually, if two nodes are symmetric, they have the same y-coordinate. In the framework of undirected graphs, it is customary to denote two nodes i and j as symmetric if there exists a permutation π such that π(i) = j and π(j) = i, and the Laplacian is invariant under π, L = Lπ . Here, Lπ is the Laplacian whose rows and columns are permuted according to π. For digraphs, we impose symmetry also on the directionality by adding the requirement that b = bπ . This definition reduces to the standard one for undirected graphs, since in this case b is the zero vector. We expect symmetric nodes to have the same level of hierarchy, which is indeed the case. In [1], using the uniqueness of the optimal arrangement, we prove that if i and j are symmetric, then yi = yj . Hierarchy Index The y-axis in our drawings contains the entire available information about the hierarchy. We claim that the spread of the projection of the drawing on this axis is closely related to its inherent hierarchy. Two extreme examples are: (1) A directed cycle, in which no node is different from the other, and we do not expect to see any hierarchy at all. Indeed, it is the case, since the cycle is regular. (2) A (k + 1)-path has a maximal amount of hierarchy, each node having a different y-coordinate in unit increments, y = (−k/2, −k/2 + 1, . . . , k/2)T . It would be natural, therefore, to associate the hierarchy of a digraph with the mag nitude ∆y = ymax − ymin . The larger the ∆y , the more hierarchical the digraph. One can use this magnitude to measure how worthwhile it is to allot the y-axis to exhibit the directional information. In order to do so, ∆y should be compared with a measure of the dimension of the graph, had it been drawn using undirected graph drawing algorithms. A plausible candidate for measuring this is the diameter D of the digraph, which is the graph theoretic distance between the two most distant nodes. Therefore:
200
Liran Carmel, David Harel, and Yehuda Koren
Definition 4. The hierarchy index of an unweighted digraph is H=
y − ymin ∆y = max , D D
where y is its optimal arrangement and D is its diameter. If ∆y is comparable to D, the directional information is significant and one should use digraph drawing algorithms. If, on the other hand, ∆y is small with respect to D, then it is no longer ‘profitable’ to dedicate an entire axis for the directional information, and undirected graph drawing algorithms should be preferred. Regular digraphs are an extreme case of the latter scenario. Here ∆y = 0, and hence H = 0. The dual example is a k-path, where ∆y = D = k −1, implying H = 1 independent of k. Another example is that of a complete n-node binary tree. Here, D = 2 log n, while ∆y = log n. Hence, H = 12 , independently of n. This 1:2 ratio is well visualized when comparing the height of a hierarchical tree drawing with that of a radial drawing generated by undirected force models; see [1]. Cyclic Digraphs Standard layering algorithms can be applied only to acyclic digraphs. When dealing with cyclic digraphs they are first transformed into acyclic ones by inverting the direction of a minimal number of edges [2,6]. (Although, in cases where a special root node is known in advance, better strategies are possible.) Our algorithm allows to directly draw cyclic digraphs without having to invert edge directions. We believe this to be one of its most significant advantages. To make this claim stronger, we now show why it seems that there is no simple connection between the number of edges whose direction should be reversed and the inherent hierarchy of the digraph. As an example, in a directed cycle it suffices to invert the direction of a single edge in order to make it acyclic. Thus, the graph will be drawn by standard layering algorithms as a full-hierarchy path, having the lowest and the highest nodes connected by a reversed edge; see Figure 3. Obviously, this misrepresents the structure of the hierarchy-free cycle. Applying our algorithm to a directed cycle shows that it contains no directionality, being a regular digraph. In the absence of hierarchy, there is no sense in forcing the edges to be all laid out in the same direction. 1
2
3
4
5
Fig. 3. Schematic layering of 5-points circle.
Drawing Directed Graphs Using One-Dimensional Optimization
201
Another example is shown in Fig. 5(a). Here, the digraph does contain hierarchy, and the figure shows its optimal arrangement as dictated by our algorithm. We believe that we can quite objectively claim that this drawing best represents the structure of the digraph, despite of the fact that only about half of the edges point downward, and the rest point upward. This is because the only explicit hierarchy in this digraph, which is well captured in the figure, is between the highest node and the lowest one. None of the other nodes possess evident hierarchical relations, thus some of the edges connecting them are ‘allowed’ to go upward.
4
Examples
We have tested our algorithm against several unweighted digraphs with diverse structures. Figure 4 shows a complete 5-level binary tree. The y-coordinates were naturally quantized into 6 layers, as dictated by the tree structure. Recall that assigning the xcoordinates can be done in two different ways and that there is also a possibility for an additional final beautification. Figure 4(a) shows the drawing obtained when using the Fiedler vector. The result is really bad, with many nodes being placed in exactly the same location. This phenomenon is explained in Subsection 2.2. Using the minimum linear arrangement we get a much better drawing, shown in Fig. 4(b). In Fig. 4(c) we show a slightly improved result produced by the final beautification.
(a)
(b)
(c)
Fig. 4. A 5-level complete binary tree (a) x-coordinates obtained using the Fiedler vector; (b) x-coordinates obtained using the minimum linear arrangement; (c) applying final beautification to refine x-coordinates of (b)
Figure 5 shows three instructive examples. Figure 5(a) shows a directed cycle with an additional edge. In contrast to a pure cycle, which is regular and thus hierarchy-free, this digraph, thanks to the extra edge, does contain hierarchical information. Figure 5(b) shows an acyclic digraph comprised of a few parallel paths of different lengths. In spite of the diversity of path lengths, all edges are drawn in the same direction. Figure 5(c) is a cyclic version of the former digraph, with the direction of the edges along one of the paths (the middle one) being inverted. Interestingly, the drawing is almost identical to that of the acyclic version, with the principal difference being the direction of the
202
Liran Carmel, David Harel, and Yehuda Koren
(a)
(b)
(c)
Fig. 5. Three examples of digraphs; (a) a distorted cycle. The extra edge is responsible for the observed hierarchy; (b) an acyclic digraph comprised of a few parallel paths with varying lengths; (c) a cyclic version of the former digraph.
“reversed” edges. It seems that restricting the y-coordinates to strict horizontal layers would ruin the natural structure of the graphs of Fig. 5(b,c). In the rest of this section, we present graphs which are based on matrices from the Matrix Market collection (available at: math.nist.gov/MatrixMarket/). Each graph is constructed by taking a matrix and replacing each non-zero entry (i, j) with a directed edge from i to j. In Table 1 we provide the sizes of the graphs and running times, as measured on a Pentium IV 2GHz PC. The largest graph, containing 8192 nodes, was drawn in less than 12 second. Unless otherwise is stated, we computed the x-coordinates using the Fiedler vector (without final beautification). Table 1. Running time (in seconds) of the the algorithm graph
|V|
|E|
Nos6 Nos7 Dwa512 Dw2048 Dw8192
675 729 512 2048 8192
1290 1944 1004 4094 17,404
x-coords y-coords total time time time 0.000 0.015 0.015 0.000 0.016 0.016 0.000 0.016 0.016 0.015 0.11 0.125 0.150 0.250 0.4
Figure 6 shows two different drawings of the Nos6 graph. For both of them the y-coordinates are the same (as is always the case, since there is a unique minimizer of the hierarchy energy). However, the x-coordinates are different. In Fig. 6(a) they were computed using the Fiedler vector, while in Fig. 6(b) they were computed using the minimum linear arrangement. Both drawings exhibit the symmetries of the graph very well. Regarding running times, computation of the minimum linear arrangement took 3.7sec, whereas computation of the Fiedler vector took only 0.015sec.
Drawing Directed Graphs Using One-Dimensional Optimization
(a)
203
(b)
Fig. 6. The Nos6 graph. The x-coordinates are drawn by (a) Fiedler vector; (b) minimum linear arrangement.
Fig. 7. Two different drawings of the Nos7 graph. The y-coordinates are the same, whereas the x-coordinates obtained by two different Fiedler vectors.
Figure 6 shows two different layouts of the Nos7 graph. In both cases the x-coordinates were constructed using the Fiedler vector. Here, the multiplicity of the lowest positive eigenvalue of the Laplacian matrix is greater than 1, so there are two different Fiedler vectors. The left-hand-side drawing draws the graph in a “layering style”, putting the nodes on many horizontal layers. The right-hand-side drawing, has a three-dimensional look. It arranges the nodes in 9 two-dimensional layers. Note that in both drawings the edges point downwards.
204
Liran Carmel, David Harel, and Yehuda Koren
The Dwa512 graph
The Dw2048 graph
The Dw8192 graph Fig. 8. Graphs containing both directed and undirected edges. Directed edges are colored by red, while undirected edges are colored by blue (see electronic version of this paper).
Interestingly, our algorithm can be applied to graphs containing both directed and undirected edges. As was already mentioned, all we have to do to deal with an undirected edge (i, j) is to set δij = δji = 0, meaning that such an edge induces no hierarchical relation. Many graphs based on matrices in the Matrix Market collection contain both directed edges (when entry (i, j) is non-zero and entry (j, i) is zero) and undirected edges (when both entries (i, j) and (j, i) are non-zero). In Fig. 8 we show three such graphs: Dwa512, Dw2048 and Dw8192. Directed edges are colored red and undirected edges are colored blue. In all the drawings the graph structure is shown nicely with excellent
Drawing Directed Graphs Using One-Dimensional Optimization
205
symmetry preservation. Note that all directed edges point downwards, and that they induce hierarchical relations between nodes that are contained in undirected components of the graph. We think that these results demonstrate that sometimes restricting the nodes to strict layers hides the graph’s natural structure.
5
Discussion
We have presented a digraph drawing algorithm that uses several one-dimensional energy minimization problems to find an optimal drawing in two-dimensions. The vector of ycoordinates is found using a rather elegant energy minimization algorithm, which yields a unique global minimizer that nicely captures the hierarchical information. For the vector of x-coordinates, which contains non-directional information, we are using an optimization algorithm especially tailored for the one dimensional problem. The layouts produced by our algorithm are very natural, and are not subject to any predefined restrictions. In a way, they simply “let the graph speak for itself”. The fact that the layout is a global minimizer of the one-dimensional energies enables a rather accurate representation of many properties of the graph, such as its hierarchical structure and its symmetries. In terms of running time, our algorithm is very fast, being able to draw 10,000-node graphs in less than a second on a mid-range PC. Significant virtues of our algorithm include its ability to draw cyclic digraphs without having to invert edge directions, the possibility of applying it to graphs containing both directed and undirected edges and its ability to measure the amount of hierarchy in the digraph via the hierarchy index. The amount of hierarchy can be used to decide whether to use hierarchical drawing tools to represent a given digraph, or to prefer undirected graph drawing algorithms. We believe this last issue to be worthy of further research, and suggest the possibility of combining digraph drawing algorithms and undirected graph drawing algorithms into a unified tool: Given a general digraph, we could use the hierarchy index on portions of it, and draw the different portions either with this algorithm or with the other, depending of their level of hierarchy. More specifically, one can scan the optimal y-coordinates vector to find connected subgraphs, such that the nodes in each subgraph have similar y-coordinates. Such subgraphs are candidates for being hierarchy-free components, and should be processed separately. Our algorithm can be used in two different ways for the benefit of the standard approach for digraph drawing: – It can induce layering: We can think of the optimal arrangement as a kind of a ‘continuous layering’. The usual discrete layering can be easily induced from it if we divide the nodes into maximal subsets, such that within each subset the nodes have successive y-coordinates and no edge resides within a single subset. – It can induce ordering: Standard ordering algorithms are typically very local in nature. In a single iteration only one layer is free to change the order of its nodes. We can replace it with a more global approach, using the vector of x-coordinates obtained by our ‘first stage’ to impose a ‘global ordering’.
206
Liran Carmel, David Harel, and Yehuda Koren
References 1. L. Carmel, D. Harel and Y. Koren, “Drawing Directed Graphs Using One-Dimensional Optimization”, Technical Report MCS02-14, The Weizmann Institute of Science, 2001. Available on the web. 2. G. Di Battista, P. Eades, R. Tamassia, and I. G. Tollis, Graph Drawing: Algorithms for the Visualization of Graphs, Prentice-Hall, 1999. 3. J. Diaz, J. Petit and M. Serna, “A Survey on Graph Layout Problems”, to appear in ACM Computing Surveys. 4. T. M. G. Fruchterman and E. Reingold, “Graph Drawing by Force-Directed Placement”, Software-Practice and Experience 21 (1991), 1129-1164. 5. K. M. Hall, “An r-dimensional Quadratic Placement Algorithm”, Management Science 17 (1970), 219-229. 6. M. Kaufmann and D. Wagner (Eds.), Drawing Graphs: Methods and Models, Lecture Notes in Computer Science, Vol. 2025, Springer Verlag, 2001. 7. Y. Koren, “On Spectral Graph Drawing”, manuscript, 2002. 8. Y. Koren, L. Carmel and D. Harel, “ACE: A Fast Multiscale Eigenvectors Computation for Drawing Huge Graphs”, Proc. IEEE Symp. on Information Visualization 2002 (InfoVis 2002), IEEE computer society press, to appear. 9. Y. Koren and D. Harel “A Multi-Scale Algorithm for the Linear Arrangement Problem”, Proc. Graph Theoretical Concepts in Computer Science 2002 (WG 2002), Springer-Verlag, to appear. 10. K. Sugiyama and K. Misue, “A Simple and Unified Method for Drawing Graphs: MagneticSpring Algorithm”, Proc. Graph Drawing 1994, Lecture Notes in Computer Science, Vol. 894, pp. 364–375, Springer Verlag, 1995. 11. K. Sugiyama, S. Tagawa and M. Toda, “Methods for Visual Understanding of Hierarchical Systems”, IEEE Transactions on Systems, Man, and Cybernetics 11(2) (1981), 109–125. 12. W. T. Tutte, “How to draw a graph”, Proc. London Math. Society 13 (1963), 743-768.
Graph Drawing by High-Dimensional Embedding David Harel and Yehuda Koren Dept. of Computer Science and Applied Mathematics The Weizmann Institute of Science, Rehovot, Israel {harel,yehuda}@wisdom.weizmann.ac.il
Abstract. We present a novel approach to the aesthetic drawing of undirected graphs. The method has two phases: first embed the graph in a very high dimension and then project it into the 2-D plane using principal components analysis. Running time is linear in the graph size, and experiments we have carried out show the ability of the method to draw graphs of 105 nodes in few seconds. The new method appears to have several advantages over classical methods, including a significantly better running time, a useful inherent capability to exhibit the graph in various dimensions, and an effective means for interactive exploration of large graphs.
1
Introduction
A graph G(V = {1, . . . , n}, E) is an abstract structure that is used to model a relation E over a set V of entities. Graph drawing is a standard means for the visualization of relational information, and its ultimate usefulness depends on the readability of the resulting layout; that is, the drawing algorithm’s capability of conveying the meaning of the diagram quickly and clearly. Consequently, many approaches to graph drawing have been developed [3,9]. We concentrate on the problem of drawing undirected graphs with straight-line edges, and the most popular approaches to this appear to be those that define a cost function (or a force model), whose minimization determines the optimal drawing. The resulting algorithms are known as force-directed methods. We suggest a new approach to the problem of graph drawing, relying on the observation that laying out a graph in a high dimension is significantly easier than drawing it in a low dimension. Hence, the first step of our algorithm is to quickly draw the graph in a very high dimensional space (e.g., in 50 dimensions). Since standard visualization techniques allow using only 2 or 3 dimensions, the next step of our algorithm is to algorithmically project the high-dimensional drawing into a low dimension. For this, we have adopt a method called principal components analysis (PCA), which is well known in multivariate analysis. The resulting algorithm is extremely fast, yet very simple. Its time complexity is O(m · |E| + m2 · n), where m is the dimension in which the graph is embedded during the first stage of the algorithm. In fact, the running time is linear in the graph’s size, since m is independent of it. Typical computation times are of less than 3 seconds for 105 -node graphs, and are thus significantly faster than force-directed approaches. As to the quality of the drawings, Section 4 shows several very encouraging results. M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 207–219, 2002. c Springer-Verlag Berlin Heidelberg 2002
208
2
David Harel and Yehuda Koren
Drawing Graphs in High Dimension
Frequently, drawing a graph so as to achieve a certain aesthetic criterion cannot be optimally achieved in a low dimension, due to the fact that several aesthetic goals have to compete on a shared limited space. Thus, being able to carry out the initial drawing work in many dimensions leaves more space for richer expression of the desired properties, and thus makes the entire task easier. In order to draw a graph in m dimensions, we choose m pivot nodes that are almost uniformly distributed on the graph and associate each of the m axes with a unique node. Axis i, which is associated with pivot node pi , represents the graph from the “viewpoint” of node pi . This is done by defining the i-th coordinate of each of the other nodes as its graph-theoretic distance from pi . Hence pi is located at place 0 on axis i, its immediate neighbors are located at place 1 on this axis, and so on. More formally, denote by duv the graph-theoretic distance between node v and node u. Let P ivots be some set {p1 , p2 , . . . , pm } ⊂ V . Each node v ∈ V is associated with m coordinates X 1 (v), X 2 (v), . . . , X m (v), such that X i (v) = dpi v . The resulting algorithm for drawing the graph in m dimensions is given in Fig. 1. The graph theoretic distances are computed using breadth-first-search (BFS). (When edges are positively weighted, BFS should be replaced by Dijkstra’s algorithm; see e.g., [2].) The set P ivots is chosen as follows. The first member, p1 , is chosen at random. For j = 2, . . . , m, node pj is a node that maximizes the shortest distance from {p1 , p2 , . . . , pj−1 }. This method is mentioned in [8] as a 2-approximation to the k-center problem, where we want to choose k vertices of V , such that the longest distance from V to these k centers is minimized. However, different approaches to selecting the pivots may also be suitable.
Function HighDimDraw (G(V = {1, . . . , n}, E), m) % This function finds an m-dimensional layout of G: Choose node p1 randomly from V d[1, . . . , n] ← ∞ for i = 1 to m do
% Compute the i − th coordinate using BFS
dpi ∗ ← BFS(G(V, E), pi ) for every j ∈ V X i (j) ← dpi j d[j] ← min{d[j], X i (j)} end for % Choose next pivot
pi+1 ← arg max{j∈V } {d[j]} end for return X 1 , X 2 , . . . , X m Fig. 1. Drawing a graph in m dimensions
Graph Drawing by High-Dimensional Embedding
209
The time complexity of this algorithm is O(m · (|E| + |V |)), since we perform BFS in each of the m iterations. A typical value of m is 50. Here now are two observations regarding the properties of the resulting drawing. First, for every two nodes v and u and axis 1 i m, we have: duv |X i (v) − X i (u)| This follows directly from the triangle inequality, since: dpi u dpi v + duv and dpi v dpi u + duv =⇒ |X i (v) − X i (u)| = |dpi v − dpi u | duv Thus, nodes that are closely related in the graph will be drawn close together. The second observation goes in the opposite direction, and shows a kind of separation between nodes that are distant in the graph. For an axis i and nodes u and v, denote def
i δv,u = min{dpi v , dpi u }. Then, for every v, u ∈ V and axis 1 i m, we have: i duv − 2δv,u |X i (v) − X i (u)| i For the proof, assume w.l.o.g. that δv,u = dpi v . Again, using the triangle inequality: i duv dpi v + dpi u = dpi v + dpi v + (dpi u − dpi v ) = 2δv,u + |X i (v) − X i (u)| i =⇒ duv − 2δv,u |X i (v) − X i (u)|
Thus if we denote the minimal distance between {v, u} and P ivots by: def
v,u =
min
i∈{1,...,m},j∈{v,u}
dpi j ,
then there exists an axis i such that |X i (v) − X i (u)| duv − 2v,u . We note that according to the way we have chosen the pivots, we expect v,u to be fairly small.
3
Projecting into a Low Dimension
At this stage we have an m-dimensional drawing of the graph. In order to visually realize the drawing we have to project it into 2 or 3 dimensions. Picking a good projection is not straightforward, since the axes are correlated and contain redundant information. Moreover, several axes may scatter nodes better than others, thus being more informative. For example, consider a square grid. If we use two axes that correspond to two opposite corners, the resulting drawing will be essentially 1-dimensional, as the two axes convey basically the same information and are anti-correlated. (That is, being “near” one corner is exactly like being “far” from the opposite corner.) Also, taking an axis associated with a boundary node is very often more informative than taking an axis associated with a central node; the first case causes the nodes to be scattered in a much better way, since the maximal distance from a boundary node is about twice as large as the maximal distance from a central node.
210
David Harel and Yehuda Koren
To address these issues we use a tool that is well known and in standard use in multivariate analysis — principal component analysis (PCA). PCA transforms a number of (possibly) correlated variables into a (smaller) number of uncorrelated variables called principal components (PCs). The first principal component accounts for as much of the variability in the data as possible, and each succeeding component accounts for as much of the remaining variability as possible. By using only the first few principal components, PCA makes it possible to reduce the number of significant dimensions of the data, while maintaining the maximum possible variance thereof. See [4] for a comprehensive discussion of PCA. In our case, we have m n-dimensional variables X 1 , . . . , X m , describing the n nodes in m dimensions. We want to represent the n nodes using only k dimensions (typically k = 2), using k n-dimensional uncorrelated vectors Y 1 , . . . , Y k , which are the principal components. Hence, the coordinates of node i are (Y 1 (i), . . . , Y k (i)). Each of the PCs among Y 1 , . . . , Y k is a linear combination of the original variables X 1 , . . . , X m . def n X i (j) Here are the details. Denote the mean of i-th axis by mi = j=1 n . The first stage of the PCA is to center the data around 0 which is just a harmless translation of ˆ 1, . . . , X ˆ m , defined as: the drawing. We denote the vectors of centered data by X ˆ i (j) = X i (j) − mi , X
i = 1, . . . , m, j = 1, . . . , n
We now construct an m × n matrix, X, whose rows are the (centered) coordinates: 1 ˆ 1 (n) ˆ (1) . . . X X . ... . X= . ... . m m ˆ ˆ X (1) . . . X (n) The covariance matrix S, of dimension m × m, is defined as 1 XX T n We now have to compute the first k eigenvectors of S (those that correspond to the largest eigenvalues). We denote these eigenvectors by u1 , . . . , uk . The vector lengths should be normalized to 1, so that these k vectors are orthonormal. A simple method for computing the eigenvectors is described below. Now to the projection itself. The first new axis, Y 1 , is the projection of the data in the direction of u1 , the next axis, Y 2 , is the projection in the direction of u2 , and so on. Hence the new coordinates are defined by: S=
Y i = X T ui ,
i = 1, . . . , k
For the interested reader, we now briefly discuss the theoretical reasoning behind the PCA process. The projection of the data in a certain direction can be formulated by y = X T u, where u is a unit vector ( u 2 = 1) in the desired direction. Since the original data is centered, the projection, y, is also centered. Thus, the variance of y can be written simply as y T y/n. Note that, 1 T 1 1 y y = (X T u)T X T u = uT XX T u = uT Su . n n n
Graph Drawing by High-Dimensional Embedding
211
Consequently, to find the projection that retains the maximum variance, we have to solve the following constrained maximization problem: max uT Su u
(1)
subject to: u 2 = 1 Standard linear algebra shows that the maximizer of problem 1 is u1 , the first eigenvector of S. Hence, Y 1 is the 1-dimensional projection of the data that has the maximal variance (i.e., in which the data is most scattered). Using similar techniques it can be shown that Y 1 , . . . , Y k constitute the k-dimensional projection of the data that yields the maximal variance. Moreover, the orthonogonality of u1 , . . . , uk implies yiT yj = 0 for i = j. Hence, these k axes are uncorrelated In general, as we shall see in Section 4, it suffices to draw a graph on the plane using Y 1 and Y 2 only, thus scattering the nodes in a maximal fashion.1 However, sometimes using Y 3 or Y 4 may be useful too. Regarding time complexity, the most costly step is computing the covariance matrix S = n1 XX T . (In practice we do not divide by n, since multiplication by a constant does not change the eigenvectors.) This matrix multiplication is carried out in a straightforward way using exactly m2 n multiplications and additions, so the time complexity is O(m2 n), with a very small hidden constant (although matrix multiplication can be done faster in theory; see e.g., [2]). As to computing the first eigenvectors of the m × m covariance matrix S (i.e., those that correspond to the largest eigenvalues), we use the simple power-iteration method; see e.g., [15]. Since m << n, the running time is negligible (taking in practice less than a millisecond) and there is no need for more complicated techniques. The basic idea is as follows. Say we are given an m × m symmetric matrix A with eigenvectors u1 , u2 , . . . , um , whose corresponding eigenvalues are λ1 > λ2 > · · · > λm 0. Let x ∈ Rn . If x is not orthogonal to u1 (i.e., x · u1 = 0) then the series Ax, A2 x, A3 x, . . . converges in the direction of u1 . More generally, in the case where x · u1 = 0, x · u2 = 0, . . . , x · uj−1 = 0, x · uj = 0, the series Ax, A2 x, A3 x, . . . converges in the direction of uj . The full algorithm is depicted in Fig. 2.
4
Examples
Our algorithm was implemented in C, and runs on a dual processor Intel Xeon 1.7Ghz PC. Since the implementation is non-parallel, only one of the processors is used. For all the results given here we have set m = 50, meaning that the graphs are embedded in 50 dimensions. Our experience is that the results are not sensitive to the exact value of m. In fact, increasing m does not degrade the quality of the results, but doing so seems not to be needed. On the other hand, picking an overly small value for m may harm the smoothness of the drawing. We speculate that as the graphs are to be drawn in only two or three dimensions, a vast increase of m cannot be helpful. 1
Thus, using PCA is, in a sense, incorporating a global “repulsive force”, in the terms used in force-directed methods.
212
David Harel and Yehuda Koren
Function PowerIteration (S – m × m matrix )
% This function computes u1 , u2 , . . . , uk , the first k eigenvectors of S .
const ← 0.001 for i = 1 to k do u ˆi ← random u ˆi ← ˆuuˆii do ui ← u ˆi
% orthogonalize against previous eigenvectors
for j = 1 to i − 1 do ui ← ui − (ui · uj )uj end for u ˆi ← Sui u ˆi ← ˆuuˆii % normalization while u ˆi · ui < 1 − % halt when direction change is negligible ui ← u ˆi end for return u1 , u2 , . . . , uk Fig. 2. The power iteration algorithm
Table 1 gives the actual running times of the algorithm on graphs of different sizes. In addition to the total computation time, we show the times of the two most costly parts of the algorithm — computing the m-dimensional embedding (Fig. 1) and computing the covariance matrix S. We want to stress the fact that since the algorithm does not incorporate an optimization process, the running time is determined completely by the size of the graph (i.e., |V | and |E|), and is independent of the structure of the graph. This is unlike force-directed methods. Graphs of around 105 nodes take only a few seconds to draw, and 106 -node graphs take less than a minute. Thus, the algorithm exhibits a truly significant improvement in computation time for drawing large graphs over previously known ones. 2 Following is a collection of several drawings produced by the algorithm. The layouts shown in Fig. 3 are typical results of our algorithm, produced by taking the first two principal components as the axes. In Fig. 3(a) we show a square grid with 13 of the edges omitted at random. Figure 3(b) shows a folded grid, obtained by taking a square grid and connecting opposing corners. This graph has high level of symmetry, which is nicely reflected in the drawing. Figures 3(c,d) show two finite element graphs, whose drawings give a feeling of a 3-D landscape. Sometimes it is aesthetically better to take different principal components. For example, in Fig. 4(a) the 516 graph is depicted using the first and second PCs, while in Fig. 4(b) the first and third PCs are used. Note that the second PC scatters the nodes better than the third PC, as must be the case. However, here, using the third PC instead of the 2
Our recent ACE algorithm, [10], exhibits similar advantages using totally different methods.
Graph Drawing by High-Dimensional Embedding
213
Table 1. Running time (in seconds) of the various components of the algorithm graph
|V|
|E|
total high dim. covariance time embedding matrix 0.00 0.00 0.00 0.03 0.02 0.01 0.08 0.03 0.05 0.09 0.05 0.05 0.30 0.14 0.08 0.25 0.16 0.09 0.81 0.47 0.16 0.75 0.59 0.13 1.77 0.89 0.77 2.59 1.59 0.89 7.16 5.74 1.25 13.09 10.66 2.19 50.52 41.03 8.48 57.81 47.83 8.84
516 [14] 516 729 Fidap006§ 1651 23,914 4970 [14] 4970 7400 3elt† 4720 13,722 Crack‡ 10,240 30,380 4elt2† 11,143 32,818 Sphere† 16,386 49,152 16,614 537,374 Fidap011§ Sierpinski (depth 10) 88,575 177,147 grid 317 × 317 100,489 200,344 Ocean† 143,437 409,593 257,000 505,048 mrngA† grid 1000 × 1000 1,000,000 1,998,000 mrngB† 1,017,253 2,015,714 § Taken from the Matrix Market, at: http:/math.nist.gov/MatrixMarket † Taken from the University of Greenwich Graph Partitioning Archive, at: http://www.gre.ac.uk/˜c.walshaw/partition ‡ Taken from Jordi Petit’s collection, at: http://www.lsi.upc.es/˜jpetit/MinLA/Experiments
second one results in an aesthetically superior drawing. A similar example is given in Fig. 4(c,d) with the Fidap006 graph. In fact, this is the typical case with many graphs whose nice drawing has an unbalanced aspect ratio. The first two axes provide a well balanced drawing, while using different axes (the third or the forth PCs) yields a prettier result. In fact, the algorithm also produces more information than others, by drawing the graph in a high dimension. Thus, we can view the graph from different viewpoints that may reveal interesting aspects of the graph. This is demonstrated in the drawing of the Sphere graph. Fig. 5(a) shows a drawing using the first and second PCs. The six “smooth” corners appearing in Fig. 5(a) become really salient in Fig. 5(b), using the forth and fifth PCs, where a flower shape emerges. 4.1
Zooming in on Regions of Interest
Drawings in two dimensions reveal only part of the richness of the original high dimensional drawing. Indeed, the 2-D drawing must forgo showing some properties of small portions of the graph, in order to get a well balanced picture of the entire graph. This facilitates a novel kind of interactive exploration of the graph structure: The user can choose a region of interest in the drawing and ask the program to zoom in on it. We then utilize the fact that we have a high dimensional drawing of the graph, which possibly contains a better explanation for the chosen subgraph than what shows up in 2-D. First we take the coordinates of the subgraph from the already computed m-dimensional drawing. We then use PCA to project these coordinates into 2-D. In this way we may
214
David Harel and Yehuda Koren
Fig. 3. Layouts of: (a) A 50 × 50 grid with 13 of the edges omitted at random; (b) A 100 × 100 grid with opposite corners connected; (c) The Crack graph (d) The 3elt graph
Fig. 4. (a,b) Drawing the 516 graph using: (a) 1st and 2nd PCs; (b) 1st and 3rd PCs. (c,d) Drawing the Fidap006 graph using: (c) 1st and 2nd PCs; (d) 1st and 3rd PCs
Graph Drawing by High-Dimensional Embedding
215
Fig. 5. (a,b) Two viewpoints of the Sphere graph: (a) using the first and second PCs; (b) using the forth and fifth PCs; (c) zooming in on one of the corners
reveal properties appearing in the high-dimensional drawing, which are not shown in the low-dimensional drawing of the full graph. For example, we wanted to investigate the “corners” of the Sphere graph. We zoomed in on one of the corners, and the result is shown in Fig. 5(c). It can be seen that the corner is a meeting point of four faces. Another example is the dense graph, Fidap011, depicted in Fig. 6. Due to file size limitation, we cannot print this huge graph with adequate visual quality. Hence, it is very instructive to see parts of its micro-structure, as shown in the bottom of Fig. 6(b).
Fig. 6. Top: The Fidap011 graph; Bottom: zooming in on the micro-structure
216
David Harel and Yehuda Koren
Additional related examples are given in Fig. 7. The Sierpinski fractal of depth 7, is shown in Fig. 7(a). Note that the left and top parts of it are distorted (in fact, they are explained by the third PC). In Fig. 7(b) we depict the result of zooming-in on the left part of the graph, revealing its nice structure. The layout of the 4elt2 graph, depicted in Fig. 7(c), resembles the one obtained by [10]. For a better understanding of its structure we may zoom-in on parts of the drawing. Fig. 7(d) shows the results of zooming-in on the bottom strip. In Fig. 7(e) we provide a drawing of the Ocean graph, containing over 143000 nodes. To understand its micro-structure we zoom-in on it, providing a sample result in Fig. 7(f). The last example is the 4970 graph, nicely depicted in Fig. 7(g). We zoom-in on its top-center portion, as shown in Fig. 7(h). Before ending this section, we should mention that our algorithm is not suitable for drawing trees. In fact, for tree-like graphs, it may very hard to pick a suitable viewpoint for projection, probably due to the fact that the high dimensional drawing of these graphs spans a “wild” subspace of quite a high dimension.
5
Discussion
We have presented an extremely fast approach to graph drawing. It seems that our two key contributions are the simple technique for embedding the graph in a very high dimension and the use of principal components analysis for finding good projections into lower dimensions. In terms of performance and simplicity, the algorithm has some significant advantages when compared to force-directed methods. To appreciate these advantages, let us make a short divergence for surveying the state of the art in force-directed drawing of large graphs. A naive implementation of a force-directed method encounters real difficulties when dealing with graphs of more than a few hundred nodes. These difficulties stem from two reasons. First, in a typical force model there is a quadratic number of forces, making a single iteration of the optimization process v ery slow. Second, for large graphs the optimization process needs too many iterations for turning the initial random placement into a nice layout. Some researchers [13,12] have improved these methods to some extent, by accelerating force calculation using quad-trees that reduce the complexity of the force model. This way, [13] reports drawing 1000-node graphs in around 5 minutes (in [12], only running time per a single iteration is mentioned). Whereas using quad-trees addr esses the first issue by accelerating each single iteration, there is still the second issue of getting out of the initial random placement. Both these issues receive adequate treatment by incorporating the multi-scale paradigm as suggested by several authors; see [6,7,5,14]. These methods considerably improve running times by rapidly constructing a simplified initial globally nice layout and then refining it locally. The fastest of them all, [14], draws a 105 -node graph in a typical time of ten minutes. Coming back to our algorithm, we do not have an optimization process, so we do not encounter the aforementio ned difficulties of the force-directed approach. Our algorithm is considerably faster than all of these, however, being able to draw a 105 -node graph in less than three seconds. Moreover, the implementation of our algorithm is much simpler and is almost parameter-free.
Graph Drawing by High-Dimensional Embedding
217
Fig. 7. (a) A depth 7 Sierpinski graph; (b) zooming-in on the squeezed left side of (a); (c) the 4elt2 graph; (d) zooming-in on the bottom of (c); (e) the Ocean graph; (f) zooming-in on the micro structure of (e); (g) the 4970 graph; (h) zooming-in on the top-center portion of (g)
218
David Harel and Yehuda Koren
Recently, we have designed another algorithm for drawing huge graphs, which we call ACE [10]. ACE draws a graph by quickly calculating eigenvectors of the Laplacian matrix associated with it, using a special algebraic multigrid technique (for spectral graph drawing see also [11]). ACE can draw 105 -node graphs in about 2 seconds. However, the running-time of ACE (like that of force-directed methods) depends on the graph’s structure, unlike our algorithm, where it depends only on the graph’s size. A detailed comparison between the results of the two algorithms has yet to be done. The output of our algorithm is multi-dimensional, allowing multiple views of the graph. This also facilitates a novel technique for interactive exploration of the graph, by focusing on selected portions thereof, showing them in a way that is not possible in a 2-D drawing of the entire graph. Several force-directed graph drawing algorithms draw the graph in three or even four dimensions and then project it into a lower dimension, see, e.g., [1,13,5]. These algorithms could possibly benefit from incorporating principal components analysis to project the drawings into the plane. In terms of drawing quality, the results of the new algorithm resemble those of forcedirected graph drawing algorithms. However, being limited by the linear projection, frequently, the static 2-D results are inferior to those of the force-directed approach. For example, in many of the drawings that were given here, it may be observed that the boundaries are somewhat distorted, as they lie inside an absent third dimension. Nevertheless, we should stress the fact that the full power of our algorithm is not expressed well in static 2-D drawings. In order to really utilize its capabilities, one should explore the graph using the novel technique for interactive visualization, which is unique to this algorithm. Applications to information visualization Our algorithm can deal directly with edgeweighted graphs, making it suitable for information visualization tasks. In this case it has an important performance-related advantage over other algorithms, including ACE: In a typical case, one is given n objects and a distance function measuring the dissimilarity between two objects. Note that the time needed for computing the distance between two objects depends solely on the complexity of these two objects, and is independent of n. (This is unlike the computation of the graph theoretic distance, which is not needed in this case.) Frequently, computing the distance between two objects is a costly operation; e.g., when the objects are DNA sequences of length k, a common distance measure is the “edit-distance”, whose computation may take time O(k 2 ). A nice drawing puts similar objects close together, while non-similar objects are distantly located. Hence, forcedirected drawing algorithms that can draw weighted graphs are suitable. However, n is typically large in such applications, so one has to consider multi-scale enhancements, and these would require the computation of the close neighbors of each of the objects. This, in turn, would require the computation of the distances between all pairs, resulting in n · (n − 1)/2 distance computations, which is often too costly. In contrast, our method needs only m · n distance computations, which is a very significant improvement.
Graph Drawing by High-Dimensional Embedding
219
References 1. I. Bruss and A. Frick, “Fast Interactive 3-D Graph Visualization”, Proceedings of Graph Drawing 95, LNCS 1027, pp. 99–110, Springer Verlag, 1996. 2. T. H. Cormen, C. E. Leiserson and R. L. Rivest, Introduction to Algorithms, MIT Press, 1990. 3. G. Di Battista, P. Eades, R. Tamassia and I.G. Tollis, Graph Drawing: Algorithms for the Visualization of Graphs, Prentice-Hall, 1999. 4. B. S. Everitt and G. Dunn, Applied Multivariate Data Analysis, Arnold, 1991. 5. P. Gajer, M. T. Goodrich, and S. G. Kobourov, “A Multi-dimensional Approach to ForceDirected Layouts of Large Graphs”, Proceedings of Graph Drawing 2000, LNCS 1984, pp. 211–221, Springer Verlag, 2000. 6. R. Hadany and D. Harel, “A Multi-Scale Method for Drawing Graphs Nicely”, Discrete Applied Mathematics, 113 (2001), 3–21. 7. D. Harel and Y. Koren, “A Fast Multi-Scale Method for Drawing Large Graphs”, Proceedings of Graph Drawing’00 , LNCS 1984, Springer Verlag, pp. 183–196, 2000. 8. D. S. Hochbaum (ed.), Approximation Algorithms for NP-Hard Problems, PWS Publishing Company, 1996. 9. M. Kaufmann and D. Wagner (Eds.), Drawing Graphs: Methods and Models, LNCS 2025, Springer Verlag, 2001. 10. Y. Koren, L. Carmel and D. Harel “ACE: A Fast Multiscale Eigenvectors Computation for Drawing Huge Graphs”, to appear in Proceedings of IEEE Symposium on Information Visualization (InfoVis) 2002. 11. Y. Koren, “On Spectral Graph Drawing”, manuscript, 2002. 12. A. Quigley and P. Eades, “FADE: Graph Drawing, Clustering, and Visual Abstraction”, Proceedings of Graph Drawing 2000, LNCS 1984, pp. 183–196, Springer Verlag, 2000. 13. D. Tunkelang, A Numerical Optimization Approach to General Graph Drawing, Ph.D. Thesis, Carnegie Mellon University, 1999. 14. C. Walshaw, “A Multilevel Algorithm for Force-Directed Graph Drawing”, Proceedings of Graph Drawing 2000, LNCS 1984, pp. 171–182, Springer Verlag, 2000. 15. D. S. Watkins, Fundamentals of Matrix Computations, John Wiley, 1991.
Advances in C-Planarity Testing of Clustered Graphs (Extended Abstract) Carsten Gutwenger2 , Michael J¨ unger1 , Sebastian Leipert2 , Petra Mutzel3 , Merijam Percan1 , and Ren´e Weiskircher3 1
3
Universit¨ at zu K¨ oln, Institut f¨ ur Informatik, Pohligstraße 1, 50969 K¨ oln, Germany† {mjuenger,percan}@informatik.uni-koeln.de 2 caesar research center, Friedensplatz 16, 53111 Bonn, Germany {gutwenger,leipert}@caesar.de Technische Universit¨ at Wien E186, Favoritenstraße 9–11, 1040 Wien, Austria, {mutzel,weiskircher}@ads.tuwien.ac.at
Abstract. A clustered graph C = (G, T ) consists of an undirected graph G and a rooted tree T in which the leaves of T correspond to the vertices of G = (V, E). Each vertex µ in T corresponds to a subset of the vertices of the graph called “cluster”. c-planarity is a natural extension of graph planarity for clustered graphs, and plays an important role in automatic graph drawing. The complexity status of c-planarity testing is unknown. It has been shown in [FCE95,Dah98] that c-planarity can be tested in linear time for c-connected graphs, i.e., graphs in which the cluster induced subgraphs are connected. In this paper, we provide a polynomial time algorithm for c-planarity testing of “almost” c-connected clustered graphs, i.e., graphs for which all nodes corresponding to the non-c-connected clusters lie on the same path in T starting at the root of T , or graphs in which for each nonconnected cluster its super-cluster and all its siblings in T are connected. The algorithm is based on the concepts for the subgraph induced planar connectivity augmentation problem presented in [GJL+ 02]. We regard it as a first step towards general c-planarity testing.
1
Introduction
A clustered graph consists of a graph G and a recursive partitioning of the vertices of G. Each partition is a cluster of a subset of the vertices of G. Clustered graphs are getting increasing attention in graph drawing [BDM02,EFN00,FCE95], [Dah98]. Formally, a clustered graph C = (G, T ) is defined as an undirected graph G and a rooted tree T in which the leaves of T correspond to the vertices of G = (V, E). †
Partially supported by the Future and Emerging Technologies programme of the EU under contract number IST-1999-14186 (ALCOM-FT).
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 220–236, 2002. c Springer-Verlag Berlin Heidelberg 2002
Advances in C-Planarity Testing of Clustered Graphs
221
In a cluster drawing of a clustered graph, vertices and edges are drawn as usual, and clusters are drawn as simple closed curves defining closed regions of the plane. The region of each cluster C contains the vertices W corresponding to C and the edges of the graph induced by W . The borders of the regions for the clusters are pairwise disjoint. If a cluster drawing does not contain crossings between edge pairs or edge/region pairs, we call it a c-planar drawing. Graphs that admit such a drawing are called c-planar. While the complexity status of c-planarity testing is unknown, the problem can be solved in linear time if the graph is c-connected, i.e., all cluster induced subgraphs are connected [Dah98,FCE95]. In approaching the general case, it appears natural to augment the clustered graph by additional edges in order to achieve c-connectivity without loosing c-planarity. The results presented in this paper are the basis for a first step towards this goal. Namely, we present a polynomial time algorithm that tests c-planarity for “almost” c-connected clustered graphs, i.e., graphs for which all c-vertices corresponding to the non-connected clusters lie on the same path in T starting at the root of T , or graphs in which for each non-connected cluster its super-cluster and all its siblings are connected. The algorithm uses ideas from the linear time algorithm for subgraph induced planar connectivity augmentation presented in [GJL+ 02]. For an undirected graph G = (V, E), W ⊆ V , and EW = {(v1 , v2 ) ∈ E : {v1 , v2 } ⊆ W } let GW = (W, EW ) be the subgraph of G induced by W . If G is planar, a subgraph induced planar connectivity augmentation for W is a set F of additional edges with end vertices in W such that the graph G = (V, E ∪ F ) is planar and the graph GW is connected. The paper is organized as follows: After an introduction into the SPQR data structure and clustered graphs in Sect. 2, we describe in Sect. 3 a linear time algorithm for c-planarity testing of a clustered graph with exactly one cluster in addition to the root cluster. This algorithm can be extended to a quadratic time algorithm for c-planarity testing in clustered graphs with one level beyond the root level in which at most one cluster is non-connected (see Sect. 4). In Sect. 5 we present a technique to extend the previous results to graphs with arbitrarily many non-connected clusters with the restriction that for each non-connected cluster, all its siblings and its super-cluster are connected. The same technique can be applied for graphs in which all the non-connected clusters lie on the same path in T .
2 2.1
Preliminaries SPQR-Trees
The data structure we use is called SPQR-tree and has been introduced by Di Battista and Tamassia [BT96]. It represents a decomposition of a planar biconnected graph according to its split pairs (pairs of vertices whose removal splits the graph or vertices connected by an edge). The construction of the SPQR-tree works recursively. At every node ℘ of the tree, we split the graph
222
Carsten Gutwenger et al.
into the split components of the split pair associated with that node. The first split pair of the decomposition is an edge of the graph and is called the reference edge of the SPQR-tree. We add an edge to every split pair to make sure that they are biconnected and continue by computing the SPQR-tree for every split pair and making the resulting trees the subtrees of the node used for splitting. Every node of the SPQR-tree has two associated graphs: – The skeleton of the node associated with a split pair p is a simplified version of the whole graph where some split-components are replaced by single edges. – The pertinent graph of a node v is the subgraph of the original graph that is represented by the subtree rooted at v. The two vertices of the split pair that are associated with a node ℘ are called the poles of ℘. There are four different node types in an SPQR-tree (S-,P -,Qand R-nodes) that differ in the number and structure of the split components of the split pair associated with the node. The Q-nodes are the leaves of the tree, and there is one Q-node for every edge in the graph. The skeleton of a Q-node consists of the poles connected by two edges. The skeletons of S-nodes are cycles, while the skeletons of R-nodes are triconnected graphs. P -node skeletons consist of the poles connected by at least three edges. Fig. 1 shows examples for skeletons of S-, P - and R-nodes. Skeletons of adjacent nodes in the SPQR-tree share a pair of vertices. In each of the two skeletons, one edge connecting the two vertices is associated with a corresponding edge in the other skeleton. These two edges are called twin edges. The edge in a skeleton that has a twin edge in the parent node is called the virtual edge of the skeleton. Each edge e in a skeleton represents a subgraph of the original graph. This graph together with e is the expansion graph of e. All leaves of the SPQR-tree are Q-nodes and all inner nodes S-, P - or R-nodes. When we see the SPQR-tree as an unrooted tree, then it is unique for every biconnected planar graph. Another important property of these trees is that their size (including the skeletons) is linear in the size of the original graph and that they can be constructed in linear time [BT96,GM01]. As described in [BT96,GM01], SPQR-trees can be used to represent the set of all combinatorial embeddings of a biconnected planar graph. Every combinatorial embedding of the original graph defines a unique combinatorial embedding for each skeleton of a node in the SPQR-tree. Conversely, when we define an embedding for each skeleton of a node in the SPQR-tree, we define a unique embedding for the original graph. The skeleton of S- and Q-nodes are simple cycles, so they have only one embedding. But the skeletons of R-and P -nodes have at least two different embeddings. Therefore, the embeddings of the Rand P -nodes determine the embedding of the graph and we call these nodes the decision nodes of the SPQR-tree. The BC-tree of a connected graph has two types of nodes: The c-nodes correspond to cut-vertices of G and the b-nodes to biconnected components (blocks). There is an edge connecting a c-node and a b-node, if the cut-vertex is contained in the block.
Advances in C-Planarity Testing of Clustered Graphs s B1 v1 B2 v2
e2 v2
B3
e3 t
t
s
s
s e1 v1 C1
223
C2
e1 e2
C3
e3
e4
t
t
(a) Case S-node
(b) Case P -node s
s
U1 U2
e2
e1
U3 U4
e3 U5
e5
e4
t
t (c) Case R-node
Fig. 1. The structure of biconnected graphs and the skeleton of the root of the corresponding SPQR-tree 1
Q-node
1 4
5 1
2
P-node
3
4
1
6 4
1 5
2
3
4
6 4
R-node
S-node
Fig. 2. A graph G and its SPQR-tree (the Q-nodes of the R- and S-node are omitted)
2.2
Clustered Graphs
The following definitions are based on the work of Cohen, Eades and Feng [FCE95]. A clustered graph C = (G, T ) consists of an undirected graph G and a rooted tree T where the leaves of T are the vertices of G. Each node ν of T represents a cluster V (ν) of the vertices of G that are leaves of the subtree rooted at ν. Therefore, the tree T describes an inclusion relation between clusters. T is
224
Carsten Gutwenger et al.
called the inclusion tree of C, and G is the underlying graph of C. The root of T is called root cluster. We let T (ν) denote the subtree of T rooted at node ν and G(ν) denote the subgraph of G induced by the cluster associated with node ν. We define C(ν) = (G(ν), T (ν)) to be the sub-clustered graph associated with node ν. We define pa(ν) the parent cluster of ν in T and chl(ν) the set of child clusters of ν in T . A drawing of a clustered graph C = (G, T ) is a representation of the clustered graph in the plane. Each vertex of G is represented by a point. Each edge of G is represented by a simple curve between the drawings of its endpoints. For each node ν of T , the cluster V (ν) is drawn as a simple closed region R that contains the drawing of G(ν), such that: – the regions for all sub-clusters of R are completely in the interior of R; – the regions for all other clusters are completely contained in the exterior of R; – if there is an edge e between two vertices of V (ν) then the drawing of e is completely contained in R. We say that there is an edge-region crossing in the drawing if the drawing of edge e crosses the drawing of region R more than once. A drawing of a clustered graph is c-planar if there are no edge crossings or edge-region crossings. If a clustered graph C has a c-planar drawing then we say that it is c-planar (see Figure 3). Therefore, a c-planar drawing contains a planar drawing of the underlying graph.
Fig. 3. A planar clustered graph that is not c-planar [FCE95] (the three disjoint clusters are represented by different types of vertices)
An edge is said to be incident to a cluster V (ν) if one end of the edge is a vertex of the cluster but the other endpoint is not in V (ν). An embedding of C includes an embedding of G plus the circular ordering of edges crossing the boundary of the region of each non-trivial cluster (a cluster which is not a single vertex). A clustered graph C = (G, T ) is connected if G is connected. A clustered graph C = (G, T ) is c-connected if each cluster induces a connected subgraph of G. Suppose that C1 = (G1 , T1 ) and C2 = (G2 , T2 ) are two clustered graphs such that T1 is a subtree of T2 , and for each node ν of T1 , G1 (ν) is a subgraph of G2 (ν). Then we say C1 is a sub-clustered graph of C2 , and C2 is a super-clustered graph of C1 . The following results from [FCE95] characterize c-planarity:
Advances in C-Planarity Testing of Clustered Graphs
225
Theorem 1. [FCE95] A c-connected clustered graph C = (G, T ) is c-planar if and only if graph G is planar and there exists a planar drawing D of G, such that for each node ν of T , all the vertices and edges of G − G(ν) are in the outer face of the drawing of G(ν). Theorem 2. [FCE95] A clustered graph C = (G, T ) is c-planar if and only if it is a sub-clustered graph of a connected and c-planar clustered graph. A further result from [FCE95] is a c-planarity testing algorithm for c-connected clustered graphs based on Theorem 1 with running time O(n2 ), where n is the number of vertices of the underlying graph and each non-trivial cluster has at least two children. An improvement in time complexity is given by Dahlhaus who constructed a linear time algorithm [Dah98].
3
Clustered Graphs with Two Clusters
Let C = (G, T ) be a clustered graph with a root cluster and a cluster ν. Let the graph G be connected and the subgraph induced by the vertices of the cluster ν non-connected. The problem of connecting the subgraph induced by one cluster is similar to the problem of planar connectivity augmentation of an induced subgraph [GJL+ 02]. In the following, we name the vertices of G(ν) blue vertices. After constructing an SPQR-tree T for every biconnected component of G we mark for every SPQRtree each edge in every skeleton either blue or black. An edge of a skeleton is marked blue, if its expansion graph contains blue vertices. Otherwise it is marked black. Additionally, we assign an attribute called permeable to certain blue edges. Intuitively, an edge is permeable if it is possible to construct a path connecting only blue vertices through its expansion graph. Let G(e) be the expansion graph of edge e in skeleton S. Since G(e) is biconnected we have that in any planar embedding G(e) there are exactly two faces that have e on their boundary. The edge e in S is permeable with respect to W , if there is an embedding Π of G(e) and a list of at least two faces L = (f1 , . . . , fk ) in Π that satisfies the following properties: 1. The two faces f1 and fk are the two faces with e on their boundary. 2. For any two faces fi , fi+1 with 1 ≤ i < k, there is a blue vertex on the boundary between fi and fi+1 . We call a skeleton S of a node ℘ of T permeable if the pertinent graph of ℘ and the virtual edge of S have the two properties stated above. Thus S is permeable if the twin edge of its virtual edge is permeable. Theorem 3. Let C = (G, T ) be a clustered graph such that the following conditions hold: – G is series-parallel
226
Carsten Gutwenger et al.
– C contains only one non-trivial non-root cluster ν and W is its corresponding vertex set. Let T be set of the SPQR-trees of every biconnected component of G. Let C := {V ∈ 2W |V is a circle in the expansion graph of a P-node and contains both pole vertices} be the set of the vertex sets of all circles in the expansion graphs of P-nodes that contain both pole vertices. Let the subgraph GW induced by W in G allow a planar connectivity augmentation for W . If for every P-node the following property (∗) holds, then C is c-planar: (∗) In every P-node, there is at the most one circle V of C such that 1. the union of the expansion graphs of two children ℘1 and ℘2 contains V and 2. for i ∈ {1, 2} the cut of G − GW with the expansion graph of child ℘i is nonempty. Proof. We calculate the BC-tree of G and for every block B the SP QR-tree of its biconnected component. The SP QR-tree of a series-parallel graph does not contain R-nodes. Hence GW has a planar connectivity augmentation, we assume that GW is connected. As we introduce a minimum cardinality edge set applying the planar connectivity augmentation, we do not loose c-planarity. According to Theorem 1 we need to show that a planar embedding exists such that the subgraph G − GW is embedded into the outside of GW . It follows that we need to show that G−GW is not embedded partially inside of GW (if it is embedded completely in an inner face we choose a face f that has an edge e = (v, w) with v ∈ W and w ∈ / W as outer face). Consider now the P -, S- and Q-nodes. For P -nodes we have the following cases – the P -node is black, that is it contains only black edges, – the P-node is blue and there exists exactly one blue edge in a P -node. The expansion graph of this blue edge contains the subgraph GW or – the P-node is blue and permeable. A blue P-node that is not permeable such that case 2 does not hold cannot exist for the following reasoning. If there is at least one blue edge in the P -node and another blue vertex or blue edge in another node, at least one pole vertex has to be blue due to the connectivity of GW . If there are at least two blue edges in the P -node, the pole vertex must be blue. Similar reasoning holds for S- and Q-nodes of the SPQR-trees and for the cut vertices of graph G. The latter are blue if at least two blocks which they belong to are blue. We have to show that there does not exist a planar embedding such that the subgraph G − GW is embedded in the outside of GW if and only if there exists a P-node P with more than one circle of vertices of W in the corresponding expansion graph fulfilling conditions 1. and 2. Note, that G(ν) is equal to GW and that P is in this case permeable as both pole vertices belong to G(ν).
Advances in C-Planarity Testing of Clustered Graphs
227
If there exists a P-node P with more than one circle of vertices of W in the corresponding expansion graph fulfilling conditions 1. and 2., then we order the edges that correspond to the union of expansion graphs fulfilling conditions 1. and 2. consecutively in P. We want to find an embedding according to Theorem 1. As we have only two clusters (a root cluster and cluster ν) this is equal to the fact, that G(ν) can be embedded into the outside of G − G(ν). As G(ν) is connected (there exists a planar connectivity augmentation) there has to be an embedding Π of G with a sequence of faces f1 , . . . , fk such that there is at least one vertex of G − G(ν) in the boundary between two consecutive faces fi and fi+1 and the boundaries of all those faces contain all vertices of G − G(ν). This is equal to the fact that G − GW has a planar connectivity augmentation for V − W in G as described in [GJL+ 02]. The faces containing vertices of G − G(ν) in their boundaries in P are contained in the sequence of faces f1 , . . . , fk . As the pole vertices are contained in G(ν) and there exists at least two circles of vertices of G(ν) that are contained in at least three expansions graphs, the sequence of faces f1 , . . . , fk cannot be consecutive and therefore there cannot exist a planar connectivity augmentation of G − GW for V − W in G. Therefore, we cannot find an embedding according to Theorem 1 and therefore C is not c-planar. If C is not c-planar, then there is an embedding Π in which the vertices of G − G(ν) cannot be embedded into the outside of G(ν) according to Theorem 1. As G(ν) is connected (there exists a planar connectivity augmentation) there does not exist a sequence of consecutive faces f1 , . . . , fk which are consecutive so that there is at least one vertex of V − W on the boundary between two faces and all vertices of V − W are included in the union of the boundaries of f1 , . . . , fk . Therefore there exists a sequence of faces f1 , . . . , fk in which their boundaries contain all vertices of G − G(ν) and there is a minimum number of consecutive faces fi and fi+1 so that on the boundary between fi and fi+1 is no vertex of G − G(ν). This is equal to the fact, that on the boundary between fi and fi+1 are vertices of G(ν). Let F be the set of all the faces fi and fi+1 . As the S- and Q-nodes have skeletons with only one embedding and a skeleton represents the whole corresponding biconnected component in G, we have to consider the P-nodes. As the pole vertices are contained in G(ν) and F is a minimum cardinality face set, there has to be l paths of vertices of G(ν) from one pole vertex to the other with l = |F2 | + 2 and l ≥ 3. Combining the paths to circles (the first and the last vertex of the paths are the pole vertices), we get more than one circle fulfilling condition 1. and 2. Note, that (∗) in the previous theorem can be replaced by: There exists a planar connectivity augmentation for V − W in G, if the subgraph GW is connected using the planar connectivity augmentation. Figure 4 gives an example for a clustered graph with underlying series-parallel graph which is not c-planar. The previous theorem can be easily extended to c-connected clustered graph C = (G, T ) with series-parallel underlying graph G. Theorem 4. Let C = (G, T ) be a clustered graph where G is a connected planar graph and W is the vertex set corresponding to the only non-trivial non-root cluster in T . We further assume that the subgraph GW induced by W is connected.
228
Carsten Gutwenger et al.
Fig. 4. Isolations in the expansion graph of P-nodes: The vertices with a circle around are vertices of the connected cluster, the others belong to the root cluster
The clustered graph C is c-planar if and only if there is an embedding of G that contains no cycle of blue vertices that separates the black vertices. Therefore c-planarity can be destroyed in the expansion graphs of R-nodes and in the expansion graphs of P -nodes if the clustered graph is c-connected. Theorem 5. A connected clustered graph C = (G, T ) where G is planar with one non-connected cluster ν is c-planar if and only if 1. there exists a planar connectivity augmentation of the subgraph induced by the non-connected cluster ν and 2. there is an embedding of G that contains no circle of vertices of G(ν) that separates vertices of G − G(ν). Proof. The proof follows from the previous theorems.
Note, that item 2. in the previous theorem can be replaced by: There exists a planar connectivity augmentation for the vertices of G − G(ν) in G. As a result, we are able to deal with c-planarity of a special subclass of clustered graphs using planar connectivity augmentation and SPQR-trees. According to Theorem 5, we know how to test planar connectivity augmentation of a subgraph of a planar graph. We now show how to test whether there exists an embedding of G that contains no circle in G(ν) that separates G−G(ν). Consider a clustered graph C = (G, T ) that has only one non-root cluster ν that is non-connected. Therefore the subgraph G(ν) has more than one connected component. As we choose a minimum cardinality planar augmenting edge set M and take the pole vertices belonging to G(ν) into account to augment C to a c-connected clustered graph and if such an augmentation exists, c-planarity of C is maintained if C is c-planar. Therefore to test whether C is c-planar is equal to the following: Let Ci , i = 1, . . . , l, l ≥ 2 be the connected components of G(ν). I. There exists a drawing such that the drawing of G−Ci can be drawn outside of the drawing Ci for all i = 1, . . . , l and II. there exists a planar connectivity augmentation between all Ci , i ∈ N and therefore for G(ν).
Advances in C-Planarity Testing of Clustered Graphs
229
Fig. 5. A clustered graph C with a non-connected cluster. By splitting the nonconnected cluster, C is extended to a c-connected clustered graph.
We test I. on an auxiliary modified clustered graph C˜ of C as follows. Cluster ν is split into l dummy clusters so that each connected component Ci i = 1, . . . , l corresponds to a dummy cluster. By construction C˜ is a c-connected clustered graph and can be tested according Feng, Eades and Cohen and according Dahlhaus for c-planarity. Definition 1. Let C be a clustered graph with a connected root cluster and a non-connected cluster ν. Let Csub be the clustered graph created by splitting ν into one dummy cluster for each connected component of the subgraph induced by ν that contain at least two vertices (see Fig. 5). A connected component that contains only one vertex is treated as a trivial cluster. We call Csub the c-split clustered graph of C. Note, that Csub is a c-connected clustered graph. Theorem 6. Let C be a clustered graph with a connected root cluster and a non-connected cluster ν. Let Csub be its c-split clustered graph. If Csub is not c-planar then C is not c-planar. Proof. If Csub is not c-planar, there exists an edge-crossing or a cluster-crossing in at least one cluster µ. The subgraphs induced by the dummy clusters of Csub are connected components of the corresponding non-connected cluster ν of C. Thus there exists an edge-crossing or a cluster-crossing in ν and C is not cplanar. Note that C must not be c-planar if its c-split clustered graph Csub is c-planar (see Fig. 6). In the case that Csub is c-planar and C is not there will not exist a planar connectivity augmentation in C for the non-connected cluster ν. Thus after a positive result after the application of the c-planarity test by Dahlhaus we apply the planar connectivity augmentation algorithm on G and the vertices of ν as subset W (if we have pole vertices that belong to G(ν), we use them for connectivity). Together with Theorem 5 we get the following theorem. Theorem 7. Let C = (G, T ) be a connected clustered graph and ν its only nontrivial non-root cluster that is non-connected. C can be tested for c-planarity in linear time with respect to the number of vertices of C and in the positive case embedded in linear time.
230
Carsten Gutwenger et al. Input: A clustered graph C = (G, T ) that contains a connected root cluster and a non-connected cluster ν. Result : true if and only if there is a c-planar connectivity augmentation for ν; in the positive case an embedding Π and the minimum cardinality augmenting edge set. Compute Csub by splitting the non-connected cluster for each connected component of the subgraph G(ν); Apply the linear time c-planarity test on Csub ; if the test return false then return false; Apply the subgraph induced planarity augmentation algorithm for C and ν; if a planar connectivity augmentation exists then Compute Π; return true; else return false; Algorithm 1. The algorithm for clustered graphs C = (G, T ) that contain a connected root cluster and a non-connected cluster ν. It computes an embedding Π and the minimum cardinality augmenting edge set.
Next we consider the case that G is non-connected and there is only one cluster ν that is not the root cluster and is non-connected. For all connected components of G we apply our algorithm for clustered graphs with one nonconnected cluster. Then we choose for each connected component a face as outer face that contains at least one blue vertex v1 and one non-blue vertex v2 . We connect the blue vertices in the outer face so that the edges of a minimum cardinality augmenting edge set is inserted (as described in [GJL+ 02]). In the positive case a c-planar embedding with a minimum cardinality augmenting edge set will be computed. Thus we have that the clustered graph has a c-planar connectivity augmentation for the non-connected cluster ν which leads us to the following theorem.
Fig. 6. An example where C is not c-planar but its c-split clustered graph Csub is c-planar
Advances in C-Planarity Testing of Clustered Graphs
231
Theorem 8. Let C = (G, T ) be a not necessarily connected clustered graph and ν its only non-trivial non-root cluster that is non-connected. C can be tested for c-planarity in linear time concerning the number of vertices of C and in the positive case embedded in O(n).
4
One-Level Clustered Graphs
As shown in the last section it is possible to test c-planarity of a clustered graph with one non-connected cluster and a root cluster in O(n) time, where n is the number of vertices of G. Next, we consider a clustered graph C = (G, T ) with a cluster tree T with only one level below the root cluster. So now we allow more than one non-root cluster. Further let only one child cluster of the root cluster be non-connected. We assume, that every non-trivial cluster has at least two vertices. We construct a c-split clustered graph Csub of C as described in Sect. 3. If G is not connected, we apply this technique to every connected component of G. First, we test if the c-split clustered graph Csub of C is c-planar. We call Gmod by the c-planarity test of Feng, Eades and Cohen modified graph G. Then we apply the planar connectivity augmentation algorithm described in [GJL+ 02] for the vertices belonging to ν in Gmod . If one exists, then an embedding Π and a minimum cardinality augmenting edge set is computed and true is returned. Otherwise, C is not c-planar. If we get Π, we can apply the techniques used in the c-planarity embedding algorithm of Feng, Eades for the connected clusters using Π to obtain a c-planar embedding of C. For the case that the root cluster is non-connected, we apply further the planar connectivity augmentation algorithm for the root cluster. Theorem 9. Let C = (G, T ) be a connected clustered graph with a cluster tree T with only one level below the root cluster and ν its only non-root nonconnected cluster. Let Csub be the c-split clustered graph of C. Let Gmod be the modified graph G obtained by the c-planarity test by Feng, Eades and Cohen of Csub = (G, Tsub ). C is c-planar if and only if Csub is c-planar and there exists a planar connectivity augmentation of the vertices belonging to the subgraph G(ν) in Gmod . Proof. – “⇐” We have that Csub is c-planar and there exists a planar connectivity augmentation of G(ν) in Gmod . Thus G is planar and there exists a planar drawing of G, such that for every node µ of Tsub , all the vertices and edges of G − G(µ) are in the external face of the drawing of G(µ). Note that this holds for the connected clusters of C and for the dummy clusters in Csub constructed of ν. Therefore, Gmod allows only those c-planar embeddings that respect the connected clusters of C and takes the connected components of G(ν) into account. Hence the planar connectivity augmentation within Gmod has introduced a minimum cardinality augmenting edge set, connecting G(ν) such that the boundary of its external face in any planar drawing
232
Carsten Gutwenger et al.
of G(ν) consists of a connected not simple cycle. Furthermore, the minimum cardinality augmenting edge set connects the connected components of the original G(ν), so that there exists at the most one edge between two connected components. Therefore Gmod − G(ν) is embedded in the outer face of G(ν) after planar connectivity augmentation. Hence, C is c-planar. – “⇒” We have that C is c-planar. Thus Csub is c-planar. Hence the vertices of G(ν) can be embedded so that there is a sequence of faces f1 , . . . , fk with the following property: for all 1 ≤ i < k, there is at least one vertex of W on the boundary between fi and fi+1 and the boundaries of the faces fi (1 ≤ i ≤ k) contain all vertices of W . Therefore G has a planar connectivity augmentation in respect to the vertices of G(ν). Theorem 10. Let C = (G, T ) be a connected clustered graph with a cluster tree T with only one level below the root cluster and ν its only non-root non-connected cluster. C can be tested for c-planarity in O(n2 ) time in respect to the number n of vertices of C. Proof. We can create the c-split clustered graph Csub in O(n) time where n is the number of vertices of G. The c-planarity testing can be done in O(n2 ) time and the planar connectivity augmentation of the subgraph induced by the non-connected clustered graph in O(n) time. As a result the algorithm can be implemented in O(n2 ) time where n is the number of vertices of G.
5
Multi-level Clustered Graphs
We extend the algorithm of the previous section to clustered graphs with more than one level in the tree T . Consider a clustered graph C = (G, T ) with at least two non-connected clusters where G is connected. Then if for every nonconnected cluster ν in the cluster tree T the parent cluster and all siblings of ν are connected, we show that it is possible to connect the non-connected clusters using the planar connectivity augmentation [GJL+ 02]. To do so, we compute the c-split clustered graph Csub of C. Then, we traverse T towards the root starting at the leaves in order to do the followings: For every non-connected cluster ν of C that has connected siblings µ and a connected parent pa(ν), we test whether the subgraph G(pa(ν)) is planar, test whether the edges that are incident to pa(ν) can be drawn into the outside of the drawing of G(pa(ν)) (see Figure 7) and test whether there exists a planar connectivity augmentation of the vertices of ν. If a planar connectivity augmentation exists, then an embedding Π and a minimum cardinality augmenting edge set is computed and true is returned. Otherwise, C is not c-planar. If we get Π, we can apply the techniques used in the c-planarity embedding algorithm of Feng and Eades for the connected clusters using Π to obtain a c-planar embedding of C.
Advances in C-Planarity Testing of Clustered Graphs
233
Input: A clustered graph C = (G, T ) that contains a connected root cluster, a non-connected child cluster ν and an arbitrarily number of connected child clusters. Result : true if and only if there is a c-planar connectivity augmentation for ν; in the positive case an embedding Π and the minimum cardinality augmenting edge set will be computed. Compute Csub by splitting the non-connected cluster for each connected component of the subgraph G(ν); Apply the c-planarity test by Cohen, Eades and Feng on Csub ; if the test return false then return false; Apply on Gmod (see Theorem 9) in respect to the vertices of G(ν) the planar connectivity augmentation algorithm; if a planar connectivity augmentation exists then Compute Π; return true; else return false; Algorithm 2. The algorithm for clustered graphs C = (G, T ) that contain a connected root cluster, a non-connected child cluster ν and an arbitrarily number of connected child clusters. It computes an embedding Π and the minimum cardinality augmenting edge set if C is c-planar.
G(ν)
t
Fig. 7. Constructing an auxiliary graph Gmod from the connected subgraph G(ν) where the incident edges of ν are connected with a dummy vertex t [FCE95]
Theorem 11. Let C = (G, T ) be a connected clustered graph where its nonconnected clusters ν have a connected parent cluster and only connected sibling clusters. Let Csub = (G, Tsub ) be its c-split clustered graph. Let Gmod be the graph constructed by the c-planarity test of Feng, Eades and Cohen applied to pa(ν) of Csub and where the subgraphs G(chl(pa(ν))) are replaced with their wheel graphs. If Csub is c-planar and there exists for every non-connected cluster ν a planar connectivity augmentation for the vertices of the subgraph G(ν) in Gmod then C is c-planar.
234
Carsten Gutwenger et al.
Proof. The proof is by construction. We extend the c-planarity test by Cohen, Eades and Feng as follows: For every connected parent cluster pa(ν) with a non-connected child cluster ν, we construct the graph Gmod as stated in the theorem (see Fig. 7). Then we apply the linear time planarity test based on PQtrees [BL76,CEL67] to Gmod and in the positive case the planar connectivity augmentation for the subgraph induced by the non-connected cluster [GJL+ 02]. As we do this recursively for every connected parent node that has a nonconnected cluster by taking the wheel graphs as constructed in the c-planarity test into account, we can test c-planarity in O(n2 ) time where n is the number of vertices of G. Theorem 12. Let C = (G, T ) be a connected clustered graph where its nonconnected clusters ν have a connected parent cluster and only connected sibling clusters. C can be tested for c-planarity and in the positive case embedded in O(n2 ) time with respect to the number n of vertices of C. Input: A clustered graph C = (G, T ) that contains a connected root cluster and non-connected clusters with connected parent cluster and sibling clusters. Result : true if and only if there is a c-planar connectivity augmentation for ν; in the positive case an embedding Π and the minimum cardinality augmenting edge set will be computed. Compute Csub by splitting the non-connected cluster for each connected component of the subgraph G(ν); Change the c-planarity test of Cohen, Eades and Feng as follows and apply it to Csub ; for for every connected parent cluster of a non-connected cluster do Construct Gmod as described in Theorem 11; Test planarity of Gmod ; if the planarity test returns false then return false; Apply the subgraph induced planar connectivity augmentation algorithm for the vertices of G(ν) in Gmod ; if a planar connectivity augmentation exists then Compute Π; return true; else return false; Algorithm 3. The algorithm for clustered graphs that contain a connected root cluster and non-connected clusters with a connected parent cluster and sibling clusters. It computes an embedding Π and the minimum cardinality augmenting edge set if C is c-planar.
We note that this technique can be applied to connected clustered graphs C = (G, T ) where the non-connected clusters lie on the same path from the root
Advances in C-Planarity Testing of Clustered Graphs
235
to the leaves. This is done again by computing the c-split clustered graph Csub for every connected component Ci of C, testing it for c-planarity. In this step, every connected component is modified with wheel graphs. Then we get graph Gmod . We now traverse the path of non-connected clusters in the original cluster tree T from the leaves to the root and apply to the vertices of these clusters the planar connectivity augmentation algorithm [GJL+ 02] in Gmod . This can be done in O(n2 ) time where n is the number of vertices in the underlying graph G. In the positive case, an embedding can be computed in O(n2 ) time. Finally, we consider two non-connected clusters that are siblings in an arbitrary clustered graph where all other clusters are connected and G is planar. If the two clusters are contained in two different connected components (if additionally the root is non-connected) or if they are contained in two different biconnected components or in two different subtrees of a BC-tree, we can apply the one-cluster-method for each connected or biconnected component independently. This can be extended to an arbitrarily number of non-connected clusters that are siblings under the condition that they are in different connected or biconnected components. Combining the techniques used in this paper, there is a large class of clustered graphs that can now be tested for c-planarity.
References BDM02. G. Di Battista, W. Didimo, and A. Marcandalli. Planarization of clustered graphs (extended abstract). In P. Mutzel, Michael J¨ unger, and Sebastian Leipert, editors, Graph Drawing, volume 2265 of Lecture Notes in Computer Science, pages 60–74. Springer-Verlag, 2002. BL76. K. Booth and G. Lueker. Testing for the consecutive ones property, interval graphs, and graph planarity using pq-tree algorithms. Journal of Computer and System Sciences, 13(1):335–379, 1976. BT96. G. Di Battista and R. Tamassia. On-line planarity testing. SIAM Journal on Computing, 25(5):956–997, 1996. CEL67. I. Cederbaum, S. Even, and A. Lempel. An algorithm for planarity testing of graphs. In Theory of Graphs, International Symposium, Rome, pages 215– 232, 1967. Dah98. E. Dahlhaus. Linear time algorithm to recognize clustered planar graphs and its parallelization (extended abstract). In C. L. Lucchesi, editor, LATIN ’98, 3rd Latin American symposium on theoretical informatics, Campinas, Brazil, April 20–24, 1998., volume 1380 of Lecture Notes in Computer Science, pages 239–248, 1998. EFN00. P. Eades, Q.-W. Feng, and H. Nagamochi. Drawing clustered graphs on an orthogonal grid. Journal of Graph Algorithms and Applications, 3:3–29, 2000. FCE95. Q.-W. Feng, R.-F. Cohen, and P. Eades. Planarity for clustered graphs. In P. Spirakis, editor, Algorithms – ESA ’95, Third Annual European Symposium, volume 979 of Lecture Notes in Computer Science, pages 213–226. Springer-Verlag, 1995.
236
Carsten Gutwenger et al.
unger, S. Leipert, P. Mutzel, M. Percan, and GJL+ 02. C. Gutwenger, M. J¨ R. Weiskircher. Subgraph induced planar connectivity augmentation. Technical report, Institut f¨ ur Informatik, Universit¨ at zu K¨ oln, 2002. zaik2002-435. GM01. C. Gutwenger and P. Mutzel. A linear time implementation of SPQR-trees. In J. Marks, editor, Graph Drawing (Proc. 2000), volume 1984 of Lecture Notes in Computer Science, pages 77–90. Springer-Verlag, 2001.
HGV: A Library for Hierarchies, Graphs, and Views Marcus Raitner University of Passau, D-94032 Passau, Germany, [email protected]
Abstract. We introduce the base architecture of a software library which combines graphs, hierarchies, and views and describes the interactions between them. Each graph may have arbitrarily many hierarchies and each hierarchy may have arbitrarily many views. Both the hierarchies and the views can be added and removed dynamically from the corresponding graph and hierarchy, respectively. The software library shall serve as a platform for algorithms and data structures on hierarchically structured graphs. Such graphs become increasingly important and occur in special applications, e. g., call graphs in software engineering or biochemical pathways, with a particular need to manipulate and draw graphs.
1
Introduction
Graphs are often used to model structured data, e. g., road maps with locations connected by roads, the web-graph with web-pages connected by links or biochemical pathways with substances connected by reactions [3]. Particularly for large graphs it is important to view, manipulate, and automatically draw them using some software tools. Clearly, all these tools rely on an appropriate data structure for graphs. There already exist various libraries implementing data structures for graphs, e. g., Leda [15], Gtl [9], or Boost Graph Library [2]. There are many applications with very large graphs. Such graphs must be manipulated efficiently by powerful operations acting on subgraphs. Repeated use of subgraphs induces a hierarchical structure. This is a particular means also for the visualization of large graphs, because certain subgraphs may be collapsed and represented by a meta-node. There are various concepts for extending graphs with such a hierarchical structure [7,10,12,18]. Moreover there are layout algorithms [7, 18] and interactive systems [17, 13] working with these concepts. The inclusion hierarchy on top of a graph can be used to define abstract representations of the graph, so called views [5,6,7] or abridgements [13]. Instead of displaying every single node of the graph, in a view a subset of the nodes is represented as one (abstract) node. These nodes are connected by an (abstract) edge if there is an edge between nodes in the corresponding subsets. In a graph editor views are very convenient since they simultaneously provide an overview of the whole graph and some details from a special portion. In some respects a view can be compared to the well known tree views of file systems where M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 236–243, 2002. c Springer-Verlag Berlin Heidelberg 2002
HGV: A Library for Hierarchies, Graphs, and Views
237
initially only the topmost layer of folders is shown and the folders of interest can be expanded within the view. Up to now there is no thorough description of the software architecture for a library providing graphs with hierarchies and views. This contribution and the prototype implementation [11] are a first step. 1.1
Related Work
There are several notions of hierarchically structured graphs in the literature. Depending on their purpose these definitions come in different flavors ranging from succinct representations of large graphs [16] to graph drawing [7, 18]. The latter is surveyed in [4]. Structuring a graph hierarchically was first employed on statecharts [10]. There the term higraph is defined as an ordinary graph with an acyclic inclusion relation on its nodes. A higraph can be seen as a directed acyclic graph (DAG) describing an inclusion hierarchy with additional graph edges connecting arbitrary nodes. The compound graphs [18] consist of a set of nodes together with inclusion edges and adjacency edges such that the inclusion edges induce a directed graph (mostly a tree) and the adjacency edges induce a directed graph. Like a higraph a compound graph can be seen as a directed graph describing the hierarchy with additional (adjacency) edges connecting arbitrary nodes. Closely related to compound graphs and higraphs are the cigraphs [14]. A cigraph is a root node together with a possibly empty set of sub-cigraphs and a set of edges between nodes in different sub-cigraphs. This means that an edge is always stored at the least common ancestor of the cigraphs it connects. Neither higraphs nor compound graphs nor cigraphs distinguish properly between the nodes of the underlying graph and the nodes of the hierarchy. On the other hand the clustered graphs [7] consist of an ordinary graph and a tree with the leaves of the tree being exactly the nodes of the graph. This can be seen as a tree describing an inclusion hierarchy with additional graph edges between its leaves only. Each node in the tree represents a cluster of nodes of the graph that are leaves of the subtree rooted at the node. With the additional restriction that there are no long tree edges, i. e., tree edges connecting nodes whose heights in the tree differ by more than one, a view at level i of a clustered graph is a graph consisting of all nodes of height i in the tree. Two nodes in the view are connected by an edge if there is at least one graph edge connecting the respective clusters. In [6,5] the notion of a view of a clustered graph is generalized. There a view is a subset of the nodes of the tree such that the corresponding clusters partition the set of nodes of the graph. Hence the view can be detailed and coarsened as needed. In [6] it is shown how to maintain a view on a clustered graph efficiently while navigating up and down the hierarchy using the methods collapse and expand. Some interactive systems [13, 17] actually use these two operations to explore clustered graphs. However, they do not describe thoroughly the coherence
238
Marcus Raitner
of graph, hierarchies and views from a software-engineering perspective. Other systems [1] model clustered graphs as an extension of ordinary graphs and do not provide views at all. 1.2
Our Results
We propose a software architecture for the interaction of graphs, hierarchies, and views. Employing the Observer design pattern [8] twice, our model features an arbitrary number of hierarchies for each graph as well as an arbitrary number of views for each hierarchy. Our model prepares the ground for a graph library with hierarchies and views. Such a library, integrated in a graph editor or a graph layout tool, provides an additional dimension for the structuring of graphs and makes working with large graphs more convenient. A first implementation of our model is available [11]. Since we allow more than one hierarchy per graph we need a rigid distinction between graph and hierarchy. Therefore we extend the clustered graphs by cross edges between tree nodes. Cross edges can be seen as edges on a higher level of abstraction, They describe a relation between clusters of nodes while edges in the graph describe a relation between the nodes of the graph. For our model we generalize the views in [6, 5], which are defined only on clustered graphs. Moreover, our views need not cover the whole graph and can therefore be used to model subgraphs and views of subgraphs.
2
Basic Notions
Definition 1. Let G be a graph with nodes V (G) and edges E(G). A hierarchy ˙ i (H), cross edges Ec (H) and a H over G consists of nodes V (H) = V (G)∪V grouping function cH : V (H) → P(V (G)) such that (i) (ii) (iii) (iv)
∀ v ∈ V (G) : cH (v) = {v} ∃ v ∈ Vi (H) : cH (v) = V (G) ∀ u, v ∈ V (H) : cH (u) ∩ cH (v) = ∅ ⇒ (cH (v) ⊆ cH (u) ∨ cH (u) ⊆ cH (v)) ∀ e = (u, v) ∈ Ec (H) : cH (u) ∩ cH (v) = ∅
The nodes Vi (H) are the called inner nodes and cH (v) is called the cluster of v. A hierarchy over a graph can be seen as a rooted tree with its leaves corresponding exactly to the nodes of the underlying graph and with cross edges connecting tree nodes which are not predecessors of one another. In Fig. 1 the hierarchy over a graph is depicted as an inclusion diagram. The solid lines are edges of the graph and the dashed ones are cross edges. The boxes represent the clusters cH (v) for v ∈ V (H). Figure 2 shows the same graph and the same hierarchy as a tree with graph edges and cross edges. Because of the cross edges this notion of a hierarchy is more general than the clustered graphs of [7]. Our definition differs from compound graphs of [18] and the higraphs of [10] since the hierarchy may not be a DAG and only cross
HGV: A Library for Hierarchies, Graphs, and Views
239
f
e
Fig. 1. Inclusion Diagram
Fig. 2. Tree
Fig. 3. View
edges are allowed. The cigraphs of [14] are equivalent to our model, but do not provide a rigid distinction between graph and hierarchy which is necessary for more than one hierarchy per graph. Definition 2. A view S of a hierarchy H over a graph G is a graph with nodes V (S) ⊂ V (H) such that ∀ u, v ∈ V (S) : u = v ⇒ cH (u) ∩ cH (v) = ∅. Two nodes u, v ∈ V (S) are connected by an edge if and only if (i) ∃ u , v ∈ V (H) : cH (u ) ⊆ cH (u) ∧ cH (v ) ⊆ cH (v) ∧ u is connected to v by a cross edge or (ii) ∃ u ∈ cH (u), v ∈ cH (v) : u and v are connected by an edge in G. Figure 3 shows a view of the hierarchy of Fig. 1. The edges e and f are examples for (i) and (ii), respectively. There are many other views. Our definition generalizes the one given in [6, 5] in various respects. The clusters of nodes in the view need not cover the whole graph. Therefore we can model subgraphs and views of subgraphs. Using cross edges, our views can have edges connecting clusters which are not connected in the underlying graph.
3
Core Architecture
The three main classes in the class diagram in Fig. 4 are graph, hierarchy, and view. The other two classes, observable_graph and observer, are primarily abstract interfaces modeling the observer design pattern [8]. 3.1
Assumptions
The following assumptions guided the design of our library. 1. Fully dynamic graph, hierarchy and view: Nodes and edges can be added or removed from the underlying graph. The inner nodes of the hierarchy can be inserted or deleted and nodes in the view can be expanded or collapsed.
240
Marcus Raitner graph + + + + +
graph() new_node() : node new_edge(node, node) : edge delete_node(node) delete_edge(edge)
observer observable_graph + observable_graph() + add(observer&) + remove(observer&)
1 observed
1..* observers
+ + + + +
observer(observable_graph&) new_node_handler(node) new_edge_handler(edge) delete_node_handler(node) delete_edge_handler(edge)
hierarchy + + + + + + + + + +
view
hierarchy(observable_graph&) new_node(InputIterator, InputIterator) : node get_root() : node son_edges_begin() : son_edge_iterator son_edges_end() : son_edge_iterator get_father_edge(node) : edge induced_edge(node, node) : int is_predecessor_of(node, node) : bool is_inner_node(node) : bool is_cross_edge(edge) : bool
+ view(hierarchy&, InputIterator, InputIterator) + expand(node) + collapse(node)
Fig. 4. Core Architecture
2. Arbitrarily many hierarchies per graph: A hierarchy always describes one dimension of abstraction, e. g., grouping locations in a road map by their geographical proximity. Sometimes it may be necessary or convenient to use more than one dimension of abstraction for the same graph, i. e., more than one hierarchy. Consider for instance the web-graph, which can be grouped either by domain or by topic. 3. Arbitrarily many views per hierarchy: A view defines an abstract version of a graph in terms of an associated abstraction hierarchy (cf. Definition 2). Clearly, it is very convenient to have more than one view, especially in a viewer or editor, where the user can see one abstract overview and work in another more detailed view. 4. Minimize redundant information: By Definition 1 the graph is part of each associated hierarchy and each view is part of a hierarchy (cf. Definition 2). Since all objects are subject to change it is very important to minimize redundancy. 5. Reusable algorithms: Hierarchies and views can be seen as graphs and thus many graph algorithms are applicable to them. Clearly, these algorithms should be implemented only once. 3.2
Graphs, Nodes and Edges
The class graph is the common base class for hierarchy and view. It consists of nodes and edges and the basic methods for adding and removing these objects. It also provides methods for traversing and accessing nodes and edges. This includes methods for traversing the adjacency of a node in particular. In other words, the graph has full control and the nodes and edges are only handles without state or
HGV: A Library for Hierarchies, Graphs, and Views
241
functionality of their own. Examples for this model are the graphs in Leda [15] and in Boost Graph Library [2]. This is more appropriate here than the alternative, where nodes and edges are objects of their own controlling their adjacency lists themselves as in Gtl [9], because then there can be at most one adjacency list for each node. On the other hand there can be at most one adjacency list per graph and node if the graph manages the lists. In other words nodes can be shared by several graphs, which is important to avoid redundancy. 3.3
The Observer Pattern
The partly abstract classes observer and observable_graph form the observer design pattern [8]. observable_graph extends graph with methods for adding and removing observers dynamically. Any object used as such an observer has to be derived from observer and thus has to implement the callback methods like new_node_handler. All the methods that modify the graph are redefined in observable_graph in order to trigger the appropriate callback method in all its observers with the modified object as argument. Notification of a new node or edge occurs after the change whereas deleting a node or edge is announced in advance. 3.4
Hierarchies
As shown in Fig. 4 a hierarchy is both observer and observable_graph. The observer part keeps track of modifications of the underlying graph whereas the observable_graph part informs the attached views about changes of either the graph or the hierarchy. By definition a hierarchy cannot exist without an underlying graph. Therefore its constructor takes an observable_graph as argument. Initially a hierarchy consists of one root with all the nodes of the associated graph as sons and no cross edges. A hierarchy is a graph and thus it can be modified using the methods already defined in graph. On the other hand, a hierarchy is a special graph, namely a tree with some cross-edges, and imprudent use of such a method could violate this invariant. Therefore these methods are redefined as follows: – new_node(): Creates a new leaf, i. e., a new node in the underlying graph, and attaches it to the root. – new_edge(s,t): If both s and t are leaves then a new edge in the underlying graph is created. If at least one is an inner node and neither is a predecessor of the other a new cross-edge is inserted. – delete_node(n): If n is a leaf it is deleted in the underlying graph. If it is an inner node and is not the root all its sons are attached directly to its father before it is deleted. – delete_edge(e): Depending on whether e is a cross-edge or an edge between leaves it is deleted in the hierarchy or in the underlying graph, respectively.
242
Marcus Raitner
For inserting a new inner node the method new_node(it,end) is provided. Its arguments specify a set of nodes as the range [it,end), where it and end are iterators over some collection of nodes. It is required that all the nodes in this range have the same father in the hierarchy. The new inner node is inserted between these nodes and their father, i. e., the new node becomes the new father of these nodes and is inserted as son of the old father. Apart from these explicit changes a hierarchy must be adapted whenever the underlying graph is modified. This is achieved by implementing the callback methods of the observer interface accordingly. A new node in the underlying graph becomes a leaf attached to the root node and deleting a node in the graph results in removing the corresponding leaf from the hierarchy. Adding or removing an edge from the graph does not result in a change in the hierarchy. However, all attached views are notified about changes of either the graph or the hierarchy. The other new methods in hierarchy as shown in Fig. 4 are either for navigation in the hierarchy, e. g., son_edges_begin or get_father_edge, or provide information used by the views, e. g., induced_edge or is_predecessor_of. 3.5
Views
A view is both a graph and an observer. The graph part is the abstract version of the underlying graph in terms of the associated hierarchy. The observer part listens to changes of this hierarchy and updates the view accordingly. At any time a view consists of a subset of the nodes of its hierarchy and thus the constructor of view takes two arguments: the hierarchy and the initial subset for this view. The subset is given as a range [it,end) in a collection of nodes, where it and end are iterators. Since a view is a graph it can be modified through the standard methods defined in graph. On the other hand a view consists of nodes of the associated hierarchy and induced edges and thus all modifications must be forwarded to the hierarchy. Hence those methods are redefined in view in order to call the respective methods in hierarchy. Whenever a view is notified of a change of the hierarchy (or the graph) it has to check whether it is affected. For instance, if a node in the hierarchy is deleted the view must be adapted if and only if this node was part of the view. In order to perform these updates efficiently the view makes use of the query methods provided in hierarchy, e. g., induced_edge or is_predecessor_of. The method view::expand replaces a node in the view by its sons, and conversely view::collapse replaces all the sons of a node with the node itself. For both methods the view removes some nodes with all their incident edges and inserts one or more others. After inserting the new nodes the view uses query methods like hierarchy::induced_edge to determine their adjacency. Thus a view can not only be used to represent an abstract version of a graph but also to navigate through the hierarchy in either direction.
HGV: A Library for Hierarchies, Graphs, and Views
4
243
Conclusion
We have presented an architecture model for a library featuring graphs with an arbitrary number of hierarchies and views. Such a library shall help in handling large graphs in a convenient manner. It can be used in graph editors for drawing and exploring large graphs interactively. Our model prepares the ground for data structures for the efficient implementation of hierarchies and views and algorithms taking advantage of the additional hierarchical structure.
References 1. Agd. http://www.ads.tuwien.ac.at/AGD/index.html. 2. Boost Graph Library. http://www.boost.org/libs/graph/doc/. 3. F. J. Brandenburg, M. Forster, A. Pick, M. Raitner, and F. Schreiber. Biopath. In Proc. GD 2001, LNCS 2265, pp. 451–456, 2001. 4. R. Brockenauer and S. Cornelsen. Drawing clusters and hierarchies. In Drawing Graphs – Methods and Models, LNCS 2025, pp. 193–227, 2001. 5. A. L. Buchsbaum, M. T. Goodrich, and J. R. Westbrook. Range searching over tree cross products. In 8th ESA, 2000. 6. A. L. Buchsbaum and J. R. Westbrook. Maintaining hierarchical graph views. In 11th ACM-SIAM Symposium on Discrete Algorithms, 2000. 7. P. Eades and Q.-W. Feng. Multilevel visualization of clustered graphs. In Proc. GD 1996, LNCS 1190, pp. 101–112, 1996. 8. E. Gamma, R. Helm, R. Johnson, and J. Vlissides. Design Patterns: Elements od Reusable Object-Oriented Software. AW Professional Computing Series, 1995. 9. Gtl. http://www.infosun.fmi.uni-passau.de/GTL. 10. D. Harel. On visual formalisms. Comm. of the ACM, 31(5):588–600, 1988. 11. Hgv. http://www.infosun.fmi.uni-passau.de/˜raitner/HGV/. 12. M. Himsolt. Konzeption und Implementierung von Grapheneditoren. PhD thesis, Fakult¨ at f¨ ur Mathematik und Informatik, Universit¨ at Passau, 1993. 13. M. L. Huang and P. Eades. A fully animated interactive system for clustering and navigating huge graphs. In Proc. GD 1998, LNCS 1547, pp. 374–383, 1998. 14. W. Lai and P. Eades. A graph model which supports flexible layout functions. Technical Report 96–15, 1996. 15. Leda. http://www.algorithmic-solutions.com/. 16. T. Lengauer and E. Wanke. Efficient solution of connectivity problems on hierarchically defined graphs. SIAM Journal on Computing, 17(6):1063–1080, 1988. 17. I. A. Lisitsyn and V. N. Kasyanov. Higres - visualization system for clustered graphs and graph algorithms. In Proc. GD 1999, LNCS 1731, pp. 82–89, 1999. 18. K. Sugiyama and K. Misue. Visualization of structural information: Automatic drawing of compound digraphs. IEEE Trans. Systems, Man and Cybernetics, 21(4):876–892, 1991.
Rectangular Drawings of Planar Graphs (Extended Abstract) Md. Saidur Rahman1 , Takao Nishizeki2 , and Shubhashis Ghosh3 1
Graduate School of Information Sciences, Tohoku University, Aoba-yama 05, Sendai 980-8579, Japan. On leave from Bangladesh University of Engineering and Technology (BUET). [email protected] 2 Graduate School of Information Sciences, Tohoku University, Aoba-yama 05, Sendai 980-8579, Japan. [email protected] 3 Department of Computing Science, University of Alberta, Edmonton, Alberta T6G 2E8, Canada. On leave from Bangladesh University of Engineering and Technology (BUET). [email protected]
Abstract. A plane graph is a planar graph with a fixed embedding. In a rectangular drawing of a plane graph, each vertex is drawn as a point, each edge is drawn as a horizontal or vertical line segment, and each face is drawn as a rectangle. A planar graph is said to have a rectangular drawing if at least one of its plane embeddings has a rectangular drawing. In this paper we give a linear-time algorithm to examine whether a planar graph G of the maximum degree three has a rectangular drawing or not, and to find a rectangular drawing of G if it exists.
1
Introduction
The necessity of automatic graph drawing in various areas of science and technology has accelerated the development of many graph drawing styles, and different algorithms have been developed for producing these graph drawing styles [DETT99]. Among different drawing styles a “rectangular drawing” has attracted much attention due to its applications in VLSI floorplanning [KK84, L90, RNN98, RNN02, RNN02, TTSS91] and architectural floorplanning [MKI00]. A plane graph is a planar graph with a fixed embedding. A rectangular drawing of a plane graph G is a drawing of G in which each vertex is drawn as a point, each edge is drawn as a horizontal or vertical line segment without edge-crossings, and each face is drawn as a rectangle. (See Figure 1(a).) Not every plane graph has a rectangular drawing. We denote by ∆ the maximum degree of G. If a plane graph G has a rectangular drawing, then ∆ ≤ 4 and G must be biconnected and have four or more vertices of degree 2 on the outer face. Thomassen [T84] obtained a necessary and sufficient condition for a plane graph of ∆ ≤ 3 to have a rectangular drawing when four vertices of degree two on the outer face are designated as convex corners of a rectangular drawing of the outer face. Linear-time algorithms are given in [BS88, H93, KH97, RNN98] to obtain a rectangular drawing of such
This work is supported by JSPS grants.
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 244–255, 2002. c Springer-Verlag Berlin Heidelberg 2002
Rectangular Drawings of Planar Graphs
245
a plane graph. The plane graph in Figure 1(b) has a rectangular drawing for the four designated corners a, f , i, and l as illustrated in Figure 1(a). Rahman et al. [RNN02] gave a necessary and sufficient condition for a plane graph of ∆ ≤ 3 to have a rectangular drawing when no vertex is designated as a corner, and developed a linear-time algorithm to find a rectangular drawing of a plane graph if it exits. c b a m m
a b c
o n
u
d e
k
q
s
u t
g k
i
t
u
c
o r
(d)
j
n o p q r
d l
f e
k j g i h
s
P 3
h (b)
u
t (c)
m n
k
n p
c u
s j
q
s
a
b e d
f
k
i g
l
P 2
r
m
h
n
f
i
h (a)
g
d
l o p
e
j
r
t
f
P a 1 b c
l p
m
s
e
r
j
q p
g
h (e)
Fig. 1. A rectangular drawing (a) and three different embeddings (b), (c) and (d) of the same graph which is subdivision of the graph in (e).
A planar graph G is said to have a rectangular drawing if at least one of the plane embeddings of G has a rectangular drawing. Figures 1(b), (c) and (d) depict three different plane embedings of the same planar graph. Among them only the embedding in Figure 1(b) has a rectangular drawing as illustrated in Figure 1(a). Thus the planar graph has a rectangular drawing. A rectangular drawing of a planar graph with ∆ ≤ 3 has practical application in VLSI floorplanning [KK84, L90, RNN98, RNN02] and architectural floorplanning [MKI00]. Examining whether a planar graph G of ∆ ≤ 3 has a rectangular drawing is not a trivial problem, since G may have an exponential number of plane embeddings in general. A straightforward algorithm checking each of all the embeddings by the linear algorithm above in [RNN02] does not run in polynomial time. It has thus been desired to obtain an efficient algorithm. In this paper we give a lineartime algorithm to examine whether a planar graph G of ∆ ≤ 3 has a rectangular drawing and find a rectangular drawing of G if it exists. We first consider the case where G is a “subdivision” of a planar 3-connected cubic graph, and then consider the case where G is not a “subdivision” of a planar 3-connected cubic graph. The plane graph in Figure 1(b) is a subdivision of the planar 3-connected cubic graph in Figure 1(e). A subdivision G of a planar 3-connected cubic graph has exactly one embedding for each face embedded as
246
Md. Saidur Rahman, Takao Nishizeki, and Shubhashis Ghosh
the outer face [NC88]. Hence G has an O(n) number of embeddings, one for each chosen outer face. Thus, the straightforward algorithm takes time O(n2 ) to examine whether the planar graph G has a rectangular drawing. We however obtain a necessary and sufficient condition for a subdivision G of a planar 3connected cubic graph to have a rectangular drawing, which leads to a linear-time algorithm to examine whether the planar graph G has a rectangular drawing. If G is not a subdivision of a planar 3-connected cubic graph, then G may have an exponential number of embeddings, and hence a straightforward algorithm does not run in polynomial time. We however give a linear-time algorithm to examine whether G has a rectangular drawing or not; we indeed show that it suffices to examine whether only four embeddings of G have rectangular drawings or not. The rest of the paper is organized as follows. Section 2 describes some definitions and presents preliminary results. Section 3 presents the necessary and sufficient conditions for a planar graph of ∆ ≤ 3 to have a rectangular drawing. Section 4 presents a linear-time algorithm to find a rectangular drawing of a planar graph G of ∆ ≤ 3 if it exists. Finally, Section 5 concludes with discussions.
2
Preliminaries
In this section we give some definitions and present preliminary results. Let G = (V, E) be a connected simple graph with vertex set V and edge set E. We denote by d(v) the degree of v. A graph G is called cubic if d(v) = 3 for every vertex v. For V ⊆ V, G − V denotes a graph obtained from G by deleting all vertices in V together with all edges incident to them. For a subgraph G of G, we denote by G − G the graph obtained from G by deleting all vertices in G . The connectivity κ(G) of a graph G is the minimum number of vertices whose removal results in a disconnected graph or a single-vertex graph K1 . We say that G is k-connected if κ(G) ≥ k. A separation pair of a 2-connected graph G is a pair of vertices whose deletion disconnects G. A 3-connected graph has no separation pair. Let P = w0 , w1 , w2 , ..., wk+1 , k ≥ 1, be a path of G such that d(w0 ) ≥ 3, d(w1 ) = d(w2 ) = · · · = d(wk ) = 2, and d(wk+1 ) ≥ 3. Then we call the subpath P = w1 , w2 , ..., wk of P a chain of G, and we call vertices w0 and wk+1 the supports of the chain P . If G is a subdivision of a 3-connected graph, then any vertex of degree 2 in G is contained in exactly one of the chains of G. Two chains on a cycle are consecutive if they have a common support. Chains P1 = a, b and P2 = l on the outer face of the plane graph in Figure 1(b) are consecutive, while P1 and P3 = i are not. Subdividing an edge (u, v) of a graph G is the operation of deleting the edge (u, v) and adding a path u(= w0 ), w1 , w2 , ..., wk , v(= wk+1 ) through new vertices w1 , w2 , ..., wk , k ≥ 1, of degree 2. A graph G is said to be a subdivision of a graph G if G is obtained from G by subdividing some of the edges of G . A graph G is called cyclically 4-edge-connected if the removal of any three or fewer edges leaves a graph such that exactly one of the connected components has a cycle [T92].
Rectangular Drawings of Planar Graphs
247
Let G be a planar biconnected graph, and let Γ be a plane embedding of G. The contour of a face is a cycle of G, and is simply called a face or a facial cycle. We denote by Fo (Γ ) the outer face of Γ . For a cycle C of Γ , we call the plane subgraph of Γ inside C (including C) the inner subgraph ΓI (C) for C, and call the plane subgraph of Γ outside C (including C) the outer subgraph ΓO (C) for C. An edge of G which is incident to exactly one vertex of a cycle C and located outside C is called a leg of C. The vertex of C to which a leg is incident is called a leg-vertex of C. A cycle C in Γ is called a k-legged cycle of Γ if C has exactly k legs in Γ and there is no edge which joins two vertices on C and is located outside C. The set of k legs of a k-legged cycle in Γ corresponds to a “cutset” of k edges for k = 2 or 3. We call a face F of Γ a peripheral face for a 3-legged cycle C in Γ if F is in ΓO (C) and the contour of F contains some edges on C. Clearly there are exactly three peripheral faces for any 3-legged cycle in Γ . A k-legged cycle C is called a minimal k-legged cycle if GI (C) does not contain any other k-legged cycle of G. We say that cycles C and C in Γ are independent if ΓI (C) and ΓI (C ) have no common vertex. A set S of cycles is independent if any pair of cycles in S are independent. A plane biconnected graph G may have a separation pair, and the pair of leg-vertices of any 2-legged cycle in G is a separation pair. A cycle C in a plane embedding Γ of G is called regular if the plane graph Γ − ΓI (C) has a cycle. Clearly a 2-legged cycle C in Γ is not regular if and only if Γ − ΓI (C) is a chain of G, while a 3-legged cycle C is not regular if and only if Γ − ΓI (C) contains exactly one vertex that has degree 3 in G. Let G be a subdivision of a planar 3-connected cubic graph, then Γ has no regular 2-legged cycle, but may have a regular 3-legged cycle, and Γ has no regular 3-legged cycle if and only if G is cyclically 4-edge-connected. Ungar [U53] showed that any plane embedding Γ of a cyclically 4-edgeconnected planar cubic graph G has a rectangular drawing if four vertices of degree 2 are inserted on some edges on the outer face Fo (Γ ). Generalizing the results of Ungar, Thomassen [T84] obtained a necessary and sufficient condition for a plane embedding of a planar graph G with ∆ ≤ 3 to have a rectangular drawing when four vertices of degree 2 on Fo (Γ ) are designated as corners for a rectangular drawing. Generalizing the result of Thomassen, Rahman et al. [RNN02] gave a necessary and sufficient condition for a plane embedding of a planar graph G with ∆ ≤ 3 to have a rectangular drawing when no vertex is designated as a corner, and developed a linear-time algorithm to find a rectangular drawing of G if it exits, as in the following Lemma 1. Lemma 1. [RNN02] A plane embedding Γ of a planar biconnected graph G of ∆ ≤ 3 has a rectangular drawing if and only if Γ satisfies the following four conditions: (a) there are four or more vertices of degree 2 on Fo (Γ ); (b) every 2-legged cycle in Γ contains at least two vertices of degree 2 on Fo (Γ ); (c) every 3-legged cycle in Γ contains at least one vertex of degree 2 on Fo (Γ ); and (d) if an independent set S of cycles in Γ consists of c2 2-legged cycles and c3 3-legged cycles, then 2c2 + c3 ≤4 .
248
Md. Saidur Rahman, Takao Nishizeki, and Shubhashis Ghosh
Furthermore one can examine in linear time whether Γ satisfies the condition above, and if Γ does then one can find a rectangular drawing of Γ in linear time. Although the results above for plane embeddings are known, it is difficult to examine whether a planar graph has a rectangular drawing or not, since a planar graph may have an exponential number of plane embeddings in general. The following fact is known for subdivisions of planar 3-connected cubic graphs. Fact 2 [NC88] Let G be a subdivision of a 3-connected planar graph. Then there is exactly one embedding of G for each face embedded as the outer face. Furthermore, for any two plane embeddings Γ and Γ of G, any facial cycle in Γ is a facial cycle in Γ .
3
Rectangular Drawings of Planar Graphs
In this section we give necessary and sufficient conditions for a planar graph of ∆ ≤ 3 to have a rectangular drawing. In Section 3.1 we consider the case where G is a subdivision of a planar 3-connected cubic graph, and in Section 3.2 the other case. 3.1
Case for a Subdivision of a Planar 3-Connected Cubic Graph
Let G be a subdivision of a planar 3-connected cubic graph. Then by Fact 2 G has an O(n) number of embeddings, one for each chosen outer face. Examining by the linear algorithm in Lemma 1 whether the four conditions hold for each of the O(n) embeddings, one can examine in time O(n2 ) whether G has a rectangular drawing. However, we obtain the following necessary and sufficient condition for G to have a rectangular drawing, which leads to a linear-time algorithm. Theorem 1. Let G be a subdivision of a planar 3-connected cubic graph, and let Γ be an arbitrary plane embedding of G. (a) Suppose first that G is cyclically 4-edge-connected, that is, Γ has no regular 3-legged cycle. Then the planar graph G has a rectangular drawing if and only if Γ has a face F such that (i) F contains at least four vertices of degree 2; (ii) there are at least two chains on F ; and (iii) if there are exactly two chains on F , then they are not consecutive and each of them contains at least two vertices. (b) Suppose next that G is not cyclically 4-edge connected, that is, Γ has a regular 3-legged cycle C. Let F1 , F2 and F3 be the three peripheral faces for C, and let Γ1 , Γ2 and Γ3 be the plane embeddings of G taking F1 , F2 and F3 , respectively, as the outer face. Then the planar graph G has a rectangular drawing if and only if at least one of the three embeddings Γ1 , Γ2 and Γ3 has a rectangular drawing.
Rectangular Drawings of Planar Graphs
249
Before giving a proof of Theorem 1, we observe the following lemma on subdivisions of planar 3-connected cubic graphs. Lemma 3. Let G be a subdivision of a planar 3-connected cubic graph G , and let Γ be an arbitrary plane embedding of G. Then the following (a) – (c) hold. (a) If C is a 2-legged cycle in Γ , then the legs e1 and e2 and the leg-vertices v1 and v2 of C are on the outer face Fo (Γ ), and the set of all vertices not in ΓI (C) induces a chain of G on Fo (Γ ) with supports v1 and v2 . (b) For any chain P on Fo (Γ ), the outer face of the plane graph Γ − P is a 2-legged cycle in Γ . (c) Any pair of 2-legged cycles in Γ are not independent. We are now ready to give a proof of Theorem 1. Proof of Theorem 1(a): Necessity: Assume that G is cyclically 4-edge-connected and has a rectangular drawing. Then a plane embedding Γ of G has a rectangular drawing. The four corner vertices of a rectangular drawing of Fo (Γ ) have degree 2, and hence Fo (Γ ) has at least four vertices of degree 2. If all the four corner vertices are contained in the same chain on Fo (Γ ), then G would not have a rectangular drawing. Therefore, there are two or more chains on Fo (Γ ). Suppose that there are exactly two chains on Fo (Γ ). Then clearly each of them contains exactly two of the four corner vertices of degree 2; otherwise, Γ would not have a rectangular drawing. Furthermore, the two chains must be non-consecutive; otherwise, Γ would have a 3-legged cycle C containing no vertex of degree 2 on Fo (Γ ), contrary to Lemma 1(c). Thus the outer face Fo (Γ ) satisfies Conditions (i) – (iii) of Theorem 1(a). By Fact 2, the outer face Fo (Γ ) corresponds to a face F of the arbitrary plane embedding Γ of G. Therefore, the face F in Γ satisfies Conditions (i), (ii) and (iii) of Theorem 1. Sufficiency: We give a constructive proof for the sufficiency of Theorem 1(a). Assume that Γ has a face F satisfying Conditions (i) – (iii) of Theorem 1(a). Let Γ be an embedding of G such that F = Fo (Γ ). It is sufficient to prove that Γ satisfies Conditions (a) – (d) in Lemma 1. (a) By Condition (i) in Theorem 1(a) Fo (Γ ) = F contains at least four vertices of degree 2, and hence Γ satisfies Condition (a) in Lemma 1. (b) We now show that Γ satisfies Condititon (b) in Lemma 1, that is, every 2-legged cycle C in Γ contains at least two vertices of degree 2 on Fo (Γ ). By Condition (ii) in Theorem 1(a) there are at least two chains on Fo (Γ ), and hence we have the following two cases to consider. Case 1: there are exactly two chains P1 and P2 on Fo (Γ ). By Lemmas 3(a) – (c) Γ has exactly two 2-legged cycles C1 and C2 . Clearly each of the 2-legged cycles C1 and C2 contains exactly one chain. By Condition (iii) of Theorem 1(a) each of the two chains P1 and P2 contains at least two vertices of degree 2. Therefore, each 2-legged cycle contains at least two vertices of degree 2 on Fo (Γ ). Thus Γ satisfies Condition (b) of Lemma 1.
250
Md. Saidur Rahman, Takao Nishizeki, and Shubhashis Ghosh
Case 2: there are more than two chains on Fo (Γ ). Assume that there are exactly r chains on Fo (Γ ) and r ≥ 3. Then each 2-legged cycle contains r − 1 (≥ 2) chains on Fo (Γ ), and hence contains at least two vertices of degree 2 on Fo (Γ ). Thus Γ satisfies Condition (b) of Lemma 1. (c) We next show that Γ satisfies Condition (c) in Lemma 1, that is, every 3-legged cycle C in Γ contains at least one vertex of degree 2 on Fo (Γ ). Since G is cyclically 4-edge connected, C is not regular and hence Γ − ΓI (C) has no cycle. Therefore, C contains edges on Fo (Γ ), two of the three leg-vertices of C, say u and v, are on Fo (Γ ), and Γ − ΓI (C) contains exactly one vertex w that has degree three in G. Clearly w is on Fo (Γ ). The three vertices u, w and v divide Fo (Γ ) to three paths P1 , P2 and P3 ; P1 goes from u to w on Fo (Γ ), P2 from w to v, and P3 from v to u. By Condition (ii) in Theorem 1(a) there are at least two chains on F = Fo (Γ ). We now have the following two cases. Case 1: at most one of P1 and P2 contains a chain. In this case there are at least one chain on P3 since there are at least two chains on Fo (Γ ). Therefore, C contains at least one vertex of degree 2 on Fo (Γ ). Thus Γ satisfies Condition (c) in Lemma 1. Case 2: each of P1 and P2 contains a chain. In this case the two chains on P1 and P2 are consecutive. Therefore by Condition (iii) in Theorem 1(a) Fo (Γ ) contains three or more chains, and hence there is at least one chain on P3 . Thus C contains at least one vertex of degree 2 on Fo (Γ ), and hence Γ satisfies Condition (c) in Lemma 1. (d) We finally show that Γ satisfies Condition (d) in Lemma 1. Let S be any independent set of cycles in Γ . Then c2 ≤ 1 by Lemma 3(c). We now claim that c3 ≤ 1. Otherwise, there are two different 3-legged cycles C and C in S. By (c) above each of C and C contains at least one vertex of Fo (Γ ). Since G is cyclically 4-edge connected, C and C are not regular and hence each of the plane graphs Γ − ΓI (C) and Γ − ΓI (C ) contains exactly one vertex that has degree 3 in G. Then clearly ΓI (C) and ΓI (C ) have common vertices, contrary to the assumption that S is an independent set of cycles. Since c2 ≤ 1 and c3 ≤ 1, we have 2c2 + c3 ≤ 3. Thus Γ satisfies Condition (d) of Lemma 1. Q.E.D. Proof of Theorem 1(b): Since the proof for the sufficiency is obvious, we give a proof for the necessity. Suppose that Γ has a regular 3-legged cycle C and that the planar graph G has a rectangular drawing. Then there is a plane embedding Γ of G which has a rectangular drawing. Let F be the face of Γ corresponding to Fo (Γ ). It suffices to show that F is one of the three peripheral faces F1 , F2 and F3 for C in Γ . We first consider the case where C contains an edge on Fo (Γ ). Let C be the cycle in Γ − ΓI (C) such that ΓI (C ) has the maximum number of edges. One can observe that C is a 3-legged cycle in Γ , and any face of Γ other than F1 , F2 and F3 is in ΓI (C) or ΓI (C ). Therefore it is sufficient to prove that F is neither in ΓI (C) nor in ΓI (C ). If F is in ΓI (C), then a 3-legged cycle C in Γ contains no vertex on Fo (Γ ) = F , a contradiction to Lemma 1(c). Similarly, if
Rectangular Drawings of Planar Graphs
251
F is in ΓI (C ), then a 3-legged cycle C in Γ contains no vertex on Fo (Γ ) = F , a contradiction to Lemma 1(c). We next consider the case where C does not contain any edge on Fo (Γ ). Let C be the cycle in Γ − ΓI (C) such that ΓI (C ) includes ΓI (C) and has the minimum number of edges. Any face of Γ other than F1 , F2 and F3 is in ΓI (C) or ΓO (C ). Therefore it is sufficient to prove that F is neither in ΓI (C) nor in ΓO (C ). If F is in ΓI (C), then a 3-legged cycle C in Γ contains no vertex on Fo (Γ ) = F , a contradiction to Lemma 1(c). If F is in ΓO (C ), then a 3-legged cycle C in Γ contains no vertex on Fo (Γ ) = F , a contradiction to Lemma 1(c). Q.E.D. Theorem 1 immediately yields the following algorithm to examine whether a subdivision G of a planar 3-connected cubic graph has a rectangular drawing and to find a rectangular drawing of G if it exists.
1 2 3 4 5 6 7 8 9
10 11 12
Algorithm Subdivision-Draw(G) begin Let Γ be any plane emebedding of G; Examine whether Γ has a regular 3-legged cycle C; if Γ has no regular 3-legged cycle then begin{ G is cyclically 4-edge-connected.} Find a face F in Γ which satisfies Conditions (i)–(iii) in Theorem 1(a); if Γ has such a face F then begin Let Γ be the plane embedding of G whose outer face is F ; Find a rectangular drawing of Γ by the algorithm in [RNN02] end else G has no rectangular drawing; end else { Γ has a regular 3-legged cycle, and G is not cyclically 4-edge-connected.} begin let C be a regular 3-legged cycle; Let F1 , F2 and F3 be the three peripheral faces of C; Let Γ1 , Γ2 and Γ3 be three plane embeddings of G taking F1 , F2 , and F3 as the outer face, respectively; Examine whether Γ1 , Γ2 and Γ3 have rectangular drawings by the algorithm in [RNN02]; if Γ1 , Γ2 or Γ3 , say Γ1 , has a rectangular drawing then Find a rectangular drawing of Γ1 by the algorithm in [RNN02] else G has no rectangular drawing; end end.
252
Md. Saidur Rahman, Takao Nishizeki, and Shubhashis Ghosh
Theorem 2. Algorithm Subdivision-Draw examines in linear time whether a subdivision G of a planar 3-connected cubic graph has a rectangular drawing, and finds a rectangular drawing of G in linear time if it exists.
3.2
The Other Case
In this section we assume that G is a planar biconnected graph of ∆ ≤ 3 but is not a subdivision of a 3-connected cubic graph, and give a linear-time algorithm to examine whether G has a rectangular drawing and to find a rectangular drawing of G if it exists. Let Γ be an arbitrary plane embedding of G. It is trivial to examine whether G has a rectangular drawing if Γ has at most two inner faces. We may thus assume that Γ has three or more inner faces. Since G is not a subdivision of a planar 3-connected cubic graph, Γ has a regular 2-legged cycle. Let C1 , C2 , · · · , Cl be the regular 2-legged cycles in Γ , and let xi , yi , 1 ≤ i ≤ l, be the two leg-vertices of Ci . One can easily observe that l = O(n) if G has n vertices [HT73]. If the planar graph G has a rectangular drawing, then a plane embedding Γ of G has a rectangular drawing. The outer face Fo (Γ ) must contain all vertices x1 , y1 , x2 , y2 , · · · , xl , yl ; otherwise, Γ would not have a rectangular drawing as known from Lemma 1(b). Construct a graph G+ from G by adding a dummy vertex z and dummy edges (xi , z) and (yi , z) for all indices i, 1 ≤ i ≤ l. If G+ is not planar, then G has no rectangular drawing. We thus assume that G+ is planar and has an embedding Γ + such that z is embedded on the outer face. We delete from Γ + the dummy vertex z and all dummy edges incident to z, and let Γ ∗ be the resulting plane embedding of G, in which Fo (Γ ∗ ) contains all vertices x1 , y1 , x2 , y2 , · · · , xl , yl . If Γ ∗ has three or more independent 2-legged cycles, then any plane embedding Γ of G whose outer face contains all vertices x1 , y1 , x2 , y2 , · · · , xl , yl has three or more independent 2-legged cycles, and hence by Lemma 1(d) Γ has no rectangular drawing, and consequently the planar graph G has no rectangular drawing. We may thus assume that Γ ∗ has two or less independent 2-legged cycle. Since Γ has a regular 2-legged cycle, Γ ∗ has two or more independent 2legged cycles. Thus Γ ∗ has exactly two independent 2-legged cycles C1 and C2 . We may assume without loss of generality that C1 and C2 are minimal 2-legged cycles, as illustrated in Figure 2(a). If we flip ΓI∗ (C) for any 2-legged cycle C other than C1 and C2 , then the outer face of the resulting embedding does not contain the leg-vertices of C1 or C2 . By flipping ΓI∗ (C1 ) or ΓI∗ (C2 ) around the leg-vertices of C1 or C2 , we have four different embeddings Γ1 (= Γ ∗ ), Γ2 , Γ3 and Γ4 such that each Fo (Γi ), 1 ≤ i ≤ 4, contains all vertices x1 , y1 , x2 , y2 , · · · , xl , yl . Γ1 and Γ2 are illustrated in Figure 2. Clearly, only these four embeddings Γ1 , Γ2 , Γ3 and Γ4 have all vertices x1 , y1 , x2 , y2 , · · · , xl , yl on the outer face. Thus G has a rectangular drawing if and only if any of Γ1 , Γ2 , Γ3 and Γ4 has a rectangular drawing. We thus have the following theorem.
Rectangular Drawings of Planar Graphs x2
x1
x2
x1
C1
C1
C2
C2
y1
Γ1
y2
y1
253
Γ2
y2
Fig. 2. (a) Γ1 = Γ ∗ , and (b) Γ2 is obtained by flipping ΓI∗ (C1 ) only.
Theorem 3. Let G be a planar biconnected graph of ∆ ≤ 3 which is not a subdivision of a planar 3-connected cubic graph. Let Γ be a planar embedding of G such that every 2-legged cycle in Γ has leg-vertices on Fo (Γ ), and let C1 and C2 be the two minimal 2-legged cycles in Γ . Let Γ1 (= Γ ), Γ2 , Γ3 , and Γ4 be the four embeddings of G obtained from Γ by flipping ΓI (C1 ) or ΓI (C2 ) around the leg-vertices of C1 and C2 . Then G has a rectangular drawing if and only if at least one of the four embeddings Γ1 , Γ2 , Γ3 , and Γ4 has a rectangular drawing.
4
Algorithm
In this section we formally describe our algorithm Planar-Rectangular-Draw to examine whether a planar graph G of ∆ ≤ 3 has a rectangular drawing and to find a rectangular drawing of G if it exists.
1 2 3 4 5 6 7 8 9
10 11
Algorithm Planar-Rectangular-Draw(G) begin Let Γ be any plane emebedding of G; Examine whether Γ has a regular 2-legged cycle; if Γ has no regular 2-legged cycle then { G is a subdivision of a planar 3-connected cubic graph.} Examine by Algorithm Subdivision-Draw whether G has a rectangular drawing and find a rectangular drawing of G if it exists; else {G is not a subdivision of a planar 3-connected cubic graph.} begin let x1 , y1 , x2 , y2 , · · · , xl , yl be the leg-vertices of regular 2-legged cycles C1 , C2 , · · · , Cl in Γ ; Construct a graph G+ from G by adding a dummy vertex z and dummy edges (xi , z) and (yi , z) for all indices i, 1 ≤ i ≤ l; Examine whether G+ is planar; if G+ is not planar then G has no rectangular drawing else begin Find a planar embedding Γ + of G+ such that z is embedded on the outer face; Delete from Γ + the dummy vertex z and all dummy edges incident to z,
254
Md. Saidur Rahman, Takao Nishizeki, and Shubhashis Ghosh
12 13
14 15 16 17
end.
and let Γ ∗ be the resulting plane graph; Let C1 and C2 be the two minimal regular 2-legged cycles in Γ ∗ ; Let Γ1 , Γ2 Γ3 and Γ4 be the four plane embeddings of G obtained from Γ ∗ by flipping ΓI∗ (C1 ) or ΓI∗ (C2 ) around the leg-vertices of C1 or C2 ; Examine whether Γ1 , Γ2 Γ3 and Γ4 have rectangular drawings by the algorithm in [RNN02]; if Γ1 , Γ2 , Γ3 or Γ4 , say Γ1 , has a rectangular drawing then Find a rectangular drawing of Γ1 by the algorithm in [RNN02] else G has no rectangular drawing; end
We now have the following theorem on Algorithm Planar-RectangularDraw. Theorem 4. Let G be a planar biconnected graph of ∆ ≤ 3. Then Algorithm Planar-Rectangular-Draw examines in linear time whether G has a rectangular drawing and finds a rectangular drawing of G if it exists.
5
Conclusions
In this paper we give a linear-time algorithm to examine whether a planar graph G of ∆ ≤ 3 has a rectangular drawing and to find a rectangular drawing of G if it exists. A box-rectangular drawing of a plane graph G is a drawing of G such that each vertex is drawn as a (possibly degenerated) rectangle, called a box, each edge is drawn as a horizontal or a vertical line segment and the contour of each face is drawn as a rectangle. Linear-time algorithms are known to determine whether a plane graph has a box-rectangular drawing and find a box-rectangular drawing if it exists [RNN00, H01]. A planar graph is said to have a box-rectangular drawing if one of its plane embeddings has a box-rectangular drawing. A straightforward algorithm checking each of all embeddings by a linear algorithm in [RNN00, H01] does not run in polynomial time. Extending the algorithm in this paper, one can obtain a linear algorithm to examine whether a planar graph has a box-rectangular drawing and find a box-rectangular drawing if it exists.
References BS88.
J. Bhasker and S. Sahni, A linear algorithm to find a rectangular dual of a planar triangulated graph, Algorithmica, 3, pp. 247-278, 1988. DETT99. G. Di Battista, P. Eades, R. Tamassia and I. G. Tollis. Graph Drawing, Prentice Hall, Upper Saddle River, NJ, 1999.
Rectangular Drawings of Planar Graphs H93. H01. HT73. KH97. KK84. L90. MKI00. NC88. RNN98. RNN99. RNN00. RNN02. TTSS91. T84. T92. U53.
255
X. He, On finding the rectangular duals of planar triangulated graphs, SIAM J. Comput., 22(6), pp. 1218-1226, 1993. X. He, A simple linear time algorithm for proper box rectangular drawings of plane graphs, Journal of Algorithms, 40(1), pp. 82-101, 2001. J. E. Hopcroft and R. E. Tarjan, Dividing a graph into triconnected components, SIAM J. Comput., 2(3), pp. 135-158, 1973. G. Kant and X. He, Regular edge labeling of 4-connected plane graphs and its applications in graph drawing problems, Theoretical Computer Science, 172, pp. 175-193, 1997. K. Kozminski and E. Kinnen, An algorithm for finding a rectangular dual of a planar graph for use in area planning for VLSI integrated circuits, Proc. 21st DAC, Albuquerque, pp. 655-656, 1984. T. Lengauer, Combinatirial Algorithms for Integrated Circuit Layout, John Wiley & Sons, Chichester, 1990. S. Munemoto, N. Katoh and G. Imamura, Finding an optimal floor layout based on an orthogonal graph drawing algorithm, J. Archit. Plann. Enviroment Eng. AIJ, No. 524, pp. 279-286, 2000. T. Nishizeki and N. Chiba, Planar Graphs: Theory and Algorithms, NorthHolland, Amsterdam, 1988. M. S. Rahman, S. Nakano and T. Nishizeki, Rectangular grid drawings of plane graphs, Comp. Geom. Theo. Appl., 10(3), pp. 203-220, 1998. M. S. Rahman, S. Nakano and T. Nishizeki, A linear algorithm for bendoptimal orthogonal drawings of triconnected cubic plane graphs, Journal of Graph Alg. Appl., 3, No.4, pp. 31-62, 1999. M. S. Rahman, S. Nakano and T. Nishizeki, Box-rectangular drawings of plane graphs, Journal of Algorithms, 37(2), pp. 363-398, 2000. M. S. Rahman, S. Nakano and T. Nishizeki, Rectangular drawings of plane graphs without designated corners, Comp. Geom. Theo. Appl., 21(3), pp. 121-138, 2002. K. Tani, S. Tsukiyama, S. Shinoda and I. Shirakawa, On area-efficient drawings of rectangular duals for VLSI floor-plan, Mathematical Programming, 52, pp. 29-43, 1991. C. Thomassen, Plane representations of graphs, (Eds.) J. A. Bondy and U. S. R. Murty, Progress in Graph Theory, Academic Press Canada, pp. 43-69, 1984. C. Thomassen, Plane cubic graphs with prescribed face areas, Combinatorics, Probability and Computing, 1, pp. 371-381, 1992. P. Ungar, On diagrams representing maps, J. London Math. Soc., 28, pp. 336-342, 1953.
Extended Rectangular Drawings of Plane Graphs with Designated Corners (Extended Abstract) Kazuyuki Miura, Ayako Miyazawa, and Takao Nishizeki Graduate School of Information Sciences Tohoku University, Sendai 980-8579, Japan {miura,miyazawa}@nishizeki.ecei.tohoku.ac.jp [email protected]
Abstract. In a rectangular drawing of a plane graph, each edge is drawn as a horizontal or vertical line segment, and all faces including the outer face are drawn as rectangles. In this paper, we introduce an “extended rectangular drawing” in which all inner faces are drawn as rectangles but the outer face is drawn as a rectilinear polygon with designated corners, and give a necessary and sufficient condition for a plane graph to have an extended rectangular drawing.
1
Introduction
Automatic drawing of graphs has recently created intense interest due to their broad applications in VLSI floorplanning, computer network, software design etc. [BETT99,BS88,GT97,L90,RNN02,RNN98]. In this paper, we introduce an “extended rectangular drawing” of a plane graph, which is a generalization of a “rectangluar drawing,” and obtain a characterization of plane graphs having extended rectangular drawings. In a rectangular drawing of a plane graph G, each edge is drawn as a horizontal or vertical line segment, and all faces including the outer face are drawn as rectangles, as illustrated in Fig. 1(a). Rectangular drawings have applications in VLSI floorplanning. The outer boundary of a VLSI chip is not always a rectangle but is often a rectilinear polygon of L-, T-, and X-shape, and hence it is desired to find a floorplan of a VLSI chip where each “module” is assigned a rectangular space inside a rectilinear polygon [KK84,L90]. VLSI floorplans with outer boundary of L-, T-, and X-shape are illustrated in Fig. 1. Each vertex which we wish to draw as a “convex corner” of the outer face is drawn by a white circle in Fig. 1, each vertex which we wish to draw as a “concave corner” is drawn by a white circle with ×, each of the other vertices on the outer face is drawn by a black circle, and all vertices not on the outer face are drawn by gray circles. We call a drawing an extended rectangular drawing (with designated corners) if all inner faces are drawn as rectangles and the outer face is drawn as such a rectilinear polygon with designated corners. The maximum degree of a graph G is denoted by ∆. Thomassen obtained a necessary and sufficient condition for M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 256–267, 2002. c Springer-Verlag Berlin Heidelberg 2002
Extended Rectangular Drawings of Plane Graphs with Designated Corners
(a) Rectangular outer face
(c) T-type outer face
257
(b) L-type outer face
(d) X-type outer face R (convex corner) S (non-corner) L (concave corner) inner vertex
Fig. 1. Extended rectangular drawings.
the existence of a rectangular drawing of a plane graph G with ∆ ≤ 3 [T84], and linear-time algorithms were obtained for finding a rectangular drawing of G [BS88,H93,KH97,KK84,RNN98,RNN02]. However, for a general plane graph G which does not necessarily satisfy ∆ ≤ 3, a necessary and sufficient condition has not been known for the existence of a rectangular drawing or an extended rectangular drawing. Of course, ∆ ≤ 4 if G has a rectangular drawing or an extended rectangular drawing. As a main theorem of the paper, we give a necessary and sufficient condition for a plane graph to have an extended rectangular drawing. It immediately yields a necessary and sufficient condition for a plane graph of ∆ ≤ 4 to have an ordinary rectangular drawing. Thomassen’s condition [T84] can be immediately obtained from our main theorem as a corollary. The necessity of our condition is trivial, while the sufficiency is not. Our constructive proof of the sufficiency is outlined as follows. Let G be a plane graph satisfying our condition. We choose an appropriate inner face F of G called a “corner face,” and draw F as a rectangle as illustrated in Figs. 2(a) and (b). Let G∗ = G − F be a graph obtained from G by “trimming off” the face F , then G∗ satisfies our condition. We now choose a corner face of G∗ , and draw the face as a rectangle. Repeating the operation, we eventually obtain an extended rectangular drawing of the whole graph G.
258
Kazuyuki Miura, Ayako Miyazawa, and Takao Nishizeki
-
G*= G F
G
fc F
F (a)
(b)
F F
(c)
(d)
. . .
G
F (f)
(e)
R
S
L
Fig. 2. The outline for a proof of the sufficiency of our main Theorem.
The remainder of the paper is organized as follows. In Section 2, we give some definitions and lemmas. In Section 3, we give a necessary and sufficient condition for a plane graph to have an extended rectangular drawing. Finally we conclude in Section 4.
2
Preliminaries
In this section we give some definitions and lemmas. Let G be a simple connected undirected graph having no multiple edge or loop. The degree of a vertex v in G is the number of neighbors of v in G, and is denoted by d(v). We call a vertex of G a cut vertex if its removal results in a disconnected graph. A graph G is biconnected if G has no cut vertex. A plane graph G is a graph embedded in the plane so that no two edges intersect geometrically except at a vertex to which they are both incident. In this paper, we assume that a plane embedding of G is fixed. If a plane graph G has a rectangular drawing or an extended rectangular drawing, then clearly G is biconnected and ∆ ≤ 4. We thus assume that G is a plane biconnected graph with ∆ ≤ 4. G divides the plane into connected regions called faces. The contour of a face is a cycle of G, and is often called simply a face. We denote the outer face of G by Fo . A vertex and an edge of Fo is called an outer vertex and an outer edge, respectively. A vertex and an edge not on Fo is called an inner vertex and an inner edge, respectively.
Extended Rectangular Drawings of Plane Graphs with Designated Corners
259
A drawing D(G) of G is called an extended rectangular drawing of a plane graph G if (a) each vertex of G is drawn as a point in D(G); (b) each edge of G is drawn as a horizontal or vertical line segment in D(G); (c) each inner face of G is drawn as a rectangle in D(G); and (d) the outer face of G is drawn as a rectilinear polygon in D(G). In an extended rectangular drawing D(G), each cycle C of G is drawn as a rectilinear polygon, which is denoted by D(C). A vertex of polygon D(C) is a vertex of graph G, and is called a corner of a cycle C. The inner angle of a corner is either π/2 or 3π/2. A corner of inner angle π/2 is called a convex corner of a cycle C, while a corner of inner angle 3π/2 is called a concave corner of C. A vertex v of C is called a non-corner of C if v is not a vertex of polygon D(C). In this paper, we assume that a rectilinear polygonal drawing D(Fo ) of the outer face Fo is roughly given: each outer vertex is designated as a convex corner, a concave corner, or a non-corner of Fo . A vertex designated as a convex corner of Fo is called an R-vertex of Fo , a vertex designated as a concave corner is called an L-vertex of Fo , and a vertex designated as a non-corner is called an S-vertex of Fo . (See Fig. 3(a).) If we turn around Fo clockwise, then we turn right at an R-vertex, turn left at an L-vertex, and go straight through an S-vertex. An extended rectangular drawing D(G) is called an extended rectangular drawing with designated corners if all R-vertices of Fo are drawn as convex corners of Fo , all L-vertices as concave corners, and all S-vertices as non-corners, as illustrated in Fig. 3(b). In this paper, we give a necessary and sufficient condition for a plane graph G to have an extended rectangular drawing with designated corners. Thomassen gave a necessary and sufficient condition for a plane graph of ∆ ≤ 3 to have a rectangular drawing [T84]. His condition corresponds to our condition for the special case where exactly four of the outer vertices are designated as R-vertices and all the other outer vertices are designated as S-vertices as illustrated in Fig. 1(a). Therefore his condition can be immediately derived from our condition. The drawings in Figs. 1(a) and (b) are an rectangular drawing and an extended rectangular drawing of the same graph. Thus the same graph may have various extended rectangular drawings. On the other hand, the plane graph in Fig. 3(a) has an extended rectangular drawing in Fig. 3(b), but has no rectangular drawing because there is an outer vertex of degree four. An extended rectangular drawing D(G) satisfies the following four Conditions (i)–(iii) for any outer vertex v of Fo : (i) if d(v) = 2, then v is a convex corner or a non-corner of Fo ; (ii) if d(v) = 3, then v is a concave corner or a non-corner of Fo ; and (iii) if d(v) = 4, then v is a concave corner of Fo . We may thus assume without loss of generality that each outer vertex v of G is designated as follows:
260
Kazuyuki Miura, Ayako Miyazawa, and Takao Nishizeki
R
S L
(a) A plane graph with designated outer corners
(b) An extended rectangular drawing
Fig. 3. An extended rectangular drawing.
(O-1) if d(v) = 2, then v is either an R-vertex or an S-vertex of Fo ; (O-2) if d(v) = 3, then v is either an L-vertex or an S-vertex of Fo ; and (O-3) if d(v) = 4, then v is an L-vertex of Fo . According to the designation of outer vertices, a labeling λ of graph G is defined as follows. [Definition 1] A labeling λ of G assigns R, S, L, R or L as a label λ(C, v) to each pair of a cycle C of G and a vertex v of C, as follows. Case 1: both of the two edges e1 and e2 of C incident to v are outer edges. (See Fig. 4.) Let λ(C, v) be the same as the designation of v for Fo : R if v is designated as an R-vertex of Fo ; λ(C, v) = S if v is designated as an S-vertex of Fo ; L if v is designated as an L-vertex of Fo . In Fig. 4 a label λ(C, v) is written in cycle C; v is designated as an R-vertex of Fo in Fig. 4(a), as an S-vertex in Fig. 4(b), and as an L-vertex in Fig. 4(c). Case 2: both e1 and e2 are inner edges, and d(v) = 2. (See Fig. 5.) In this case, v is an inner vertex. Let λ(C, v) = S. (That is, e1 and e2 must be drawn on the same straight line.) Case 3: both e1 and e2 are inner edges, and d(v) = 3. (See Fig. 6.) In this case, v is an inner vertex. Let e3 be the edge incident to v other than e1 and e2 , then λ(C, v) is defined as follows: R if e3 is outside C; λ(C, v) = L if e3 is inside C. Label R means that v must be either a convex corner or a non-corner of C as illustrated in Figs. 6(a) and (b). Label L means that v must be either a concave corner or a non-corner of C as illustrated in Figs. 6(c) and (d).
Extended Rectangular Drawings of Plane Graphs with Designated Corners
261
e2 e1
e1 v
v
R e2
(a) A convex corner v of C and Fo
e1
S
C
Fo
v
e2
C
L
e3
C
Fo
Fo (b) A non-corner v of C and Fo
(c) A concave corner v of C and Fo
Fig. 4. Illustration for Case 1.
e1 v
e2 S
C
Fo
Fig. 5. Illustration for Case 2.
Case 4: exactly one of e1 and e2 is an outer edge, and d(v) = 3. (See Fig. 7.) In this case, v is an outer vertex, and the edge e3 incident to v other than e1 and e2 is an outer edge. By Condition (O-2), v is either an S-vertex or an L-vertex of Fo . Label λ(C, v) is defined as follows: R if v is an S-vertex of Fo ; λ(C, v) = R if v is an L-vertex of Fo . Case 5: d(v) = 4. (See Fig. 8.) Let e3 and e4 be the edges incident to v other than e1 and e2 , then λ(C, v) is defined as follows: R if both e3 and e4 are outside C; λ(C, v) = S if exactly one of e3 and e4 is outside C; L if both e3 and e4 are inside C. Clearly the following lemma holds.
✷
Lemma 1. If G has an extended rectangular drawing with designated corners, then the following (a)–(e) holds for any cycle C of G and any vertex v of C:
262
Kazuyuki Miura, Ayako Miyazawa, and Takao Nishizeki
e1 v e3 R' e2
v
v
e3
L' e3
C
C
Fo (a)A convex corner v of C
v e 2
e1
e1 L' e3
e1 R' e2
C
e2
C Fo (c) A concave corner v of C
Fo (b) A non-corner v of C
Fo (d) A non-corner v of C
Fig. 6. Illustration for Case 3. e3 e1
e1 v e3 R e 2
R'
e3 v
v
e1
e2
C
C
Fo (a) A convex corner v of C
Fo (b) A convex corner v of C
R' e2
C
Fo (c) A non-corner v of C
Fig. 7. Illustration for Case 4.
(a) (b) (c) (d) (e)
if λ(C, v) = R, then v is a convex corner of C. if λ(C, v) = S, then v is a non-corner of C. if λ(C, v) = L, then v is a concave corner of C. if λ(C, v) = R , then v is either a convex corner or a non-corner of C. if λ(C, v) = L , then v is either a concave corner or a non-corner of C.
According to λ(C, v) = R, S, L, R and L , we call v an R-, S-, L-, R - and L -vertex of cycle C, respectively. Let nR (C) be the number of R-vertices of cycle C. Define nL (C), nR (C) and nL (C) similarly. One can easily know from Definition 1 that the following lemma hold.
Lemma 2. (a) nR (Fo ) = nL (Fo ) = 0 for the outer face Fo of G. (b) nL (F ) = nL (F ) = 0 for any inner face F of G. (c) If v is an inner vertex and λ(C, v) = R or L for a cycle C, then d(v) = 4.
3
Extended Rectangular Drawing
In this section, we prove the following main theorem. Theorem 1. A plane biconnected graph G has an extended rectangular drawing with designated corners if and only if each cycle C of G satisfies nR (C) − (nL (C) + nL (C)) ≤ 4
(1)
Extended Rectangular Drawings of Plane Graphs with Designated Corners
e4 v e1 e3 R e2
e4
e1
S
C
e2 e1 v e3 L e4
v e2
e3
C
C
Fo (a) A convex corner v of C
Fo (b) A non-corner v of C
263
Fo (c) A concave corner v of C
Fig. 8. Illustration for Case 5.
and
(nR (C) + nR (C)) − nL (C) ≥ 4.
(2)
One can derive Thomassen’s condition as a corollary of Theorem 1. Although Corollary 1 below is slightly different from the presentation of Thomassen’s condition [T84, Theorem 7.1], they are effectively equivalent with each other. Corollary 1. Let G be a plane biconnected graph of ∆ ≤ 3. Assume that exactly four of the outer vertices of degree two are designated as R-vertices of Fo , and all the other outer vertices are designated as S-vertices of Fo , as illustrated in Fig. 1(a). Then G has an extended rectangular drawing with designated corners, that is, a rectangular drawing if and only if each cycle C of G satisfies nR (C) + nR (C) ≥ 4. Proof. Omitted in this extended abstract due to the page limitation.
(3) ✷
Before giving a proof of Theorem 1, we present some definitions and lemmas. A labeling ψC of a cycle C assigns a label R, S, or L to each vertex v of C. We say that ψC is consistent with the labeling λ of G if R if λ(C, v) = R; if λ(C, v) = S; S if λ(C, v) = L; ψC (v) = L R or S if λ(C, v) = R ; L or S if λ(C, v) = L . We call a labeling of C consistent with λ simply a consistent labeling of C. We denote by nR (ψC ) the number of vertices v of C such that ψC (v) = R, and denote by nL (ψC ) the number of vertices v of C such that ψC (v) = L. If ψC is a consistent labeling of C, then and
nR (C) ≤ nR (ψC ) ≤ nR (C) + nR (C)
(4)
nL (C) ≤ nL (ψC ) ≤ nL (C) + nL (C).
(5)
We then immediately have the following lemma.
264
Kazuyuki Miura, Ayako Miyazawa, and Takao Nishizeki
Lemma 3. If a plane graph G has an extended rectangular drawing D(G) with designated corners, then each cycle C of G has a consistent labeling ψC such that nR (ψC ) − nL (ψC ) = 4. (6) We are now ready to give a proof of the necessity of Theorem 1, which is rather trivial. Proof of the necessity of Theorem 1 Assume that G has an extended rectangular drawing D(G) with designated corners. By Lemma 3, each cycle C of G has a consistent labeling ψC such that nR (ψC ) − nL (ψC ) = 4. Since ψC is a consistent labeling, by Eqs. (4) and (5) we have that nR (C) ≤ nR (ψC ) and nL (ψC ) ≤ nL (C) + nL (C). We thus have nR (C) − (nL (C) + nL (C)) ≤ nR (ψC ) − nL (ψC ) = 4, and hence C satisfies Eq. (1). Similarly one can show that C satisfies Eq. (2). ✷ In the remainder of this section, we give a proof for the sufficiency of Theorem 1. The proof of the sufficiency is outlined as follows. First, we choose an appropriate inner face F called a “corner face,” as illustrated in Fig. 2(a). Next, we draw F as a rectangle, and let G∗ = G − F be a graph obtained from G by “trimming off” the face F from G as illustrated in Fig. 2(b). As shown in Lemma 5 later, every cycle of G∗ satisfies Eqs. (1) and (2). Repeating this operation, we can eventually obtain an extended rectangular drawing of G with designated corners. Before giving a proof of the sufficiency, we present some definitions and lemmas. Let F be an inner face of G containing an outer edge. Delete from G all the outer edges on F , and then delete all resulting isolated vertices. The resulting graph is denoted by G∗ = G − F . We call an inner face F of G a corner face if F satisfies the following four Conditions (a)–(d): (a) at least one vertex of F is designated as an R-vertex of Fo . (Hence, the vertex is an outer vertex, and has degree two.) (b) 2 ≤ nR (F ) ≤ 4. (Hence, F has two, three, or four R-vertices.) (c) at least two of the R-vertices of F are outer vertices. (Two of the R-vertices of F are outer vertices in Fig. 9(a), three are outer vertices in Fig. 9(b), and four are outer vertices in Fig. 9(c).) (d) G∗ = G − F is biconnected. We have the following lemma. Lemma 4. If each cycle C of a plane biconnected graph G satisfies Eqs. (1) and (2), then G has a corner face. Proof. Omitted in this extended abstract due to the page limitation.
✷
Extended Rectangular Drawings of Plane Graphs with Designated Corners
265
G* G*
R
G*
F
R
R F
R R Puv u' v u (a) Two outer R-vertices of F
F
R R Puv u v u' (b) Three outer R-vertices of F
R R u v=u' Puv (c) Four outer R-vertices of F
Fig. 9. Illustration for a corner face F .
If G has an extended rectangular drawing with designated corners, then by Lemma 3 each cycle C has a consistent labeling ψC such that nR (ψC )−nL (ψC ) = 4. We say that such a labeling ψC is rectangular if nR (ψC ) = 4 and nL (ψC ) = 0. We then have the following lemma. Lemma 5. If each cycle of G satisfies Eqs. (1) and (2), then any inner face F has a consistent rectangular labeling ψF . Proof. Omitted in this extended abstract due to the page limitation.
✷
Let F be a corner face of F . Then, by Condition (d) of a corner face, G∗ = G − F is biconnected and hence the intersection of G∗ and F is a single path P ∗ of G, which is called the partitioning path of F . In Fig. 10, P ∗ is drawn by thick lines. Clearly, the ends of P ∗ are outer vertices and have degree three or four. All vertices of P ∗ other than the ends are inner vertices of G. Since F is an inner face of G, by Lemma 5 F has a consistent rectangular labeling ψF . We then decide the rough shape of the outer face Fo∗ of G∗ according to ψF : we designate each outer vertex v of G∗ as a convex corner, a concave corner, or a non-corner, as follows. (See Fig. 10.)
L R v R
S
L P*
F
G* S
S
R S v
P*
G* S
S
G*
P* F R
R (b)
L
S
v R
S
F
R (a)
L
(c)
Fig. 10. Illustration for the designation of outer vertices of G∗ .
[Definition 2] (Designation of outer vertices of G∗ ) Case 1: v is not on P ∗ . In this case, v is an outer vertex of G. We designate v as an R-, S-, and L-vertex of Fo∗ if v was designated as an R-, S- and L-vertex of Fo , respectively. Case 2: v is a vertex of P ∗ other than its ends.
266
Kazuyuki Miura, Ayako Miyazawa, and Takao Nishizeki
Since ψF is rectangular, ψF (v) is either S or R. If ψF (v) = S then we designate v as an S-vertex of Fo∗ , while if ψF (v) = R then we designate v as an L-vertex of Fo∗ . Case 3: v is an end of P ∗ . In this case, v has degree three or four, and hence by Condition (O-2) v is either an S-vertex of Fo or an L-vertex of Fo . Consider first the case where v is an S-vertex of Fo as illustrated in Fig. 10(a). In this case, v has degree three, and hence by Case 4 of Definition 1, we have λ(F, v) = R. Since ψF is consistent with λ, ψF (v) = λ(F, v) = R. Thus the vertex v of polygon D(Fo∗ ) must have an inner angle π − π/2, and hence we designate v as an R-vertex of Fo∗ . Consider next the case where v is an L-vertex of Fo as illustrated in Figs. 10(b) and (c). Since ψF is rectangular, either ψF (v) = S or ψF (v) = R. If ψF (v) = S as illustrated in Fig. 10(b), then we designate v as an R-vertex of Fo∗ . If ψF (v) = R as illustrated in Fig. 10(c), then we designate v as an S-vertex of Fo∗ . ✷ One can easily observe that the designation of the outer vertices of G∗ above satisfies Conditions (O-1)–(O-3). We have the following lemma. Lemma 6. If every cycle of G satisfies Eqs. (1) and (2), then any corner face F of G has a consistent rectangular labeling such that each cycle of G∗ = G − F satisfies Eqs. (1) and (2). Proof. Omitted in this extended abstract due to the page limitation.
✷
We are now ready to give a proof of the sufficiency of Theorem 1. Proof of the sufficiency of Theorem 1 We prove, by induction of the number i of inner faces of G, the proposition that if every cycle of G satisfies Eqs. (1) and (2) then G has an extended rectangular drawing with designated corners. If i = 1, then G = Fo and by Lemma 2 and Eqs. (1) and (2), nR (Fo ) = 4 and nL (Fo ) = 0, and hence G can be drawn as a rectangle having the four Rvertices of Fo as the convex corners. The drawing of G is an extended rectangular drawing with designated corners. The proposition thus holds for i = 1. Assume inductively that i ≥ 2 and the proposition holds for any plane graph of less than i inner faces. We shall prove that the proposition holds for a plane graph G of exactly i inner faces. By Lemma 4 G has a corner face F , and by Lemma 6 F has a consistent rectangular labeling ψF for which each cycle of G∗ = G − F satisfies Eqs. (1) and (2). Since ψF is rectangular, F can be drawn as a rectangle D(F ) having the four R-vertices of ψF as convex corners. Since the number of inner faces of G∗ is equal to i − 1, by the inductive assumption G∗ has an extended rectangular drawing D(G∗ ) with designated corners. The designation of outer vertices of G∗ in Definition 2 implies that one can combine the drawings D(F ) and D(G∗ ) to an extended rectangular drawing of G with designated corners. ✷
Extended Rectangular Drawings of Plane Graphs with Designated Corners
4
267
Conclusion
In this paper, we gave in Theorem 1 a necessary and sufficient condition for a plane graph to have an extended rectangular drawing with designated corners. It immediately yields a necessary and sufficient condition for a plane graph of ∆ ≤ 4 to have an ordinary rectangular drawing. Thomassen’s condition for a plane graph of ∆ ≤ 3 to have a rectangular drawing can be easily derived from our condition as in Corollary 1. It is remaining to obtain an efficient algorithm to find an extended rectangular drawing with designated corners.
References BETT99. BS88. GT97. H93. H99. KH97. KK84. L90. RNN02. RNN98. T84.
G. Di Battista, P. Eades, R. Tamassia and I. G. Tollis, Graph Drawing, Prentice Hall, NJ (1999). J. Bhasker and S. Sahni, A linear algorithm to find a rectangular dual of a planar triangulated graph, Algorithmica, 3, pp.247-278, 1988. A. Garg and R. Tamassia, A new minimum cost flow algorithm with applications to graph drawing, Proc. of Graph Drawing’96, Lect. Notes in Computer Science, 1190, pp. 201-206, 1997. X. He, On finding the rectangular duals of planar triangulated graphs, SIAM J. Comput., 22, 6, pp. 1218-1226, 1993. X. He, On floor-plan of plane graphs, SIAM J. Comput., 28, 6, pp. 21502167, 1999. G. Kant and X. He, Regular edge-labeling of 4-connected plane graphs and its applications in graph drawing problems, Theoret. Comput. Sci., 172, pp. 175-193, 1997. K. Kozminski and E. Kinnen, An algorithm for finding a rectangular dual of a planar graph for use in area planning for VLSI integrated circuits, Proc. of 21st DAC, Albuquerque, pp. 655-656, 1984. T. Lengauer, Combinatorial Algorithms for Integrated Circuit Layout, Wiley, Chichester, 1990. M. S. Rahman, S. Nakano and T. Nishizeki, Rectangular drawings of plane graphs without designated corners, Computational Geometry, 21, pp. 121138, 2002. M. S. Rahman, S. Nakano and T. Nishizeki, Rectangular grid drawings of plane graphs, Comp. Geom. Theo. Appl., 10(3), pp. 203-220, 1998. C. Thomassen, Plane representations of graphs, J. A. Bondy, U. S. R. Murty (Eds.), Progress in Graph Theory, Academic Press Canada, Don Mills, Ontario, Canada, pp. 43–69, 1984.
RINGS: A Technique for Visualizing Large Hierarchies Soon Tee Teoh and Kwan-Liu Ma Computer Science Department, University of California, Davis {teoh, ma}@cs.ucdavis.edu
Abstract. We present RINGS, a technique for visualizing large trees. We introduce a new ringed circular layout of nodes to make more efficient use of limited display space. RINGS provides the user with the means to specify areas of primary and secondary focus, and is able to show multiple foci without compromising understanding of the graph. The strength of RINGS is its ability to show more area in focus and more contextual information than existing techniques. We demonstrate the effectiveness of RINGS by applying it to the visualization of a Unix file directory.
1
Introduction
Ringed Interactive-Navigation Graph System (RINGS) is a technique for visualizing large hierarchical data, as well as large graphs if a spanning tree of the graph is provided as input. RINGS is based on a new ringed circular tree layout algorithm described in more detail in Section 2. Existing methods such as [3,5,7] tend to leave large regions of space empty. Shneiderman’s Tree-maps [8] method makes efficient use of screen space to show a large number of nodes, but in the Tree-map layout, the structural information of the trees is unclear. Three-dimensional visualization methods such as Munzner’s hyperbolic tree [5] and Kleiberg’s botanical tree [2] can be used to navigate through very large graphs and trees, respectively. However, overlapping of edges due to projecting a three-dimensional graph onto a two-dimensional space can lead to occlusion and ambiguity, limiting their effectiveness. The main advantage of the ringed circular method is its efficient use of limited display size by showing more distinguishable nodes at one time, without any of the other methods’ shortcomings listed above. Another important feature of RINGS is its capability to show more contextual information without compromising the clarity of the area in focus. Besides providing interactive navigation and focus+context solutions common in many existing systems, RINGS can also show areas in secondary focus effectively. We also describe how RINGS handles the problem of edge crossing and occlusion. Graphs are often used to display embedded information. RINGS is conducive for this purpose. In Section 5, we demonstrate how RINGS can be used to visualize file sizes, locate specific files and types of files in a directory, and reveal other aspects of the file directory structure. M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 268–275, 2002. c Springer-Verlag Berlin Heidelberg 2002
RINGS: A Technique for Visualizing Large Hierarchies
2
269
Layout Algorithm
Recent graph-drawing algorithms such as Kreuseler et al.’s tree on a hemisphere [3] and Munzner’s hyperbolic tree [5] provide good navigation and focus+context solutions, but they are often less effective in using the available screen space. With a 512×512 display, typically less than 100 nodes and edges are distinguisable at one time while the rest of the graph appears clumped together. In RINGS, we make better use of the available screen space, showing more distinguishable edges and also more structural information in context. In RINGS, a node and all its children are placed in a circle. In this way, the branch any node belongs to is easily identified. Representing each node by a circle has been described in [1,4,6]; however, they place children only on the circumference of the parent circle, wasting empty space in the interior. In the new ringed layout used by RINGS, equal-sized circles corresponding to children are placed in concentric rings around the center of the parent circle (see Figure 1).
Fig. 1. Ringed circular layout of nodes: The four green circles represent the four largest children of the parent node, represented by the large blue circle. The small yellow inner circle is the area left for the remaining children.
Connecting the centers of n equal circles placed in a ring makes an n-sided regular polygon. In Figure 1, θ = π/n , where n is the number of circles in a ring, and θ is in radians. A simple relationship can be derived between the number of children circles in the outermost ring and the percentage of area taken up by the ring. f(n), the fraction of the area left after n circles have been placed in the ring is given by: f (n) =
(1 − sin( nπ ))2 (R2 )2 (1 − sin(θ))2 = . = 2 2 (R1 ) (1 + sin(θ)) (1 + sin( nπ ))2
(1)
This relationship is used to determine the number of children to be placed in each concentric ring. The algorithm first sorts the children by their number of
270
Soon Tee Teoh and Kwan-Liu Ma
Fig. 2. Each node is placed at the center of its circle, and edges are drawn between each pair of connected nodes. Edges are colored according to their distance from the root. Level 1 edges are those directly connected to the root.
children. Next, the algorithm finds the smallest k for which the sum of the number of children of the first k children expressed as a fraction of the total number of grandchildren is greater or equal to f(k). The first k children are placed in the outermost ring. The rest of the children are placed in the same way in the inner rings. A node is positioned in the center of its circle. Edges are drawn as straight lines connecting nodes, as shown in Figure 2. The child labelled C itself has 35 children, and one of those children has descendents, whose circles are outlined in the figure. By placing the largest children in the outermost ring, the number of children in the outer rings is minimized, thereby minimizing the amount of occlusion due to edges drawn from the parent to the children.
3
Interactive Navigation
Like other graph visualization systems, RINGS allows the user to interactively explore the large data. The primary focus is changed by clicking on the child to focus on. The child will be moved to the center and the parent moved to the side as a smooth animation. Figure 3 demonstrates change of focus performed on a 20,000-node Unix file directory. The child in focus becomes the pictorial root because of its central position, and its true parent becomes a pictorial child, since it is placed in a circle on a ring just as any child is. Secondary foci is set by clicking on a child to focus on and dragging it to another child currently occupying a larger area. The positions of the two children are swapped, again with smooth animation (see Figure 4). In addition, the user can reduce the number of children in the outermost ring so that the secondary focus can be enhanced, also shown in Figure 4. The ability to effectively show secondary foci is generally not found in existing methods.
RINGS: A Technique for Visualizing Large Hierarchies
271
Fig. 3. Primary focus is changed by moving a child to the center. The circled child in the left drawing is expanded to the center in the right drawing, while the rest of the graph is moved to the circle in the right drawing. The edge from the focus to its true parent is colored black to distinguish it from the other edges. RINGS smoothly animates these changes.
Fig. 4. Secondary focus is changed by swapping two children. In this example, the user wants to increase the focus on the circled child in the left picture. It is swapped with the selected child at the bottom, resulting in the center picture. To further increase the secondary focus, the user can reduce the number of children in the outermost ring, giving each child more screen space. The number of children is reduced from eleven in the center to five in the right picture.
4
Other Features
Nodes at larger topological distances from the pictorial root occupy very little screen area, so they may become indistiguisable from neighboring nodes. Many edges far away from the foci map to the same pixels on the screen. Figure 5 shows how RINGS provides the option of expanding those nodes out of the confines of their circle. This additional contextual information gives the user a sense of the depth and topology of particular branches without compromising the clarity of the regions in focus.
272
Soon Tee Teoh and Kwan-Liu Ma
Fig. 5. The drawing on the right shows circles at topological distance 4 from the root expanded 200 times. A better sense of topology is gained without losing focus. The depth of certain sub-directories under “research” and “linux home” is revealed.
Fig. 6. Rotation: Occlusion of particular nodes can be eliminated by rotating adjacent rings in opposite directions.
A simple way to improve topology perception is to use different colors for edges with different topological distances from the root. In the color map (shown in Figure 2) used in our examples, darker, more saturated colors are used for edges closer to the root to highlight them. With the RINGS layout, occluded edges are topologically further away from the focus, so they are relatively unimportant. Nevertheless, to overcome the inevitable occlusion, edges are drawn as semi-transparent lines. In addition, RINGS allows the user to rotate adjacent concentric rings in opposite directions (see figure 6) to reveal a particular occluded branch. When visualizing very large graphs, it becomes computationally very expensive to traverse every node in the graph and render individual edges. To maintain
RINGS: A Technique for Visualizing Large Hierarchies
273
navigation at interactive rate, RINGS first creates texture maps of each branch. During interactive navigation of the graph, branches are rendered as texturemapped polygons whereever possible. In this way, even very large trees can be rendered at interactive rates.
5
Visualizing Information Beyond Topology
Figure 7 shows the application of RINGS to the visualization of a Unix file directory. Edges in the graph are colored according to the size of the file or directory. The two pictures show how varying the color map can be used to explore the data.
Fig. 7. Visualizing a Unix directory: In the left picture, the colormap value 1.0 is clipped at 0.1 of the total size of all files in the directory. In the right picture, it is clipped at 0.01.
Other information in the data can also be visualized. Figure 8 shows the result of searching for a file “texture.tga”. The entire path to the file is highlighted in red. In this picture, the user can see the location of the file in relation to the whole directory. The branch and sub-branches the file belongs to are also revealed. Figure 8 highlights all the files in the directory tree with “.cpp”, “.cc”, “.c” or “.h” extensions. This identifies all the sub-directories containing those C++ source files. Examining individual sub-directories of Figure 8 gives insight into their internal structure. Examples of interpreting the visualization are explained in Figure 9. By visualizing typical ringed circular graphs, we can classify the patterns observed (see Figure 10). Understanding this classification aids the gaining of insights into the visualization.
6
Conclusion
We have presented a new ringed circular layout algorithm to visualize large graphs. The main contribution of RINGS is its efficient use of limited display
274
Soon Tee Teoh and Kwan-Liu Ma
Fig. 8. Left: Visualizing the location of a particular file with respect to its neighbors, the branch it belongs to, and the entire directory tree. Right: Highlighting all C++ source files and the directories containing them.
Fig. 9. Interpretation of sub-directories from Figure 8: Sub-directory “240” has 6 subdirectories, 5 of which have a very similar structure. The arrowed one is the exception. “278” has many more sub-directories than “240” and some of them are similar, for example those labelled “A” and “B”. “code” has children which are leaves (files). “277” has children of different sizes. 5 of the largest children are similar, but the child labelled “C” is slightly different in the composition of C++ source files and the child labelled “D” is topologically different from the rest.
space by showing more distinguishable nodes at one time. Other important features of RINGS include showing more contextual information without compromising the clarity of the area in focus, and showing areas in secondary focus. We have demonstrated the effectiveness of RINGS in visualizing specific information embedded in a Unix file directory. RINGS is able to highlight subdirectories with large files and/or large number of files. RINGS is also able to locate specific files and show where they are in relation to the rest of the directory. RINGS is a general graph visualization technique, not limited to the visualization of directory trees. In the future, we plan to apply the technique to the visualization of a variety of hierarchical data, as well as general graphs with spanning trees.
RINGS: A Technique for Visualizing Large Hierarchies
275
Fig. 10. Classification of basic patterns: A) A Solid circle indicates that this node has numerous children of similar size. B) A pattern of radiating lines indicates that the children are leaves. C) Radial lines with large end-points indicate that children are not leaves. D) Many overlapping circles and lines in the expanded view indicate that this node has many very deep descendents. In practice, most nodes in a graph exhibit mixed patterns. However, this simple classification allows intuitive interpretation.
References 1. E.H. Chi and S.K. Card. Sensemaking of Evolving Web Sites Using Visualization Spreadsheets. Proceedings of the Symposium on Information Visualization (InfoViz’99), pp. 18–25, 142. IEEE Press, 1999. 2. E. Kleiberg, H. van de Wetering and J.J. van Wijk. Botanical Visualization of Huge Hierarchies. Proceedings of the Symposium on Information Visualization (InfoViz’01), pp. 87–94. IEEE Press, 2001. 3. M. Kreuseler, N. Lopez and H. Schumann. A Scalable Framework for Information Visualization. Proceedings of the Symposium on Information Visualization (InfoViz’00), pp. 27–36. IEEE Press, 2000. 4. G. Melancon and I. Herman. Circular Drawing of Rooted Trees. Reports of the Center for Mathematics and Computer Sciences, Report number INS-9817, available at: http://www.cwi.nl/InfoVisu/papers/circular.pdf, 1998. 5. T. Munzner. H3: Laying out Large Directed Graphs in 3D Hyperbolic Space. Proceedings of the IEEE Symposium on Information Visualization (InfoViz’97), IEEE CS Press, pp. 2–10, 1997. 6. G.G. Robertson, J.D. Mackinlay and S.K. Card. Cone Trees: Animated 3D Visualization of Hierarchical Information. Human Factors in Computing Systems, CHI’91 Conference Proceedings, ACM Press, pp. 189–194, 1991. 7. M. Sarkar and M.H. Brown. Graphical Fisheye View of Graphs. Human Factors in Computing Systems (CHI’92) Conference Proceedings, ACM Press, pp. 83–91, 1992. 8. B. Shneiderman. Tree Visualization with Tree-maps: A 2D space-filling approach. ACM Transactions on Graphics, 11(1):92–99, September 1990.
Applying Crossing Reduction Strategies to Layered Compound Graphs Michael Forster University of Passau, 94030 Passau, Germany [email protected]
Abstract. We present a new method for the application of 2-layer crossing reduction algorithms to layered compound graphs. It is based on an algorithm by Sander [9, 7, 8] and improves it with fewer crossings. Our method is optimal in the sense that it does not introduce unnecessary crossings by itself. If used with an optimal 2-layer crossing reduction algorithm, the crossing reduction for 2-layer compound graphs is optimal, too.
1
Introduction
Compound graphs are graphs with two sets of edges, adjacency edges and hierarchy edges. The hierarchy edges are interpreted as an inclusion relationship. They are also called “inclusion edges”. There are different notions of compound graphs. Some only restrict the hierarchy edges to be acyclic, others require them to form a tree. This paper uses the latter concept. There are many areas of application for compound graphs. The motivation for our research on the topic comes from the visualization of biochemical pathways. This is an interesting area of application for graph drawing. Parts of a reaction network take place in different regions of the cell, e. g., in the nucleus or in the cytoplasm. Moreover, there are situations where these regions are nested. This leads to clustered graphs, a special type of compound graphs, where adjacency edges are only allowed between leaves of the hierarchy tree. The usual way to draw compound graphs is as follows: compound nodes, i. e., nodes that contain other nodes are drawn as rectangles. The contained nodes – and only these – are drawn within the rectangle. There are some extensions of layout algorithms for planar graphs and of force directed algorithms to compound graphs. See [1] for an overview. Since we focus on directed compound graphs, we use a drawing style where the nodes are partitioned into layers. All nodes of one layer are drawn on a horizontal line. Edges are routed top down. This is similar to the layout style generated by the well-known algorithm of Sugiyama, Tagawa, and Toda for the layout of directed acyclic graphs, see Fig. 1.
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 276–284, 2002. c Springer-Verlag Berlin Heidelberg 2002
Applying Crossing Reduction Strategies to Layered Compound Graphs
277
Fig. 1. A layered compound graph
2
Related Work
There are two variants of layered drawings of compound graphs: If using local layers, each node spans exactly one layer. The interior of compound nodes has its own interior layers that are independent of the exterior layers. The representative algorithm with local layers is an algorithm by Sugiyama and Misue [13]. With global layers, there is only one set of layers for all nodes. Compound nodes are allowed to span multiple layers. This is the drawing style used by Sander [9,7,8]. Drawings with local layers typically can be computed faster, while global layers give more compact drawings. Fig. 2 shows the same compound graph drawn with both variants. See [7, 8] for a more detailed comparison. For this paper, we will focus on a global layering scheme.
(a) Local layers
(b) Global layers
Fig. 2. Local vs. global layers
278
Michael Forster
An obvious approach for drawing directed compound graphs is to draw the interior and exterior of compound nodes independently of each other. First, the interior of the compound nodes at the lowest level of the hierarchy is drawn. Then the internal structure is hidden and the compound node is treated as a single big node. Instead of working the hierarchy bottom up, it is possible to start at the root of the hierarchy, first drawing the outside of the compound nodes and then inserting the contents recursively. For this variant, the layering of the graph must be computed as a preprocessing step, because the size of all compound nodes must be known before the top level layering can be done. No matter whether the hierarchy is traversed top down or bottom up, this strategy leads to unnecessary edge crossings, since parts of the layout are computed without considering the global connectivity of the graph. Fig. 3(a) shows a given compound graph, drawn without any edge crossings. Fig. 3(b) shows the graph after the first step of the algorithm. The top level of the hierarchy has been drawn, the interior of the compound node has been ignored. Up to now, we have no crossings, but the positions of the shown nodes hence are fixed. As a result, any order of the interior nodes will lead to an edge crossing, see Fig. 3(c). The other three images of Fig. 3 show a similar example for an unnecessary edge crossing, when traversing the hierarchy bottom up.
a
b
c
d
e
f
(a)
a
f (b)
b
e
a
b
c
d
f
e
(c)
a
b
a
b
a
b
c
d
d
c
d
c
(d)
(e)
(f)
Fig. 3. Unnecessary edge crossings when considering hierarchy levels separately
It is well known that crossing reduction is NP-hard already for ordinary graphs, even if they only consist of two layers [3]. Therefore we cannot expect an efficient optimal crossing reduction algorithm for compound graphs. But in this case, the crossings do not originate from the used crossing reduction method itself, they arise from the application of the crossing reduction method to the compound graph. This means, that even with an optimal 2-layer crossing reduction strategy for ordinary graphs, these crossings are unavoidable. Sander [9,7,8] uses a different approach. His algorithm works as the algorithm of Sugiyama, Tagawa, and Toda for the layout of directed acyclic graphs [13]. The hierarchical structure is considered only when it is necessary to prevent violations of the drawing conventions. Since Sander’s method is the base of our algorithm, we recall it in section 4, in direct comparison to our method.
Applying Crossing Reduction Strategies to Layered Compound Graphs
3
279
Notation
A (directed) graph G = (V, E) consists of nodes V and edges E ⊆ V × V . The direct predecessors and direct successors of a node v ∈ V are defined as predG (v) = { u ∈ V | (u, v) ∈ E } and succG (v) = { u ∈ V | (v, u) ∈ E }. The successors succ∗G (v) and predecessors pred∗G (v) of v are the respective reflexive transitive closures. A compound graph G = (V, E, H) consists of a graph (V, E) with adjacency edges E and an additional relation H ⊆ V ×V such that the graph T = (V, H) is a directed rooted tree with its edges oriented from the root towards the leaves. T is called the hierarchy tree of G, its edges are called hierarchy edges. The nodes of a compound graph G are partitioned into base nodes B = { v ∈ V | succT (v) = ∅ } and compound nodes C = V \B. G|B is called the base graph of G. A layered compound graph G = (V, E, H, L) is a compound graph (V, E, H) where each base node is assigned to a positive integer L : B → N. B is partitioned into disjoint layers B1 , . . . , Bn , where Bi = { v ∈ B | L(v) = i }. The minimum (maximum) layer Lmin (v) (Lmax (v)) of a node v ∈ V is defined as the minimum (maximum) layer number of the leaves reachable in the hierarchy tree. For a base node b ∈ B this results in Lmin (b) = Lmax (b) = L(b). The layer hierarchy tree Ti = (Vi , Hi ) for the i-th layer of an layered compound graph G = (V, E, H, L) is that part of the hierarchy tree that is relevant for the i-th layer, its nodes are Vi = { v ∈ V | Lmin (v) ≤ i ≤ Lmax (v) }. A (layered) clustered graph is a (layered) compound graph where edges are only allowed between the base nodes. A layered compound (or clustered) graph is said to be proper if every edge (u, v) ∈ E is directed downwards and spans exactly one layer, i. e., Lmin (v) = Lmax (u) + 1. This implies that there are no adjacency edges between a node and a predecessor or successor of it in the hierarchy tree. Any layered compound graph can be converted to a proper layered clustered graph by reversing edges and inserting dummy nodes, see Fig. 4 for an example.
(a) A layered compound graph
(b) Inserted dummy nodes
Fig. 4. Converting a layered compound graph to a proper layered clustered graph
280
4
Michael Forster
Crossing Reduction
Reducing the crossings in the drawing of a compound graph is a crucial step in the layout process. We assume that the given compound graph has already been layered and has been converted to a proper layered clustered graph by reversing some edges and inserting dummy nodes. This can be done as described in [7, 8]. The crossing reduction method for clustered graphs proposed by Sander is based on the crossing reduction step in the conventional Sugiyama algorithm for drawing directed acyclic graphs. It starts with a random order of the topmost layer. It then iteratively considers each layer from top to bottom and reorders the nodes on that layer such that the crossings between incoming edges are reduced. When the algorithm has reordered the last layer, it traverses the graph from bottom to top, reordering the layers so that crossings between outgoing edges are reduced. These two traversals are repeated until some termination criterion is met. Since the problem to minimize the crossings between two layers is NPhard, heuristics are used, e. g. the well-known barycenter heuristic, and there are others with varying quality and running times [2, 4, 5]. The main idea of our algorithm is a scheme, how any standard 2-layer crossing reduction method can be applied to proper layered clustered graphs. The main part of the crossing reduction step stays the same, but only base nodes are considered. The base graph is traversed top down and bottom up in the same way, considering the hierarchy only when doing the 2-layer crossing reduction. There are two new restrictions which must be satisfied when reducing crossings in clustered graphs as opposed to unclustered graphs. R1: The nodes on a layer that belong to the same compound node must be placed next to each other with no other nodes between them. R2: The relative position of two compound nodes must be the same on all layers, i. e., compound nodes must not “cross” each other. If any of these restrictions is violated, it is not possible to draw compound nodes as rectangles that contain exactly the respective subtree of the hierarchy, see Fig. 5 for examples. It is the strict enforcement of these extra restrictions that differentiates our method from that of Sander. In Sander’s method the hierarchy is ignored first,
(a) Violation of R1
(b) Violation of R2
Fig. 5. Violations of the order restrictions
Applying Crossing Reduction Strategies to Layered Compound Graphs
281
which leads to violations of the restrictions. These violations are resolved afterwards by sorting the compound nodes by the barycenter of the contained base nodes. Only the intermediate base node order is considered and the adjacency edges are ignored. It is easy to construct simple examples, where this strategy gives many unnecessary crossings, see Fig. 6. Our strategy is to consider the restrictions right from the start.
(a) before reordering
(b) after reordering
(c) optimal result
Fig. 6. Unnecessary crossings with Sander’s method
4.1
Respecting the Hierarchy on a Single Layer (R1)
Our method works by modifying the 2-layer crossing reduction step used as a subroutine in the global crossing reduction. We assume a layered clustered graph G = (V, E, H, L), with two layers B1 and B2 and compound nodes C, V = B1 ∪ B2 ∪ C, its hierarchy tree T = (V, H), and two layer hierarchy trees T1 , T2 . The order of B1 is fixed, B2 must be reordered. We consider the layer hierarchy tree of the bottom layer T2 and ignore R2 for now. We observe the following lemma: Lemma 1. An order of the base nodes complies with R1 if and only if there exists a child order of the layer hierarchy tree so that the order of the base nodes can be obtained by a preorder (postorder) traversal. Because of this observation we will concentrate on finding child orders for the layer hierarchy tree and from this obtain the order of the base nodes. The following lemma characterizes the relationship between edge crossings and the child order of some node in the layer hierarchy tree: Lemma 2. Let e1 = (s1 , t1 ), e2 = (s2 , t2 ) ∈ E be two adjacency edges in G, and let t be the lowest common ancestor of t1 and t2 in the layer hierarchy tree with two children t1 and t2 that are predecessors of t1 and t2 , respectively. The edges e1 and e2 cross if and only if t1 and t2 have a different relative order than s1 and s2 . Thus each possible edge crossing can be associated with a unique compound node in the layer hierarchy tree. Also each edge crossing is independent of the child orders of all other hierarchy tree nodes in T2 . The number of crossings in some order of the base nodes is the sum of the crossings associated to each layer hierarchy node. We get the following theorem:
282
Michael Forster
Theorem 1. An order of the base nodes has a minimal number of crossings if and only if the corresponding layer hierarchy tree has a minimal number of crossings at each node. By Theorem 1, it is justified to compute the child order of all compound nodes independently without losing quality. To minimize the number of crossings associated to a compound node h ∈ V2 we construct a new graph Gh called the crossing reduction graph of h. Gh consists of two layers. The upper layer B1 stays the same as in G, the lower layer B2 consists of the children of h in T2 . The relevant adjacency edges of G are then transferred to Gh in the following manner: – Edges (s, t) ending in a node t that is not a successor of h in T2 are ignored. – For each remaining edge (s, t), an edge (s, c) with weight w(s, c) = 1 is created, where c is the unique child of h which is a predecessor of t. If the edge already exists, its weight is increased by 1. We get the following weight function B1 × B2 → N0 , w: (s, c) → { t ∈ B2 ∩ succ∗T2 (c) | (s, t) ∈ E } and a corresponding weighted graph Gh : Gh =(Vh , Eh , w) Vh =B1 ∪ B2 , B2 = succT2 (h) Eh ={ (s, c) ∈ B1 × B2 | w(s, c) > 0 } . See Fig. 7 for an illustration. Please note that all crossing reduction graphs can be precomputed before starting the traversal of the graph, since they do not change during the crossing reduction. A conventional algorithm for weighted 2-layer crossing reduction is then applied to the crossing reduction graph and the given order of the upper layer. The resulting order of the lower layer is used as the order for the children of h. In the same way a child order for all other internal nodes of the layer hierarchy tree is computed, and we get an order for the base nodes by traversing the tree.
2
(a) A clustered graph
(b) The crossing reduction graph of the grey node
Fig. 7. Creating the crossing reduction graph
Applying Crossing Reduction Strategies to Layered Compound Graphs
2
(a) Compound nodes across two layers
(b) Constraint method
∞
283
∞
(c) Heavy edge method
Fig. 8. Respecting the hierarchy across layers (R2)
4.2
Respecting the Hierarchy Across Layers (R2)
To respect R2 right from the start, we present two alternative strategies: the constraint method and the heavy edge method. The constraint method is the more promising alternative. It guarantees the compliance with R2, but it depends on a 2-layer crossing reduction algorithm that supports constraints, i. e., predefined relative orders of some node pairs. Some of the conventional crossing reduction methods have been extended to support constraints with varying success. There is also a crossing reduction method by Schreiber [10], that has been designed specifically for the support of constraints. To comply with R2, the constraint method prohibits the relative position of two compound nodes spanning adjacent layers being different. This is done by inserting a constraint into the crossing reduction graph of one specific node. In Fig. 8(b) the dotted arrow shows how constraints are inserted. Please note that it is sufficient to add constraints between compounds nodes having the same parent in the layer hierarchy tree. An alternative to the constraint method is the heavy edge method. It does not need a crossing minimization algorithm that supports constraints, but models compound nodes as edges with a very high weight instead. These are labeled with ∞ in Fig. 8(c). Unfortunately, this approach does not guarantee compliance with R2 when used with a non-optimal crossing reduction algorithm. Consequently it may be necessary to reorder the nodes in the same way as Sander. Additionally, these edges penalize crossings between adjacency edges and compound nodes. Avoiding these crossings make drawing better understandable, but it also leads to more crossings between adjacency edges.
5
Discussion
We presented a new method for crossing reduction in layered compound graphs. Our method improves Sander’s method with regard to the number of crossings. Depending on structure of the hierarchy we may also gain running time improvements. An implementation of the algorithm is in progress, using Schreiber’s 2-layer crossing minimization with constraints support [10]. We shall have experimental results soon.
284
Michael Forster
References 1. Ralf Brockenauer and Sabine Cornelsen. Drawing clusters and hierarchies. In Kaufmann and Wagner [6], chapter 8, pages 193–227. 2. Giuseppe di Battista, Peter Eades, Roberto Tamassia, and Ioannis G. Tollis. Graph Drawing. Prentice Hall, 1999. 3. Peter Eades and Nicholas C. Wormald. Edge crossings in drawings of bipartite graphs. Algorithmica, 11:379–403, 1994. 4. Michael J¨ unger and Petra Mutzel. Exact and heuristic algorithms for 2-layer straightline crossing minimization. In Proc. Workshop on Graph Drawing ’95, pages 337–348. Springer, 1996. 5. Michael J¨ unger and Petra Mutzel. 2-layer straightline crossing minimization: Performance of exact and heuristic algorithms. Journal of Graph Algorithms and Application, 1(1):1–25, 1997. 6. Michael Kaufmann and Dorothea Wagner, editors. Drawing Graphs, volume 2025 of Lecture Notes in Computer Science. Springer, 2001. 7. Georg Sander. Layout of compound directed graphs. Technical Report A/03/96, Universit¨ at Saarbr¨ ucken, 1996. 8. Georg Sander. Visualisierungstechniken f¨ ur den Compilerbau. PhD thesis, Universit¨ at Saarbr¨ ucken, 1996. 9. Georg Sander. Graph layout for applications in compiler construction. Theoretical Computer Science, 217:175–214, 1999. 10. Falk Schreiber. Visualisierung biochemischer Reaktionsnetze. PhD thesis, Universit¨ at Passau, 2001. 11. Falk Schreiber. High quality visualization of biochemical pathways in biopath. In Silico Biology, 2(0006), 2002. http://www.bioinfo.de/isb/2002/02/0006/. 12. Kozo Sugiyama and Kazuo Misue. Visualization of structural information: Automatic drawing of compound digraphs. IEEE Trans. Systems, Man and Cybernetics, 21(4):876–892, 1991. 13. Kozo Sugiyama, Shojiro Tagawa, and Mitsuhiko Toda. Methods for visual understanding of hierarchical system structures. IEEE Trans. Systems, Man and Cybernetics, SMC-11(2):109–125, 1981.
Crossing Reduction by Windows Optimization Thomas Eschbach1 , Wolfgang G¨ unther2 , Rolf Drechsler3 , and Bernd Becker1 1 Institute for Computer Science Albert-Ludwigs-University, Freiburg, Germany {eschbach,becker}@informatik.uni-freiburg.de 2 Infineon AG CL DAT DF LD V, Munich, Germany [email protected] 3 Institute for Computer Science University of Bremen, Bremen ,Germany [email protected]
Abstract. The number of edge crossings is a commonly accepted measure to judge the “readability” of graph drawings. In this paper we present a new algorithm for high quality multi-layer straight-line crossing minimization. The proposed method uses a local optimization technique where subsets of nodes and edges are processed exactly. The algorithm uses optimization on a window applied in a manner, similar to those used in the area of formal verification of logic circuits. In contrast to most existing heuristics, more than two layers are considered simultaneously. The algorithm tries to reduce the total number of crossings based on an initial placement of the nodes and can thus also be used in a postprocessing step. Experiments are given to demonstrate the efficacy of the proposed technique on benchmarks from the area of circuit design.
1
Introduction
In the last few years the area of automated graph drawing has received a lot of attention from academic and industrial researchers as well. Many relations arising in computer science and in other areas such as chemistry can be modeled by graphs. Concerning computer science visualization of graphs has a growing number of applications e.g. in the areas of data bases, software engineering, graphical interfaces, production scheduling and VLSI CAD (Very Large Scale Integration Computer Aided Design). To allow humans to quickly and efficiently interpret information given as graphs, a good drawing is very useful. In the following, we are especially interested in the drawing of digital circuits occurring in VLSI CAD applications, which can be modeled by graphs. Circuit designers need a fast tool to visualize the given circuit to get a good understanding of the design or diagnose bugs. Furthermore, highest drawing quality is needed for public presentation or documentation in this field. Here, the drawing quality is much more important than the required computation time. Graph drawing - from the initial graph to the final layout - is usually split into several sub-tasks (for an overview of graph drawing see [1]). One very important step in the overall flow of graph drawing is crossing minimization, (see M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 285–294, 2002. c Springer-Verlag Berlin Heidelberg 2002
286
Thomas Eschbach et al.
e.g. [5,20,21]). Unfortunately, even minimizing edge crossings in graphs with only two layers is NP-hard [7] and remains NP-hard even if the positions of the nodes in one layer are fixed. Several heuristic methods have been developed [4,8,12,15,18,20], but exact solutions can be found only for small graphs [10,11]. Almost all heuristic methods are based on the so-called layer-by-layer sweep: – First, an initial order is chosen for all nodes. Then the positions of all nodes in the first layer are fixed and the positions of all nodes in the second layer are computed with respect to all nodes in the first layer. – In the next step the algorithm fixes the positions of the nodes in the second layer and computes the positions of the nodes located in the third layer with respect to the second layer. – The algorithm continues until the positions of the nodes in the last layer are computed followed by a sweep in the reverse order of layers from the last layer to the first layer. Typically the procedure given above is iterated until no reduction in the number of crossings can be achieved in an iteration. By this method the multi-layer crossing minimization problem is reduced to the minimization of the edge crossings in the corresponding two-layer graphs by reordering only the nodes of one layer. Due to the significance of the problem, several heuristics have been proposed, e.g. [4,15,20,21,18]. In particular the barycenter method [20] is known for computing good solutions in a short time. Somewhat surprising is that using it in the same layer-by-layer sweep framework yields slightly better results than using a one-sided exact algorithm [11]. In [12] the crossing reduction is solved with tabu search, which usually computes good solutions at the expense of run time. In [15,8] sifting has been proposed, a heuristic that was originally used for minimizing the number of nodes in Binary Decision Diagrams (BDDs) used frequently in logic synthesis applications and formal verification of logic circuits. In the BDD context, a technique called window optimization [6,9] has been proposed that facilitates smooth tradeoff of run time for quality. In this paper we propose the use of windows optimization for multi-layer crossing minimization. It is designed for post-processing a given solution in the area of circuit visualization, if the corresponding graph is too large for an exact approach. An initial order, e.g. computed by one of the approaches described above is improved in the following way: A series of subsets of nodes with constant size typically spreading over several layers are extracted and optimized exactly with respect to their adjacent nodes. The exact method makes use of lower bound computations to prune the search space. Only if the local solution induces a crossing reduction of the whole graph the order of all nodes is re-adjusted. The designer can smoothly influence the trade-off between run time and solution quality by choosing the size of the window. The implementation of the algorithms is done in AGD [19], a state-of-the-art library of algorithms for graph drawing. Since most of the algorithms discussed above are implemented in AGD, a fair comparison is possible. The AGD uses the efficient LEDA graph package for combinatorial and geometric computing
Crossing Reduction by Windows Optimization
287
[17]. Our experiments show that further reductions of up to 10% compared to the AGD results can be obtained by using the new technique. The paper is organized in the following way. First we introduce the basic definitions in the field of the multi-layer straight-line crossing minimization problem. Then a brief outline of the exact algorithm used is given. In the following section the new approach is presented. Next we give the experimental results showing the crossing reduction obtained by applying the windows optimization procedure on the graphs already optimized with the AGD package.
2
Preliminaries
A directed graph G = (V, E) is a multi-layered graph with d layers if the node set V is partitioned into d subsets V1 , V2 , . . ., Vd , i.e. V1 ∪ V2 ∪ . . . ∪ Vd = V and (∀m = m ) Vm ∩ Vm = ∅. Vm is called the m-th layer of the graph. All edges in E connect nodes in different layers. A layering of a graph is called proper if the edges only connect nodes of adjacent layers Vm and Vm+1 . If a layering of a graph is not proper one can introduce dummy nodes along edges (u, v) for which l = layer(v) − layer(u) > 1. We replace (u, v) by a path (u = v1 , v2 , . . . , vl = v) of length l. In each layer between u and v, one dummy node has to be placed. Algorithms for layering graphs which represent circuits are discussed e.g. in [3]. It is important to note that only the order of the nodes in a layer Vm , m ∈ {1, . . . , d}, affects the number of crossings with adjacent layers. To solve the exact multi-layer straight-line crossing minimization problem we have to determine for all layers m an order ordm containing all nodes in layer Vm so that the number of crossings is minimized. In the following a set of orders ordm , m ∈ {1, . . . , d}, is called an order for the graph. We define xm ij = 1 if ordm (i) < ordm (j), 0 otherwise. It is easily seen, that for a given order of a graph with d layers the number of crossings can be expressed by: C(order) =
d−1 |V m |−1 |Vm | m=1
i=1
k=i+1 j∈N (i) l∈N (k)
m+1 m+1 (xm + xm ) ik · xlj ki · xjl
(1)
where N (u) = {v ∈ V | e = (u, v) ∈ E} denotes the set of neighbors of u ∈ V . 2.1
Exact Algorithm
We briefly sketch the algorithm for the multi-layer straight-line crossing minimization problem. The algorithm computes the exact optimum and makes use of a lower bound technique to reduce the search space. The main idea goes back to dynamic programming. – The algorithm computes the minimum number of edge crossings for all nodes by considering the solutions for all subsets of nodes. In the first step we consider all subsets S with one node. For each subset the algorithm creates
288
–
–
–
–
Thomas Eschbach et al.
an entry I and stores it in a table. Each entry I contains the number of edge crossings caused by the edges with both ends in S. Additionally the algorithm stores the permutation of the nodes within S in every entry I. In the first step the first node is also the first node in the permutation of the nodes in S An initial upper bound of edge crossings is obtained by using the barycenter heuristic method to compute an order for all nodes [20]. Let S(I) denote the set of nodes stored in the entry I. In the second step we process every entry I of the table in the following way: For each node ni , with ni ∈ / S(I), we create a new entry Inew for S(I) ∪ ni and store it in the new table if the upper bound is larger than the number of crossings of the new subset S(Inew ). Then the algorithm enlarges the permutation of Inew with ni and updates the number of crossings. If there are two table entries with the same subsets of nodes, the one with the larger number of crossings can be deleted, if the following holds: there exists no more than one edge per layer, that is connected to a node u outside S(I), except that they point to different layers. Otherwise, we cannot compute the number of crossings induced by the permutation of the nodes in the subset S(I). To prune the search space the following lower bound L is used: We count the number |u| of edges which leave I from layer m for nodes in layer m+1 (not in I ) and the number |v| of edges which leave I in layer m+1 for nodes in layer m not in I. Then L can be computed as the number of crossings in I plus the product of |u| and |v|. If L is larger than the upper bound we can also delete the table entry. To speed up the algorithm a dynamic hash table is used to store the current permutation together with the current lower bound. For each entry I the corresponding set of nodes is used as a hash key.
In the following we embed this exact algorithm in our windows optimization scenario. However it should be noted that, in principle, the optimization technique described below also works in combination with other exact approaches, like e.g. [11].
3
Windows Optimization
The basic idea is to extract subsets S of nodes from the graph with constant size and the corresponding subset of edges with at least one end in S. Then the optimal order for S and a somewhat simplified representation of neighborhood N of S is computed. (The notion simplified neighborhood is explained below.) If the exactly optimized order of the nodes in S with regard to N reduces the number of crossings of the graph we adopt the locally optimized solution, otherwise we proceed with a new subset S. More precisely, the algorithm extracts windows of D layers with a maximum of W nodes in each layer1 . First, we extract windows with nodes located in the 1
In the experiments we initialize the values D with two and W to four.
Crossing Reduction by Windows Optimization
289
upper D layers. Starting at the leftmost nodes occurring in the current global permutation the algorithm slides the window one position to the right after each attempt to reduce the number of crossings. We compute a sequence of windows whose horizontal size is adapted layer by layer based on the layers with the largest number of nodes. Then the window processes the following D layers, i.e. layers two to layer D + 1, in the same manner until we have traversed the whole graph. We repeat the procedure described above until no further reduction of the number of crossings can be achieved. Then we may increase the number of layers which are considered by incrementing D and repeat the windows optimization procedure to reduce the number of crossings. This allows to achieve a smooth trade-off between quality and run time. A sketch of the algorithm is given below: WindowsOptimization(Graph G, Order Ord, int D, int W ) { Cold = #crossings(G, Ord) d = number of layers in G repeat { Cnew = Cold for(i = 1; i ≤ d − D + 1) { k = maxi≤m
290
Thomas Eschbach et al.
S and which are not connected to a node n E S are also ignored. A boundary node is created for each node in the layer that is above all nodes in S if at least one of its edges is connected t o a node in S. It is important to notice that the given graph is converted to a proper graph by adding dummy nodes and hence the layer above all nodes in the subset S is uniquely defined. Edges which are connected to nodes in a layer which all point in the same direction with respect t o the current order of the graph are redirected to a single boundary node located in the same layer and in the same direction. In other words, the problem is solved using the exact algorithm to compute the optimal order of S with respect to a simplified representation of the neighborhood. An example given below illustrates an instance of the simplified representation of the neighborhood.
first layer
second layer
third layer
Fig. 1. Subset {9,10,15,16) and the corresponding boundary nodes
Example 1. T h e left side of Figure 1 shows a n example graph. T h e algorithm tries t o reduce the edge crossings by optimizing the order of the nodes in the subset S ({9,10,15,16)). First the algorithm computes a simplified representat i o n of the neighborhood ( s h o w n in the right side of Figure 1). Node 1 can be ignored, because it i s n o t connected t o a node in S . T h e node sets { 7 , 8 ) , { 1 1 , 1 2 ) , {13,14), and {17,18) are each collapsed t o single boundary nodes B 8 , B 2 , B 9 and B 1 respectively. T h e procedure computes the optimal order of S w i t h respect t o this neighborhood.
4
Experimental Results
The algorithm has been implemented in C and integrated in AGD. All experimental results are based on graphs which are extracted from the sequential benchmark circuits in [2,16]. The circuits are modeled as proposed in [14] by creating a node for every input, every output and every gate of the circuit. Also one has to create a fanout node for every gate ni which has more than one fanout branch. The fanout node is conected with the output of ni and the inputs of the corresponding gates. A depth first search assigned each node t o one level, starting at the input nodes. Also dummy nodes were created to compute a proper layering of the graph. All experiments were carried out by running the
Crossing Reduction by Windows Optimization
291
implemented procedures on a 900 MHz personal computer with 500 MB main memory with linux OS. All run times are given in CPU seconds. For comparison we utilized the AGD [19] barycenter, median, weightedmedian, split and sifting implementation all combined with the greedy switch method after each traversal of the graph. It turned out, that the barycenter method combined with the greedy switch method clearly dominates the others (see also [11]). In Figure 2 we illustrate the crossing reduction in percent referenced to the barycenter method. The x-axis corresponds to different benchmarks and on the y-axis we give the number of crossings obtained using different procedures relative to the number of crossings obtained using barycenter procedure. Due to these results, we restrict ourselves to a comparison of the proposed procedure with barycenter (bc) in combination with greedy switch (bc+gs) in the following. 200 "barycenter+gs" "median+gs" "weighted-median+gs" "split+gs" "sifting+gs"
180
160
140
120
100
80
60 0
5
10
15
20
25
Fig. 2. Crossing reduction compared to barycenter+greedyswitch.
In Table 1 the results are given. In the second column the number of nodes of each graph is shown. In the third and the fourth column the number of edge crossings using AGD barycenter implementation and the barycenter implementation combined with the greedy switch method are given, respectively. On average 13% less crossings are obtained with bc+gs. This demonstrates that in the VLSI CAD scenario it is very effective to use the greedy switch method. We further post-processed the order obtained by bc+gs method with our windows optimization algorithm shown in the column wo+bc+gs. In almost all cases the number
292
Thomas Eschbach et al.
of crossings could be further reduced. On average the number of crossings went down by 4% and in some cases we even obtained a reduction of more than 10%. We also made experiments running more iterations of the layer-by-layer based methods. Spending the same amount of time as for window optimization usually dose not lead to better results. Table 1. Benchmark results
circuit add6 alu1 alu2 alu3 adr4 co14 dk17 dk27 dk48 mish radd rd53 s208 s298 s382 s386 s400 vg2 x1dn x9dn z4 Z9sym
nodes 504 125 391 452 210 261 437 186 641 571 215 193 665 638 903 763 941 456 470 419 238 767
bc 230 101 602 791 186 97 444 111 619 127 68 371 385 1312 1288 4243 1380 241 218 209 184 5300
bc + gs 170 91 558 742 144 76 440 95 591 108 61 320 280 1142 1199 3868 1366 157 185 188 149 5189
wo + bc + gs 159 86 536 721 137 69 435 95 582 107 54 290 269 1119 1143 3723 1342 149 179 183 140 4917
time 30 5 52 43 10 13 37 4 67 11 5 27 65 42 204 254 77 27 43 24 17 414
Another advantage of the proposed method is that it allows to smoothly trade-off run time versus quality. A trade-off between crossing reduction and run time consumption can be achieved if we start with a small window and successively increment the number of affected layers. More precisely, at the beginning we adjust the window to observe two layers with four nodes in each layer. If no crossing reduction could be achieved after a traversal of the graph we enlarge the window adding one layer until we reach a depth of four layers. In Figure 3 the effect of the process is demonstrated by an experiment. In Figure 3 also the bc+gs procedure gives the 100%-line. It can be easily seen that with increasing window size the quality is significantly improved.
Crossing Reduction by Windows Optimization
293
100 "barycenter+gs" "windows_optimization_up_to_4x2" "windows_optimization_up_to_4x3" "windows_optimization_up_to_4x4" 98
96
94
92
90
88 0
5
10
15
20
25
Fig. 3. Trade-off between quality and run time
5
Conclusions
We presented a new method to improve the results of layer by layer sweep crossing minimization algorithms. The algorithm changes the permutation of the nodes if the local optimization leads to a reduction of the number of crossings. The experiments have shown that this method can enhance the quality of already locally optimized solutions produced by AGD by more than 10%. In the average case a crossing reduction of four percent could be observed. If graph drawings are used for documentation in VLSI CAD a small improvement is of significant value. Future work is directed towards improving the run time of the algorithm. For this, alternative implementations of the exact method [10,11] will be studied instead of the one used here. Acknowledgment We are grateful to professor Sudhakar Reddy, University of Iowa, for fruitful discussions.
294
Thomas Eschbach et al.
References 1. G. Di Battista, P. Eades, R. Tamassia, and I.G. Tollis. Algorithms for Drawing Graphs: An annotated bibliography. Computational Geometry: Theory and Applications, 4:235-282,1994. 2. F. Brglez, D. Bryan, and K. Kozminski. Combinational Profiles of Sequential Benchmark Circuits. Int’l Symp. Circ. and Systems, 1924-1934,1989. 3. R. Drechsler, W. G¨ unther, L. Linhard, and G. Angst. Level Assignment for Displaying Combinational Logic. In EUROMICRO, 148-151,2001. 4. P. Eades, and D. Kelly. Heuristics for reducing crossings in 2-layered networks. Ars Combin., 21.A:89-98,1986. 5. P. Eades, and K. Sugiyama. How to draw a Directed Graph. Journal of Information Processing, Vol.13,4,424-437,1991. 6. M. Fujita, Y. Matsunaga, and T. Kakuda. On Variable Ordering of Binary Decision Diagrams for the Application of Multi-Level Synthesis. European Conf. on Design Automation, 50-54,1991. 7. M. R. Garey, and D.S. Johnson. Crossing number is NP-Complete. SIAM Journal on Algebraic and Discrete Methods, 4:312-316,1983. 8. W. G¨ unther, R. Sch¨ onfeld, B. Becker, and P. Molitor. K-Layer Straightline Crossing Minimization by Speeding up Sifting. Proceedings of the 8th International Symposium on Graph Drawing, 253-258,2000. 9. N. Ishiura, H. Sawada, and S. Yajima. Minimization of Binary Decision Diagrams Based on Exchange of Variables. Int’l Conf. on CAD, 472-475,1991. 10. M. J¨ unger, E.K. Lee, P. Mutzel, and T. Odenthal. A Polyhedral Approach to the Multi-Layer Crossing Number Problem. Proceedings of the 5th International Symposium on Graph Drawing, LNCS Vol. 1353,13-24,1997. 11. M. J¨ unger and P. Mutzel. 2-Layer Straightline Crosing Minimization: Performance of Exact and Heuristic Algorithms. J. Graph Agorithms Appl., 1(1):1-25,1997. 12. M. Laguna, R. Mart´ı, and V. Valls. Arc Crossing Minimization in Hierarchical Digraphs with Tabu Search. Computers and Operations Research, Vol. 24,2:1175– 1186,1997. 13. E. M¨ akinen. Experiments on drawing 2-level hierarchical graphs. International Journal of Computer and Mathematics, 36:175-181,1990. 14. E. M¨ akinen. How to draw a hypergraph. International Journal of Computer and Mathematics, 34:177-185,1990. 15. C. Matuszewski, R. Sch¨ onfeld, and P. Molitor. Using Sifting for k-Layer straightline crossing minimization. Proceedings of the 7th International Symposium on Graph Drawing, LNCS 1731,217-224,1999. 16. K. McElvain Benchmark Set: Version 4.0. International Workshop on Logic Synthesis, 1993. 17. K. Mehlhorn, and S. N¨ aher. LEAD: A Platform for Combinatorial and Geometric Computing. Communications of the ACM, 38,1:96-102,1995. 18. P. Mutzel. An Alternative Method for Crossing Minimization on Hierarchical Graphs. SIAM Journal on Optimization,11,4, 1065-1080,2001. 19. P. Mutzel, C. Gutwenger, R. Brockenauer, S. Fialko, G. W. Klau, M. Kr¨ uger, T. Ziegler, S. N¨ aher, D. Alberts, D. Ambras, G. Koch, M. J¨ unger, C. Buchheim, and S. Leipert. AGD: A Library of Algorithms for Graph Drawing. Proceedings of the 6th International Symposium on Graph Drawing, LNCS 1547,456-457,1998. 20. K. Sugiyama, S.Tagawa, and M.Toda. Methods for visual understanding of hierarchical system structures. IEEE Transaction on Systems, Man and Cybernetics, 11(2):109-125,1981. 21. J. Warfield. Crossing Theory and Hierarchy Mapping. IEEE Transactions on System, Man, and Cybernetics, SMC-7,7,502-523,1977.
Geometric Graphs with No Self-intersecting Path of Length Three J´ anos Pach1 , Rom Pinchasi2 , G´ abor Tardos3 , and G´eza T´oth4 1
City College, CUNY and Courant Institute of Mathematical Sciences, New York University, New York, NY 10012, USA [email protected] 2 Department of Mathematics, Massachusetts Institute of Technology, Cambridge, MA 02139, USA [email protected] 3 R´enyi Institute of the Hungarian Academy of Sciences, H-1364 Budapest, P.O.B. 127, Hungary [email protected] 4 R´enyi Institute of the Hungarian Academy of Sciences, H-1364 Budapest, P.O.B. 127, Hungary [email protected]
Abstract. Let G be a geometric graph with n vertices, i.e., a graph drawn in the plane with straight-line edges. It is shown that if G has no self-intersecting path of length 3, then its number of edges is O(n log n). This result is asymptotically tight. Analogous questions for curvilinear drawings and for longer paths are also considered.
1
Introduction
A geometric graph is a graph drawn in the plane so that its vertices are points and its edges are possibly crossing straight-line segments. We assume, for simplicity, that the points are in general position, i.e., no three points are on a line and no three edges pass through the same point. Topological graphs are defined similarly, except that now the edges are not necessarily rectilinear; every edge can be represented by an arbitrary continuous arc which does not pass through any vertex different from its endpoints. Throughout this paper, we also assume that any two edges have a finite number of common interior points and they properly cross at each of them. Clearly, every geometric graph is also a topological graph. Using this terminology, the fact that every planar graph with n vertices has at most 3n − 6 edges can be rephrased as follows: any topological graph with n vertices and more than 3n − 6 edges must have two edges that cross each other. This result is tight even for geometric graphs.
Work on this paper by J´ anos Pach and Rom Pinchasi has been supported by NSF grant CCR-00-98246, by PSC-CUNY Research Award 63382-0032. Work by J´ anos Pach and G´ abor Tardos has also been supported by Hungarian Science Foundation grant OTKA T-032452. Work by G´eza T´ oth has been supported by Hungarian Science Foundation grant OTKA T-038397.
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 295–311, 2002. c Springer-Verlag Berlin Heidelberg 2002
296
J´ anos Pach et al.
In the mid-sixties Avital and Hanani [AH66], Erd˝ os, and Perles initiated, later Kupitz [K79] and many others continued the systematic study of extremal problems for geometric graphs. In particular, they proposed the following general question. Let H be a so-called forbidden geometric configuration or a class of forbidden configurations. For example, H may consist of k pairwise crossing edges or may be the class of all configurations of k +1 edges, one of which crosses all the others, etc. What is the maximum number of edges that a geometric graph with n vertices can have without containing any forbidden subconfiguration? If H consists of k = 2 (pairwise) crossing edges, then, according to the previous paragraph, the answer is 3n − 6. For k = 3, this maximum is linear in n (see [AAPPS97]), but for larger values of k the best known bound due to Valtr is only O(n log n) [V98]. It is an exciting open problem to decide whether one can get rid of the logarithmic factor here. If H is the class of all configurations consisting of k + 1 edges, one of which crosses all the others, then the maximum number of edges √ is equal to (k + 2)(n − 3), provided that k = 1, 2, 3, and the maximum is O( kn) for large values of k (cf. [PT97]). For a survey of many similar results in Geometric Graph Theory, consult [P99]. The above questions can also be regarded as geometric analogues of the fundamental problem of Extremal Graph Theory [B78]: determine the maximum number of edges of all K-free graphs on n vertices, i.e., all graphs which do not contain a subgraph isomorphic to a fixed graph K. Denote this maximum by ex(n, K). In the present note, we consider the special instance of the above question when H consists of all self-intersecting straight-line drawings of a fixed graph K. In other words, what is the maximum number excr (n, K) of edges that a geometric graph with n vertices can have, if it contains no self-intersecting copy of K? Obviously, we have excr (n, K) ≥ ex(n, K), because if a graph contains no copy of K, then it cannot contain a self-intersecting copy either. Therefore, if K is not a bipartite graph, then excr (n, K) is quadratic in n. The question is more exciting for bipartite planar graphs. What happens if K = Pk (or K = Ck ), a path (or a cycle) of (an even) length k? The case where K = C4 is discussed in [PR02]. We analyze the case when K = P3 . The corresponding graph property is a relaxation of planarity: the geometric graphs satisfying the condition are allowed to have two crossing edges, but if this is the case, no endpoint of one of these edges can be joined to an endpoint of the other. Is it still true that the number of edges of such geometric graphs is O(n)? The following theorem provides a negative answer to this question. Theorem 1. The maximum number of edges of a geometric graph with n vertices, containing no self-intersecting path of length 3, satisfies excr (n, P3 ) ≤ cn log n, for a suitable constant c. Apart from the value of the constant, this bound cannot be improved.
Geometric Graphs with No Self-intersecting Path of Length Three
297
The proof of this result (presented in three different versions in the next three sections) applies to a slightly more general situation. Theorem 1 remains true for topological graphs whose edges are continuous functions defined on subintervals of the x-axis, i.e., every line perpendicular to the x-axis intersects each edge in at most one point. The topological graphs satisfying this condition are usually called x-monotone. On the other hand, a construction in Section 3 shows that Theorem 1 cannot be improved even for geometric graphs all of whose edges are crossed by a straight line. What happens if we drop the requirement of x-monotonicity? We do not have any example of a topological graph with n vertices and more than constant times n log n edges, in which every path of length 3 is simple, i.e., non-self-intersecting. The best upper bound we have is the following. Theorem 2. The maximum number of edges of a topological graph with n vertices, containing no self-intersecting path of length 3, is O(n3/2 ). As was pointed out by Tutte [T70], parity plays an important role in determining the possible crossing patterns between the edges of a topological graph. This may well be a consequence of the Jordan Curve Theorem: every Jordan arc connecting an interior point and an exterior point of a simple closed Jordan curve must cross this curve an odd number of times. In particular, Tutte showed that every topological graph with n vertices and more than 3n − 6 edges has two edges that not only cross each other, but (i) they cross an odd number of times, and (ii) they do not share an endpoint. (See also [H34].) This may suggest that Theorem 2 and perhaps any other bound of this type can be sharpened as follows. Theorem 3. The maximum number of edges of a topological graph with n vertices, containing no path of length 3 whose first and last edges cross an odd number of times, is O(n3/2 ). In Section 5 we prove this stronger statement. Somewhat surprisingly (to the authors), it turns out that this last result is asymptotically tight. More precisely, in Section 6 we establish Theorem 4. Let G be a bipartite graph on n vertices, containing no cycle of length 4. Then G can be drawn in the plane as an x-monotone topological graph with the property that any two edges belonging to a path of length 3 cross an even number of times. It is well known that there are C4 -free bipartite graphs of n vertices and at least constant times n3/2 edges (see e.g. [B78]). In Section 7, we consider geometric and x-monotone topological graphs with no self-intersecting path of length five. In this case, Theorem 9 provides a slightly stronger bound on the number of edges than those obtained for graphs with no self-intersecting P3 . We do not believe that Theorem 9 is tight. However, a recent
298
J´ anos Pach et al.
construction of Tardos [T02] shows that excr (n, Pk ) is superlinear in n, for any fixed value k ≥ 3. In the final section, we discuss a few related results and open problems.
2
A Davenport-Schinzel Bound for Double Arrays
In this section, we discuss the special case of Theorem 1 when G is a bipartite geometric (or x-monotone topological) graph, whose vertices are divided by the y-axis into two classes, A and B, and all edges of G run between these classes. We assume, for simplicity, that no two edges of G cross the y-axis at the same point. Let a1 b1 , a2 b2 , . . . , am bm be the edges of G listed from top to bottom, in the order of their intersections with the y-axis, where ai ∈ A and bi ∈ B for every i. Consider the corresponding double array (2 × m matrix) a1 a2 . . . am M= b1 b2 . . . bm It is easy to verify that if G is a geometric graph (or an x-monotone topological graph) without any self-intersecting path of length three, thenthe corre uvuv sponding matrix M does not contain any submatrix of the form F1 = ∗xx∗ ∗uu∗ or F2 = , where u = v, x = y and ∗ stands for an unspecified entry xyxy (see Fig. 1(a)).
y u
x
(a)
x u y
(b)
Fig. 1. (a) F2 is forbidden, (b) not necessarily forbidden if adjacent edges may cross
In what follows, we show that if a 2 × m matrix M having at most n distinct entries does not contain any forbidden submatrix of the above two types, then its number of columns is O(n log n). Therefore, the number of edges of G is at most O(n log n), as required by Theorem 1.
Geometric Graphs with No Self-intersecting Path of Length Three
299
If G is an x-monotone topological graph whose adjacent edges are allowed to cross, and we only require that the first and last edges of every path of length three must be disjoint, then the situation is slightly more complicated, because M may contain submatrices of the above forms (see Fig. 1(b)). However, in this case the following 2 × 6 submatrices are forbidden: v↔uvuv↔u (1) ∗ ∗xx∗ ∗ and
∗ ∗uu∗ ∗ y↔xyxy↔x
.
(2)
Here the signs ↔ indicate that the order of the first two columns and the order of the last two columns are not specified. Theorem 5. Let M be a 2 × m matrix with at most n distinct entries, all of whose columns are different. If M has no 2 × 6 submatrix of types (1) or (2), then m ≤ 17n log2 n. It follows from the construction at the end of Section 3, that the bound in Theorem 5 is tight apart from the value of the constant. In fact, for any n there exist a 2 × m matrix with at most n distinct entries having neither F1 nor F2 as a submatrix with m ≥ n log2 n/4. Proof. We need some definitions. Let a1 a2 . . . am M= b1 b2 . . . bm For any 1 ≤ i ≤ m, we say that ai is a leftmost (or rightmost) entry if ak = ai for every k < i (or k > i, resp.). Accordingly, ai is called a second leftmost (or second rightmost) entry if ak = ai for precisely one index k < i (or precisely one index k > i, resp.). Analogous terms are used for the entries bi in the second row of M . A set of consecutive columns of M is called a block. A block is said to be pure if all elements in the first row of the block are distinct and the same is true for the elements in the second row. Assume the columns of M are partitioned into l pure blocks. Consider now two consecutive pure blocks, B1 and B2 , consisting of the columns i+1, i+2, . . . , j and j + 1, j + 2, . . . , k, resp., for some 0 ≤ i < j < k ≤ n. Suppose that there is an element which appears in the first row of B1 as well as in the first row of B2 . That is, ap = aq for some i < p ≤ j and j < q ≤ k. We claim that either bq is a leftmost, second leftmost or rightmost entry, or bp is a rightmost, second rightmost or leftmost entry. Indeed, otherwise, using the fact that bq is neither a leftmost nor a second leftmost entry, we obtain that there exists an index r ≤ i such that br = bq . Since bq is not a rightmost entry, there is an index s > k such that bs = bq . Similarly, in view of the fact that bp is neither a rightmost nor a second rightmost entry, we can conclude that bs = bp for some s > k. Since
300
J´ anos Pach et al.
bp is not leftmost, there is a r ≤ i such that br = bp . Observe that now the columns r, r < p < q < s, s form a forbidden submatrix of type ∗ ∗uu∗ ∗ , y↔xyxy↔x a contradiction. A symmetric argument shows that if bp = bq for some i < p ≤ j and j < q ≤ k, then either aq is a leftmost, second leftmost or rightmost entry, or ap is a rightmost, second rightmost or leftmost entry. Thus, if we delete from M (and from its block decomposition) every column whose upper or lower element is a leftmost, second leftmost, rightmost, or second rightmost entry, the union of the remainders of any two consecutive blocks becomes pure. There are at most n distinct entries, each may appear in the first row and in the second row, so the number of deleted columns is at most 8n. The resulting matrix M can be decomposed into l/2 pure blocks. Repeating this process at most log2 l times, we end up with a matrix consisting of at least m − 8n log2 l columns that form a single pure block. Thus, we have m − 8n log2 l ≤ n. Applying the above procedure to the initial partition of M into l = m pure blocks, each consisting of a single column, the upper bound follows. For many other Davenport-Schinzel type results for matrices, consult [FH92]. As we have pointed out before, the last theorem implies that every geometric or x-monotone topological graph with n vertices and no path of length three whose first and last edges cross each other, has at most constant times n log n edges, provided that all of its edges can be stabbed by a line. Thus, we immediately obtain Corollary 1. The maximum number of edges of an x-monotone topological graph with n vertices, containing no path of length 3 whose first and last edges cross, is O(n log2 n). This result is slightly weaker than the bound in Theorem 1.
3
Proof of Theorem 1
We prove the following more general statement. Theorem 6. Let G be an x-monotone topological graph of n vertices, which has no self-intersecting path of length 3. Then G has at most constant times n log n edges. We assume without loss of generality that no two edges that share an endpoint cross each other. Otherwise, the two non-common endpoints of these edges must be of degree 1 or 2, because G has no self-intersecting path of length 3. So
Geometric Graphs with No Self-intersecting Path of Length Three
301
we can delete these endpoints, and complete the argument by induction on the number of vertices. It will be convenient to use the following terminology. If a vertex v is the left (resp. right) endpoint of an edge e, then e is said to be a right (resp. left) edge at v. It follows from our assumption on adjacent edges that the left and the right edges at a given vertex can be ordered from bottom to top. Let e1 = vu1 and e2 = vu2 be two right edges at a vertex v such that the x-coordinate of u1 is at most as large as the x-coordinate of u2 . We define the right triangle determined by them as the bounded closed region bounded by e1 , a segment of e2 ,, and a segment of the vertical line passing through u1 . The vertex v is called the apex of this triangle. Analogously, we can introduce the notion of left triangle. Construct a sequence of subgraphs G0 , G1 , G2 , . . . of G, as follows. Let G0 = G. If Gi has already been defined for some i, then let Gi+1 be the topological graph obtained from Gi by deleting at each vertex the bottom 2 and the top 2 left and right edges (if they exist). We delete at most 8 edges per vertex. Claim. For any k ≥ 0, every triangle determined by two edges of Gk contains at least 2k pairwise different triangles of G. Proof of Claim. By induction on k. Obviously, for k = 0, the claim is true, because every triangle contains itself. Assume that the claim holds for k − 1 (k > 0). Consider, e.g., a right triangle T in Gk , determined by the edges e1 = vu1 and e2 = vu2 , where the x-coordinate of u1 is at most as large as the x-coordinate of u2 . Suppose without loss of generality that e1 lies below e2 . Using the fact that e1 ∈ E(Gk ), we obtain that at u1 there are at least two left edges f1 , f2 ∈ E(Gk−1 ) which lie above e1 . Both of these edges must be entirely contained in T , otherwise we could find a self-intersecting path of length 3. Suppose that f1 lies below f2 . Let T1 and T2 denote the left triangles with apex u1 , determined by e1 and f1 , and by f1 and f2 , resp. Clearly, T1 and T2 both belong to Gk−1 , and they have disjoint interiors. By the induction hypothesis, both T1 and T2 contain 2k−1 pairwise different triangles. It follows that T contains 2k pairwise different triangles, as required. Now we can easily complete the proof of Theorem 6. Since every triangle is specified by a pair of edges meeting at its apex, the total number of different triangles is at most n3 . Hence, for k > 3 log2 n, the graph Gk cannot determine any triangle, and its number of edges is smaller than n. On the other hand, we have that |E(Gk )| ≥ |E(G0 )| − 8kn. Therefore, |E(G)| = |E(G0 )| ≤ 25n log2 n, completing the proof of Theorem 6. We close this section by showing that, up to the value of the constant c, Theorem 1 (and hence Theorem 6, too) is best possible. Let n = 2k be fixed. We (k) will recursively construct a sequence of bipartite geometric graphs Gi = Gi , i i−2 edges, and contains no i = 1, 2, . . . , k, such that Gi has 2 vertices, (i + 1)2 self-intersecting path of length 3. Furthermore, we will maintain the following properties for every i.
302
J´ anos Pach et al.
1. The vertices of Gi have distinct x-coordinates, which are all integers in the closed intervals [−2k , −2k + 2i − 1] and [0, 2i − 1]. Vertices with x-coordinates in the first (resp. second) interval are called left (resp. right). 2. Every edge of Gi connects a left vertex to a right vertex, and hence it must cross the vertical line (x = − 12 ). 3. The horizontal edges of Gi are of length 2k and form a perfect matching. If two vertices of u, v ∈ V (Gi ), are connected by a horizontal edge, than they are said to form a pair. 4. For any vertex v of Gi , the order of the edges incident to v according to their slopes coincides with the order according to the lengths of their projections to the x-axis. Let G1 consist of two vertices, (−2k , 0) and (0, 0), connected by an edge. Obviously, this meets the requirements. Assuming that we have already constructed Gi for some i, we show how to obtain Gi+1 . Let Gi denote the translate of Gi by a vector (2i−1 , Yi ), where Yi is a very large positive integer to be specified later. Let Gi+1 be the union of Gi and Gi , together with the following 2i−1 “new” edges: connect every left vertex v ∈ V (Gi ) to the right vertex v + (2k + 2i−1 , Yi ) ∈ V (Gi ), that is, to the right vertex forming a pair with the translate of v. See Fig. 2. Choose Yi so large that the slope of the new edges exceeds the slope of any line induced by the points of Gi (or by the points of Gi ). We have to check that Gi+1 has the required properties. We have |V (Gi+1 )| = 2|V (G)| = 2i+1 and |E(Gi+1 )| = 2|E(Gi )| + 2i−1 = (i + 2)2i−1 . Properties 1, 2, 3 and 4 are all inherited from Gi . To see that property 4 is maintained, it is sufficient to recall that both the slope and length of the x-projection of every new edge between Gi and Gi is larger than the corresponding values for the old edges. It remains to verify that Gi+1 does not contain a self-intersecting path of length 3. Assume to the contrary that there is such a path P in Gi+1 , and denote its edges by e1 = uv, e2 = vw, and e3 = wz. Since Gi (and thus Gi ) does not contain a self-intersecting path of length 3, at least one of these edges must run between Gi and Gi . Note that there cannot be two such edges, because all edges of Gi+1 running between Gi and Gi are parallel. It is also clear that e2 is not such an edge. Assume, without loss of generality, that e1 runs between Gi and Gi , and that we have u ∈ V (Gi ) and v ∈ V (Gi ). Thus, e2 and e3 belong to Gi . As v is a right vertex, w must be a left vertex, and both e2 and e3 are to the right of w. Since e3 crosses e1 , the slope of e3 must be smaller than that of e2 . In view of property 4, we conclude that the x-coordinate of z is smaller than the x-coordinate of v. This implies that the slope of the line connecting z and v is larger than the slope of e2 , contradicting our assumption.
Geometric Graphs with No Self-intersecting Path of Length Three
303
Fig. 2. The construction of Gi (i = 3)
4
A Strengthening of Theorem 6
The aim of this section is to establish the following stronger form of Theorem 6. Theorem 7. The maximum number of edges of an x-monotone topological graph with n vertices, containing no path of length 3 whose first and last edges cross, is O(n log n). Proof. Let G be an x-monotone topological graph with n vertices and m edges, containing no path of length 3 whose first and last edges cross. Our goal is to construct another topological graph G with n = 2n vertices and m ≥ m/2 − n edges, with the property that G has no path of length 3 whose first and last edges cross, and no two adjacent edges of G cross each other. Applying Theorem 6 to G , the statement follows. First, we split each vertex of G into into two vertices, one of them just a bit left to the other, so that every original edge e becomes an edge connecting the right copy of the left endpoint of e to the left copy of its right endpoint. The resulting x-monotone topological graph G0 has n = 2n vertices and m edges, it has no self-intersecting path of length three, and the right endpoint of any edge of G0 is distinct from the left endpoint of any other edge. In the rest of this section, the length of an edge means the length of its projection to the x-axis, and the terms shorter and longer will be used in the same sense. We write e = uv for an edge of G0 , whose left and right endpoints are u and v, resp. We call an edge e = uv long if it is the longest either among all edges uv or among all edges u v ∈ E(G0 ). Clearly, G0 has fewer than n long edges. Let e and e be two edges of G, where e is shorter than e , and we have either e = uv and e = uw, or e = vu and e = wu. We say that e is above e if v is above e . Similarly, we say e is below e if v is below e . Note that if e is above or below e then e is shorter, but e and e may cross several times. Let e = uv be an edge of G0 which is not long. By definition, there exist two edges, e = uw and e = zv ∈ E(G0 ), such that both of them are longer than
304
J´ anos Pach et al.
e. So e is either above or below e and e is also above or below e . However, e cannot be above both e and e . Indeed, otherwise u is above e while v is above e , so e and e cross, contradicting our assumption on G. Similarly, e cannot be below both e and e . Thus, each edge e = uv ∈ E(G0 ) which is not long either satisfies that e is above every longer edge uw and below every longer edge zv, or it satisfies that e is below every longer edge uw and above every longer edge zv. We can assume, by symmetry, that the former condition (which will be referred to as the monotonicity condition) holds for m ≥ (m − n )/2 = m/2 − n edges. Let G1 be the subgraph of G0 formed by these edges. We are now in a position to define G . As an abstract graph, G is identical to G1 . The locations of the vertices will coincide, too. For any edge e ∈ E(G1 ), denote by eˆ the corresponding edge of G . We draw the edges of G one by one, in decreasing order of length. If e in G1 is neither above nor below another edge, set eˆ = e. If e = uv is above (below) at least one other edge, let e− be the shortest edge such that e is above e− (let e+ be the shortest edge such that e is below e+ , resp.). Draw eˆ in such a way that all of its internal points lie strictly above eˆ− and below eˆ+ (if these edges exist). Notice that, if they exist, e+ and e− are longer than e, so eˆ+ and eˆ− are already defined. We make sure during the construction that, if e+ exists, it passes above u, if e− exists, it passes below v (see property 2 below), and if both of them exist, they are disjoint (see property 4 below). We define eˆ to follow e, except in the intervals where eˆ+ is below e or eˆ− is above e. In these intervals, let eˆ run just below eˆ+ or just above eˆ− , close enough not to intersect any further edges and going on the same side of every vertex. See Fig. 3.
e^+
e^
e
e^Fig. 3. The construction of the edge eˆ in G
Geometric Graphs with No Self-intersecting Path of Length Three
305
We claim that the resulting graph G has the following properties. 1. If e is below (above) e in G1 , then every interior point of eˆ is below (above, resp.) eˆ . 2. If e is below (above) e in G1 , then the endpoint of e which is not an endpoint of e is below (above, resp.) eˆ. 3. If e, e , and e form a path in G1 and e is longer than e , then eˆ and e do not cross. 4. If e, e , and e form a path in G1 then eˆ and eˆ do not cross. We verify these properties by showing that if they hold for the partially drawn graph, they do not get violated when we add an extra edge eˆ. (1) By the monotonicity, if there exists at least one edge f such that e is below f , then the shortest among them, e+ , must be below all others. Similarly, e− (if exists) must be above all other edges that e is above. Therefore, as property 1 has held so far, it does not get violated now, provided that eˆ is in between eˆ− and eˆ+ , which is the case. (2) Let e = uv and assume that e = uw is above e. By definition, w is above e and, by the monotonicity condition, w is above e− , if the latter exists. As property 2 has held so far, w is above eˆ− , so w must be above eˆ. Similarly, if e = zv is below e, then z is below eˆ. (3) Note that e is above or below e. By symmetry, we can assume without loss of generality that e is below e. By monotonicity, this means that they share their right endpoints. Here e and e do not cross, as they are first and last edges of a path of length 3, and the left endpoint of e is below e. So every point of e must be below e or to the right of the right endpoint of e. If e+ exists, we can apply property 3 to the edges e+ , e , e , and find that eˆ+ does not cross e . By the construction, wherever eˆ runs below e, it follows eˆ+ , so eˆ is disjoint from e . (4) We consider two cases. If both e and e are shorter than e , then one of them is below and the other is above e (monotonicity). Thus, by property 1, eˆ (drawn before the other two) separates eˆ from eˆ , so they cannot cross. We may assume that e is shorter than e , so in the remaining case e is longer than e . The edge e is below or above e , and we can again assume, by symmetry, that e is below e . Applying property 3 to the path e , e , e, we find that e is disjoint from eˆ . By property 2, the left endpoint of e lies below eˆ . Thus, all points of e must be below eˆ or to the right of its right endpoint. As eˆ follows eˆ− wherever it runs above e, it is enough to show that if e− exists, eˆ− is disjoint from eˆ . If e− = e , this follows from property 1, otherwise, from property 4 of the initial configuration (before eˆ has been drawn). Observe that, by property 1, no two adjacent edges of G cross each other and, by property 4, the same is true for second neighbors. Hence, we can indeed apply Theorem 6 to G , and Theorem 7 follows.
306
5
J´ anos Pach et al.
Forbidden Subgraphs – Proof of Theorem 3
For any k ≥ 2, let Fk denote a graph with vertex set V (Fk ) = {x, y} ∪ {bi : 1 ≤ i ≤ k} ∪ {cij : 1 ≤ i < j ≤ k} and edge set E(Fk ) = {xbi , ybi : 1 ≤ i ≤ k} ∪ {cij bi , cij bj : 1 ≤ i < j ≤ k}. We need the following theorem, which can be obtained by a straightforward generalization of a result of F¨ uredi [F91]. Theorem 8. For any fixed integer k ≥ 2, let ex(n, Fk ) denote the maximum number of edges of an Fk -free graph with n vertices. Then we have ex(n, Fk ) = O(n3/2 ). Let G be a topological graph with n vertices, containing no path of length 3 whose first and last edges cross an odd number of times. To establish Theorem 3, it is sufficient to verify that the abstract graph obtained from G by disregarding how the edges are drawn does not have a subgraph isomorphic to F4 . In fact, it is enough to concentrate to a the subgraph F4 of F4 induceed by the vertex set {x, y} ∪ {bi : 1 ≤ i ≤ 4} ∪ {cij : 1 ≤ i < j ≤ 3}. Notice that F4 is a subdivision of K5 : it can be obtained from K5 by replacing four of its edges (a triangle and an edge not incident to the triangle) by paths of length two. This means that a topological graph isomorphic to F4 can be also considered as a topological graph isomorphic to K5 (simply remove the subdividing points). As K5 is not a planar graph, any topological graph isomorphic to it must have at least one crossing. Furthermore, by Tutte’s theorem [T70], there must exist two non-adjacent edges that cross an odd number of times. Thus, any topological graph isomorphic to F4 has two edges that cross an odd number of times and they are either nonadjacent edges of the underlying K5 or portions of two such edges. However, any two edges with this property can be extended to a self-intersecting path of length 3. Consequently, F4 is not isomorphic to a subgraph of G, and Theorem 3 follows.
6
Drawing C4 -Free Graphs – Proof of Theorem 4
Let G be a C4 -free bipartite graph with vertex set V (G) = A ∪ B, where A = {a1 , a2 , . . . , an } and B = {b1 , b2 , . . . , bn }. The edge set of G is denoted by E(G). We now construct a drawing of G. Pick 2n points, a1 , . . . , an , b1 , . . . bn , on the x-axis, from left to right in this order. These points will be identified with the vertices of G. For every edge ai bj ∈ E(G), draw an x-monotone arc eij connecting ai to bj , according to the following rules: (i) for any k > i, the arc eij passes above ak if and only if ak bj ∈ E(G); (ii) for any l < j, the arc eij passes above bl if and only if ai bl ∈ E(G); (iii) no two distinct arcs “touch” each other (internal crossings are proper).
Geometric Graphs with No Self-intersecting Path of Length Three
307
Notice that, unless two arcs share an endpoint, the parity of their number of intersections is determined by these rules. Take two non-adjacent edges ai bj , ak bl ∈ E(G) that belong to a path of length 3. We have to distinguish four different cases: 1. 2. 3. 4.
i < k, i < k, i < k, i < k,
j < l, j < l, l < j, l < j,
and and and and
ak bj ∈ E(G); ai bl ∈ E(G); ai bl ∈ E(G); ak bj ∈ E(G).
Consider the first case. By drawing rule (i), the arc eij passes below ak . By rule (ii), ekl passes above bj . In view of rule (iii), this implies that eij and ekl cross an even number of times, as required. The second case can be treated similarly and is left to the reader. In the third case, applying rule (i), we obtain that ak lies above eij . It is sufficient to show that the same is true for bl . At this point, we use that G is C4 -free: since ai bj , bj ak , ak bl ∈ E(G), we have ai bl ∈ E(G). By rule (ii), this implies that bl is above eij , as required. The last case follows in the same way, by symmetry. So far we have checked that in our drawing any two non-adjacent edges cross an even number of times. It is not hard to extend the same property to all pairs of edges, even if they share endpoints. To this end, we slightly modify the arcs eij in some very small neighborhoods of their endpoints. Clearly, this will not effect the crossing patterns of non-adjacent pairs. Fix a vertex ai . Redraw the arcs eij incident to ai so that the counterclockwise order of their initial pieces in a small neighborhood of ai will be the same as the order of x-coordinates of their right endpoints. Consider now two arcs, eij , eil , (l < j), incident to ai . By rule (ii), bl lies below eij . On the other hand, after performing the local change described above, the initial piece of eil will also lie below eij . This guarantees that eij and eil cross an even number of times. Repeating this procedure for each vertex ai , and its symmetric version for each bj , we obtain a drawing which meets the requirements of Theorem 4.
7
Paths of Length Five
If we exclude self-intersecting paths of length five (rather than three), we can establish a slightly better upper bound on the number of edges of a geometric or x-monotone topological graph. Theorem 9. Let G be an x-monotone topological graph of n vertices with no self-intersecting path of length 5. Then G has at most constant times n log n/ log log n edges. We modify the proof of Theorem 6, and use the same notation. We call an edge a left edge at its right endpoint and a right edge at its left endpoint. Suppose G has nm edges with m ≥ 8. Construct a sequence of subgraphs G, G0 , G0 , G0 , G1 , G1 , G1 , G2 , . . . of G, as follows. Let G0 be the topological
308
J´ anos Pach et al.
graph obtained from G by deleting each vertex of degree at most m 2 . Notice that no two edges of G0 that share an endpoint cross each other. Otherwise, since all degrees are at least 5, those two edges could be extended to a crossing path of length 5. Thus, the left and the right edges at a vertex are naturally ordered from top to bottom. Similarly, no path of length 3 or 4 is self-intersecting. 1. If Gi has already been defined for some i, let Gi denote the topological graph obtained from Gi by deleting the bottom and the top left and right edges at each vertex (if they exist). We delete at most four edges per vertex. 2. If Gi has already been defined for some i, let Gi denote the topological graph obtained from Gi by deleting the bottom and the top left and right edges at every vertex (if they exist). We delete at most four edges per vertex. 3. If Gi has already been defined for some i, let Gi+1 be the topological graph obtained from Gi by deleting recursively each vertex of degree at most m 2, . Clearly, as long as so that all vertices of Gi+1 have degree higher than m 2 the average degree of Gi is at least m, it cannot decrease in this step. Let ai denote the average degree in Gi . It is easy to see that a0 ≥ 2m and m ai ≥ ai−1 − 16 as long as ai−1 − 16 ≥ m. So, we have a 16 ≥ m. Therefore, m G 16 still determines at least one (actually, many) triangle(s). Recall that a left (right) triangle at a vertex is determined by two left (right, resp.) edges of the vertex, and it is the region bounded by one of the edges, a piece of the other edge, and a vertical interval. It is sufficient to establish the following. m Claim. For any 0 ≤ k ≤ 16 , every triangle determined by two edges of Gk k m contains at least 2 − 2 pairwise different triangles of G. m Indeed, assuming that the Claim is true, a triangle determined by G 16 m m 16 3 contains at least 2 − 2 triangles, and this number is at most n . It follows that m ≤ c log n/ log log n, as required by the theorem. Proof of Claim. By induction on k. Obviously, for k = 0, the assertion is true, because every triangle contains itself. Assume that the claim holds for k − 1 (k > 0). Consider a right triangle T in Gk , determined by the edges e1 = vu1 and e2 = vu2 , where the x-coordinate of u1 is at most as large as the x-coordinate of u2 . Suppose without loss of generality that e1 lies below e2 . Since e1 ∈ E(Gk−1 ), there is at least one left edge, f1 ∈ E(Gk−1 ), at u1 above e1 . This edge, f1 = w1 u1 , must entirely be contained in T , otherwise we could find a self-intersecting path of length 3. Since f1 ∈ E(Gk−1 ), there is at least one right edge, f2 ∈ E(Gk−1 ), at w1 below f1 . Similarly, this edge, f2 = w1 w, must be entirely contained in the triangle determined by e1 and f1 . Therefore, f2 must also lie in T . See Fig. 4. The degree of w in Gk−1 is at least m 2 . In view of the fact that there is no self-intersecting path of length 5 or shorter, none of these edges can cross e1 , e2 , f1 , and f2 . Therefore, all of them are entirely −2 triangles with pairwise disjoint interiors, inside T . They determine at least m m2 k−1 each of which contains at least 2 − 2 further triangles, and we are done by induction.
Geometric Graphs with No Self-intersecting Path of Length Three
309
u2
v w u1 Fig. 4. The edges at w are all in T
8
Related Problems
A. Theorems 1 and 6 easily imply Corollary 2. For any tree T other than a star, there exists a constant c(T ) such that every geometric (or x-monotone topological) graph G with n vertices and more than c(T )n log n edges contains a self-intersecting copy of T . That is, we have excr (n, T ) ≤ c(T )n log n. Indeed, deleting one-by-one every vertex of G whose degree is smaller than |V (T )|, we end up with a graph G having at most n vertices and at least (c(T ) log n − |V (T )|)n edges. If c(T ) is sufficiently large, then G has a selfintersecting path of length 3. Using the fact that the degree of every vertex in G is at least |V (T )|, this path can be extended to a copy of T in G (and hence in G). B. A slight modification of the proof of Theorem 1 gives Corollary 3. For any positive integer k, there exists a constant ck with the property that every geometric graph with n vertices and at least ck n log n edges has two adjacent vertices, u and v, and 2k edges incident to them, uu1 , uu2 , . . . , uuk and vv1 , vv2 , . . . , vvk , such that uui crosses vvj for every pair 1 ≤ i, j ≤ k. C. We conjecture that Theorem 1 can be generalized to all topological graphs with with no self-intersecting path of length 3. Recently, we have proved that if G is an x-monotone topological graph with n vertices, all of whose edges cross the yaxis, and G has no self-intersecting path of length 4, then |E(G)| = O(n log1/2 n). It is interesting to note that one cannot guarantee the existence of any specific crossing pattern of a path of length 4, even if the number of edges is at least
310
J´ anos Pach et al.
Ω(n log n). Indeed, the construction in Section 3 provides such a geometric graph with no self-intersecting path of length 3. On the other hand, a convex, balanced, complete bipartite geometric graph, all of whose edges cross the y-axis, has no path of length 4, whose only self-intersection occurs between its first and last edges. D. Any drawing of K3,3 , a complete bipartite graph with 3 vertices in each of its classes, has two non-adjacent edges that cross each other. Clearly, any two edges belong to a cycle of length 4, so excr (n, C4 ) ≤ ex(n, K3,3 ) = O(n5/3 ). This bound has been recently improved to O(n8/5 ) by Pinchasi and Radoiˇci´c [PR02]. It seems likely that the best possible bound is close to n3/2 . It also follows from Theorem 8 that excr (n, C6 ) = O(n3/2 ), and it generalizes to topological graphs. On the other hand, we have excr (n, C6 ) ≥ ex(n, C6 ) ≥ cn4/3 , for a suitable constant c > 0 (see [BS74]). For C4 -free graphs this bound is almost tight. Theorem 10. Let G be a C4 -free geometric (or x-monotone topological) graph on n vertices. If G has no self-intersecting cycle of length 6, then G has O(n4/3 log2/3 n) edges. Proof. Assume without loss of generality that the left end of an edge is not the right end of another edge in G. This can be achieved by splitting the vertices in two as in the proof of Theorem 7. Let G have n vertices and |E(G)| = m > log n c n4/3 log2/3 n edges. For p = 2cn |E(G)| < 1, color randomly and independently with probability p each vertex of G red. Let G be the subgraph of G induced by the red vertices. Let i(G ) denote the number of self-intersecting paths of length 3 in G . Deleting one edge from each such path, we obtain a graph with no self-intersecting path of length 3. Thus, in view of Theorem 1, we have |E(G )| − i(G ) < c|V (G )| log |V (G )|, for some positive c. Taking expected values, this yields p2 |E(G)| − p4 i(G) < cpn log n. n 3 We obtain i(G) > 8c|E(G)| 2 n2 log2 n . If c is large enough, then i(G) > 2 , and there must exist two self-intersecting paths of length 3 connecting the same pair of vertices. These paths cannot share an internal vertex as that would lead to a C4 . Therefore, putting them together, we get a C6 which intersects itself at least twice.
Geometric Graphs with No Self-intersecting Path of Length Three
311
References AAPPS97. AH66. B78. BS74. F91. FH92. H34. K79. P99. PT97. PR02. T02. T70. V98.
P. K. Agarwal, B. Aronov, J. Pach, R. Pollack, and M. Sharir, Quasiplanar graphs have a linear number of edges, Combinatorica 17 (1997), 1–9. S. Avital and H. Hanani, Graphs (in Hebrew), Gilyonot Lematematika 3 (1966), 2–8. B. Bollob´ as, Extremal Graph Theory, Academic Press, New York, 1978. A. Bondy and M. Simonovits, Cycles of even length in graphs, J. Combinatorial Theory, Ser. B 16 (1974), 97–105. Z. F¨ uredi, On a Tur´ an type problem of Erd˝ os, Combinatorica 11 1 (1991), 75–79. Z. F¨ uredi and P. Hajnal, Davenport-Schinzel theory of matrices, Discrete Mathematics 103 (1992), 233–251. ¨ H. Hanani (C. Chojnacki), Uber wesentlich unpl¨ attbare Kurven in dreidimensionalen Raume, Fundamenta Mathematicae 23 (1934), 135–142. Y. Kupitz, Extremal Problems in Combinatorial Geometry, Aarhus University Lecture Notes Series 53, Aarhus University, Denmark, 1979. J. Pach, Geometric graph theory, in: Surveys in Combinatorics, 1999 (J. D. Lamb and D. A. Preece, eds.), London Mathematical Society Lecture Notes 267, Cambridge University Press, Cambridge, 1999, 167–200. J. Pach and G. T´ oth, Graphs drawn with few crossings per edge, Combinatorica 17 (1997), 427–439. R. Pinchasi and R. Radoiˇci´c, On the number of edges in geometric graphs with no self-intersecting cycle of length 4, to appear. G. Tardos, On the number of edges in a geometric graph with no short self-intersecting paths, to appear. W. T. Tutte, Toward a theory of crossing numbers, J. Combinatorial Theory 8 (1970), 45–53. P. Valtr, On geometric graphs with no k pairwise parallel edges, Discrete and Computational Geometry 19 (1998), 461–469.
Two New Heuristics for Two-Sided Bipartite Graph Drawing Matthew Newton1 , Ondrej S´ ykora1 , and Imrich Vrt’o2 1
Department of Computer Science, Loughborough University Loughborough, Leicestershire LE11 3TU, The United Kingdom {m.c.newton,o.sykora}@lboro.ac.uk, Fax: +44 (0)1509 211 586 http://parc.lboro.ac.uk/ 2 Institute of Mathematics, Slovak Academy of Sciences D´ ubravsk´ a 9, 842 35 Bratislava, Slovak Republic [email protected], Fax: +421 2 59306522
Abstract. Two new heuristic strategies are studied based on heuristics for the linear arrangement problem and a stochastic hill-climbing method for the two-sided bipartite crossing number problem. These are compared to the standard heuristic for two-sided bipartite drawing based on iteration of the barycentre method. Our experiments show that they can efficiently find good solutions.
1
Introduction
Graph drawing addresses the problem of finding a layout of a graph that satisfies given aesthetic and readability objectives. One standard problem with the drawing of bipartite graphs is that of two layer automatic drawing where the two vertex partitions are put in distinct points on two parallel lines and edges are drawn as straight line segments between the two lines. This type of drawing is the basic building block used for drawing hierarchical graphs [5,14,20] or producing row-based vlsi layouts [17]. The most important objective is probably minimisation of the number of crossings in the drawing, as the aesthetics and readability of graph drawings depend on the number of edge crossings (see [16]). vlsi layouts containing less crossings are more easily realisable and consequently cheaper. There are two basic variants of the problem: one-sided and two-sided crossing minimisation. In the one-sided problem the vertices of one part of the bipartite graph are placed in fixed positions on one line. The vertices of the other part are placed on the other line and their positions are found so that the number of pairwise edge crossings is minimised. The two-sided bipartite crossing number problem (or just the bipartite crossing number problem) is if the vertices on both sides are not restricted. Unfortunately, both problems are np-hard [7,8]. A lot of different methods have been designed to solve the one-sided problem—heuristics
Research of all the authors was supported by the epsrc grant GR/R37395/01. Research of the last two authors was supported by the Slovak Scientific Grant Agency grant No. 2/7007/20.
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 312–319, 2002. c Springer-Verlag Berlin Heidelberg 2002
Two New Heuristics for Two-Sided Bipartite Graph Drawing
313
and approximation algorithms (see e.g. [1,4]). For the two-sided bipartite problem a common technique is to apply a one-sided method iteratively. In [10] the one-sided methods, barycentre, lr-Opt (branch and cut method of [10]), split, median, stochastic, greedy-switch, assign and greedy-insert were applied iteratively until there was no change, i.e. until a local minimum had been achieved. The resulting ranking of the heuristics was as above. The iterated barycentre method was the best among the tested methods both in terms of quality and computation time. An interesting observation by the authors of [10], for graphs of up to about 15 vertices on both sides, was that for the graphs with a density of 10%, the resulting number of crossings were 5 to 33 times larger than the optimal value. In this paper we suggest two new heuristic strategies. The first is based on the result in [18] showing a strong relation between the linear arrangement problem of a bipartite graph and its bipartite crossing number. We used two different methods to find a solution to the linear arrangement problem which implies respective permutations of vertices on both sides (layers). One (linear arrangement based on Fiedler’s vector: laf-method) is based on computing the graph’s second laplacian eigenvalue and its corresponding vector, usually called Fiedler’s vector [9]. The other (linear arrangement based on Koren and Harel’s method: lakh-method) is based on the multiscale method of Koren and Harel [12]. The second strategy, stochastic hill-climbing (sh)-method, is based on hill-climbing, a standard optimisation technique, and randomised swapping of vertices. In comparison with genetic algorithms or simulated annealing, stochastic hill-climbing is simpler and faster. Our method is different from the method of [3], which is also called ‘stochastic’ in [10]. It also differs from the greedy-switch heuristic of [6] and from sifting [13] which are based on the swapping of neighbouring vertices. In our experiments we compared the above three methods with the iterated barycentre (ib)-method. The results show that both la* -methods usually outperform the ib-method, especially lakh-method, which produces good drawings in an acceptable running time. The sh-method often produces the best results (see Table 1, shown instead of a graphical comparison due to lack of space).
2
Notations
Let G = (V, E), V = V0 ∪ V1 be a bipartite graph with vertex partitions V0 and V1 . A bipartite drawing of G is obtained by placing the vertices of V0 and V1 into distinct points on two horizontal lines y0 and y1 , respectively, and drawing each edge with one straight line segment. Any bipartite drawing of G is identified by two permutations π0 and π1 of the vertices on y0 and y1 . The problem of the two-sided bipartite drawing of G is to find permutations π0 and π1 that minimise the number of pairwise edge crossings in the corresponding bipartite drawing. The problem of the one-sided bipartite drawing of G is the same, except the permutation π1 is fixed.
314
Matthew Newton, Ondrej S´ ykora, and Imrich Vrt’o
Let bcr(G, π0 , π1 ) denote the total number of crossings in the bipartite drawing represented by the permutations π0 and π1 . The bipartite crossing number of G, denoted by bcr(G), is the minimum number of crossings over all π0 and π1 . Clearly, bcr(G) = minπ0 ,π1 bcr(G, π0 , π1 ). Given an arbitrary graph G = (V, E), the linear arrangement problem is to determine a bijection f : V → {1, 2, 3, ..., |V |} such that uv∈E |f (u) − f (v)| is minimised. This minimum value, whose computation is np-hard [8], is denoted by L(G). Furthermore, dv denotes the degree of v, δG the minimum degree of G and ∆G , the maximum degree of G.
3
Linear Arrangement Problem Based Methods
The bipartite crossing number problem was studied in [18] and a connection between this problem and the linear arrangement problem was established. Lower and upper bounds for bipartite crossing number bcr(G) were derived, where the main term is the optimal arrangement value: Theorem 1 Let G = (V0 , V1 , E), then 1 1 2 δG L(G) − dv ≤ bcr(G) ≤ 5∆G L(G). 12 36 v∈V
By using this result, a polynomial time approximation algorithm [18] with performance guarantee O(log n) from the optimal was obtained for the bipartite crossing number problem if ∆G = O(δG ). The algorithm is based on an approximation algorithm for the linear arrangement problem, where an approximated solution of the linear arrangement problem is found and then the vertices of the partitions of V0 and V1 are put on the lines y0 and y1 in the same order as produced for the linear arrangement problem. Using this idea, we can use any heuristic that solves the linear arrangement problem to produce the pair of permutations π0 and π1 . In [9] a heuristic is suggested that solves the linear arrangement problem by computing the corresponding (so called Fiedler’s) eigenvector f to the smallest positive Laplacian eigenvalue λG of the graph G. Recall that the Laplacian of a graph G is the matrix I(G) − A(G), where A(G) is the adjacency matrix of the graph G and I(G) is the diagonal matrix with vertex degrees on the diagonal, i.e. ivv = dv , and iuv = 0 if u = v and the Fiedler’s eigenvector f fulfills: (I(G) − A(G))f = λG f . Using this approximation of linear arrangement we get the laf-method shown in Algorithm 1. The other method (lakh-method) is based on the multiscale method of Koren and Harel [12] that computes an approximation of the linear arrangement.
4
Stochastic Hill-Climbing Method
The space of orderings of vertices of both sides for two-sided bipartite drawing problem can be represented by all pairs of permutations of {0, 1, 2, . . . , n0 − 1},
Two New Heuristics for Two-Sided Bipartite Graph Drawing
315
Algorithm 1. “Linear Arrangement based on Fiedler’s vector” (laf-method) find smallest positive Laplacian eigenvalue λG or a good approximation find corresponding eigenvector (Fiedler vector) construct approximation to the solution of the Linear Arrangement Problem construct permutations π0 and π1 evaluate the number of crossings for the pair of permutations
and of {0, 1, 2, . . . , n1 − 1}, where n0 and n1 are the number of vertices in V0 and V1 , respectively. To find a solution of the two-sided bipartite drawing problem means searching this space for a pair of permutations providing the minimum number of crossings. To move across the space we might use some type of steps, evaluate a new visited pair of permutations, accept it if it fulfills a condition (e.g. it has lower or equal number of crossings) and continue to search from the new accepted permutation. If the new permutation was not accepted we continue from the old one. The starting permutations are given by the input. Algorithm 2 shows the specific method we used.
Algorithm 2. “Stochastic Hill-Climbing Method” (sh-method) repeat until (termination-condition) randomly choose one of the sides 0 or 1 randomly choose two different vertices on the chosen side swap their positions evaluate the number of crossings for the new pair of permutations if the number of crossings decreases then keep the new pair of permutations else return to the previous pair of permutations
The termination condition can be defined by the number of iterations, or the number of iterations that have passed since the last swap that gave an improvement to the number of crossings (the number of stagnations). According to our experience, the termination should happen if the number of stagnations exceeds a value α ∗ density/(density + β) where density = |E|/|V |, and α, β are proper constants. For the sizes of our graphs these constants could be: α = 1350, β = 65. In our experiments we ran the sh-method while the number of crossings was higher than that achieved by the ib-method, the laf-method and lahk-method. The sh-method program also had a maximum time limit of five minutes and a few graphs did not complete within this limit. For some graphs sh-method stagnated and did not reach the number of crossings of the ib (this includes e.g. leonardo-90x64 and hyper-9) or la* -methods (this includes e.g. bcspwr01 and
316
Matthew Newton, Ondrej S´ ykora, and Imrich Vrt’o
cycle-100). An asterisk in Table 1 indicates one of the previous two conditions. Some graphs completed in less than 0.00005 second, so due to rounding it looks like they finished immediately (climb-100x100-t10 and ball-100x100). The number of crossings that each algorithm reached, together with the time taken, is shown in Table 1; ib-method in columns two and three, laf-method in columns five and six, lakh-method in columns eight and nine. The running times of shmethod necessary to achieve the number of crossings equal to or below that of the ib–, laf– and lakh-methods are shown in columns four, seven and ten, respectively. The best number of crossings found for each graph is shown in boldface.
5
Experiments
Our algorithms were implemented in c, running on 50 Sun ULTRAsparc 5 workstations running Solaris 7. The algorithms were compiled with the gnu c compiler version 2.95.2. One of the computers ran a job control system, written in Perl, to run experiments continuously on the other machines. The experiments for the ib–, laf– and lakh-methods were run first. These programs output the pair of permutations of the nodes in each graph, π0 followed by π1 , from which the number of crossings was counted. Before each experiment, π0 and π1 were randomised (this did not affect the la* -methods, which do not need an initial permutation). The quality of the results of the la* -methods depends on the quality of the approximation of L(G) for a graph G. To compute the Fiedler’s eigenvector in the laf-method we used the procedure jacobi from Numerical Recipes [15]. Although the jacobi procedure is not too efficient, it gives trustworthy results and is recommended for problems of small-to-moderate order. Typical n × n matrices require 12n3 to 20n3 operations. In the lakh-method we used the multiscale algorithm of Koren and Harel [12] for solving the linear arrangement problem running in linear time in the graph size (|V | + |E|). Apart from meshes, the lakh-method gave better results than the laf-method. It is also much faster, especially for larger graphs. Thanks are due to Yehuda Koren who kindly provided us their procedure so we were able to test this method. All ib–, laf– and lakh-methods were run ten times on each graph and the average number of crossings and running time were recorded. A new set of experiments were then run for the sh-method. The algorithm was run thirty times for each graph. For the first, second and third ten runs the program halted when the number of crossings was equal to or below that of the ib–, laf–, lakh-methods, respectively. As in the first set of experiments, π0 and π1 of each graph were randomised before each test run. Graph Test Sets. For our experiments we used the classes of graphs from [4] that contain ‘synthetic’ bipartite graphs with a known bipartite crossing number, bipartite graphs extracted from digitised images (originally suggested by Knuth in the Stanford Graphbase [11]) and from test data retrieved from US National Institute of Standards and Technology [2]. For our tests we also added
Two New Heuristics for Two-Sided Bipartite Graph Drawing
317
the following graphs for which we either know, or believe we know, the optimum drawings. Among these are cycles (with bipartite crossing number n2 − 1, if there are n vertices in the cycle, n is even), rectangular meshes, square n × n meshes (with supposed bipartite crossing number 43 n(n − 1)(n − 2) + 1) and hypercubes (see [19]). Finally, we also used randomly generated graphs. Random Graphs. The random graphs we used were generated based on edge density. The generator takes two arguments: n, the number of nodes the graph should have, and p ∈ [0..100] that determines the percentage chance that an edge will exist between two nodes. n must be an even number, and the graph is generated with n2 nodes in each part. The general graphs were generated having sizes n ∈ [20, 40, 60, 80, 100, 200, 400, 600, 800, 1000] and densities of 10%, 1% and 0.1%. Acknowledgement The authors wish to thank Yehuda Koren and Irene Finocchi, for making available their software, and Mark Withall for useful discussions during the preparation of this paper. Table 1. Comparisons between ib-method (columns two and three), laf-method (columns five and six), lakh-method (columns eight and nine) and sh-method. In columns four, seven and ten are the running times necessary for sh-method to achieve the number of crossings equal to or below that of the ib–, laf– and lakh-methods, respectively. Time is in seconds. Graph Name a-100x100 a-87x81 add20 andywarhol-100x65 ball-100x100 barpermute-100x100 bars-100x100 bcspwr01 bcsstk15 brick-100x100 camil-100x78 can61 cbar-100x100 cbar-20x20 cbar-50x50 climb-100x100-t10 climb-100x100-t100 climb-100x100-t110 climb-100x100-t120 climb-100x100-t130 climb-100x100-t140 climb-100x100-t150 climb-100x100-t160 climb-100x100-t20 climb-100x100-t30 climb-100x100-t40 climb-100x100-t50 climb-100x100-t60 climb-100x100-t70 climb-100x100-t80 climb-100x100-t90 climb-100x100 climb-20x20 climb-40x40 climb-60x60 climb-80x80 cycle-100 cycle-1000 cycle-20 cycle-200 cycle-300
IB-method Crossings 2550802 2414484 3621791 1893498 947575 3175608 3517232 2954 889155 501133 1559231 69842 88815 465 3870 19276 544406 672990 760146 989397 1355640 2627049 3796488 83505 136135 169887 217630 239888 271755 268910 341906 997171 1316 24032 131937 415731 467 6639 48 1057 1813
SH to LAF-method IB Time Time Crossings Time 0.0031 0.3989 2716464 19.3547 0.0025 0.8535 1327488 2.5816 1177229 1296.39 0.4223 0.0088 0.0074 * 2856377 2.248 0.004 0 934566 9.413 0.004 2.6106 4161703 5.4557 0.0325 0.0324 2075771 6.7551 0.0019 0.0029 464 0.2698 0.1933 * 727592 923.3729 473653 24.6587 0.0171 0 0.0078 * 2076490 3.7254 0.0026 0.0075 12788 1.1197 0.0027 * 88815 6.4762 0.0004 0.0018 19 0.0314 0.0015 19.2498 3870 0.6231 0 10824 10.7103 0.0077 0.0066 0.0182 536316 29.5412 0.0071 0 604213 6.1009 0.0062 0.0116 655080 5.3363 0.0093 0 923308 6.1088 0.0138 0 1081502 5.6321 0.0155 0 1690572 5.7368 0.0297 0 2697887 5.6074 0.0087 0 39548 11.8175 0.0062 0.0022 75347 14.7937 0.0082 0.0087 100168 15.6475 0.0078 0.038 203147 18.0365 0.0067 0.0406 151225 19.583 0.0066 0.05 178569 20.3396 0.0076 0.1685 298802 21.2215 0.0084 0.0457 224044 24.6957 0.0084 0 914106 5.539 0.0004 0 1084 0.0322 0.0016 0.0001 19797 0.3074 0.004 0 109592 0.9228 0.005 0 335135 2.2201 0.0043 * 49 0.7583 1.1338 * 499 4875.714 0.0001 0.0004 9 0.009 0.0198 * 99 10.3766 0.054 * 149 41.6743
SH to LAKH-method LAF Time Crossings Time 0.0111 1301275 15.888 25.6836 1301275 15.034 51.7084 1021504 37.708 11.4422 2784605 17.056 0.0068 749982 9.038 0.0162 2040676 18.829 * 2153777 21.607 * 422 1.263 * 741208 36.756 0.0011 248575 10.123 1.2589 1708444 15.594 * 12847 3.835 * 88815 8.597 * 19 0.515 21.2854 3870 2.64 0.0212 4764 3.768 0.0359 252671 9.847 0.0876 307040 10.205 0.243 367847 11.468 0.0194 493285 12.783 0.4582 694349 14.181 11.4668 1569210 17.33 8.7222 2597067 19.739 1.0374 35877 5.512 0.8598 70994 6.53 0.7436 96179 6.581 0.0756 124927 7.506 0.782 128702 7.294 1.0076 156352 7.927 0.0607 174073 8.199 0.7863 184132 8.31 0.0136 471565 12.415 0.0004 536 0.659 0.0076 11464 2.31 0.0246 64596 6.069 0.1762 211614 8.251 * 83 1.53 * 778 17.825 * 13 0.168 * 171 3.355 * 250 5.077
SH to LAKH Time * * * 35.1931 22.3192 61.6639 45.9696 * * 3.3267 12.8803 * 91.8295 * 26.1418 * * 10.0924 7.8663 6.3544 11.065 20.2285 20.7422 0.4004 0.8385 0.5109 0.9283 2.0096 1.025 1.1534 2.4242 13.5789 0.0221 0.1219 1.0191 2.6622 * * * * *
318
Matthew Newton, Ondrej Sikora, and Imrich Vrt'o
Graph Name
IB-method
Crossings cycle-40 122 cycle-400 2228 cycle-500 2987 cycle-60 274 cycle-80 253 geom2-100x100 179880 hyper-10 2221867 hyper-4 131 999 hyper-5 4710 hyper-6 22714 hyper-7 108038 hyper-8 494357 hyper-9 886963 irregular-100x100 883543 ladyshoe-67x100 leonardo-90x64 455396 mahindas 1318184 mesh-10-10 1212 mesh-15-15 6286 mesh-20-20 12570 mesh-25-25 30245 mesh-30-10 6246 mesh-30-15 16014 mesh-30-20 27610 mesh-30-25 39139 mesh-30-30 45950 mesh-30-5 1225 mesh-35-35 85203 mesh-40-40 120812 mesh-5-5 252 monnalisa-100x65 1945030 monnalisa-20x13 3588 monnalisa-40x26 50578 monnalisa-60x39 257956 monnalisa-80x52 770234 moonsurface-100x100 2146803 orani678 4941969 psmigrl 2.05e+09 random-100-0.1 0 random-100-1 102 random-100-10 16707 random-1000-0.1 19093 random-1000-1 1683123 1.58e+08 random-1000-10 0 random-20-0.1 0 random-20.1 25 random-20-10 5 random-200-0.1 2257 random-200-1 275147 random-200-10 1 random-40-0.1 3 random-40.1 370 random-40-10 400 random-400-0.1 42140 random-400-1 4210581 random-400-10 0 random-60-0.1 13 random-60.1 1798 random-60-10 2806 random-600-0.1 204855 random-600-1 20385097 random-600-10 0 random-80-0.1 31 random-80.1 5416 random-80-10 6687 random-800-0.1 620494 random-800-1 64476577 random-800-10 1376092 ring-100x100 12979 ring-80x80 scra-100x100 2754221 scra-87x81 2322384 scrball-100x100 928260 texturel-100x100 3894302 texture2-100x100 814985 texture3-100x100 5035435 texture4-100x100 2226143 texture5-100x100 2224888 texture6-100x100 5572581 texture7-100x100 2900151 tie-100x100 3190315 triangle-100x100 6123591 zenios 6845283
SH t o LAF-method SH t o LAKH-method SH t o IB LAF LAKH Time Time Time Time Crossings Time Crossings Time 0.0005 0.0053 19 0.0457 29 0.474 199 152.9575 0.0981 328 7.116 249 282.9466 0.2015 404 8.998 29 0.1782 0.0014 0.0104 45 0.8 39 0.4786 0.0024 0.0684 63 1.185 0 43073 6.538 391832 2.4829 0.0037 0.1256 * 2548526 7116.157 144.4579 0.2571 118 0.0049 0.0001 0.0011 0.0022 124 0.154 0.0011 0.0002 0.0018 776 0.0346 0.0143 786 0.545 0.0093 * 4200 0.1669 0.0006 0.0395 4359 1 . 4 9 4 0.0845 * 0.526 22134 3.957 1.2749 23464 16.9141 0.0026 * * 106400 38.4887 106922 9.756 9.6853 0.013 * 0.0541 535292 1247.529 24.5621 498715 21.38 70.8947 492835 12.699 0.0027 6.6072 0 3690604 5.2365 669064 1 1 . 1 5 1 13.8607 0.0054 0.9114 2.7296 727351 2.0314 * 1341314 1.8802 0.3251 1 0 7 3 7 5 8 1 1 . 9 8 8 4.9457 0.0077 324736 25.755 0.8055 0.0013 1266715 836.6369 299.3661 997 0.7666 1009 1.978 0.0028 * * 3858 5.614 3 8 9 7 23.6179 0.0175 * * 9519 118.2442 9993 8.964 0.0701 * * 19340 551.8628 1 9 7 0 8 14.722 0.2926 * * 3367 6.287 3729 31.9283 0.0445 * * 8119 10.96 8 8 6 6 182.8301 0.1238 * * 14920 13.7 1 6 4 6 5 650.1603 0.2655 * * 23524 1 8 . 8 4 3 25258 1056.526 0.5404 * * 34200 2470.742 34836 23.848 0.654 679 2.946 706 2.3688 0.0066 * 55098 6805.752 1.5665 * 84679 21971.12 3.2542 84 0.0088 90 0.302 0.0124 0.0002 0.0007 * 5179482 2.7837 0.4914 4314354 19.776 93.816 0.0101 * 0.0003 0.919 0.0336 6332 0.021 6156 * 0.0023 106336 3.903 0.0044 128954 0.153 * 0.0035 540595 7.249 11.2691 0.0472 656433 0.5054 * 2072231 1 . 3 0 4 3 0.2279 1 7 3 1 7 7 8 12.19 56.0786 0.0077 1599527 1 6 . 8 4 7 36.2476 0.0175 0.7537 3.1508 1807232 5.771 1955821 36.533 8 8 . 4 4 0 3 0.9359 0.0601 2202672 710.6326 26.2889 * 1.85e+09 423.455 * 0.265 73.6012 l . Q l e + O Q 608.8471 0.0005 0 0.1306 0 0 0 0 0 0 1.201 0.0009 0.0001 102 0.0126 0 8304 2.706 1.2585 0.0074 0.0003 9575 0.7139 0.0667 0 0 0.3769 0.0049 18980 3.6272 0.0039 772973 41.513 9.4952 0.0113 1672515 3937.91 0.009 * 6.0268 1 . 4 e + 0 8 3973.301 197.7546 1.36e+08 226.149 1.243 0.0001 0 0.0001 0 0 0 0 0 0.0001 0 0.0001 0 0.075 0 0 0 0 0.126 0.0001 12 0.0007 0.0003 0 0 0 0.0092 0.0016 0.0006 5 0.4618 0.0011 0 0 0.0119 1748 0.1166 0.0017 0 182662 9.832 3.8573 0.0446 0.0011 201022 6.843 0.4308 0 0.286 0.0001 0.0001 1 0.0003 0 0 0 0.375 0.0004 0.0001 1 0.0106 0.0003 0 87 0.498 0.0004 0.0002 268 0.0217 0.0006 0 0 0.0154 0.0006 288 0.6268 0.0032 5032 7.745 0.442 0.0006 21995 234.6991 0.0763 3215659 35.652 41.3217 0.6203 0.0424 3435193 118.4158 5.4909 0.0002 0 0.0261 0 0 0 0 0 0 0.594 0.0021 0.0002 0.0001 8 0.0263 0.0004 376 1.011 0.0015 0.0002 2018 0.164 0 0 0 0.1033 0.0013 2497 0.92 0.0035 0.001 58159 1 5 . 6 3 7 0.8702 0.0043 206670 611.0068 2.5476 0.0854 17455934 715.8014 299.6423 16400000 8 1 . 4 0 8 0.0003 0 0.0721 0 0 0 0 0 0.0005 0.0002 15 0.0151 0.0011 0 0.9 * 0.0041 0.0002 2143 0.3074 2011 1.673 0.0036 0 0 0.1985 0.0032 6851 2.5984 233566 25.781 0.0794 6.4117 0.0066 555193 2080.685 3.8251 0.1718 56162991 2123.121 299.6723 53900000 140.667 344728 1 1 . 2 8 7 0 0.0053 0.0032 1389508 4.7603 338 2.731 0.0035 0.0025 0.0004 10506 0.1934 1301275 16.005 0.3933 0.0034 2558436 3.6129 0 1301275 1 5 . 0 9 8 0.0023 1.0449 1327488 2.4466 28.4834 749982 9.185 23.8414 0.0048 0.0034 0.0315 934566 9.1585 3211303 21.713 21.8718 5.6343 0.0612 0.0167 3323967 6.5414 390889 1 1 . 8 3 13.0504 2.2476 0.0215 0.0005 432977 5.7274 4024066 23.237 32.7983 7.0197 0.0327 0.0182 4238284 6.0099 1073482 5.5928 28.7785 1080003 15.952 40.5893 0.0112 0 1636037 1 7 . 3 1 8 36.0044 1797332 6.7338 3.0323 0.0284 0.0003 3744003 22.265 60.4353 3745269 5 . 7 8 8 31.4037 0.01 0.088 2075480 1 7 . 8 3 3 18.7751 2319081 5.1494 3.2826 0.018 0 2033573 16.586 3184326 5.0847 0.3251 0.0059 0.2814 * 4003275 20.285 4003275 6.5481 0.0029 0.008 * 987540 33.587 1113354 1220.934 0.6242 1.0495
Two New Heuristics for Two-Sided Bipartite Graph Drawing
319
References 1. Bastert, O., Matuszewski, C.: Layered drawings of digraphs. In: Drawing Graphs, Methods and Models (eds. Kaufmann, M., Wagner D.), LNCS 2025, Springer (2001) 87–118 2. Boisvert, R., Pozo, R., Remington, K., Barrett, R., Dongarra, J.: Matrix Market: a web resource for test matrix collections. In: The Quality of Numerical Software: Assessment and Enhancement (ed. Boisvert, R.), Chapman and Hall, London, (1997) 125–137, Matrix Market is available at the url: http://math.nist.gov/MatrixMarket/ 3. Dresbach, S.: A new heuristic layout algorithm for DAGs. In: Operations Research Proceedings 1994 (eds. Derigs, U., Drexl, A.B.A.), Springer (1994) 121–126 4. Demetrescu, C., Finocchi, I.: Removing cycles for minimizing crossings. J. Experimental Algorithmics, to appear 5. Di Battista, G., Eades, P., Tamassia, R., Tollis, I.G.: Graph Drawing: Algorithms for Visualization of Graphs. Prentice Hall (1999) 6. Eades, P., Kelly, D.: Heuristics for reducing crossings in 2-layered networks. Ars Combin. 21 (1986) 89–98 7. Eades, P., Wormald, N.: Edge crossings in drawings of bipartite graphs. Algorithmica 11 (1994) 379–403 8. Garey, M.R., Johnson, D.S.: Crossing number is np-complete. SIAM J. Algebraic Disc. Meth. 4 (1983) 312–316 9. Juvan, M., Mohar, B.: Optimal linear labellings and eigenvalues of graphs. Discrete Appl. Math. 36 (1992) 153–168 10. J¨ unger, M., Mutzel, P.: 2-Layer straight line crossing minimization: Performance of exact and heuristic algorithms. J. Graph Algorithms Appl., 1 (1997) 1–25 11. Knuth, D.E.: The Stanford GraphBase: A platform for combinatorial computing. Addision-Wesley, (1993) 12. Koren, Y., Harel, D.: A multi-scale algorithm for the linear arrangement problem. In: 28th Intl. Workshop on Graph-Theoretic Concepts in Computer Science (WG’2002), LNCS, Springer (2002), to appear 13. Matuszewski, C., Sch¨ onfeld, R., Molitor, P.: Using sifting for k-layer straightline crossing minimization. In: 7th Intl. Symp. on Graph Drawing (GD’99), LNCS 1731, Springer (1999) 217–224 14. Mutzel, P.: Optimization in leveled graphs. In: Pardalos, M., Floudas C.A. (eds.): Encyclopedia of Optimization. Kluwer, Dordrecht (2001) 15. Press, W.H., Teukolsky, S.A., Vetterling, W.T., Flannery, B.P.: Numerical Recipes in C. The Art of Scientific Computing. Second edition, Cambridge University Press (1992) http://www.nr.com/ 16. Purchase, H.: Which aesthetic has the greatest effect on human understanding? In: 5th Intl. Symp. on Graph Drawing (GD’97), LNCS 1353, Springer (1998) 248–261 17. Sarrafzadeh, M., Wong, C.K.: An Introduction to VLSI Physical Design. McGraw Hill, (1996) 18. Shahrokhi, F., S´ ykora, O., Sz´ekely, L.A., Vrˇto, I.: On bipartite drawings and the linear arrangement problem. SIAM J. Computing 30 (2001), 1773–1789 19. Shahrokhi, F., S´ ykora, O., Sz´ekely, L.A., Vrˇto, I.: A new lower bound for the bipartite crossing number with algorithmic applications. Theoretical Computer Science 245 (2000) 281–294 20. Sugiyama, K., Tagawa, S., Toda, M.: Methods for visual understanding of hierarchical system structures. IEEE Transactions on Systems, Man, and Cybernetics SMC-11 (1981) 109–125
Straight-Line Drawings of Binary Trees with Linear Area and Arbitrary Aspect Ratio
(Extended Abstract) Ashim Garg and Adrian Rusu Department of Computer Science and Engineering University at Buffalo Buffalo, NY 14260 {agarg,adirusu}@cse.buffalo.edu Abstract. Trees are usually drawn planar, i.e. without any crossings. In this paper, we investigate the area requirement of (non-upward) planar straight-line grid drawings of binary trees. Let T be a binary tree with n nodes. We show that T admits a planar straight-line grid drawing with area O(n) and with any pre-specified aspect ratio in the range [1, nα ], where α is a constant such that 0 ≤ α < 1. We also show that such a drawing can be constructed in O(n log n) time.
1
Introduction
A drawing Γ of a tree T maps each node of T to a distinct point in the plane and each edge (u, v) of T to a simple Jordan curve with endpoints u and v. Γ is a straight-line drawing if each edge is drawn as a single straight-line segment. Γ is a polyline drawing if each edge is drawn as a connected sequence of one or more line-segments, where the meeting point of consecutive line-segments is called a bend. Γ is a grid drawing if all the nodes and edge-bends have integer coordinates. Γ is a planar drawing if edges do not intersect each other in the drawing. Γ is an upward drawing if a parent is always assigned either the same or higher y-coordinate than its children. In this paper, we concentrate on grid drawings. So, we will assume that the plane is covered by a rectangular grid. Let R be a rectangle with sides parallel to the X- and Y -axes. The width (height) of R is equal to the number of grid points with the same y (x) coordinate contained within R. The area of R is equal to the number of grid points contained within R. The aspect ratio of R is the ratio of its longer and shorter sides. R is the enclosing rectangle of Γ , if it is the smallest rectangle that covers the entire drawing. The width, height, area, and aspect ratio of Γ is equal to the width, height, area, and aspect ratio, respectively, of its enclosing rectangle. T is a binary tree if each node has at most two children. We denote by T [v], the subtree of T rooted at a node v of T . T [v] consists of v and all the descendents of v. Γ has the subtree separation property [1] if, for any two node-disjoint subtrees T [u] and T [v] of T , the enclosing rectangles of the drawings of T [u] and T [v] do not overlap with each other.
Research supported by NSF CAREER Award IIS-9985136 and NSF CISE Research Infrastructure Award No. 0101244.
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 320–332, 2002. c Springer-Verlag Berlin Heidelberg 2002
Straight-Line Drawings of Binary Trees
2
321
Our Result
Planar straight-line drawings are more aesthetically pleasing than non-planar polyline drawings. Grid drawings guarantee at least unit distance separation between the nodes of the tree, and the integer coordinates of the nodes and edge-bends allow the drawings to be displayed in a display surface, such as computer screen, without any distortions due to truncation and rounding-off errors. Giving users control over the aspect ratio of a drawing allows them to display the drawing in different kinds of display surfaces with different aspect ratios. The subtree separation property makes it is easier for the user to detect the subtrees in the drawing. Finally, it is important to minimize the area of a drawing, so that the users can display a tree in as small drawing area as possible. We, therefore, investigate the problem of constructing (non-upward) planar straight-line grid drawings of binary trees with small area. Clearly, any planar grid drawing of a binary tree with n nodes requires Ω(n) area. A long-standing fundamental question, therefore, has been that whether this is a tight bound also, i.e., given a binary tree T with n nodes, can we construct a planar straight-line grid drawing of T with area O(n)? In this paper, we answer this question in affirmative, by giving an algorithm that constructs a planar straight-line grid drawing of a binary tree with n nodes with O(n) area in O(n log n) time. Moreover, the drawing can be parameterized for its aspect ratio, i.e., for any constant α, where 0 ≤ α < 1, the algorithm can construct a drawing with any user-specified aspect ratio in the range [1, nα ]. The drawing also exhibits the subtree separation property.
3
Previous Results
Previously, the best-known bound on area of planar straight-line grid drawings of binary trees was O(n log log n), which was shown in [1] and [7]. We now summarize some other known results on planar grid drawings of binary trees (for more results, see [4]). Let T be a binary tree. [5] presents an algorithm for constructing an upward polyline drawing of T in O(n) area. [6] and [9] present algorithms for constructing an orthogonal polyline drawing of T in O(n) area. [2] gives an algorithm for constructing upward straight-line drawing of T in O(n log n) area. If T is a Fibonacci tree, (AVL tree, balanced tree, respectively), then [2,8] ([3],[2], respectively) give algorithms for constructing an upward straight-line drawing of T in O(n) area.
4
Preliminaries
Throughout this paper, by the term drawing, we will mean a planar straight-line grid drawing. We will assume that the plane is covered by an infinite rectangular grid. A horizontal channel (vertical channel) is an infinite line parallel to X- (Y -) axis, passing through the grid-points.
322
Ashim Garg and Adrian Rusu
Let T be a tree, with one distinguished node v, which has at most one child. v is called the link node of T . Let n be the number of nodes in T . T is an ordered tree if the children of each node are assigned a left-to-right order. A partial tree of T is a connected subgraph of T . If T is an ordered tree, then the leftmost path p of T is the maximal path consisting of nodes that are leftmost children, except the first one, which is the root of T . The last node of p is called the leftmost node of T . Two nodes of T are siblings if they have the same parent in T . T is an empty tree, i.e., T = φ, if it has zero nodes in it. Let Γ be a drawing of T . By bottom (top, left, and right, respectively) boundary of Γ , we will mean the bottom (top, left, and right, respectively) boundary of the enclosing rectangle R(Γ ) of Γ . Similarly, by top-left (top-right, bottomleft, and bottom-right, respectively) corner of Γ , we mean the top-left (top-right, bottom-left, and bottom-right, respectively) corner of R(Γ ). Let R be a rectangle, such that Γ is entirely contained within R. R has a good aspect ratio, if its aspect ratio is in the range [1, nα ], where α is a constant, such that 0 ≤ α < 1. Let r be the root of T . Let u∗ be the link node of T . Γ is a feasible drawing of T , if it has the following three properties: – Property 1: The root r is placed at the top-left corner of Γ . – Property 2: If u∗ = r, then u∗ is placed at the bottom boundary of Γ . More over, we can move u∗ downwards in its vertical channel by any distance without causing any edge-crossings in Γ . – Property 3: If u∗ = r, then no other node or edge of T is placed on, or crosses the vertical and horizontal channels occupied by r. Theorem 1 ([9]). Let n0 and α be two constants, where n0 ≥ 1 and 0 < α < 1/2. Let m1 , m2 , . . . , mn0 be a set of positive numbers. Let G(n), and g(n) be two functions such that – ∀n > n0 , and ∀x, where 0 < x ≤ 1 − α, G(xn) ≤ x(G(n) − g(n) G(n)), and – ∀n ≤ n0 , G(n) ≥ mn . and 0 ≤ β < 1/2, Then, if g(n) ≤ cnβ , where c > 0 and β are constants, √ then G(n) = O(n). More specifically, G(n) = γn − δ ng(n) is a solution, where γ and δ are constants that satisfy the following conditions: √ – ∀n ≤ n0 , γn − δ ncnβ ≥ mn , and √ – δ(µ1/2−β − 1) > γ, where µ = 1/(1 − α). Theorem 2 (Separator Theorem [9]). Every n-node binary tree T contains an edge e, called a separator edge, such that removing e from T splits T into two trees T1 and T2 , with n1 and n2 nodes, respectively, such that for some x, where 1/3 ≤ x ≤ 2/3, n1 ≤ xn, and n2 ≤ (1 − x)n. More over, e can be found in O(n) time. Let v be a node of tree T located at grid point (i, j) in Γ . Let Γ be a drawing of T . Assume that the root r of T is located at the grid point (0, 0) in Γ . We define the following operations on Γ :
Straight-Line Drawings of Binary Trees
323
– rotate operation: rotate Γ counterclockwise by δ degrees around the z-axis passing through r. After a rotation by δ degrees of Γ , node v will be located at grid point (i cos δ − j sin δ, i sin δ + j cos δ). – flip operation: flip Γ vertically or horizontally. After a horizontal flip of Γ , node v will be located at grid point (−i, j). After a vertical flip of Γ , node v will be located at grid point (i, −j).
5
Algorithm u∗ -HV-Draw
We first describe Algorithm u∗ -HV-Draw, which is used by our main drawing algorithm (described in Section 6). Algorithm u∗ -HV-Draw is based on the well-known HV -Drawing algorithm of [2]. Lemma 1 summarizes the main result on HV -Drawing algorithm: Lemma 1 ([2]). Let T be an n-node binary tree with root r. Let R be a rectangle with width (height) n and height (width) log2 n + 2. We can construct a drawing of T within R in O(n) time, such that r is placed at the top-left corner of R. Unfortunately, given a tree T with a link node u∗ , HV -Drawing algorithm may not construct a feasible drawing of T because it may not place u∗ at the bottom of the drawing. Algorithm u∗ -HV-Draw will, however, construct a feasible drawing. Algorithm u∗ -HV-Draw can be described as follows: Let W and H be the width and height of R, respectively. – Order the children of each node such that u∗ becomes the leftmost node of T . – Let r = r1 , r2 , . . . , rk−1 , rk = u∗ , be the nodes in the leftmost path of T (see Figure 1(a)). Let c = c1 , c2 , . . . , ck be the right children of r1 , r2 , . . . , rk , respectively. Let T1 , T2 , . . . , Tk be the subtrees of T rooted at c1 , c2 , . . . , ck , respectively. For each i, where 1 ≤ i ≤ k, let ni be the number of nodes in Ti . – If W ≤ H (H < W ), for each i, where 1 ≤ i ≤ k, construct a drawing Γi of Ti , using HV -Drawing algorithm, within a rectangle Ri with height (width) ni and width (height) log2 ni + 2 (see Lemma 1). – Based on the value of k, tree T is drawn as follows: • k ≥ 2: If W ≤ H, then as shown in Figure 1(b), stack the drawings of Γ1 , Γ2 , . . . , Γk one above the other such that their left boundaries are aligned. Place each ri , where 1 ≤ i ≤ k − 1, at the same height as ci and at unit horizontal distance from it towards its left. Place u∗ to the left of ck at unit horizontal distance and at unit vertical distance below the bottom boundary of Γk . If H < W , then first flip Γk vertically, and then, as shown in Figure 1(c), place Γ1 , Γ2 , . . . , Γk in a left-to-right order with two units of horizontal separation between them, such that their top boundaries are aligned. Let Γh be the drawing among Γ1 , Γ2 , . . . , Γk with maximum height. Place u∗ one unit below the bottom boundary of Γh , and one unit to the left of ck−1 . Move Γk down until its bottom boundary is either below, or aligned with the bottom boundary of Γk−1 . Place each ri , where 1 ≤ i ≤ k − 1, at one unit above and one unit to the left of ci , and draw edges (ri , ci ), and (ri , ri+1 ). Draw the edge (u∗ , ck ).
324
Ashim Garg and Adrian Rusu
(a)
(b)
(c)
(d)
(e)
(f)
Fig. 1. (a) General form of a binary tree T with link node u∗ and root r, where u∗ is also the leftmost node of T . This figure uses the notation of Section 5. (b,c) Drawing T when k ≥ 2: if (b) W ≤ H, and if (c) H < W . (d) Special case when k = 1. (e,f) Drawing T when k = 1: if (e) W ≤ H, and if (f) H < W . For simplicity, we have shown Γ1 , Γ2 , . . . , Γk as identically sized boxes, but in actuality, they may have different sizes.
• k = 1: For both W ≤ H and H < W , place r one unit above and to the left of the top-left corner of Γ1 (see Figure 1 (d,e,f)). Draw edge (r, c). Lemma 2. Let T be an n-node binary tree with a link vertex u∗ . Algorithm u∗ HV-Draw can be used to construct in O(n) time, a feasible drawing of T within a rectangle with width n and height log2 n + 4, as well as within a rectangle with width log2 n + 4 and height n.
6
Our Overall Tree Drawing Algorithm
Let T be a binary tree with a link node u∗ . Let n be the number of nodes in T . Let A and ' be two numbers such that 1/3 < ' < 1, and A is in the range [1, n ]. Let R be a large enough rectangle with aspect ratio A, width W and height H (we will determine later on, how large R should be). Notice that because 1 ≤ A < n , R has a good aspect ratio. Our tree drawing algorithm, called DrawTree, uses a simple divide-andconquer strategy to recursively construct a feasible drawing Γ of T within R, by performing the following actions at each recursive step: – Split Tree: Split T into at most five partial trees by removing at most two nodes and their incident edges from it. Each partial tree has at most (2/3)n nodes. Based on the arrangement of these partial trees within T , we get two cases, which are shown in Figures 2 and 3, and described later in Section 6.1. – Assign Rectangles: Correspondingly, split R into at most five smaller rectangles, and assigns each smaller rectangle to a partial tree. The splitting is done by cutting the longer side (height or width) of R. – Draw Partial Trees: Recursively construct a feasible drawing of each partial tree within its assigned rectangle.
Straight-Line Drawings of Binary Trees
(a)
(b)
(c)
(e)
325
(d)
(f)
Fig. 2. Drawing T in all the subcases of Case 1 (when the separator (u, v) is not in the leftmost path of T ): (a) TA = ∅, TC = ∅, d = u∗ , (b) TA = ∅, TC = ∅, (c) TA = ∅, TC = ∅, d = u∗ , (d) TA = ∅, TC = ∅, r = e, (e) TA = ∅, TC = ∅, r = e, (f) TA = ∅, TC = ∅, d = u∗ . For each subcase, we first show the structure of T for that subcase, then its drawing when W ≤ H, and then its drawing when H < W . In Subcases (a) and (c), for simplicity, e is shown to be in the interior of ΓA , but actually, either it is the same as r, or if W ≤ H (H < W ), then it is placed on the bottom (right) boundary of ΓA . For simplicity, we have shown ΓA , ΓB , and ΓC as identically sized boxes, but in actuality, they may have different sizes.
– Compose Drawings: Within R, arrange the drawings of the partial trees, and draw the nodes and edges, that were removed from T to split it, such that the drawing Γ of T thus obtained is a feasible drawing. Note that the arrangement of these drawings is done based on the cases shown in Figures 2 and 3. We now give details of each action performed by Algorithm DrawTree: 6.1
Split Tree
The splitting of tree T into partial trees is done as follows: – Order the children of each node such that u∗ becomes the leftmost node of T . – Using Theorem 2, find a separator edge (u, v) of T , where u is the parent of v. – Based on whether, or not, (u, v) is in the leftmost path of T , we get two cases: • Case 1: The separator edge (u, v) is not in the leftmost path of T . We get six subcases: (a) In the general case, T has the form as shown in Figure 2(a). In this figure: r is the root of T , T2 is the subtree of T rooted at v, c is the sibling of v, T1 is the subtree rooted at c, Tα is the
326
Ashim Garg and Adrian Rusu
(a)
(c)
(b)
(d)
Fig. 3. Drawing T in all the subcases of Case 2 (when the separator (u, v) is in the leftmost path of T ): (a) TA = ∅, TB = ∅. (b) TA = ∅, TB = ∅. (c) TA = ∅, TB = ∅. (d) TA = ∅, TB = ∅. For each subcase, we first show the structure of T for that subcase, then its drawing when W ≤ H, and then its drawing when H < W . In Subcases (a) and (d), for simplicity, e is shown to be in the interior of ΓA , but actually, either it is same as r, or if W ≤ H (H < W ), then it is placed on the bottom (right) boundary of ΓA . For simplicity, we have shown ΓA , ΓB , and ΓC as identically sized boxes, but in actuality, they may have different sizes.
subtree rooted at u, w is the parent of u, a is the last common node of the path r ❀ v and the leftmost path of T , f is the right child of a, Tβ is the maximal tree rooted at f that contains w but not u, TB is the tree consisting of the trees Tα and Tβ , and the edge (w, u), e is the parent of a, and d is the left child of a, TA is the maximal tree rooted at r that contains e but not a, and TC is the tree rooted at d. In addition to this general case, we get five special cases: (b) when TA = ∅ and TC = ∅ (see Figure 2(b)), (c) TA = ∅, TC = ∅, d = u∗ (see Figure 2(c)), (d) TA = ∅, TC = ∅, r = e (see Figure 2(d)), (e) TA = ∅, TC = ∅, r = e (see Figure 2(e)), and (f) TA = ∅, TC = ∅, d = u∗ (see Figure 2(f)). In each case, we remove nodes a and u, and their incident edges, to split T into at most five partial trees TA , TC , Tβ , T1 , and T2 . We also designate e as the link node of TA , w as the link node of Tβ , and u∗ as the link node of TC . We randomly select a leaf of T1 , and a leaf of T2 , and designate them as the link nodes of T1 and T2 , respectively. • Case 2: The separator edge (u, v) is in the leftmost path of T . We get four subcases: (a) In the general case, T has the form as shown in Figure 3(a). In this figure, r is the root of T , c is the right child of u, TB is the subtree of T rooted at c, e is the parent of u, TA is the maximal tree rooted at r that contains e but not u, and TC is the tree rooted at v. In addition to the general case, we get the following three special cases: (b) TA = ∅, TB = ∅ (see Figure 3(b)), (c) TA = ∅, TB = ∅ (see Figure 3(c)), and (d) TA = ∅, TB = ∅ (see Figure 3(d)). In each case, we remove node u, and its incident edges, to split T into at most three partial trees TA , TB , and TC . We also designate e as the link node of TA ,
Straight-Line Drawings of Binary Trees
327
and u∗ as the link node of TC . We randomly select a leaf of TB and designate it as the link node of TB . 6.2
Assign Rectangles
Let Tk be a partial tree of T , where for Case 1, Tk is either TA , TC , Tβ , T1 , or T2 , and for Case 2, Tk is either TA , TB , or TC . Let nk be number of nodes in Tk . Algorithm DrawTree assigns a rectangle Rk , with width Wk and height Hk , to Tk , where Wk and Hk are as follows: Let W and H be the width and height, respectively, of R. Assume that H < W (the case when W ≤ H is handled similarly). 1− Let H = H − 2, and W = W − 3 max{n 1+ , log2 n + 4} − 2. Let x = nk /n. – If nk < H (i.e., if Tk is a very small tree), then Wk = log2 nk + 4, and Hk = H ; – Otherwise, if xW /H ≤ n− k (i.e., if Tk is a moderately large tree), then Wk = H /nk , and Hk = H ; – Otherwise (i.e., if Tk is a large tree), Wk = xW /H and Hk = H . This assignment strategy ensures that when the drawings of all the partial trees are composed together to obtain a drawing Γ of T in the Compose Drawings step, then Γ will fit inside R. It also ensures that, except when Tk is a very small tree, Rk has a good aspect ratio. 6.3
Draw Partial Trees
In Subcase (d) of Case 1, and if H < W , then in Subcases (a) and (c) of Case 1, and Subcases (a) and (d) of Case 2, we first change the orientation of RA , so that its height becomes its width, and its width becomes its height. Also, in Case 1, if H < W , and Tβ = φ, we change the orientation of Rβ . This is done so because, in these situations, as explained later in Subsection 6.4, we need to rotate RA and Rβ during the Compose Drawings step. In all other situations, we do not change the orientation of the rectangle assigned to a partial tree. Next we draw each partial tree Tk within its assigned rectangle Rk . If Tk is a large tree or a moderately large tree (see their definitions in Subsection 6.2), then Tk is drawn within Rk by calling Algorithm DrawTree recursively for it, and if Tk is a very small tree, then Tk is drawn within Rk by calling Algorithm u∗ -HV-Draw for it. Note that recursion for DrawTree stops when either T is empty, or contains exactly one node, or gets designated as a very small tree (in which case, it is drawn using u∗ -HV-Draw). 6.4
Compose Drawings
Let Γk denote the drawing of a partial tree Tk constructed in Step Draw Partial Trees. We now describe the construction of a feasible drawing Γ of T from the drawings of the partial trees in both Cases 1 and 2.
328
Ashim Garg and Adrian Rusu
In Case 1, we first construct a feasible drawing Γα of the partial tree Tα by composing Γ1 and Γ2 as shown in Figure 4, then construct a feasible drawing ΓB of TB by composing Γα and Γβ as shown in Figure 5, and finally construct Γ by composing ΓA , ΓB and ΓC as shown in Figure 2. Γα is constructed as follows (see Figure 4): – If u does not belong to the leftmost path of T , and T1 = ∅ (see Figure 4(a)), then, if W ≤ H, place Γ1 above Γ2 such that the left boundaries of Γ1 and Γ2 are aligned; otherwise (i.e., if W > H) place Γ1 to the left of Γ2 , such that the top boundaries of Γ1 and Γ2 are aligned. Place u at one unit to the left and one unit above Γ1 . Draw edges (u, c) and (u, v). – If u does not belong to the leftmost path of T , and T1 = ∅ (see Figure 4(b)), then for both W ≤ H and H < W , place u at one unit to the left and one unit above Γ2 . Draw edge (u, v). – Otherwise (i.e., if u ∈ leftmost path of T ), Γα is same as Γ2 (see Figure 4(c)). ΓB is constructed as follows (see Figure 5): Let y be the root of Tα . Note that y = u if u does not belong to the leftmost path of T , and y = v otherwise. – if Tβ = ∅ (see Figure 5(a)) then, if W ≤ H, then place Γβ above Γα such that the left boundaries of Γβ and Γα are aligned; otherwise (i.e., if W > H), first rotate Γβ by 90◦ and then flip it vertically, then place Γβ to the left of Γα such that the top boundaries of Γβ and Γα are aligned. Draw edge (w, y). – Otherwise (i.e., if Tβ = ∅), ΓB is same as Γα (see Figure 5(b)). Γ is constructed from ΓA , ΓB and ΓC as follows (see Figure 2): Let x be the root of TB . Note that x = f if Tβ = ∅, and x = y otherwise. – In Subcase (a), as shown in Figure 2(a), if W ≤ H, stack ΓA , ΓB , and Γc one above the other and place node a between ΓA and ΓB , such that ΓA , a, ΓB , and ΓC are separated by unit vertical distance from each other, left boundaries of ΓB and ΓC are aligned with each other and are placed at unit horizontal distance to the right of the left boundary of ΓA , and a is aligned with the left boundary of ΓA . If H < W , then first rotate ΓA by 90◦ , and then flip it vertically. Then, place ΓA , a, ΓC , and ΓB from left-to-right in that order, separated by unit horizontal distances, such that a is aligned with the top boundary of ΓA , the top boundaries of ΓB and ΓC are aligned, and are at unit vertical distance below the top boundary of ΓA . Then, move ΓC down until u∗ becomes the lowest node of Γ . Draw edges (e, a), (a, x), and (a, d). – In Subcase (b), for both W ≤ H and H < W , place node r one unit above and left of the top boundary of ΓB (see Figure 2(b)). Draw edge (r, x). – The drawing procedure for Subcase (c) is similar to the one in Subcase (a), except that we also flip ΓC vertically (see Figure 2(c)). – In Subcase (d), as shown in Figure 2(d), if W ≤ H, first flip ΓB vertically, and then flip it horizontally, so that its root x gets placed at its lower-right corner. Then, first rotate ΓA by 90◦ , and then flip it vertically. Next, place ΓA above ΓB with unit vertical separation, such that their left boundaries are aligned, next move node e (which is the link node of TA ) to the right until
Straight-Line Drawings of Binary Trees
(a)
(b)
329
(c)
Fig. 4. Drawing Tα , when: (a) u does not belong to the leftmost path of T and T1 = ∅, (b) u does not belong to the leftmost path of T and T1 = ∅, and (c) u ∈ leftmost path of T . For each case, we first show the structure of Tα for that case, then its drawing when W ≤ H, and then its drawing when H < W . For simplicity, we have shown Γ1 and Γ2 as identically sized boxes, but in actuality, their sizes may be different.
it is either to the right of, or aligned with the right boundary of ΓB (since ΓA is a feasible drawing, by Property 2, as given in Section 4, moving e will not create any edge-crossings), and then place u∗ one unit to the right of and below x. If H < W , first rotate ΓA by 90◦ , and then flip it vertically. Then, place ΓA , u∗ , and ΓB left-to-right in that order separated by unit horizontal distances, such that the top boundaries of ΓA and ΓB are aligned, and u∗ is placed one unit below the bottom boundary of the drawing among ΓA and ΓB with greater height. Draw edges (u∗ , e) and (u∗ , x). – In Subcase (e), as shown in Figure 2(e), if W ≤ H, first flip ΓB vertically, then place ΓA , ΓB , and u∗ one above the other with unit vertical separation, such that the left boundary of ΓA is at unit horizontal distance to the left of the left boundary of ΓB , and u∗ is aligned with the left boundary of ΓA . If H < W , then first flip ΓB vertically, place ΓA to the left of ΓB at unit horizontal distance, such that their top boundaries are aligned. Next, move ΓB down until its bottom boundary is either aligned with or below the bottom boundary of ΓA . Then, place u∗ one unit below the bottom boundary of ΓB , such that it is aligned with left boundary of ΓA . Draw edges (u∗ , r) and (u∗ , x). Note that, since ΓA is a feasible drawing, by Property 3 (see Section 4), drawing (u∗ , r) will not create any edge-crossings. – The drawing procedure in Subcase (f) is similar to the one in Subcase (a), except that we do not have ΓA here (see Figure 2(f)). In Case 2, we construct Γ by composing ΓA , ΓB and ΓC , as follows (see Figure 3): – The drawing procedures in Subcases (a), (b), and (c) are similar to those in Subcases (a), (b), and (f), respectively, of Case 1 (see Figures 3(a,b,c)). – In Subcase (d), as shown in Figure 3(d), if W ≤ H, we place ΓA , u, and ΓC one above the other separated by unit vertical distances such that u is aligned with the left boundary of ΓA , and the left boundary of ΓC is one unit to the right of the left boundary of ΓA . If H < W , then first rotate ΓA by 90◦ , and then flip it vertically. Then, place ΓA , u, and ΓC from left to right in that order, separated by unit horizontal distances, such that u is aligned with the top boundary of ΓA , and the top boundary of ΓC is one unit below the top boundary of ΓA . Draw edges (u, v) and (u, e). Lemma 3 (Planarity). Given a binary tree T with a link node u∗ , Algorithm DrawTree will construct a feasible drawing Γ of T .
330
Ashim Garg and Adrian Rusu
(a)
(b)
Fig. 5. Drawing TB when: (a) Tβ = ∅, and (b) Tβ = ∅. Node y shown here is either node u or v. For each case, we first show the structure of TB for that case, then its drawing when W ≤ H, and then its drawing when H < W . In Case (a), for simplicity, w is shown to be in the interior of Γβ , but actually, it is either same as f , or if W ≤ H (H < W ), then is placed on the bottom (right) boundary of Γβ . For simplicity, we have shown Γβ and Γα as identically sized boxes, but in actuality, their sizes may be different.
Lemma 4 (Time). Given an n-node binary tree T with a link node u∗ , Algorithm DrawTree will construct a drawing Γ of T in O(n log n) time. Lemma 5 (Area). Given an n-node binary tree T with a link node u∗ , Algorithm DrawTree can construct a drawing of T within a rectangle with O(n) area. Sketch of Proof. The proof is similar to the proof of Theorem 5 of [9]. Let R be a rectangle assigned to T , with aspect ratio A, such that A is in the range [1, n ], where ' is a constant, such that 1/3 < ' < 1. Let D(n) be some function such that the area of R should be at least D(n) for the algorithm to succeed in drawing T entirely within R. Let H be the height and W be the width of R. We have two cases: H < W and W ≤ H. Consider the case when H < W (the case W ≤ H is analogous). Let Tk be a partial tree of T into which T is split, as described in Section 6.1. Let Rk , nk , x, Hk , Wk , W , and H be as defined in Section 6.2. 1− We show that the condition D(xn) ≤ xW H = x(W − 3 max{n 1+ , log2 n + 4} − 2)(H − 2) is a sufficient condition for Algorithm DrawTree to draw T within R. For T to be drawn succesfully within R, each partial tree Tk should be drawn successfully within its assigned rectangle, and their drawings should be succesfully combined to lie entirely within R. If Tk is a very small tree, then it can be drawn within its assigned rectangle Rk using Algorithm u∗ -HV-Draw, as shown in Lemma 2. If Tk is a moderately large partial tree, then Rk has area equal to (H /nk )H ≥ xW H , and if it is a large partial tree, then Rk has area exactly equal to xW H . Thus, if D(xn) ≤ xW H , we can draw Tk within its assigned rectangle. In both Case 1 and Case 2, as shown in Figures 2, 3, 4, and 5, Algorithm DrawTree uses at most 2 extra horizontal channels and 2 extra vertical channels to combine the drawings of the partial trees to obtain a drawing of T . The rectangles assigned to all the partial trees have equal height, namely, H = H − 2. At least two of the partial trees contain n/12 nodes each. Hence, at most three partial trees can get designated as very small or moderately large. 1 We can show that if Tk is a moderately large tree, then it has at most n 1+ nodes 1− in it, and Wk ≤ n 1+ . Hence, the total area of the rectangles assigned to the 1− very small and moderately large trees is at most 3 max{n 1+ , log2 n + 4}(H − 2).
Straight-Line Drawings of Binary Trees
331
Thus, the total area within R available for drawing all the large partial trees is 1− at least W H = (W − 3 max{n 1+ , log2 n + 4} − 2)(H − 2). Therefore, if each large partial tree Tk can be drawn within area xW H , i.e., within its assigned rectangle, then the entire drawing of T can fit within R. 1− Thus, D(xn) ≤ x(W − 3 max{n 1+ , log2 n + 4} − 2)(H − 2) is a sufficient condition for drawing T within R. Since we are interested in finding D(n), suppose the rectangle R assigned to T has area equal to D(n). Then, because H isthe shorter side of R, H ≤ D(n), and since A = W/H ≤ n , W ≤ n/2 D(n). Substituting W and 1− H by these bounds in D(xn) ≤ x(W − 3 max{n 1+ , log2 n + 4} − 2)(H − 2) and with some mathematical manipulation, we get that D(xn) ≤ x(D(n) − 1− (3 max{n 1+ , log2 n+4}+2n/2 +2) D(n)) is a sufficient condition for drawing T within R. Since 1/3 < ' < 1, (1−')/(1+') and '/2 are both less than 1/2. Hence, 1− 3 max{n 1+ , log2 n + 4} + 2n/2 + 2 ≤ cnβ , for some constants c and β, where c > 0, and 0 ≤ β < 1/2. Hence, from Theorem 1, we get that D(n) = O(n). Theorem 3 (Main Theorem). Let T be a binary tree with n nodes. Given any number A, where 1 ≤ A ≤ nα , for some constant α, where 0 ≤ α < 1, we can construct in O(n log n) time, a planar straight-line grid drawing Γ of T with O(n) area, and aspect ratio A. Proof. Let ' be a constant such that 1 ≤ A ≤ n and 1/3 < ' < 1. Assign a rectangle R with area D(n) and aspect ratio A to T , where D(n) is the function defined in the proof of Lemma 5. Note that from the proof of Lemma 5, D(n) = O(n). Construct a drawing Γ of T in R by calling Algorithm DrawTree with T , R and ' as input. From Lemmas 3, 4, and 5, Γ will be a planar straight-line grid drawing of T contained entirely within R.
References 1. T. Chan, M. Goodrich, S. Rao Kosaraju, and R. Tamassia. Optimizing area and aspect ratio in straight-line orthogonal tree drawings. Comput. Geom. Theory Appl. to appear. Prel. version in Proc. Graph Drawing’96, LNCS, vol. 1190, pp. 63-75. 2. P. Crescenzi, G. Di Battista, and A. Piperno. A note on optimal area algorithms for upward drawings of binary trees. Comput. Geom. Theory Appl., 2:187-200, 1992. 3. P. Crescenzi, P. Penna, and A. Piperno. Linear-area upward drawings of AVL trees. Comput. Geom. Theory Appl., 9:25–42, 1998. 4. G. Di Battista, P. Eades, R. Tamassia, and I. G. Tollis. Graph Drawing. Prentice Hall, Upper Saddle River, NJ, 1999. 5. A. Garg, M. T. Goodrich, and R. Tamassia. Planar upward tree drawings with optimal area. Internat. J. Comput. Geom. Appl., 6:333–356, 1996. 6. C. E. Leiserson. Area-efficient graph layouts (for VLSI). In Proc. 21st Annu. IEEE Sympos. Found. Comput. Sci., pages 270–281, 1980. 7. C.-S. Shin, S.K. Kim, S.-H. Kim, and K.-Y. Chwa. Area-efficient algorithms for straight-line tree drawings. Comput. Geom. Theory Appl., 15:175–2002, 2000.
332
Ashim Garg and Adrian Rusu
8. L. Trevisan. A note on minimum-area upward drawing of complete and Fibonacci trees. Inform. Process. Lett., 57(5):231–236, 1996. 9. L. Valiant. Universality considerations in VLSI circuits. IEEE Trans. Comput., C-30(2):135–140, 1981.
Some Applications of Orderly Spanning Trees in Graph Drawing Ho-Lin Chen1 , Chien-Chih Liao1 , Hsueh-I Lu2 , and Hsu-Chun Yen1 1
Department of Electrical Engineering, National Taiwan University Taipei 106, Taiwan, Republic of China [email protected], [email protected] [email protected], http://www.ee.ntu.edu.tw/˜yen/ 2 Institute of Information Science, Academia Sinica Taipei 115, Taiwan, Republic of China [email protected], http://www.iis.sinica.edu.tw/˜hil/
Abstract. Orderly spanning trees seem to have the potential of becoming a new and promising technique capable of unifying known results as well as deriving new results in graph drawing. Our exploration in this paper provides new evidence to demonstrate such a potential. Two applications of the orderly spanning trees of plane graphs are investigated. Our first application deals with Podevs drawing, i.e., planar orthogonal drawing with equal vertex size, introduced by F¨ oßmeier and Kaufmann. Based upon orderly spanning trees, we give an algorithm that produces a Podevs drawing with half-perimeter no more than 3n + 1 and at most 2 one bend per edge for any n-node plane graph with maximal degree ∆, a notable improvement over the existing results in the literature in terms of the size of the drawing area. The second application is an alternative proof for the sufficient and necessary condition for a graph to admit a rectangular dual, i.e., a floor-plan using only rectangles.
1
Introduction
Graph drawing has emerged as an exciting and fast growing area of research in the computer science community in recent years [10]. Among various techniques for drawing planar graphs, the canonical orderings of triconnected plane graphs have served as a fundamental step upon which many drawing algorithms are built [6, 9, 12, 15, 16, 18, 19]. The work by de Fraysseix, Pach and Pollack [9] is considered to be the first using the canonical orderings to produce straight-line drawings with polynomial sizes for planar graphs. The technique of canonical orderings has subsequently been applied to drawing graphs with respect to a variety of aesthetic constraints, including straight-line, convexity, orthogonality, 2-visibility, floor-planning, among others. Alternatively, Schnyder [32] introduced the concept of realizers which provides an interesting characterization for vertices and edges in triangulated planar graphs. Applications of realizers to graph drawing can be found in [8, 32], for instance.
Research supported in part by NSC Grant 90-2213-E-002-100.
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 332–343, 2002. c Springer-Verlag Berlin Heidelberg 2002
Some Applications of Orderly Spanning Trees in Graph Drawing
333
Fig. 1. (a) A plane triangulation G, where an orderly spanning tree T of G rooted at node 1 is drawn in dark. The node labels show the counterclockwise preordering of the nodes in T . (b) A Podevs drawing of G. (c) A floor-plan of G.
(a)
(b)
(c)
(d)
Fig. 2. Module types: (a) I-module, (b) L-module, (c) T-module, and (d) Z-module.
Recently, Chiang, Lin, Lu [5] introduced the concept of orderly spanning trees for planar graphs, extending that of canonical ordering for plane graphs not required to be triconnected and that of realizer for plane graphs not required to be triangulated. In fact, for a plane triangulation G, (i) if T is an orderly spanning tree of G, then the counterclockwise preordering of the nodes of T is always a canonical ordering of G, and (ii) if (T1 , T2 , Tn ) is a realizer of G, where Ti is rooted at vi for each i = 1, 2, n, then each Ti plus both external edges of G incident to vi is an orderly spanning tree of G. In addition, orderly spanning trees of planar graphs can be computed in linear time [5]. In light of their recent success in establishing floor-planning [23] and 2-visibility drawing [5], we feel that orderly spanning trees have the potential of becoming a new and promising technique capable of unifying known results as well as deriving new results in graph drawing. Along this line of research, in this article we demonstrate two additional applications of orderly spanning trees in graph drawing, namely, Podevs drawing and rectangular dual. For more about the applications of ordering spanning trees, the interested reader is referred to [5] for succinct graph encoding and [24] for the design of compact routing tables. Our first application of orderly spanning tree is concerned with Podevs drawings of planar graphs, introduced by F¨ oßmeier and Kaufmann [13]. In Podevs drawings, all vertices are given as identical k × k squares, with the size k de-
334
Ho-Lin Chen et al.
termined appropriately. Edges are routed as axis-parallel paths along the grid lines. See Figure 1(b) for an illustration. Let ∆ be the degree of the input n-node m-edge planar graph. F¨ oßmeier and Kaufmann [13] gave a linear-time algorithm for computing a (∆ + 1)n × (∆ + 1)n Podevs drawing with at most 2m bends.1 They also gave an O(n2 log n)-time algorithm, extending from Tamassia’s classic result [35], that computes a Podevs drawing with minimum number of bends.2 Bonichon, Le Sa¨ec and Mosbah [4] gave a linear-time algorithm to obtain a (∆ − 1)(n − 2) × (∆ − 1)(n with at most one bend per edge. ∆ − 1) Podevs ∆drawing (n − 1) Podevs drawing with at most They also provided a (n − 2) × 2 2 3m bends. Based upon orderly spanning trees, we give a linear-time algorithm 2 to produce a Podevs drawing with half-perimeter (i.e., height plus width) no more than ( 3n + 1)∆ and at most one bend per edge, a notable improvement 2 over [4, 13] in terms of the drawing area.3 Our second application has to do with floor-planning planar graphs. Floorplanning [25, 36], a fundamental step in VLSI chip design, refers to the process of, given a graph whose nodes (respectively, edges) representing functional entities (respectively, interconnections), partitioning a rectangular chip area into a set of non-overlapping rectilinear polygonal modules (each of which describes a functional entity) in such a way that the modules of adjacent nodes share a common boundary. For example, Figure 1(c) is a floor-plan of the graph in Figure 1(a). For floor-planning general plane graphs, Yeap and Sarrafzadeh [37] showed that rectilinear modules with at most two concave corners are sufficient and necessary. He [15], measuring the complexity of a module in terms of the number of its constituent rectangles, presented a linear-time algorithm to construct a floor-plan of a plane triangulation using modules, each of which is a union of two disjoint rectangles (called 2-rectangular modules). More recently, Liao, Lu and Yen [23] used orderly spanning trees to demonstrate a linear-time algorithm to layout, given an n-node plane triangulation, a floor-plan in an area bounded by (n − 1) × 2n+1 using three basic modules, namely, I-module, 3 L-module, and T-module depicted in Figures 2(a), 2(b), and 2(c), respectively. (He’s algorithm [15] may produce a floor-plan containing Z-modules as shown in Figure 2(d).) A floor-plan using only rectangles to represent nodes is called a rectangular dual. It was shown in [20–22] that an internally triangulated plane G admits a rectangular dual if and only if G has four exterior nodes, and G has no 1
2
3
The area bound mentioned in [13] is 2(∆ + 1)n × (∆ + 1)n, which has to do with the 2n × n straight-line drawing of [7]. Using an n × n straight-line drawing of G (e.g., [32]), the area bound of [13] can be reduced by a factor of two. The optimality for the number of bends has to do with an additional property required by the drawing. That is, each nontrivial face should occupy a nonempty region in the drawing, which is for putting the labels of faces. Such a drawing is called a Podevsnef drawing, standing for planar orthogonal drawing with equal vertex size and none-empty face. Very recently, Mutzel and Weiskircher [28] resorted to integer programming to minimize the number of bends in such a drawing. Under slightly modified conditions, e.g., the nodes need not be of the same size, there are efficient algorithms producing more compact orthogonal drawings [1–3, 11, 12, 30].
Some Applications of Orderly Spanning Trees in Graph Drawing
335
separating triangles.4 In this paper, we are able to provide an alternative proof, based upon orderly spanning trees, for the above sufficient and necessary condition for a graph to admit rectangular dual. Aside from offering a simpler proof in comparison with that of [36, 37], we feel that our exploration might lead to new algorithms and characterization for the so-called slicible floor-plans [29, 34], i.e., those obtainable by means of horizontal or vertical cuts. As we shall see later, our exploration also leads to a simple way of achieving proper box rectangular drawing of [16, 31]. The remainder of this paper is organized as follows. Section 2 gives the preliminaries. Section 3 presents our Podevs drawing algorithm. Section 4 shows the sufficient and necessary condition for a planar graph that admits a rectangular dual. Section 5 concludes the paper with future work and some comments on applying rectangular-dual algorithms to obtaining proper box-rectangular drawing.
2
Preliminaries
A plane graph is a planar graph equipped with a fixed planar embedding. The embedding of a plane graph divides the plane into a number of connected regions, each of which is called a face. The unbounded face of G is called the exterior face, whereas the remaining faces are interior faces. G is a plane triangulation if G has at least three nodes and the boundary of each face, including the exterior face, of G is a triangle. Let T be a rooted spanning tree of a plane graph G. Two nodes are unrelated in T if they are distinct and neither of them is an ancestor of the other in T . An edge of G is unrelated with respect to T if its endpoints are unrelated in T . Let v1 , v2 , . . . , vn be the counterclockwise preordering of the nodes in T . A node vi is orderly in G with respect to T if the neighbors of vi in G form the following four blocks in counterclockwise order around vi : B1 (vi ): B2 (vi ): B3 (vi ): B4 (vi ):
the the the the
parent of vi , unrelated neighbors vj of vi with j < i, children of vi , and unrelated neighbors vj of vi with j > i,
where each block could be empty. T is an orderly spanning tree of G if v1 is on the boundary of G’s exterior face, and each vi , 1 ≤ i ≤ n, is orderly in G with respect to T . It is not difficult to see that if G is a plane triangulation, then B2 (vi ) (respectively, B4 (vi )) is nonempty for each i = 3, 4, . . . , n (respectively, i = 2, 3, . . . , n − 1. For each i = 2, 3, . . . , n, let p(i) be the index of the parent of vi in T . Let w(i) denote the number of leaves in the subtree of T rooted at vi . Let (i) and r(i) be the functions such that v(i) (respectively, vr(i) ) is the last (respectively, first) neighbor of vi in B2 (vi ) (respectively, B4 (vi )) in counterclockwise order around vi . For example, in the example shown in Figure 1(a), 4
A separating triangle, which is also known as complex triangle [36, 37], is a cycle of three edges enclosing some nodes in its interior. For example, (2, 3, 5) and (8, 10, 12) are two separating triangles of the graph shown in Figure 1(a).
336
Ho-Lin Chen et al.
one can easily verify that node 3 is indeed orderly with respect to T , where B1 (3) = {1}, B2 (3) = {2}, B3 (3) = {4, 5}, B4 (3) = {6, 9}, p(3) = 1, w(3) = 2, (3) = 2, and r(3) = 9. When G is a plane triangulation, it is known [5] that for each edge (vi , vj ) of G − T with i < j, at least one of i = (i) and j = r(i) holds. To be more specific, if i = 2 and j = n, then both 3 = (n) and n = r(3) hold; otherwise, precisely one of i = (i) and j = r(i) holds. The following lemma is an important property of orderly spanning tree. Lemma 1 (see [5]). Given an n-node span plane triangulation G, an orderly 5 leaves is obtainable in O(n) time. ning tree T of G with at most 2n+1 3 A floor-plan F of G is a partition of a rectangle into n non-overlapping rectangular modules r1 , r2 , . . . , rn such that vi and vj are adjacent in G if and only if the boundaries of ri and rj share at least one non-degenerated line segment. The size of F is the area of the rectangle being partitioned by F with the convention that the corners of all modules are placed on integral grid points. For example, the size of the floor-plan shown in Figure 1(c) is 8 × 7. Based upon Lemma 1, Liao, Lu, and Yen [23] gave a linear-time algorithm for obtaining floor-plans for plane triangulations with the best known worst-case size. Lemma 2 (see [23]). Given an n-node plane triangulation G with n ≥ 3, a floor-plan F of G can be constructed in O(n) time such that F consists of Imodules, 2n+1 L-modules, and T-modules only. The size of F is at most (n − 1) × . 3
3
Podevs Drawings
The following corollary of Lemma 2 shows how to obtain a Podevs drawing from the output floor-plan of [23]. Corollary 1. Let G be an n-node internally triangulated plane graph with at least four vertices on the external boundary of G. Let a and b be two nodes of G on the external boundary of G. Then, G admits an (n − 1)∆ × 2n+1 ∆ Podevs 3 drawing with at most one bend per edge. Moreover, nodes a and b on the external cycle have only upward edges except edge (a, b). Proof. (sketch) We first compute a floor-plan as guaranteed by Lemma 2. Now for each module, we place a unit square at a position that is visible to all points in the module. It is not difficult to see that one can connect the squares corresponding to two adjacent nodes in G by a line with one bend such that no two edges intersect each other. The corollary can be obtained by enlarging the above drawing by a factor of ∆. For example, the Podevs drawing in Figure 1(b) is obtained this way. 2n−f +1 5 Recently, Mosbah, Bonichon, and Le Sa¨ec [26] proved a tighter bound on 3 the number of leaves in an orderly spanning tree from the viewpoint of realizers, where f is the number of “cyclic faces” in a realizer of G. In the extreme cases, f could be O(1).
Some Applications of Orderly Spanning Trees in Graph Drawing
337
Let G be a plane triangulation on n nodes v1 , v2 , . . . , vn−1 , r, where r belongs to the external boundary of G, such that (r, vi ) is an edge of G for each i = 1, 2, . . . , n − 1. Let Ga,b denote the subgraph of G induced by r, va , va+1 , . . . , vb . We have the following two lemmas. Let h(Γ ) (respectively, w(Γ ) and hw(Γ )) denote the number x such that x∆ is the required height (respectively, width and half-perimeter) of the drawing Γ . Lemma 3. G has a Podevs drawing Γ with w(Γ ) ≤ (n − 1), h(Γ ) ≤ n2 + 1 that has at most one bend per edge. Moreover, if n is odd, then nodes r, v1 , vn−1 and edge (r, vn−1 ) occupy the four corners of Γ ; otherwise, nodes r, v1 , edge (v1 , vn−1 ), and edge (vn−1 , r) occupy the four corners of Γ . Proof. (sketch) We prove the lemma by induction on n. Clearly, the lemma holds trivially for n = 4 and n = 5. As for the induction step, consider the case that k is odd. We first find the index i such that vi is connected to both v1 and vk−1 . If i = 2 or i = k − 2, then we may assume without loss of generality that i is odd. By the inductive hypothesis, we can obtain drawings of G1,i and Gi,n−1 with total width no more than k − 1 whose maximum height is at most k2 . Now we combine the graphs to get the drawing of G, as shown in Figure 3(a). If i = 2, then we can draw Gi,k−1 and add v −1 nodes properly, each increasing the width by one, to get Γ , as shown in Figure 3(b). The case i = k − 2 is similar. The case that k is even can be proved similarly. Lemma 4. Ga,b has a Podevs drawing Γ with hw(Γ ) ≤ (n − 1) + n2 + 1 that contains at most one bend per edge. The other two nodes a and b on the external cycle has only upward edges except edge (a, b) and are on consecutive corners of the drawing. Proof. (sketch) If i = 2 or i = k − 2, find the node vi such that vi is adjacent to all three nodes on the external boundary. Without loss of generality, we may assume i ≥ (k − 1)/2. By Corollary 1, we can find a drawing D1 of Gi,k−2 with h(D1 ) ≤ k−i and w(D1 ) ≤ k−i such that r and vi are on two consecutive corners. Let j = 1 be the smallest number such that vi and vj are connected.By Lemma 3, + 2 such we have a drawing D2 of Gj,i with w(D2 ) ≤ i − j + 1 and h(D2 ) ≤ i−j 2 that r, vj , vi are three consecutive corners of D2 . Combining the two drawings and adjust the position ofr, vi , and v1 properly, we can get a drawing Dk of G with hw(D) ≤ k − i + i−j + 1 + i − j + 1 + j ≤ k + i−j + 2 ≤ (k − 1) + 2 + 2. 2 2 The second equality holds only when j = 2 and the third equality holds only when i = k − 2. If i = k − 2 or j = 2, then the hw(D) ≤ (k − 1) + k2 + 1. If i = k − 2 and j = 2, then by Lemma 3 we can draw Gj,i in a (k − 3) × k2 area. If k is even, then we can add v1 and vi such that the width and height of the drawing are increased by 2 and 1, respectively. If k is odd, then we can add v1 and vi such that the width and height of the drawing are both increased by 2. In both cases, we have hw(D) ≤ (k − 1) + k2 + 1. Theorem 1. Any n-node 2nwith half-peri plane graph G has a Podevs drawing +1)(∆−1) and width no more than ( meter no more than ( 3n 2 3 +1)(∆−1).
338
Ho-Lin Chen et al.
r
r
r
(a)
r
r
(b)
Fig. 3. (a) The left drawing is for G1,i , the middle drawing is for Gi,n−1 , and the right drawing is the combined one. (b) The left drawing is for G1,n−2 and the right drawing is the resulting drawing of adding one node.
Proof. (sketch) Find an orderly spanning tree T of G. Let the number of leaves of T be m. A cluster of leaves in T is a maximum set of connected leaves of T with the same parent in T . If m ≤ n/2, then the drawing obtained from the original floor-plan satisfies the requirement. Otherwise, by Corollary 1, we can get a drawing Γ of G with w(Γ ) ≤ m and h(Γ ) ≤ n−1. Using Lemma 4, for each cluster of the leaves, we can adjust the drawing Γ such that a cluster of t tleaves in an area with half-perimeter bounded by (t+3−1)+ t+3 +1−4 = t+ 2 +1. 2 The half-perimeter of the drawing is at most n − m/2 + m + Ne + No /2, where Ne is the number of clusters with even number of leaves and No is the number of clusters with odd number of leaves. For any two clusters C1 and C2 of leaves, we say that C1 is an ancestor of C2 if an ancestor of C2 is connected to some leaves in C1 . If C1 is an ancestor of C2 and the number of leaves in C2 is more than one, then let the parent of C2 be N2 , we can reduce the width by 1 by shifting the subtree rooted at N2 . If for two clusters Ci and Cj , we cannot find a sequence of clusters Ci , Ci+1 , · · · , Cj such that Ca is an ancestor of Ca+1 , for all a, then the height of the drawing can be reduced by 1 since the two clusters may share the same level of the Podevs drawing. Suppose the sequence of clusters that has the maximum height is S. We know that the half-perimeter of the drawing is at most n−m/2+m+Ne (S)+No (S)/2−Nt (S) ≤ 3n + 1, where Ne (S) is the number of clusters in S that has even number of 2 leaves, No (S) is the number of clusters in S that has odd number of leaves, and Nt (S) is the number of clusters in S that has at least two leaves. Since the width of the drawing in Lemma 3 is at most n−1. The above operations do not increase the width of the drawing. Therefore, the width of the drawing is at most m. By Lemma 2, we can find the desired drawing of the graph. Now we expand each node by the same factor. One problem occurs when there is a straight edge connecting two nodes such that two nodes cannot put in the same level, see Figure 4. We define a new notation: for a node N in the graph, edge-right-bend-up(N ) is the number of edges attach to the right-hand side of the node N and have an upward bend. (Similar for others.) The rest of the proof shows that The graph can be properly rearranged such that the node size is smaller than (∆ − 1) × (∆ − 1). The only problem occurs when there is a straight edge connecting two nodes. According to our algorithm, one node will have more than one downward edges
Some Applications of Orderly Spanning Trees in Graph Drawing
339
A A
B
B
Fig. 4.
if and only if its children are leaves which have already been rearranged. In this case, there is no downward straight edge. Otherwise, the node has only one downward edge and can be attached to any point of the node. So, we can always arrange the downward straight edge to satisfy the constraint that the node size is smaller than (∆ − 1) × (∆ − 1). Consider the case where two nodes A and B are connected by a horizontal straight edge and edge-right-bend-up(A) + 1 + edge-left-bend-down(B) ≥ ∆ − 1. (See Figure 4). Rearrange edge-right-bend-up(A)+edge-left-bend-down(B)−∆+1 of the nodes connecting to A such that the edges are connected to the upward side of the node A and bends toward right. (As shown in Figure 4.) This change may increase the height of the graph at most edge-right-bend-up(A) but can always be compensated since there are edge-right-bend-up(A) nodes connecting to A and edge-left-bend-down(B) nodes connecting to B that can share columns and hence decrease the width of the graph by the minimum of edge-right-bend-up(A) and edge-left-bend-down(B).
4
Rectangular Dual
This section gives an alternative proof for the following theorem. Theorem 2. Every internally triangulated plane graph G without complex triangle has a rectangular dual if and only if G has at least four vertices on the external boundary of G. For a internally triangulated plane graph G and a node r and at least three other nodes on the external cycle, let floor-plan(G, r) be a floor-plan of G consisting of I-modules, L-modules, and T-modules such that r completely occupies one of its four sides. By Lemma 2, such a floor-plan can be obtained in linear time. In such a floor-plan, the level of a node v, denoted (v), is defined as the distance between the bottom boundaries of r and v. For example, we have (1) = 0, (7) = 1, (8) = 2, and (5) = 6 in the floor-plan shown in Figure 1(c). Lemma 5. If a plane graph G is internally triangulated and has no complex triangle, then for any three consecutive nodes a, r, b on the external cycle of G, there is a rectangular dual of G with a, r, b completely occupying three sides of the drawing. Proof. (sketch) We prove the theorem by induction on the number of nodes in G. Clearly, the theorem holds trivially if G has at most three nodes. Suppose
340
Ho-Lin Chen et al.
Fig. 5. An illustration for our algorithm for rectangular dual.
for any plane graph G with less than n nodes, the theorem holds. For a graph G with n nodes and nodes a, r, b specified on the external cycle, we can find a rectangular dual by the following process. Step 1. Triangulate G so that (a, r, b) is the external boundary of the triangulated graph. Step 2. By computing floor-plan(G, r), we get a floor-plan F of G consisting of only L-modules and T-modules. We then repeat the following three steps until all nodes are picked and processed in Step 3. Step 3. Choose the node N1 having the lowest level among all L-module and T-module nodes. Without loss of generality, we may assume that N1 bends to the right, the node at the right-hand side of N1 is N2 , and the parents of N1 , N2 are N0 , N3 , respectively, as shown in Figure 5(a). Step 4. If (N0 ) < (N3 ), then draw a horizontal line L at the bottom of N3 . Let G1 be the subgraph of G induced by all nodes surrounded by N1 , N2 , N3 and L. By the induction hypothesis, we can find a rectangular dual R1 of G1 such that N1 , N2 , N3 completely occupy the remaining three sides of R1 . Adjust R1 such that the four corners of R1 are N1 , N1 , N2 , and N3 respectively. Expand R1 and F so that all the nodes on the external cycle of R1 have the same size in two graphs. Replace the subgraph G1 in F by expanding R1 . Step 5. If (N3 ) < (N0 ), then draw a horizontal line L at the bottom of N0 . Let G2 be the subgraph of G induced by all nodes surrounded by N0 , N1 , N2 and L. By the inductive hypothesis, we can find a rectangular dual R2 of G2 such that N0 , N1 , N2 are three sides of R2 . Adjust R2 such that the four corners of R2 belong to N0 , N1 , N2 , N2 , respectively. Expand R2 and F so that all the nodes on the external cycle of R2 have the same size in two graphs. Replace the subgraph G2 in F by expanding R2 . Since we maintain the property stated in Step 2 and the number of bends is reduced by 1 each time, we can get a rectangular dual of G in O(n) iterations.
Some Applications of Orderly Spanning Trees in Graph Drawing 1
2
1
2 A
3
4
3
1
3 4
341
A
2 4
Fig. 6. An illustration for using rectangular duals to obtain proper box rectangular drawings.
5
Concluding Remarks
In conventional floor-planning, two rectangles are may be adjacent even if the two modules corresponding to them do not have interconnections. Such unwanted adjacencies are not desirable in some other floor-planning problem. In floorplanning of a Multi-chip Module (MCM), two chips generating excessive heat should not be adjacent, or two chips operating on high frequency should not be adjacent to avoid malfunctioning due to their interference [33]. Unwanted adjacencies may cause a dangerous situation in some architectural floor-planning, too [14, 16, 31]. A box-rectangular drawing [31] has the nice property of avoiding unwanted adjacency of modules, but may draw some vertices as points. A proper box rectangular drawing, introduced by He [16], requires every vertex to be drawn as a real box. A rectangular-dual algorithm gives an alternative way for obtaining a proper box rectangular drawing. First of all, we add a new vertex v into each nontriangular internal face F of the given biconnected graph G with at least four nodes on the external boundary. We then triangulate F by adding an edge from v to each node on the boundary of F . G becomes a triangular plane graph G . We then obtain a rectangular dual D for G . A proper box rectangular drawing D of G can be obtained from D by turning the module for each newly introduced vertex into a dead space. Clearly, two rectangles are always adjacent if and only if the two modules corresponding to them have interconnections in G and G . See Figure 6 for an example. An interesting possibility for future work is to see whether orderly spanning trees play any constructive role in characterizing slicible floor-plans. It would also be interesting to close the gap between the upper and lower bounds for Podevs drawing for planar graphs, and to see whether new results concerning Podevs drawing with two or more bends can be derived.
References 1. P. Bertolazzi, G. Di Battista, and W. Didimo. Computing orthogonal drawings with the minimum number of bends. IEEE Transactions on Computers, 49(8):826– 840, 2000. 2. T. Biedl and M. Kaufmann. Area-efficient static and incremental graph drawings. In Proceedings of the 5th European Symposium on Algorithms, Lecture Notes in Computer Science 1284, pages 37–52. Springer-Verlag, 1997.
342
Ho-Lin Chen et al.
3. T. Biedl, B. Madden, and I. Tollis. The three-phase method: A unified approach to orthogonal graph drawing. International Journal of Computational Geometry and Applications, 10(6):553–580, 2000. 4. N. Bonichon, B. Le Sa¨ec, and M. Mosbah. Orthogonal drawings based on the stratification of planar graphs. In Proceedings of the 6th International Conference on Graph Theory, Electronic Notes in Discrete Math 5, Marseille, France, 2000. Elsevier. A full version can be found at http://citeseer.nj.nec.com/bonichon00orthogonal.html. 5. Y.-T. Chiang, C.-C. Lin, and H.-I. Lu. Orderly spanning trees with applications to graph encoding and graph drawing. In Proceedings of the 12th Annual ACM-SIAM Symposium on Discrete Algorithms, pages 506–515, Washington, D. C., USA, 7–9 Jan. 2001. A revised and extended version can be found at http://xxx.lanl.gov/abs/cs.DS/0102006. 6. M. Chrobak and G. Kant. Convex grid drawings of 3-connected planar graphs. International Journal of Computational Geometry & Applications, 7(3):211–223, 1997. 7. M. Chrobak and T. H. Payne. A linear-time algorithm for drawing a planar graph on a grid. Information Processing Letters, 54(4):241–246, May 1995. 8. H. de Fraysseix, P. Ossona de Mendez, and P. Rosenstiehl. On triangle contact graphs. Combinatorics, Probability and Computing, 3:233–246, 1994. 9. H. de Fraysseix, J. Pach, and R. Pollack. How to draw a planar graph on a grid. Combinatorica, 10:41–51, 1990. 10. G. di Battista, P. Eades, R. Tammassia, and I. Tollis. Graph Drawing: Algorithms for the Visualization of Graphs. Prentice Hall, 1998. 11. M. Eiglsperger and M. Kaufmann. Fast compaction for orthogonal drawings with vertices of prescribed size. In Mutzel et al. [27], pages 124–138. 12. U. F¨ oßmeier, G. Kant, and M. Kaufmann. 2-visibility drawings of planar graphs. In S. North, editor, Proceedings of the 4th International Symposium on Graph Drawing, Lecture Notes in Computer Science 1190, pages 155–168, California, USA, 1996. Springer-Verlag. 13. U. F¨ oßmeier and M. Kaufmann. Drawing high degree graphs with low bend numbers. In S. Whitesides, editor, Proceedings of the 3th International Symposium on Graph Drawing, Lecture Notes in Computer Science 1027, pages 254–266, Passau, Germany, 1995. Springer-Verlag. A full version: Technical Report WSI-95-21, Wilhelm-Schickard-Institut Universit¨ at T¨ ubingen, 1995. 14. R. L. Francis and J. A. White. Facility layout and location. Prentice-Hall, New Jersey, 1974. 15. X. He. On floor-plan of plane graphs. SIAM Journal on Computing, 28(6):2150– 2167, 1999. 16. X. He. A simple linear time algorithm for proper box rectangular drawings of plane graphs. Journal of Algorithms, 40(1):82–101, 2001. 17. O. H. Ibarra and L. Zhang, editors. Proceedings of the 8th International Conference on Computing and Combinatorics, Lecture Notes in Computer Science 2387, Singapore, August 15–17 2002. Springer. 18. G. Kant. Drawing planar graphs using the canonical ordering. Algorithmica, 16(1):4–32, 1996. 19. G. Kant and X. He. Regular edge labeling of 4-connected plane graphs and its applications in graph drawing problems. Theoretical Computer Science, 172(12):175–193, 1997. 20. K. Ko´zmi´ nski and E. Kinnen. Rectangular duals of planar graphs. Networks, 15(2):145–157, 1985.
Some Applications of Orderly Spanning Trees in Graph Drawing
343
21. K. A. K´ ozmi´ nski and E. Kinnen. Rectangular dualization and rectangular dissections. IEEE Transactions on Circuits and Systems, 35(11):1401–1416, 1988. 22. Y. T. Lai and S. M. Leinwand. A theory of rectangular dual graphs. Algorithmica, 5(4):467–483, 1990. 23. C.-C. Liao, H.-I. Lu, and H.-C. Yen. Floor-planning via orderly spanning trees. In Mutzel et al. [27], pages 367–377. 24. H.-I. Lu. Improved compact routing tables for planar networks via orderly spanning trees. In Ibarra and Zhang [17], pages 57–66. 25. K. Mailing, S. H. Mueller, and W. R. Heller. On finding most optimal rectangular package plans. In Proceedings of the 19th Annual IEEE Design Automation Conference, pages 263–270, 1982. 26. M. Mosbah, N. Bonichon, and B. Le Sa¨ec. Wagner’s theorem on realizers. In M. Hennessy and P. Widmayer, editors, Proceedings of the 29th International Colloquium on Automata, Languages, and Programming, Lecture Notes in Computer Science 1443, pages 1043–1063, M´ alaga, Spain, 2002. Springer-Verlag. 27. P. Mutzel, M. J¨ unger, and S. Leipert, editors. Proceedings of the 9th International Symposium on Graph Drawing, Lecture Notes in Computer Science 2265, Vienna, Austria, 2001. Springer. 28. P. Mutzel and R. Weiskircher. Bend minimization in orthogonal drawings using integer programming. In Ibarra and Zhang [17], pages 484–493. 29. R. Otten. Efficient floorplan optimization. In Proceedings of International Conference on Computer Design, pages 499–503, Port Chester, New York, 1983. 30. A. Papakostas and I. G. Tollis. Efficient orthogonal drawings of high degree graphs. Algorithmica, 26(1):100–125, 2000. 31. M. S. Rahman, S. Nakano, and T. Nishizeki. Box-rectangular drawings of plane graph. In Proceedings of the 21st Graph-Theoretic Concepts in Computer Science, Lecture Notes in Computer Science 1272, pages 250–261. Springer-Verlag, 1999. 32. W. Schnyder. Embedding planar graphs on the grid. In Proceedings of the First Annual ACM-SIAM Symposium on Discrete Algorithms, pages 138–148, 1990. 33. N. Sherwani. Algorithms for VLSI physical design automation. Kluwer Academic Publishers, 1995. 34. L. Stockmeyer. Optimal orientation of cells in slicing floorplan designs. Information and Control, 57(2):91–101, 1983. 35. R. Tamassia. On embedding a graph in the grid with the minimum number of bends. SIAM Journal on Computing, 16(3):421–444, 1987. 36. S. Tsukiyama, K. Koike, and I. Shirakawa. An algorithm to eliminate all complex triangles in a maximal planar graph for use in VLSI floorplan. In Proceedings of the IEEE International Symposium on Circuits and Systems, pages 321–324, 1986. 37. K.-H. Yeap and M. Sarrafzadeh. Floor-planning by graph dualization: 2-concave rectilinear modules. SIAM Journal on Computing, 22(3):500–526, 1993.
Improving Walker’s Algorithm to Run in Linear Time Christoph Buchheim1 , Michael J¨ unger1 , and Sebastian Leipert2 1
Universit¨ at zu K¨ oln, Institut f¨ ur Informatik, Pohligstraße 1, 50969 K¨ oln, Germany {buchheim,mjuenger}@informatik.uni-koeln.de 2 caesar research center, Friedensplatz 16, 53111 Bonn, Germany [email protected]
Abstract. The algorithm of Walker [5] is widely used for drawing trees of unbounded degree, and it is widely assumed to run in linear time, as the author claims in his article. But the presented algorithm clearly needs quadratic runtime. We explain the reasons for that and present a revised algorithm that creates the same layouts in linear time.
1
Introduction
Since Walker presented his article [5] on drawing rooted ordered trees of unbounded degree, this topic is considered a solved problem of Automatic Graph Drawing. In 1979, Wetherell and Shannon [6] presented a linear time algorithm for drawing binary trees satisfying the following aesthetic requirements: the y-coordinate of a node corresponds to its level, so that the hierarchical structure of the tree is displayed; the left child of a node is placed to the left of the right child, i.e., the order of the children is displayed; finally, each parent node is centered over its children. Nevertheless, this algorithm showed some deficiencies. In 1981, Reingold and Tilford [2] improved the Wetherell-Shannon algorithm by adding the following feature: each pair of isomorphic subtrees is drawn identically up to translation, i.e., the drawing does not depend on the position of a subtree within the complete tree. They also made the algorithm symmetrical: if all orders of children in a tree are reversed, the computed drawing is the reflected original one. The width of the drawing is not always minimized subject to these conditions, but it is close to the minimum in general. The algorithm of Reingold and Tilford runs in linear time, too. Extending this algorithm to rooted ordered trees of unbounded degree in a straightforward way produces layouts where some subtrees of the tree may get clustered on a small space, even if they could be dispersed much better. This problem was solved in 1990 by the algorithm of Walker [5], which spaces out subtrees whenever possible. Unfortunately, the runtime of the algorithm presented in [5] is quadratic, in contrary to the author’s assertion. In the present article, we close this gap by giving an adjustment of Walker’s algorithm that does not affect the computed layouts but yields linear runtime. M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 344–353, 2002. c Springer-Verlag Berlin Heidelberg 2002
Improving Walker’s Algorithm to Run in Linear Time
345
In the next section, we establish the basic notation about trees and state the aesthetic criteria guiding the algorithms to be dealt with. In Sect. 3, we explain the Reingold-Tilford algorithm. In Sect. 4, we describe the idea of Walker’s algorithm and point out the non-linear parts. We improve these parts in order to get a linear time algorithm in Sect. 5.
2
Preliminaries
We define a (rooted) tree as a directed acyclic graph with a single source, called the root of the tree, such that there is a unique directed path from the root to any other node. The level of a node is the length of this path. For each edge (v, w), we call v the parent of w and w a child of v. If w1 and w2 are two different children of v, we say that w1 and w2 are siblings. Each node w on the path from the root to a node v is called an ancestor of v, while v is called a descendant of w. A leaf of the tree is a sink of the graph, i.e., a node without children. If v− and v+ are two nodes such that v− is not an ancestor of v+ and vice versa, the greatest distinct ancestors of v− and v+ are defined as the unique ancestors w− and w+ of v− and v+ , respectively, such that w− and w+ are siblings. Each node v of a rooted tree T induces a unique subtree of T with root v. In a binary tree, each node has at most two children. In an ordered tree, a certain order of the children of each node is fixed. The first (last) child according to this order is called the leftmost (rightmost) child. The left (right) sibling of a node v is its predecessor (successor) in the list of children of the parent of v. The leftmost (rightmost) descendant of v on level l is the leftmost (rightmost) node on level l belonging to the subtree induced by v. Finally, if v1 is the left sibling of v2 , w1 is the rightmost descendant of v1 on some level l, and w2 is the leftmost descendant of v2 on the same level l, we call w1 the left neighbor of w2 and w2 the right neighbor of w1 . To draw a tree into the plane means to assign x- and y-coordinates to its nodes and to represent each edge (v, w) by a straight line connecting the points corresponding to v and w. When drawing a rooted tree, one usually requires the following aesthetic properties: (A1) The layout displays the hierarchical structure of the tree, i.e., the ycoordinate of a node is given by its level. (A2) The edges do not cross each other and nodes on the same level have a minimal horizontal distance. (A3) The drawing of a subtree does not depend on its position in the tree, i.e., isomorphic subtrees are drawn identically up to translation. If the trees to be drawn are ordered, we additionally require the following: (A4) The order of the children of a node is displayed in the drawing. (A5) The algorithm works symmetrically, i.e., the drawing of the reflection of a tree is the reflected drawing of the original tree. Here, the reflection of an ordered tree is the tree with reversed order of children for each parent node. Usually, one tries to find a layout satisfying (A1) to (A5) with a small width, i.e., with a small range of x-coordinates.
346
3
Christoph Buchheim, Michael J¨ unger, and Sebastian Leipert
Reingold and Tilford’s Algorithm
For ordered binary trees, the first linear time algorithm satisfying (A1) to (A5) was presented by Reingold and Tilford [2]. This algorithm is easy to describe informally: it draws the tree recursively in a bottom-up sweep. Leaves are placed to an arbitrary x-coordinate and to the y-coordinate given by their level. After drawing the subtrees induced by the children of a parent node independently, the right one is shifted so that it is placed as close to the right of the left subtree as possible.1 Next, the parent is placed centrally above the children, this is, at the x-coordinate given by the average x-coordinate of the children, and at the y-coordinate given by its level. Finally, the edges are inserted. The Reingold-Tilford algorithm obviously satisfies (A1) to (A5). The difficult task is how to perform the steps described above in linear time. The crucial part of the algorithm is the shifting of the second subtree; solving the following problems takes quadratic runtime in total, if a straightforward algorithm is used: first, the computation of the new position of this subtree, second, the shifting of the subtree itself. For the first problem, define the left (right) contour of a tree as the sequence of leftmost (rightmost) nodes in each level, traversed from the root to the highest level. For an illustration, see Fig. 1, where nodes belonging to the contours are shaded. To place the right subtree as close to the left one as possible, we have to compare the positions of the right contour of the left subtree with the positions of the left contour of the right subtree, for all levels occuring in both subtrees. Since each node belongs to the traversed part of the left contour of the right subtree at most for one subtree combination, the total number of such comparisons is linear for the complete tree. The runtime problem is how to traverse the contours without traversing (too many) nodes not belonging to the contours. To solve this problem, Reingold and Tilford introduce threads. For each leaf of the tree that has a successor in the same contour, the thread is a pointer to this successor. See Fig. 1 again, where the threads are represented by dotted arrows. For every node of the contour, we now have a pointer to its successor in the contour: either it is the leftmost (rightmost) child, or it is given by the thread. Finally, to keep the threads up to date, one has to add a new thread whenever two subtrees of different height are combined. For the second problem, the straightforward algorithm would shift all nodes of the right subtree by the same value. Since this needs quadratic time in total, Reingold and Tilford attach a new value mod (v) to each node v, which is called its modifier (this technique was presented by Wetherell and Shannon [6]). The position of each node is preliminary in the bottom-up traversal of the tree. When moving a subtree rooted at v, only mod (v) and a preliminary x-coordinate prelim(v) are adjusted by the amount of shifting. The modifier of a node v 1
For simplicity, we assume throughout this paper that all nodes have the same dimensions and that the minimal distance required between neighbors is the same for each pair of neighbors. Both restrictions can be relaxed easily, since we will always compare a single pair of neighbors
Improving Walker’s Algorithm to Run in Linear Time
347
t
Fig. 1. Combining two subtrees and adding a new thread t
is interpreted as a value to be added to all preliminary x-coordinates in the subtree rooted at v, except for v itself. Thus, the real position of a node is its preliminary position plus the aggregated modifier modsum(v) given by the sum of all modifiers on the path from the parent of v to the root. To compute all real positions in linear time, the tree is traversed in a top-down fashion at the end. When comparing contour nodes to compute the new position of the right subtree, we need the real positions of these nodes, too. For runtime reasons, we may not sum up modifiers on the paths to the root. Therefore, modifiers are used in leaves as well. A modifier of a leaf v with a thread to a node w stores the difference between modsum(w) and modsum(v). Since new threads are added after combining two subtrees, these modifier sums can be computed while traversing the contours of the two subtrees. We have to traverse not only the inside contours but also the outside contours for computing the modifier sums, since v is a node of the outside contour. Now the aggregated modifiers can be computed as the sums of modifiers along the contours instead of the paths to the root.
4
Walker’s Algorithm
For drawing trees of unbounded degree, the Reingold-Tilford algorithm could be adjusted easily by traversing the children from left to right, placing and shifting the corresponding subtrees one after another. However, this violates property (A5): the subtrees are placed as close to each other as possible and small subtrees between larger ones are piled to the left; see Fig. 2(a). A simple trick to avoid this effect is to add an analogous second traversal from right to left; see Fig. 2(b), and to take average positions after that. This algorithm satisfies (A1) to (A5), but smaller subtrees are usually clustered then; see Fig. 2(c). To obtain a layout where smaller subtrees are spaced out evenly, as for example in Fig. 2(d), Walker [5] proposed the following proceeding; see Fig. 3: the subtrees of the current root are processed one after another from left to right. First, each child of the current root is placed as close to the right of its left sibling as possible. As in Reingold and Tilford’s algorithm, the left contour of the current subtree is then traversed top down in order to compare the positions of its nodes to those of their left neighbors. Whenever two conflicting neighbors v− and v+ are detected, forcing v+ to be shifted to the right by an amount of
348
Christoph Buchheim, Michael J¨ unger, and Sebastian Leipert
(a)
(b)
(c)
(d)
Fig. 2. Extending the Reingold-Tilford algorithm to trees of unbounded degree
shift, we apply an appropriate shift to all smaller subtrees between the subtrees containing v− and v+ . More precisely, let w− and w+ be the greatest distinct ancestors of v− and v+ . Notice that both w− and w+ are children of the current root. Let subtrees be the number of children of the current root between w− and w+ plus 1. Spacing out the subtrees is shifting the subtree rooted at the i-th child to the right of w− by an amount of i·shift/subtrees, for i = 1, . . . ,subtrees. Observe that subtrees may be shifted several times by this algorithm, even while adding a single subtree. It is easy to see that this algorithm satisfies (A5).
Fig. 3. Spacing out the smaller subtrees
Unfortunately, many parts of the algorithm presented in [5] do not run in linear time. Some of them are easy to improve, for example by using Reingold and Tilford’s ideas, and some require new ideas. All problems concern Walker’s procedure APPORTION; see pages 695–697 in [5]. In the following, we list the critical parts. In the next section, we will explain how to change these in order to obtain linear runtime. Traversing the right contour: A recursive function GETLEFTMOST is used to find the leftmost descendant of a given node v on a given level l. If the level
Improving Walker’s Algorithm to Run in Linear Time
349
of v is l, the algorithm returns v. Otherwise, GETLEFTMOST is applied recursively to all children of v, from left to right. The aggregated runtime of GETLEFTMOST is not linear in general. To prove that, we present a series of trees Tk such that the number of nodes in Tk is n ∈ Θ(k 2 ), but the total number of GETLEFTMOST calls is Θ(k 3 ). Since k ∈ Θ(n1/2 ), this shows that the total runtime of GETLEFTMOST is Ω(k 3 ) = Ω(n3/2 ). The tree Tk is defined as follows (see Fig. 4(a) for k = 3): Beginning at the root, there is a chain of 2k nodes, each of the last 2k − 1 being the right or only child of its predecessor. For i = 1, . . . , k, the i-th node in this chain has another child to the left; this child is the first node of a chain of 2(k − i) + 1 nodes. The number of nodes in Tk is 2k +
k
(2(k − i) + 1) = 2k + k(k − 1) + k ∈ Θ(k 2 ) .
i=1
Now, for each i = 0, . . . , k − 1, we have to combine two subtrees when visiting the node on the right contour of Tk on level i. In this combination, the highest common level of the subtrees is 2k − i − 1, and by construction of Tk we always have to apply GETLEFTMOST to every node of the right subtree up to this level. The number of these nodes is k−i+
k−i−1
(2j) = (k − i) + (k − i)(k − i − 1) = (k − i)2 ,
j=0
hence the total number of GETLEFTMOST calls for all combinations is k−1 i=0
(k − i)2 =
k
i2 = k(k + 1)(2k + 1)/6 ∈ Θ(k 3 ) .
i=1
Finding the ancestors and summing up modifiers: This part of the algorithm is obviously quadratic. When adjusting the current subtree to the left subforest, the greatest distinct ancestors of the possibly conflicting neighbors are computed for each level by traversing the graph up to the current root, at the same time computing the modifier sums. Since the distance of the levels grows linearly, the total number of steps is in Ω(n2 ). Counting and shifting the smaller subtrees: When shifting the current subtree to the right because of a conflict with a subtree to the left, the procedure APPORTION also shifts all smaller subtrees in-between immediately. Furthermore, the number of these subtrees is computed by counting them one by one. Both actions have an aggregated runtime of Ω(n3/2 ), as the following example shows. Let the tree T k be constructed as follows (see Fig. 4(b) for k = 3): add k children to the root. The i-th child, counted i = 1, . . . , k from left to right, is root of a chain of i nodes. Between each pair of these children, add k children as leaves. The leftmost child of the root has 2k + 5 children, and up to level k − 1, every rightmost child of the 2k+5 children has again 2k+5 children. The number
350
Christoph Buchheim, Michael J¨ unger, and Sebastian Leipert
of nodes of T k is 1+
k
i + (k − 1)k + (k − 1)(2k + 5) ∈ Θ(k 2 ) .
i=1
Furthermore, by construction of the left subtree, adding the i-th subtree chain for i = 2, . . . , k results in a conflict with the left subtree on level i. Hence all (i − 1)(k + 1) − 1 smaller subtrees between the two conflicting ones are counted and shifted. Thus, the total number of counting and shifting steps is k
((i − 1)(k + 1) − 1) = (k + 1)k(k − 1)/2 − k + 1 ∈ Θ(k 3 ) .
i=2
As in the last example, we derive that counting and shifting needs Ω(n3/2 ) time in total.
(a) T3
(b) T 3
Fig. 4. Examples proving the non-linear runtime of Walker’s algorithm
5
Improving Walker’s Algorithm
In this section, we explain how to improve the algorithm of Walker to run in linear time without affecting the computed layouts. For a closer look, see [1], where we present the complete revised algorithm in a pseudocode style as well as an experimental runtime comparison of both versions. Traversing the contours and summing up modifiers: This can be done exactly as in the case of binary trees by using threads; see Sect. 3. The fact that the left subforest is no tree in general does not create any additional difficulty. Finding the ancestors: The problem of finding the greatest distinct ancestors w− and w+ of two nodes v− and v+ can be solved by the algorithm of Schieber and Vishkin [3]. For each pair of nodes, this algorithm can determine the greatest distinct ancestors in constant time, after an O(n) preprocessing step. However,
Improving Walker’s Algorithm to Run in Linear Time
351
in our application, a much simpler algorithm can be applied. First observe that we know the right ancestor w+ anyway; it is just the root of the current subtree. Furthermore, as v+ is always the right neighbor of v− in our algorithm, the left one of the greatest distinct ancestors only depends on v− . Thus we may shortly call it the ancestor of v− in the following. We use a node pointer ancestor (x) for each node x to save its ancestor and initialize it to x itself. Observe that this value is not correct for rightmost children, but we do not need the correct value w− of ancestor (v− ) until the right neighbor v+ of v− is added, i.e., until the current root is the parent node of w− . Hence assume that we are placing the subtrees rooted at the children of v from left to right. Since tracing all ancestor (x) consumes too much time, we use another node pointer defaultAncestor . Our aim is to have the following property (*) for all nodes v− on the right contour of the left subforest after each subtree addition: if ancestor (v− ) is up to date, i.e., is a child of v, then it points to the correct ancestor w− of v− ; otherwise, the correct ancestor is defaultAncestor . We start with placing the first subtree, rooted at w, which does not require any ancestor calculations. After that, we set defaultAncestor to w. Since all pointers ancestor (x) of the left subtree either point to w or to a node of a higher level, the desired property (*) holds, see Fig. 5(a). After placing the subtree rooted at another child w of v, we distinguish two cases: if the subtree rooted at w is smaller than the left subforest, we can actualize ancestor (x) for all nodes x on its right contour by setting it to w . By this, we obviously keep (*); see Fig. 5(b). Otherwise, if the new subtree is larger than the left subforest, we may not do the same because of runtime. But now it suffices to set defaultAncestor to w , since again all pointers ancestor (x) of the subtree induced by w either point to w or to a node of a higher level, and all other subtrees in the left subforest are hidden. Hence we have (*) again; see Fig. 5(c).
(a)
(b)
(c)
Fig. 5. Adjusting ancestor pointers when adding new subtrees: the pointer ancestor (x) is represented by a solid arrow if it is up to date and by a dashed arrow if it is expired. In the latter case, the defaultAncestor is used and drawn black. When adding a small subtree, all ancestor pointers ancestor (x) of its right contour are updated. When adding a large subtree, only defaultAncestor is updated
352
Christoph Buchheim, Michael J¨ unger, and Sebastian Leipert
Counting the smaller subtrees: For that, we just have to number the children of each node consecutively; then the number of smaller subtrees between the two greatest distinct ancestors w− and w+ is the number of w+ minus the number of w− minus 1. Hence it can be computed in constant time (after a linear time preprocessing step to compute all child numbers).
0
0
0
0
0
0
1
0
0
0
1 3
0
0
[− 13 ]
0
0
0
0
0
0
1
1 3
0
0
1
0
[− 13 ] 0
[ 13 + 15 ]
0
0
0
[− 13 ] 0
1 [− 15 ]
Fig. 6. Aggregating the shifts: the top number at node x indicates the value of shift(x), and the bottom number indicates the value of change(x)
Shifting the smaller subtrees: In order to get a linear runtime, we will shift each subtree at most once when it is not the currently added subtree. The currently added subtree, however, may be shifted whenever it conflicts with a subtree to the left, using the fact that shifting a single subtree is done in constant time (recall that we only have to adjust prelim(w+ ) and mod (w+ )). Furthermore, shifting the current subtree immediately is necessary to keep the right contour of the left subforest up to date. All shiftings of non-current subtrees are performed in a single traversal after all subtrees of the current root have been placed. To memorize the shiftings at the moment they arise, we use real numbers shift(x) and change(x) for each node x and set both to zero at the beginning. Assume that the subtree rooted at w+ is the subtree currently placed, and that a conflict with the subtree rooted at w− forces the current subtree to move to the right by an amount of shift. Let subtrees be the number of subtrees between w− and w+ , plus 1. According to Walker’s idea, the i-th of these subtrees has to be moved by i·shift/subtrees. We save this by increasing shift(w+ ) by shift, decreasing change(w+ ) by shift/subtrees, and increasing change(w− ) by shift/subtrees. The interpretation of this is the following: to the left of node w+ , the nodes are shifted by an amount initialized to shift, but this amount starts decreasing by shift/subtrees per subtree at node w+ and ends decreasing at w− , where it is zero. The trick is to aggregate the shifts: since the decrease in the amount of
Improving Walker’s Algorithm to Run in Linear Time
353
shifting is linear, we can add all these decreases in one array; see Fig. 6 for an example. Finally, we execute all shifts in a single traversal of the children of the current root as follows, see Fig. 7: we use two real values shift and change to store the shifts and the decreases of shift per subtree, respectively, and set both to zero at the beginning. Then we traverse the children from right to left. When visiting child v, we move v to the right by shift (i.e., we increase prelim(v) and mod (v) by shift), increase change by change(v), and increase shift by shift(v) and by change. Then we go on to the left sibling of v. It is easy to see that this algorithm shifts each subtree by the correct amount.
0
0
0
1
0
1
[ 13 + 15 ]
0
0
[− 13 ]
0
[− 15 ]
0
[ 15 + 13 ]
[ 25 + 23 ]
3 5
4 5
0
0
[− 15 − 13 ] [− 15 − 13 ] [− 15 − 13 ][− 15 ]
[− 15 ]
Fig. 7. Executing the shifts: the new numbers at node x indicate the values of shift and change before shifting x, respectively
References 1. C. Buchheim, M. J¨ unger, and S. Leipert. Improving Walker’s algorithm to run in linear time. Technical Report zaik2002-431, ZAIK, Universit¨ at zu K¨ oln, 2002. 2. E. Reingold and J. Tilford. Tidier drawings of trees. IEEE Transactions on Software Engineering, 7(2):223–228, 1981. 3. B. Schieber and U. Vishkin. On finding lowest common ancestors: Simplification and parallelization. In Proceedings of the Third Aegean Workshop on Computing, volume 319 of Lecture Notes in Computer Science, pages 111–123, 1988. 4. K. Supowit and E. Reingold. The complexity of drawing trees nicely. Acta Informatica, 18(4):377–392, 1983. 5. J. Walker II. A node-positioning algorithm for general trees. Software – Practice and Experience, 20(7):685–705, 1990. 6. C. Wetherell and A. Shannon. Tidy drawings of trees. IEEE Transactions on Software Engineering, 5(5):514–520, 1979.
Semi-dynamic Orthogonal Drawings of Planar Graphs (Extended Abstract) Walter Bachl sd&m AG, Thomas Dehler-Str. 27, 81837 M¨ unchen [email protected]
Abstract. We introduce a new approach to orthogonal drawings of planar graphs. We define invariants that are respected by every drawing of the graph. The invariants are the embedding together with relative positions of adjacent vertices. Insertions imply only minor changes of the invariants. This preserves the users mental map. Our technique is applicable to two-connected planar graphs with vertices of arbitrary size and degree. New vertices and edges can be added to the graph in O(log n) time. The algorithm produces drawings with at most m+f bends, where m and f are the number of edges and faces of the graph.
1
Introduction
Orthogonal drawings of graphs are used in many applications, e.g. entity-relationship diagrams or VLSI design. They occur in interactive programs like CASE tools, where graphs are built step by step in an interactive session. Clearly the user shall be supported in this task. Such a system should not only create nice drawings. The given layout shall be changed such that the users mental map is preserved ([7,10]). A lot of work has been done on incremental orthogonal layout of non planar graphs ([11,3,9,1]). But we know only one activity in the area of incremental orthogonal layout of planar graphs [2] which is based on [8]. Brandes et al. optimize a combination of static and interactive requirements, this means layout quality and the preservation of the mental map. We introduce a different approach with invariants for the representation of the users mental map. We restrict ourselves to two-connected planar graphs and allow changes of the graph by insertions of vertices and edges. These insertions must preserve planarity, the embedding, and the mental map. Our model is based on the concept of the Kandinsky algorithm [8]. There are unit size vertices with sufficiently many pins on each side to connect arbitrary many edges to the node. In the following, we first define the restrictions R and show how updateoperations change R. We examine the number of bends which can be achieved with this restrictions. This leads to the 4-sector model. Then we show how to implement the update-operations O(log n) and how to generate drawings in O(n) time. M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 354–361, 2002. c Springer-Verlag Berlin Heidelberg 2002
Semi-dynamic Orthogonal Drawings of Planar Graphs
2
355
Restrictions
We consider two-connected planar graphs together with an embedding. Additionally we define restrictions as invariants for insertions. Definition 1. Given a planar graph G(V, E). A restriction system R for G consists of 1. An embedding of the graph. 2. Two attributes e. x and e. y for each edge e = {v1 , v2 } ∈ E. A drawing of G is said to respect R, if it is drawn with the embedding and for each edge e = {v1 , v2 }, if e. x , then v1 has to be left of v2 and if e. y , then v1 has to be below v2 . Both relations are proper. Hence, e. x and e. y have an intuitive meaning. Let G(V, E, R) denote a graph G with vertices V , edges E and the restriction system R. For the semi-dynamic changes we consider the following operations: – initialize(): Create a complete graph of three vertices as initial graph. – insertV ertex(edge e): Replace the edge e = {v1 , v2 } by a new vertex v and the two edges {v1 , v} and {v, v2 }. – insertEdge(vertex v1 , v2 , f ace f ): Insert the edge {v1 , v2 } in the common face f of v1 and v2 . This set of operations is sufficient to produce any two-connected planar graph ([5]). The users mental map is preserved by the following requirements. Definition 2. Let G(V, E, R) be a planar embedded graph with a restriction system, which is transformed to G (V , E , R ) by an update operation from above. insertEdge(v1 , v2 , f ) is called restriction preserving update operation if: 1. ∀ei ∈ E: ei . x and ei . y are not changed. 2. The embeddings of G(V, E, R) and G (V , E \ {e}, R ) are identical. insertN ode(e) is called restriction preserving update operation if: 1. ∀ei ∈ E \ {e}: ei . x and ei . y are not changed. 2. The embeddings of G(V, E, R) and G (V , E , R ) are identical, if the vertex v and the edges e1 and e2 are replaced in G by a new edge {v1 , v2 }. 3. e1 and e2 inherit the attributes x and y from e, i.e. {v1 , v}. x = {v, v2 }. x = {v1 , v2 }. x ∧ {v1 , v}. y = {v, v2 }. y = {v1 , v2 }. y .
3
Bounds on the Number of Bends
We introduce the 4-sector model, which will serve as an invariant for our algorithm. From now on we use figures as graphical representations for restriction systems. If {v1 , v2 }. x , then v1 is drawn to the left of v2 . Similary for y .
356
Walter Bachl
Definition 3. A graph with the restriction system G(V,E , R ) is in the 4-sector model if the vertices around every face f are arranged such that it is possible to divide t h e m into four groups, where in -
-
-
-
sector 1, the cyclic successor sector 2, the cyclic successor sector 3, the cyclic successor sector 4, the cyclic successor
of of of of
every every every every
vertex vertex vertex vertex
is is is is
to to to to
its its its its
upper lower lower upper
right, right, left, left.
Note, that every sector can be empty or consist of a single vertex only. Figure 1 shows two graphical representations of faces in the 4-sector model. The ordering of the vertices in the 4-sector model is unique. It is a necessary condition for the insertion of a new edge with at most one bend. Is it also sufficient?
Fig. 1. Two drawings of faces in the sector model.
Lemma 1. There are graphs with a restriction systems R in the 4-sector model, where a restriction preserving update operation i n s e r t E d g e inserts a n edge with (at least) two bends in any orthogonal drawing respecting R. Proof. See Figure 2. Suppose, that by the restriction system R the vertices are in relative positions as shown. T h e n in any drawing of the graph a n edge between vl and ug in f has to be drawn with two bends.
Fig. 2. Orthogonal edge between and v g needs two bends.
vl
Fig. 3. Notations for the proof of Theorem 1.
This is no restriction of the 4-sector model, because two bends are unavoidable.
Semi-dynamic Orthogonal Drawings of Planar Graphs
357
Theorem 1. There are graphs, where a sequence of restriction preserving update operations leads to a graph with a restriction system such that in any orthogonal planar drawing that respects R, at least one edge has at least two bends. This is independent of the initial restriction system. Proof. Consider the vertices v1 and v2 in Figure 3, which shows an embedding. For any restriction system, a connecting edge {v1 , v2 } through at least one of the common faces must have at least two bends. In the remaining faces we connect the two other vertices by an edge. Thus, one common face of v1 and v2 remains, where v1 and v2 can be connected only by an edge with at least two bends.
4
Interactive Algorithm
We show how to implement the update operations in O(log n) and then construct a drawing of a graph with a restriction system in the 4-sector model. initialize() creates a triangle with a restriction system in O(1). 4.1
Insert-Operations
Theorem 2. Given a planar graph with a restriction system R in the 4-sector model. Then insertV ertex(edge e) can be made restriction preserving such that the resulting graph and the restriction system are in the 4-sector model. Proof. The proof is similar to a derivation step in [4]. The edge e is replaced and the new edges inherit x and y from e. See Figure 4 for an illustration. v1
v1 v v2
v2
Fig. 4. Insertion of a new vertex where the partial-order in x-direction is represented by a dashed arrow and the partial-order in y-direction by a dotted arrow.
Theorem 3. Given a planar graph with a restriction system in the 4-sector model. Then insertEdge(v1 , v2 , f ) can be made restriction preserving such that the resulting graph and the restriction system are in the 4-sector model. Proof. The operation insertEdge(v1 , v2 , f ) divides f into two new faces f1 and f2 . The embedding is updated by the insertion of e between the two edges adjacent to v1 and the two edges adjacent to v2 in face f . Hence, the embedding is preserved as required by definition 2.
358
Walter Bachl
Next consider the restrictions. The attributes x and y have to be computed for the new edge. We discuss the main cases. All other cases are similar. If v1 and v2 are in the same sector, then v1 and v2 are ordered in both directions and x and y of the new edge are taken from this ordering. If v2 is in the sector following the sector of v1 , then the vertices are ordered only in one direction and unordered in the other. The given direction is taken by the edge, the other is chosen arbitrarily. Finally, if v1 and v2 are in diagonal sectors of the face (e.g. v1 in sector 1 and v2 in sector 3), then v1 and v2 are unordered in both directions. Because of the geometric properties of the 4-sector model we have one forbidden ordering of the vertices (v1 can not be right and below of v2 ). The algorithm chooses one of the three remaining orderings (e.g. v1 above and left of v2 ). In all cases, this leads to two new faces which inherit a part of the sectors of face f and the new edge serves as part of one sector in both faces. The graph and the restriction system respect the 4-sector model. No dependencies are changed. 4.2
Data Structures and Time Complexity
Our data structure is an extension of a DCEL ([12]) that is commonly used for planar embeddings. The data structures consist of the following attributes: – Edge e: 1. The embedding is stored in a DCEL. Thus every edge has pointers to its cyclic successor and predecessor at both end vertices. 2. x and y are stored in the attributes of each edge. – Face f : 1. vertex[1..4]: vertex[i] is the first vertex of sector i of f . 2. edge[1..4]: edge[i] connects vertex[i] to its cyclic predecessor in f . 3. tree[1..4]: tree[i] is a balanced tree for all vertices in sector i. It supports the operations “insert()”, “navigate()” (traversal from a leaf to the root) and “split()” in logarithmic time. At the root we store the number of the face and the number of the sector. – Vertex v: Every vertex v holds pointers to the edges which end at v in a face f , if v is not the first vertex of a sector in f . The pointers to the edges have a connection to the corresponding face. Since every vertex can be in the middle of a sector in only two faces, two pointers are sufficient. 1. edge[1..2]: edge[i] is a pointer to the edge which connects v to its cyclic predecessor in face fi . 2. leaf [1..2]: leaf [i] is a pointer to a leaf in the tree, which is assigned to the sector in face i which contains vertex v. Theorem 4. The operations insertN ode(e) and insertEdge(v1 , v2 , f ) can be implemented in O(log n) time using a data structure of size O(n). Proof. For insertV ertex(e) the embedding is updated by replacing e by the new edges. Edge e is in two faces. From its end vertices we can access the trees and
Semi-dynamic Orthogonal Drawings of Planar Graphs
359
insert the new vertex in O(log n) time. For insertEdge(v1 , v2 , f ), we have to find the edges at v1 and v2 between which the new edge has to be inserted. If vi marks the beginning of a sector in f , we get the edges from the attributes edge[1..4] of f . Otherwise we traverse the trees leaf [1..2] to the root and compare the face number with f . One of them must be f and we take the edge from the attribute edge[1..2]. f is split into two new faces f1 and f2 , and we compute the attributes of f1 and f2 from the attributes of f . The attributes edge[1..4] and vertex[1..4] can be computed in constant time from the same attributes of f and the vertices v1 and v2 . tree[1..4] is either a part of a split tree or a full tree of a face f or is created with only one vertex. Additionally, the number of the face at the root of every tree has to be updated. By using the trees this takes O(log n) time. x and y : For insertV ertex(e) the replaced edge is given. Thus, we can copy x and y in O(1) to the new edges. For insertEdge(v1 , v2 , f ), we have to know the sectors of v1 and v2 in f to find valid dependencies for the new edge. If a vertex is the first vertex of a sector, then we can get this information from the attributes of the face. Otherwise, we search in the two trees which are used to find the edges that are adjacent to the vertex in face f . Since we store the number of the sector at the root we have access to the number of the sector of the vertex. The space requirement for all balanced binary trees is in O(n), because every vertex is represented in at most two trees. All other attributes have constant size. 4.3
Drawing Algorithm
We generate an orthogonal representation, and then can use any algorithm which computes an orthogonal drawing from an orthogonal representation (e.g. [8]). The algorithm has the following properties: 1. 2. 3. 4.
The drawing respects the restriction system. At most |F | edges have two bends. The remaining edges have one bend. The algorithm takes O(n) time. The routing of an edge is fixed as long as the number of its bends is unchanged. In [6] the routing of an edge is claimed to be part of the mental map. 5. The drawings are in the Kandinsky-Model [8].
Since the embedding is given, only the routing of the edges has to be computed. Every edge starts vertically at the right side of its left adjacent vertex followed by a horizontal segment. If the edge has one bend, it ends at the right vertex. In case of an edge with two bends we have an additional vertical segment. Figure 5 shows all possible edge routings. Thus it remains to compute which edges have two bends and which have only one bend. Lemma 2. Given a planar graph and its restriction system in the 4-sector model. An edge e has two bends if there exists a face where
360
Walter Bachl
Fig. 5. Possible routings of an edge.
1. sector 1 and 3 are empty and sector 4 consists only of edge e or 2. sector 2 and 4 are empty and sector 1 consists only of edge e or 3. the cyclic successor of e at the right end vertex v of e has two bends and both edges leave v to the upper left or 4. the cyclic predecessor of e at the right end vertex v of e has two bends and both edges leave v to the lower left. All other edges have one bend. The orthogonal representation which is constructed by this rules leads to a planar drawing of the graph. Proof. Clearly, edges in different sectors do not intersect, since the algorithm of [8] partitions a face into disjoint rectangles. Also edges in the same sector cannot intersect and it remains to show, that edges do not intersect at incident vertices. Consider the right side of a vertex v. Let e1 = {v, v1 } be the first edge in counterclockwise order, which ends at the right side of v. Let e2 = {v, v2 } be its successor in the counterclockwise order around vertex v and e2 ends at the right side of v. e1 and e2 cannot intersect, if edge e1 leaves v to the lower right and e2 to the upper right. If both e1 and e2 leave v to the lower right, then the vertical segment of e1 has to be left of the vertical segment of e2 . This holds as long as v1 and v2 are unordered in x-direction or v1 is to the left of v2 . If there is a path in the x-dependencies from vertex v2 to vertex v1 , then v1 has to be right of v2 . We show, that edge e1 must have two bends and therefore the vertical segment of e1 can be to the left of the vertical segment of e2 . Consider face f , which is bounded by the edges e1 and e2 (Figure 6). Let e3 be the cyclic successor of e1 at vertex v1 and e4 be the last edge in the path in the x-dependencies from v2 to v1 . Since e4 is on a path in the x-dependencies, it must be attached to v1 on the left side. The path cannot be to the left of edge e1 and therefore e4 ends above e1 at vertex v1 . Since e3 must be between e1 and e4 , it also leaves v1 to the upper left and therefore it is in face f in sector 2. Since e1 is in sector 4 and e2 and e3 are in sector 2, all remaining edges are in sector 2 and edge e1 has two bends (rule one). All other cases at other sides of the vertices are similar. Theorem 5. Given a planar embedded graph with a restriction system in the 4-sector model. Then at most f edges have two bends, where f is the number of faces of the graph.
5
Further Extensions
Our approach is easy to extend to additional requirements. For example, for graphs with vertices of arbitrary sizes, the drawing algorithm takes the width of
Semi-dynamic Orthogonal Drawings of Planar Graphs
361
Fig. 6. Notations for the proof of Lemma 2.
the vertices into account, when it evaluates the 5, dependencies and similarily for the height and 5, dependencies.
Acknowledgment
I would like to thank Prof. F.J. Brandenburg for his helpful suggestions. This research was done while the author was with the University of Passau.
References S.S. Bridgeman, J. Fanto, A. Garg, R. Tamassia, and L. Vismara. InteractiveGiotto: An algorithm for interactive orthogonal graph drawing. In Graph Drawing (GD 97), LNCS 1353, pages 303-308. Springer, 1997. 2. U. Brandes, M. Giidemann, and D. Wagner. Fully dynamic orthogonal graph layout for interactive systems. Technical report, Universitat Konstanz, 2000. 3. T.C. Biedl and M. Kaufmann. Area-efficient static and incremental graph drawings. In Proc. European Symposium on Algorithms (ESA '97), Lecture Notes in Computer Science 1284, pages 37-52. Springer, 1997. 4. F. J. Brandenburg. Designing graph drawings by layout graph grammars. In Graph Drawing (GD 94), LNCS 894, pages 416-427. Springer, 1995. 5. G. Di Battista and R. Tamassia. On-line planarity testing. SIAM Journal on Computing, 25(5):956-997, 1996. 6. S.S. Bridgeman and R. Tamassia. Difference metrics for interactive orthogonal graph drawing algorithms. In Graph Drawing (GD 98), LNCS 1547, pages 57-71. Springer, 1998. 7. P. Eades, W. Lai, K. Misue, and K. Sugiyama. Preserving the mental map of a diagram. In Proceedings of Compugraphics '91, pages 24-33, 1991. 8. U. FoBmeier and M. Kaufmann. Drawing high degree graphs with low bend numbers. In Graph Drawing (GD 95), LNCS 1353, pages 254-266. Springer, 1996. 9. U. FoBmeier. Interactive orthogonal graph drawing: Algorithms and bounds. In Graph Drawing (GD 97), LNCS 1353, pages 111-123. Springer, 1997. 10. K. Misue, P.Eades, W. Lai, and K. Sugiyama. Layout adjustment and the mental map. Journal of visual languages and computing, 6:183-210, 1995. 11. A. Papakostas and I.G. Tollis. Issues in interactive orthogonal graph drawing. In Graph Drawing (GD 95), LNCS 1027, pages 419-430. Springer, 1996. 12. F.P. Preparata and M.I. Shamos Computational Geometry: An Introduction Springer. 1985 1.
Graph Layout for Workflow Applications with ILOG JViews Gilles Diguglielmo, Eric Durocher, Philippe Kaplan, Georg Sander, and Adrian Vasiliu ILOG SA, 9, rue de Verdun - BP 85, 94253 Gentilly Cedex, FRANCE {gdigugli|durocher|kaplan|sander|vasiliu}@ilog.fr http://jviews.ilog.com
1
Introduction
Workflow is the flow of information and control in a company’s business processes [1]. Examples of such processes are purchasing procedures, production planning or customer support mechanisms. Managing business processes more efficiently can reduce the costs and improve product and customer services. A workflow modeler is a software that allows to design, document and optimize the business processes. Today’s workflow management systems are graphical tools that allow to manipulate and monitor workflows that are visualized as diagrams. The automatic layout of workflow diagrams is a central part of the GUI of such software systems. The ILOG JViews Component Suite is a set of pure Java components for building sophisticated interactive commercial Web-based user interfaces. Besides ready-to-use components for cartography, charting, resource scheduling (Gantt charts), it includes a component specialized for building the GUI of workflow applications (Fig. 1). This workflow component utilizes the powerful graphic framework and graph layout package of JViews [3]. It provides full customization of the look & feel of all graphical elements via Cascading Style Sheets, and supports XML input and output derived from the Workflow Management Coalition standards.
2
Highlights of the Layout Algorithms
Workflow graphs consist of nodes representing activities, decisions, participants or data, and edges representing transitions and relations. Workflow graphs may contain subprocesses, hence they are nested graphs with intergraph edges, that is, edges between different subgraphs (Fig. 2). A hierarchical layout [4,2] and a tree layout is used. Labels are placed at the edges by a simulated annealing technique [3]. The hierarchical layout algorithm is enhanced by various features to fit into the workflow application domain: – In incremental mode, the relative positions of nodes are preserved when the graph changes. Hence, small editing operations don’t cause a large rearrangement of the diagram. This helps the user to preserve the mental map of the diagram. M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 362–363, 2002. c Springer-Verlag Berlin Heidelberg 2002
Graph Layout for Workflow Applications with ILOG JViews
Fig. 1. Workflow Modeler
363
Fig. 2. Nested Workflow
– A constraint system allows to define relations between the node position, such as “is left of”, “is above”, “it leftmost”, or to cluster nodes. Constraints are used to place the “participant” and “data” nodes relative to the workflow skeleton that is formed by the “activity” and “decision” nodes. – Special ports specify the node side or the fixed pin points where edges start or end at the nodes. This is often required for “decision” nodes of workflow diagrams. – Swim lanes allow to divide the layout area into vertical stripes representing the business units that participate on the workflow. The JViews Graph Layout component also contains many more layout algorithms that are designed for other application domains. An online demonstration of the ILOG Workflow Cockpit is available at http://www.ilog.com/products/ jviews/workflow.
References 1. L. Fischer, editor. New tools for new times: The workflow paradigm. Future Strategies Inc., second edition, 1995. 2. G. Sander. A fast heuristic for hierarchical manhattan layout. In Proc. Symposium on Graph Drawing, GD’95, pages 447–458. Springer, LNCS 1027, 1996. 3. G. Sander and A. Vasiliu. The ILOG JViews graph layout module. In Proc. Symposium on Graph Drawing, GD’2001, pages 438–439. Springer, LNCS 2265, 2002. 4. K. Sugiyama, S. Tagawa, and M. Toda. Methods for visual understanding of hierarchical systems. IEEE Trans. Sys. Man, and Cybernetics, SMC 11(2):109–125, 1981.
InterViewer: Dynamic Visualization of Protein-Protein Interactions Kyungsook Han1 , Byong-Hyon Ju1 , and Jong H. Park2 1 2
1
Department of Computer Science & Engineering, Inca University Inchon 402-751, South Korea MRC-DUNN, Human Nutrition Unit, Cambridge CB2 2XY, UK http://wilab.inha.ac.kr/protein/
Short Description
From the perspective of graph drawing, a protein interaction network is challenging because it is a complicated, nonplanar graph with a large number of edge crossings and because it is a disconnected graph consisting of many connected components with nodes of a wide range of degrees. InterViewer is a system for drawing and exploring protein-protein interaction networks in three-dimensional space. Unique features of InterViewer include: (1) it is much faster than other recent implementations of drawing algorithms; (2) it can be used not only for drawing protein interaction networks but also for simplifying them into different types of networks; and (3) it provides an integrated framework for querying protein interaction databases and directly visualizing the query results.
2
Areas of Application
InterViewer has been developed to visualize and analyze protein-protein interactions. Uses of InterViewer include: – visualizing large protein interaction networks and exploring them in 3D by rotating or by zooming in or out of them, – finding proteins sharing a function or proteins interacting with a target protein within a specified distance level, – comparing two or more protein interaction networks, – creating a local database of protein-protein interactions, and – producing protein interaction networks for publications or presentations
3
Layout Algorithms and Layout Features
InterViewer’s layout is based on the force-directed layout of Walshaw’s algorithm [2], but different from Walshaw’s algorithm in the following sense: (1)
This work was supported by the advanced backbone IT technology development program of the Ministry of Information and Communication of Korea under grant number IMT2000-C3-4.
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 364–365, 2002. c Springer-Verlag Berlin Heidelberg 2002
InterViewer: Dynamic Visualization of Protein-Protein Interactions
(A)
365
(B)
Fig. 1. (A) Subgraph of PSIMAP [1] obtained by extracting protein families interacting with protein family 7.39.1 within distance level of 2. (B) Simplified graph of Fig. 1A by replacing a complete subgraph with a star-shaped subgraph centered at a dummy node, shown as a circle.
Walshaw’s algorithm groups nodes into clusters, whereas InterViewer does not. (2) Walshaw’s algorithm initially places nodes randomly, whereas InterViewer places nodes on the surface of a sphere for better results. (3) Walshaw’s algorithm iteratively updates layouts until the graph size falls below a certain threshold value, whereas InterViewer iterates 20 times unless specified otherwise by a user. Subgraphs with nodes of high degree often reduce the readability of the graph due to cluttered edges. We simplify this type of graph by replacing a complete subgraph with a star-shaped subgraph. While a complete graph with n nodes contains n(n − 1)/2 edges, a star-shaped graph with n nodes contains exactly n edges. Thus, replacing complete subgraphs with star-shaped subgraphs substantially reduces the number of edges (see Fig. 1).
4
Architecture and Interfaces
The layout algorithm was implemented in Borland Delphi 6.0, and databases of protein-protein interactions were constructed using Microsoft Data Access Components 2.7. InterViewer runs on Windows 2000/XP/Me/98/NT 4.0. InterViewer is not coupled with a specific database. The user can easily make his own interaction databases using our program called DataServer and exploit them with InterViewer. DataServer and InterViewer can run on a same computer or on different computers. Details are at http://wilab.inha.ac.kr/protein/.
References 1. Park, J., Lappe, M., Teichmann, S.A.: Mapping protein family interactions: intramolecular and intermolecular protein family interaction repertoires in the PDB and Yeast. J. Mol. Biol. 307 (2001) 929–938 2. Walshaw, C.: A multilevel Algorithm for Force-Directed Graph Drawing. In Proc. 8th Int. Symp. Graph Drawing, LNCS 1984, (2002) 171–182
Some Modifications of Sugiyama Approach Danil E. Baburin A.P. Ershov Institute of Informatics Systems, Lavrentev pr. 6, Novosibirsk, 630090, Russia [email protected]
Abstract. We present a graph drawing algorithm that was developed as an extension of the hierarchical layout method of Sugiyama [4]. The main features of the algorithm are that the edges are orthogonal and that each edge has at most two bends.
1
Introduction
In a number of works [2,3] Sander presents his methods and heuristics on how to combine hierarchical approach of Sugiyama [4] with methods of orthogonal graph drawing and with Manhattan conventions. In our work we develop and extend these ideas. The main difference is that we have achieved an orthogonal layout with maximum number of edge bends equal to two compared to four bends in Sander’s works. Also we solved the task of minimizing the number of orthogonal edge crossings between any pair of adjacent levels of hierarchy and tried a new heuristic to build an initial position of nodes before starting the crossing reduction step. On the Fig. 1 we present a diagram layout constructed by our algorithm. Note that this is left to right drawing as opposed to conventional hierarchical layout. The algorithm was implemented by means of C++ and provided with an interface that enabled its use in Higres system [1].
2
Our Methods and Heuristics
The crossing reduction step considers the problem of drawing a layered digraph with a small number of edge crossings. We present a heuristic method that could be used to form an initial ordering with relatively small number of edge crossings. Then this ordering could be improved using any known method. During the layer assignment step we are parsing the graph into a spanning tree plus extra edges. Our heuristic changes the order in which subtrees appear in this tree to minimize the number of crossings that are formed by non-spanning edges. Subtrees are ordered greedily according to the number of extra edges connecting them to the left and right. In our algorithm we introduce a concept of edge width. Each edge has assigned width with some minimum value that depends on the size of edge label and a number of multi edges that were combined in the preprocessor step of the algorithm into one edge. Then while assigning vertical coordinates to vertices we operate with vertical ranges. These M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 366–367, 2002. c Springer-Verlag Berlin Heidelberg 2002
Some Modifications of Sugiyama Approach
367
Fig. 1. Sample layout produced by our algorithm. The graph has 40 vertices and 60 edges.
ranges could be bounded by some coordinates or could dynamically depend on neighbor ranges. When we are drawing edges between two adjacent levels of hierarchy we are dividing horizontal space between adjacent layers into vertical levels that would contain vertical segments of the edges. Then we are defining a notion of potentially crossing edges. This crossing could be eliminated if correspondent edges are drawn in different vertical segments and in a particular order. Our task was to eliminate all such crossings and to minimize the number of vertical levels being used. We are solving this problem by constructing a supplementary directed graph G’. Now our goal could be formulated in terms of a coloring problem for G’. Vertices of G’ need to be colored in a minimum number of colors so that any adjusted vertices would have different colors. Also all directed edges should point from vertexes with smaller color indices to vertexes with larger color indices. Then we can draw edges in original graph by assigning vertical levels to colors in increasing order.
References 1. I. A. Lisitsyn, V.N. Kasyanov, “Higres – Visualization system for Clustered Graphs and Graph Algorithms”, Graph Drawing, LNCS 1731, Czech Republic 1999, pp. 82-89 2. G. Sander, “A Fast Heuristic for Hierarchical Manhattan Layout”, Graph Drawing, LNCS 1027, Germany 1995, pp. 447-458 3. G. Sander, “Graph layout through the VCG tool”, DIMACS Intern. Workshop, GD’94. LNCS. 894, 1995, pp. 194–205. 4. K. Sugiyama, S. Tagawa, M. Toda, “Methods for Visual Understanding of Hierarchical systems”, IEEE Trans. Sys., Man, and Cybernetics, SMC 11(2), 1981, pp. 109-125.
A Framework for Complexity Management in Graph Visualization Ugur Dogrusoz and Burkay Genc Computer Eng. Dept., Bilkent Univ., Ankara 06533, Turkey Tom Sawyer Software, Oakland, CA 94612, USA
1
Short Description
We present a comprehensive framework for development of complexity management techniques in graph visualization tools. The presented architecture is capable of managing multiple associated graphs with navigation links and nesting of graphs as well as ghosting, folding and hiding of unwanted graph elements. The theoretical analyses show that the involved data structures and algorithms are quite efficient, and an implementation in a graph drawing tool has proven to be successful. Our architecture is based on dynamic interactive compound graphs. The definition of compound graphs is extended to efficiently handle the graph editing and complexity management operations. A navigation forest is used to keep track of navigational links among nodes and graphs, and a nesting forest is used to keep track of nesting (inclusion) relations.
2
Complexity Management Operations
The framework manages complexity via the following instruments: Expand/Collapse: Most applications require multiple levels of abstraction, where the user would like to visualize the information with varying levels of abstraction for different parts of the drawing. A collapse operation allows us to cancel a nesting relation between a node and a graph, thus avoiding the drawing of the graph inside the node. The expand operation is defined as the reverse operation creating a nesting relation between a node and a graph. Folding/Grouping: A fold operation is applied to a group of graph members, and results in a new (folder) node and its new child graph with these members. At any time, an unfold operation may be applied on a folder node to reverse the effects of the fold operation. Often times, members of a graph need to be put together according to some criteria to emphasize certain grouping. This can be achieved through folding followed by an expand operation, enabling all the group members to be gathered in the newly created graph. M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 368–369, 2002. c Springer-Verlag Berlin Heidelberg 2002
A Framework for Complexity Management in Graph Visualization
369
Invisibility/Hiding/Ghosting: A graph member is said to be invisible when it is not rendered on the display yet it is part of the graph topology. Hiding, on the other hand, is used to avoid any means of user interaction on a set of graph members, and temporarily removes graph contents from the graph topology as well. Any set of graph members may later be unhidden. Ghosting can be used to visually decrease the importance of a graph member by means of changing its color and/or brightness of its skin, and sending it to the background. Unlike hiding, the member is still there, both visually and topologically.
3
Implementation
Our framework has been successfully implemented and integrated into Tom Sawyer Software’s Graph Editor Toolkit for Java, version 5.0.
Fig. 1. Upper Left: Map of a small network drawing in GET for Java. Upper Right: All related network devices are grouped together under a folder. Lower Left: Lab4 has been expanded to reveal details. Additionally, Printer1, PC41, PC43 and PC47 are unavailable, so they are hidden. Lower Right: The varying levels of the details of the server has been input as deeply nested graphs.
A Partitioned Approach to Protein Interaction Mapping Yanga Byun, Euna Jeong, and Kyungsook Han Department of Computer Science and Engineering Inha University, Inchon 402-751, South Korea [email protected], [email protected], [email protected] http://wilab.inha.ac.kr/protein/ Abstract. This is a brief description of a new program for drawing protein interactions in three-dimensional space. Our program divides nodes into three groups: biconnected subgraph in the center, terminal nodes at the outermost region, and the rest in between them. Experimental results show that the program efficiently generates a clear and aesthetically pleasing drawing of large-scale protein interaction networks and that it is an order of magnitude faster than other force-directed layouts.
Protein interactions, when visualized as an undirected graph, often yield a nonplanar, disconnected graph with nodes of wide range of degrees. This paper presents a new force-directed program that divides nodes into three groups: – Group V1 is a set of terminal nodes, i.e., nodes with degree 1. – Group V2 is a set of nodes in the subgraphs separated by cutvertices, except those in the longest subgraph. – Group V3 consists of nodes which are members of neither V1 nor V2 . While we find groups in the order of V1 , V2 , and V3 , we layout them in reverse order; V3 is first positioned in the center of the sphere, V2 in the outer region of V3 , and V1 in the outer region of V2 and V3 . Our program was implemented in Microsoft’s C and runs on any Windows 2000/XP/Me/98/NT 4.0 system. Table 1 shows the running times on five cases, Brain (http://www.infosun.fmi.
uni-passau.de/GD2001/graphC/brain.gml), Gd29 (http://www.infosun.fmi.uni-passau. de/GD2001/graphA/GD29.gml), Y2H (http://depts.washington.edu/sfields/yplm/dat a/), MIPS-G and MIPS-P (http://mips.gsf.de/proj/yeast/tables/interaction/), at each stage of partitioning nodes into three groups, finding shortest paths in three groups, and layout and drawing. The test cases of Brain and Gd29 are different from the other data not only in the size of data sets but also in the relative size of their V3 . Brain has 28 nodes in V3 out of total 33 nodes and Gd29 has 129 nodes in V3 out of total 178 nodes. However, in test cases Y2H, MIPS-G, and MIPS-P the ratio of V3 to the total number of nodes is less than 1/2. Comparison of our algorithm with other forcedirected layout algorithms shows that ours is more effective for bigger graphs and for graphs that do not have excessively high portion of V3 (data not shown). If the portion of V3 is high, the improvement in speed can be marginal. Fig. 1 shows the drawings of the MIPS physical interaction data.
This work was supported by the advanced backbone IT technology development program of the Ministry of Information and Communication of Korea under grant number IMT2000-C3-4.
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 370–371, 2002. c Springer-Verlag Berlin Heidelberg 2002
A Partitioned Approach to Protein Interaction Mapping
371
Table 1. Running times at each stage on five cases. P: partitioning nodes into V1 , V2 and V3 , SP: finding shortest paths in all groups, LD: layout and drawing. Data
Edges
V1
Brain Gd29 Y2H MIPS-G MIPS-P
135 344 542 805 2372
4 40 255 198 665
Nodes V2 V3 1 10 100 102 289
28 128 118 231 572
P
Running times LD total (= P + SP + LD) 0.02s 0.15s 0.25s 0.90s 2.06s 3.80s 0.87s 3.49s 5.77s 5.16s 8.52s 16.92s 1m 18.82s 56.20s 3m 11.41s SP
0.08s 0.84s 1.41s 3.24s 56.39s
(A)
(B)
(C)
(D)
Fig. 1. Drawings of the largest connected component of the MIPS physical interaction data with 1526 nodes and 2372 edges. (A) Initial layout, (B) After drawing the nodes in V3 shown in the rectangle, (C) After drawing the nodes in V3 and V2 shown in the rectangle, (D) Final drawing.
Camera Position Reconstruction and Tight Direction Networks Ileana Streinu and Elif Tosun
Computer Science Department Smith College, Northampton, MA 01063 {streinu, etosun}@cs.smith.edu
Abstract. A concrete reconstruction problem arising in Computer Vision motivates our investigation of combinatorial variations on the problem of drawing a graph with given direction vectors associated to its edges. We formulate solutions in dimension 2 and report on experimental results done with simple implementations.
Direction Networks. A (planar)direction network is a graph G = (V, E) with slopes (or direction vectors) associated to its edges. A compatible embedding is given by coordinates for the vertices V inducing edge directions equal to the given ones. A direction network is tight if it has a unique embedding, up to translations and scalings, it is inconsistent if it has no embedding at all, and it is loose or under constrained if it has more than one (non similar) embedding. An inconsistent network is usually over-constrained: some of the edge directions can be inferred algebraically from other edge directions, and thus a small error in the data leads to inconsistency. In the under-constrained case, the space of embeddings is a linear subspace whose dimension measures how loose the network is. See Fig. 1.
Fig. 1. Left: a loose graph and two non-similar parallel redrawings. Right: an overconstrained case, with consistent and inconsistent directions (the rightmost case has no solution for the given direction of the hanging edge.)
The Camera Position Reconstruction Problem. Our motivating problem comes from the MIT City Project [1]. A robot moves around the MIT campus taking pictures of the buildings. It seeks to reconstruct a model of the 3dimensional urban environment from these images. The usage of a hemispherical camera, edge detection and feature matching software produce what amounts to
Research partially supported by the first author’s NSF RUI grant CCR-0105507. Part of the work was conducted during the Workshop on Rigidity Theory and Scene Analysis, organized by the first author at McGill University Bellairs Institute in Barbados in Jan. 2002, with partial support from NSF grant CCR-0203224.
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 372–373, 2002. c Springer-Verlag Berlin Heidelberg 2002
Camera Position Reconstruction and Tight Direction Networks
373
be a 3-dimensional direction network. In [1] standard least-squares techniques are used to infer approximations of the vertex positions. The authors report that the solution is very rarely unique, with the information inferred from the images being too weak to allow correct reconstruction. Our Contribution. It is stated in [1] that the determination of the minimal set of distinct pairs needed for a non-degenerate solution is significantly more complicated and depends entirely on the topology of the adjacency graph. Our contribution is to propose a theoretical solution for what seems to be the bottleneck in the full automation of this system, and perform enough preliminary experimentation to validate the feasibility of taking it to the practical level. We formulate the problem in rigidity theoretical terms. This leads to reasonably efficient and implementable algorithms. We have experimented with algorithms in dimension 2. The real case (dimension 3) is more complicated but still reasonably well understood theoretically. Our implementation was done in Mathematica for quick prototyping. The planar case allows to develop a solid theoretical strategy for accurate testing. These preliminary results indicate that our approach may be practical even in dimension 3. The Combinatorial Rigidity approach. If one could understand which edges must additionally be sampled to ensure that a unique solution is found, then one could send the robot to retake some pictures. This being a costlier process than the off-line processing of images, one would like to do only the work that is absolutely necessary. We are led to the following three problems. 1. Decision: Given a direction network, decide whether it is tight or not. 2. Extension: Given a loose direction network, find a set of edges to be added so that the resulting network becomes tight. 3. Extraction: Given an inconsistent direction network, find a set of edges to be removed to obtain a tight network. These problems fall into the rigidity theory category of parallel redrawings. A good starting point is Whiteley ([4] and [3]). Our implementation relies on an algorithm proposed by Sugihara [2], based on matroidal concepts. In the planar case, the duality between fixed-length and fixed-direction rigidity allowed us to design a test generator using Henneberg constructions for tight graphs. Acknowledgements. We thank Seth Teller for suggesting the problem to us, and to Ruth Haas, Brigitte Servatius, Jack Snoeyink and Walter Whiteley for useful references and enjoyable conversations on these topics.
References 1. Antone, M.E., Teller, S.: Automatic Recovery of Camera Positions in Urban Scenes. Technical Report MIT LCS TR-814. December 2000 2. Sugihara, K.: Detection of Structural Inconsistency in Systems of Equations with degrees of freedom and its applications. Discrete Appl. Math. 10 (1985) 297–312. 3. Whiteley, W.: Some Matroids from Discrete Applied Geometry. Contemporary Mathematics 197 (1996) 4. Whiteley, W.: Rigidity and Scene Analysis. In J.E. Goodman and J. O’Rourke (eds.), Handbook of Discrete and Computational Geometry, pp. 893–916
Demonstration of a Preprocessor for the Spring Embedder Paul Mutton and Peter Rodgers University of Kent at Canterbury {pjm2, P.J.Rodgers}@ukc.ac.uk Abstract. Spring embedding is a widely used method for producing automated layouts of graphs. We present a preprocessor that improves the performance of the classical spring embedder, which can be used in conjunction with other optimization and approximation techniques. It creates an initial graph layout with edge lengths that are approximately equal and with a minimum node separation from which the spring embedder typically needs far fewer iterations to produce a well laid out graph.
Introduction. The spring embedder [1] is a widely used method for drawing general graphs. In its classical form, the layout is randomized before the iterative force process is simulated. We present a preprocessor for the spring embedder, discussed in more detail in [5]. Our preprocessor is a two phase process and is used before the spring embedder is initiated. The first phase attempts to keep connected nodes at a suitably close distance by an iterative method that produces edges lengths close to a user specified ideal. The second phase approximates an even node distribution by placing the nodes on a grid. The spring embedder, or some other optimized force directed variant, is applied after these two phases. In some specialized cases, such as grid or mesh like structures, or some graphs exhibiting strong clusters, the graph can be drawn with just the preprocessor and without requiring any subsequent spring embedding. Previous work in preprocessing includes placing the graph in simple binary trees or meshes [2]. The Wave Front method [6] applies the spring embedder to a subgraph wave that sweeps through the graph. Other work on initial placement includes [4] which adds nodes to the layout incrementally, placing nodes at the barycenter of its three closest graph theoretical distance neighbours. This is followed by a local application of the force directed drawing process on the node, considering just its neigbours. Brief Description of the Method. We use force models based on those of Fruchterman and Reingold, which defines k, the ideal minimum node separation. In this model, the repulsive force between nodes is k 2 /d and the attractive force due to edges is d2 /k, where d is the distance between the two nodes. The first phase of the preprocessor attempts to obtain an initial drawing where all edge lengths are approximately equal to ka, where a ≥ 1, as the spring embedder appears to perform better when reducing the volume of the graph slightly. Preliminary experimentation suggests that a = g 1/3 is a reasonable value, where g is the mean degree of nodes in the graph. Prior to phase one, the nodes are randomly distributed within a cubic volume of side length 103 ka(|N|1/3 ), which is large enough to ensure good results, as the layout will rapidly shrink with the extropic application of the iterative first phase. M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 374–375, 2002. c Springer-Verlag Berlin Heidelberg 2002
Demonstration of a Preprocessor for the Spring Embedder
375
Each iteration of phase one involves visiting every ka node in the graph. For each node n, we examine the m1 set of emanating edges. Each edge connects n to mi p1 and we calculate the position of point pi such that the vector mi pi = ka(ui ), where ui is the unit vector of mi n. Node n is moved to the mean position of all pi of n n. The graph rapidly shrinks into a more stable graph p2 where each edge length is near to ka. Each iteration m2 has linear time complexity, O(|E|). Phase one often leaves dense clusters of nodes Fig. 1. Node placement in the first very close together, so we now apply the second phase phase in order to achieve a minimum node separation. This places the nodes on a threedimensional grid of unit size k. This is much quicker than the first phase, as it is not iterative. Application of both phases results in a new graph layout where edge lengths remain close to the phase one ideal value of ka, whilst ensuring all nodes have the final graph ideal minimum node separation of k. This yields the initial drawing to which we apply the spring embedder. Summary of Results and Further Work. Preliminary results show the method is promising in improving the speed of the spring embedding process. The spring embedder finds an equilibrium for medium sized graphs of about 200 nodes approximately 10 times faster than with a random layout [5]. The time taken for the preprocessing is insignificant compared to the time required for spring embedding. Further experiments with optimized spring embedders also show improvements in performance. In some cases spring embedding was not required, as the preprocessor produced a good layout. Systematic testing with larger graphs and alongside other preprocessing methods is now needed to explore the benefits of the method. The method has been implemented in Java with a focus on encapsulation and reuse; however, a radical performance increase could be gained by concentrating on optimising the code in an effective environment. Also requiring consideration is integration with other optimization and approximation techniques, as the method is amenable to integration with common force approximation methods such as Barnes-Hut tree coding methods, and with multilevel clustering methods.
References 1. P. Eades. A Heuristic for Graph Drawing. Congressus Numerantium 42. pp. 149-60. 1984. 2. A. Frick, A. Ludwig, H. Mehldau. A Fast Adaptive Layout Algorithm for Undirected Graphs. GD’94, LNCS 894. pp. 388-403. 1995. 3. T.M.J. Fruchterman, E.M. Reingold. Graph Drawing by Force-directed Placement. Software – Practice and Experience, Vol. 21(11). pp. 1129-1164. 1991. 4. P. Gajer, M.T. Goodrich, S.G. Kobourov. A Fast Multi-Dimensional Algorithm for Drawing Large Graphs. GD 2000, LNCS 1984. pp. 211-221. 2001 5. P.J. Mutton, P.J. Rodgers. Spring Embedder Preprocessing for WWW Visualization. Proceedings of 6th International Conference on Information Visualization, IV02-WGV. pp. 744-749. 2002. 6. A.J. Quigley, Large Scale Relational Information Visualization, Clustering, and Abstraction, PhD Thesis, University of Newcastle, Australia. August 2001.
Graph-Drawing Contest Report Franz J. Brandenburg Universit¨ at Passau, D-94032 Passau, Germany, [email protected]
Abstract. This report describes the Ninth Annual Graph Drawing Contest, held in conjunction with the 2002 Graph Drawing Symposium in Irvine, California. The purpose of the contest is to monitor and challenge the current state of the graph-drawing technology.
1
Introduction
The contest had two categories, two so-called “challenge graphs” and a new interactive graph analysis, which replaced the former artistic category. The challenge graphs were open to everyone in and outside the graph drawing community. The requirements were drawings in printable from and a description of the drawing procedure. The interactive graph analysis was initiated by Joe Marks and Sue Whitesides, who also designed the two query graphs for this category. It was directed to the participants of the symposium. Text descriptions for the 2002 contest were available via the World Wide Web (WWW) and announced with the Graph Drawing Symposium. The data on the graphs was provided in GML format. However, only four submissions from three teams were received on the challenge graphs, and the participants at the symposium were not well prepared for the interactive test. The entries for graph A, the “Knowledge Nation Graph”, realize similar ideas and introduce some innovative concepts from graph drawing into the representation of the Knowledge Nation Graph. However, the created drawings are not yet capable to visualize this graph in all its aspects. For graph B it has turned out that spring embedders perform quite well on this graph and display it like a crown, although its hidden structure is not displayed by these methods. All four submissions were nominated as winners of the same grade.
2 2.1
Winning Submissions Category A
The graph for Category A is the “Knowledge Nation Graph”. Its original drawing is shown in Fig. 1. For more information on the graph and its story see http://www.cs.usyd.edu.au/˜visual/library/. The Knowledge Nation Graph has been proposed by Carsten Friedrich from the University of Sydney. M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 376–379, 2002. c Springer-Verlag Berlin Heidelberg 2002
Graph-Drawing Contest Report
377
Fig. 1. The “Knowledge Nation Graph”
From a graph theoretic view it has 23 nodes and 59 edges. Two nodes, “Government” and “Knowledge Nation” are dominant, and are connected to almost all other nodes. The entry by Daniel Gmach, Paul Holleis, and Thomas Zimmermann, students at the University of Passau, places the Government node near the center and displays the Knowledge Nation as the outer frame, see Fig. 2. So the dominance of these nodes is reflected. The frame reduces the visual complexity. However, the drawing is hard to read and has too many crossings. The drawing was made using Graphlet. The entry by Nikola S. Nikolov and Patrick Healey from the University of Limerick is a two step approach. First the graph is partitioned into the cue map, which is obtained by selecting the two highest degree nodes Government and Knowledge Nation and adding the then isolated nodes. The remaining nodes are grouped into black, grey and white nodes representing out-, in- and non-
Fig. 2. Entry of Gmach, Holleis, and Zimmermann
378
Franz J. Brandenburg
G
G
Government G
Manufacturing/ Construction
Environment
Agriculture
Law/Public Service
CSIRO/CRCs/B of M
Telstra/AP
Defence
Mining
G
G
Banking/Insurance
TAFE/Training
Third Age/ Lifelong Learning
Welfare
G
ABC/Media
Arts/Leisure/Sport
G
Schools
Knowledge Nation G
Universities
Medicine/Health
G
Infrastructure
Communications/ IT and Print
G
Trade/Commerce
G
(a) Cue Map
Tourism
(b) Main Map
Fig. 3. Entry of Nikolov and Healey
neighbours of the Knowlegde Nation node. The black and the grey clusters are represented by single nodes. The main map is obtained from the remaining nodes and copies of the Government node for each incident edge. The drawings of the graphs are shown in Fig. 3(a) and 3(b) and were made by a customized Sugiyama algorithm. 2.2
Category B
Graph B represents a gadget from an NP-reduction. There are two parallel paths such that the remaining edges connect nodes on either path. Aesthetically pleasing and almost identical drawings are obtained by spring embedders. This has been discovered by Daniel Gmach, Paul Holleis, and Thomas Zimmermann, students of the University of Passau, using the Kamada-Kawai algorithm and the constraint spring embedder from Graphlet (see Fig. 4) and by Christoph Vogt, student of the University of Cologne, using his implementation of the GEM algorithm (see Fig. 5).
Fig. 4. Entry of Gmach, Holleis, and Zimmermann for Category B
Graph-Drawing Contest Report
379
Fig. 5. Entry of Vogt for Category B
2.3
Category C
In the previous graph drawing contests the emphasis has been on the production of graph drawings that could be used to support a variety of unspecified visualization or analysis tasks. In this part of the contest the analysis part was made explicit, requiring contestants to conduct interactive graph analysis in real time and hoping that this contest task would inspire new research into graph drawing and graph analysis methods. Since the competitors were not prepared for the contest it will be repeated at the 11th Graph Drawing Symposium 2003. 2.4
Conclusion
The response on the Graph Grawing Contest has declined over the past years. To encourage submissions for the 10th Graph Drawing Contest in 2003 it is anticipated to increase the prize money to $ 1000 for the winner of the challenge graph category, and to $ 500 in the interactive category. Acknowledgement I wish to thank Carsten Friedrich, University of Sydney for providing the “Knowledge Nation Graph” and Joe Marks, MERL, Cambridge and Sue Whitesides, Mc Gill University, Montreal, for introducing and preparing Category C. The Graph Drawing Contest 2002 has been sponsered by MERL Mitsubishi Electric Research Laboratries, Cambridge, sd&m AG M¨ unchen, and Tom Sawyer Software, Oakland.
Techniques for Interactive Graph Drawing James Arvo University of California, Irvine [email protected]
Abstract. There are two complementary approaches to graph drawing: algorithmic and interactive. By algorithmic graph drawing we mean the automatic placement of vertices and routing of edges using heuristics to improve understandability. Interactive graph drawing, on the other hand, implies that a user directly influences at least some low-level aspects of graph layout, either by direct placement of vertices and edges, or by providing some form of feedback to the system. Interactively engaging the user is in some instances unavoidable. When a user desires a difficult-to-quantify aesthetic quality of the graph, or is incrementally constructing a graph (such as a state diagram for an automaton) as part of a problem-solving task or pedagogical exercise, it is difficult or impossible to employ algorithmic graph drawing. In these instances it is more natural to employ a sketching metaphor in which a user draws the graph in a traditional sense. A common strategy for making interactive drawing of diagrams immediately understandable is to incorporate physical analogies; that is, to mimic some familiar real-world appearance or process. For example, the hand-drawn appearance of a diagram can be retained by preserving its unevenness and through the use of textures that impart the appearance of physical writing implements, such as pencil, ink, or chalk. It can be advantageous to retain this type of appearance in situations where userdrawn and computer-drawn diagrams coexist. The behavior of a graph that is interactively altered can also incorporate useful physical metaphors. For example, the edges adjacent to a vertex that is interactively re-positioned by a user can mimic physical linkages that stretch when pulled, and bend or contract when pushed. Such behaviors are natural in that they are almost immediately plausible and predictable to a user. However, not all interactive techniques can benefit from physical metaphors, for some transcend the capabilities of physical media. For example, recognition of hand-drawn elements, such as those representing vertices and edges, are often combined with gradual morphing that can improve the appearance of the diagram. Since physical writing surfaces exhibit no analogous behavior, a spectrum of possibilities has been explored. One approach that has been successfully applied in the context of graph drawing is the approach known as fluid sketching in which drawing and morphing occur nearly simultaneously. There are many potential combinations of algorithmic and interactive graph drawing to explore, such as the graceful re-routing of edges as a user interactively re-positions a vertex, or systems in which a user modifies automatically generated graphs, or in which local improvements are automatically applied to user-drawn graphs. M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, p. 380, 2002. c Springer-Verlag Berlin Heidelberg 2002
Drawing Venn Diagrams Frank Ruskey University of Victoria, Victoria, B.C. V8W 3P6, Canada, [email protected]
Abstract. Venn diagrams have long been used as an aid in understanding set containment relationships and in certain logical arguments. They also have interesting combinatorial properties. This talk is a survey some of what is known about Venn diagrams, particularly the aesthetic and extremal properties of the drawings, including recent results about symmetric Venn diagrams. Connections with graph drawing, of which there are many, will be emphasized. For more about Venn diagrams see http://www.theory.cs.uvic.ca/˜cos/venn.
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, p. 381, 2002. c Springer-Verlag Berlin Heidelberg 2002
Author Index
Abelson, David 86 Arvo, James 380 Baburin, Danil E. 366 Bachl, Sabine 74 Bachl, Walter 354 Barth, Wilhelm 130 Becker, Bernd 285 Biedl, Therese 54 Binucci, Carla 66 Brandenburg, Franz-Josef 74, 376 Brandes, Ulrik 1 Buchheim, Christoph 344 Byun, Yanga 370 Carmel, Liran 193 Chanda, Amrita 174 Chen, Ho-Lin 332 Cornelsen, Sabine 31 Didimo, Walter 66, 162 Diehl, Stephan 23 Diguglielmo, Gilles 362 Dogrusoz, Ugur 368 Drechsler, Rolf 285 Dujmovi´c, Vida 42, 118 Durocher, Eric 362 Eiglsperger, Markus 1 Eppstein, David 150 Eschbach, Thomas 285 Fiala, Jiˇr´ı 110 Forster, Michael
276
Garg, Ashim 174, 320 Genc, Burkay 368 Ghosh, Shubhashis 244 Giacomo, Emilio Di 142, 162 G¨ org, Carsten 23 G¨ unther, Wolfgang 285 Gutwenger, Carsten 220 Han, Kyungsook 364, 370 Harel, David 193, 207 Healy, Patrick 98
Hong, Seok-Hee
86
Jeong, Euna 370 Ju, Byong-Hyon 364 J¨ unger, Michael 130, 220, 344 Kaplan, Philippe 362 Kaufmann, Michael 1, 12 Koren, Yehuda 193, 207 Kratochv´ıl, Jan 110 Leipert, Sebastian 220, 344 Liao, Chien-Chih 332 Liotta, Giuseppe 66, 142, 162 Lu, Hsueh-I 332 Ma, Kwan-Liu 268 Miura, Kazuyuki 256 Miyazawa, Ayako 256 Morin, Pat 42 Mutton, Paul 374 Mutzel, Petra 130, 220 Newton, Matthew 312 Nikolov, Nikola S. 98 Nishizeki, Takao 244, 256 Nonato, Maddalena 66 Pach, J´ anos 295 Park, Jong H. 364 Patrignani, Maurizio 142 Percan, Merijam 220 Pinchasi, Rom 295 Proskurowski, Andrzej 110 Rahman, Md. Saidur 244 Raitner, Marcus 236 Rodgers, Peter 374 Ruskey, Frank 381 Rusu, Adrian 320 Sander, Georg 362 Schank, Thomas 31 Streinu, Ileana 372 S´ ykora, Ondrej 186, 312 Sz´ekely, L´ aszl´ o A. 186
384
Author Index
Tardos, G´ abor 295 Taylor, Donald E. 86 Teoh, Soon Tee 268 Tosun, Elif 372 T´ oth, G´eza 295 Vasiliu, Adrian 362 Vrt’o, Imrich 186, 312
Wagner, Dorothea 1, 31 Weiskircher, Ren´e 220 Whitesides, Sue 118 Wiese, Roland 12 Wismath, Stephen K. 162 Wood, David R. 42 Yen, Hsu-Chun
332