Lecture Notes in Computer Science Edited by G. Goos, J. Hartmanis, and J. van Leeuwen
2528
3
Berlin Heidelberg New York Barcelona Hong Kong London Milan Paris Tokyo
Michael T. Goodrich Stephen G. Kobourov (Eds.)
Graph Drawing 10th International Symposium, GD 2002 Irvine, CA, USA, August 26-28, 2002 Revised Papers
13
Series Editors Gerhard Goos, Karlsruhe University, Germany Juris Hartmanis, Cornell University, NY, USA Jan van Leeuwen, Utrecht University, The Netherlands Volume Editors Michael T. Goodrich University of California at Irvine Department of Information and Computer Science Irvine, CA 92697-3425, USA E-mail:
[email protected] Stephen G. Kobourov University of Arizona Department of Computer Science Tucson, AZ 85721-0077, USA E-mail:
[email protected]
Cataloging-in-Publication Data applied for A catalog record for this book is available from the Library of Congress. Bibliographic information published by Die Deutsche Bibliothek Die Deutsche Bibliothek lists this publication in the Deutsche Nationalbibliografie; detailed bibliographic data is available in the Internet at
.
CR Subject Classification (1998): G.2, I.3, F.2 ISSN 0302-9743 ISBN 3-540-00158-1 Springer-Verlag Berlin Heidelberg New York This work is subject to copyright. All rights are reserved, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, re-use of illustrations, recitation, broadcasting, reproduction on microfilms or in any other way, and storage in data banks. Duplication of this publication or parts thereof is permitted only under the provisions of the German Copyright Law of September 9, 1965, in its current version, and permission for use must always be obtained from Springer-Verlag. Violations are liable for prosecution under the German Copyright Law. Springer-Verlag Berlin Heidelberg New York a member of BertelsmannSpringer Science+Business Media GmbH http://www.springer.de © Springer-Verlag Berlin Heidelberg 2002 Printed in Germany Typesetting: Camera-ready by author, data conversion by Steingr¨aber Satztechnik GmbH, Heidelberg Printed on acid-free paper SPIN: 10873154 06/3142 543210
Preface
The 10th International Symposium on Graph Drawing (GD 2002) was held on August 26–28, 2002, at Irvine, California. The conference attracted 74 participants from academic and industrial institutions in 14 countries. As in previous years, the review process was competitive: 24 out of 48 regular submissions were accepted. In addition, 9 short papers and 8 system demonstrations (1 withdrawn) were also accepted. Each submission was refereed by at least 4 members of the program committee, and detailed comments were returned to the authors. GD 2002 invited two speakers: Frank Ruskey, from the University of Victoria, gave a talk on drawing Venn diagrams; James Arvo, from the California Institute of Technology, gave a talk on techniques for interactive graph drawing. As usual, the Graph Drawing contest was held during the conference. The report on the contest is included in the proceedings. We would like to thank all the people who helped organize and run the conference. We would like to thank our sponsors: ILOG, MERL (Mitsubishi Electric Research Laboratories), sd&m (Software Design & Management), Tom Sawyer Software, and the University of California, Irvine. We would also like to thank all the contributors and participants who made GD 2002 a success. The 11th International Symposium of Graph Drawing (GD 2003) will be held on September 21–24, 2003 at Perugia, Italy, with Giuseppe Liotta as the conference chair.
August 2002
Michael T. Goodrich Stephen G. Kobourov
Organization
Program Committee Ulrik Brandes Franz Brandenburg Giuseppe di Battista Christian Duncan Michael T. Goodrich (Co-chair) Xin He Seok-Hee Hong Michael Kaufmann Stephen G. Kobourov (Co-chair) Giuseppe Liotta Anna Lubiw Petra Mutzel Stephen North Roberto Tamassia Ioannis Tollis Sue Whitesides
University of Konstanz University of Passau University of Rome University of Miami University of California, Irvine SUNY Buffalo University of Sydney University of T¨ ubingen University of Arizona University of Perugia University of Waterloo Vienna University of Technology AT&T Research Brown University University of Texas, Dallas McGill University
Steering Committee Franz Brandenburg Giuseppe di Battista Peter Eades Michael T. Goodrich Michael J¨ unger Stephen G. Kobourov Giuseppe Liotta Petra Mutzel Takao Nishizeki Pierre Rosenstiehl Roberto Tamassia Ioannis Tollis
University of Passau University of Rome University of Sydney University of California, Irvine University of Cologne University of Arizona University of Perugia Vienna University of Technology Tohoku University Ecole des Hautes Etudes en Sciences Sociales Brown University University of Texas, Dallas
External Referees Christian Bachmaier Vladimir Batagelj Carla Binucci
Sabine Cornelsen Emilio Di Giacomo Walter Didimo
Organization
Tim Dwyer Hugo do Nascimento Markus Eiglsperger Cesim Erten Michael Forster Carsten Friedrich Marco Gaertler Emden Gansner Jan-Willem Goossens Gunnar Klau Gabriele Kodydek Maria Flavia Mammana Alessandro Marcandalli Maurizio Patrignani Leon Peeters
Sponsoring Institutions
Andreas Pick Maurizio Pizzonia Marcus Raitner Thomas Schank Martin Sch¨ onhacker Falk Schreiber Frank Schulz Don E. Taylor Luca Vismara Dorothea Wagner Roland Wiese Ren´e Weiskircher Thomas Willhalm
VII
In Memoriam: Ivan Rival
The Graph Drawing community is saddened by the loss of Ivan Rival in January, 2002. Ivan was a Professor in the School of Information Technology and Engineering at the University of Ottawa, where he led the Algorithms Research Group. He was raised in Hamilton, Ontario, earned a Ph.D. in Mathematics at the University of Manitoba, and taught there until joining the University of Ottawa in 1986. He was internationally known for his outstanding research work in discrete mathematics and combinatorial geometry. Ivan had a profound interest in all aspects of ordered sets. In the 1980s, he organized a number of workshops on this topic; their proceedings, which he edited, are still in demand. He also founded a journal, Order, available from Kluwer Academic Publishers. Ivan’s interest in the applications of precedence constraints to scheduling and motion planning led him to a new kind of problem: how to visualize ordered sets. It was this interest that prompted his participation in the graph drawing community in its early days. He published various papers on graph drawing problems and he served on the program committee for GD 1994. His interest in precedence constraints also led him to design software that aids students in planning their course schedules. This software grew into a company, Decision Academic Graphics, which he founded. Its main product is the Degree Navigator software that is used by dozens of colleges and universities in North America. Ivan’s contributions to the graph drawing literature include the following papers: – “The Diagram,” in Graphs and Orders, Kluwer, 1985. – “Representing Orders on the Plane by Translating Convex Figures,” Order 4:319–339, 1988 (with J. Urrutia) – “Graphical Data Structures for Ordered Sets,” in Algorithms and Order, Kluwer, 1989 – “Bipartite Graphs, Upward Drawings, and Planarity,” Information Processing Letters 36:317–322, 1990 (with G. Di Battista and W.-P. Liu) – “Light Sources, Obstructions and Spherical Orders,” Discrete Mathematics 102:13–24, 1992 (with S. Foldes and J. Urrutia) – “Reading, Drawing, and Order,” in Algebras and Order, Kluwer, 1993 – “Upward Drawing on Surfaces,” Proc. GD 1993, 1993 – “Upward Drawings to Fit Surfaces,” Proc. ORDAL 1994, LNCS 831, 1994 (with S.M. Hashemi) – “Upward Drawing on the Plane Grid Using Less Ink,” Proc. GD 1994, LNCS 894, 1995 (with G.-V. Jourdan and N. Zaguia) – “Upward Drawings on Planes and Spheres,” Proc. GD 1995, LNCS 1027, 1966 (with S.M. Hashemi and A. Kisielewicz) – “Series-Parallel Planar Ordered Sets Have Pagenumber Two,” Proc. GD 1996, LNCS 1190, 1997 (with M. Alzohairi)
In Memoriam: Ivan Rival
IX
In addition to founding the journal Order, Ivan served on the editorial boards of Algebra Universalis, and Discrete Mathematics. He also edited the following books: – Ordered Sets, Reidel/Kluwer, 1982, ISBN 9027713960 – Graphs and Order, Kluwer, 1985, ISBN 9027719438 – Combinatorics and Ordered Sets, American Mathematical Society, 1986, ISBN 0821850512 – Algorithms and Order, Kluwer, 1989, ISBN 0792300076 These books are the proceedings of conferences Ivan organized (two NATO conferences, a joint AMS-IMS-SIAM summer research conference, and another NATO conference, respectively). Ivan’s interest in all aspects of order relations intersected naturally with the developing graph drawing community’s interest in graph layout and visualization. His support of the Graph Drawing Symposium in its early days and his passion for the subject greatly enriched our community. By dedicating the first invited talk of GD 2002 to his memory, we would like to honor Ivan’s research accomplishments and express our admiration and gratitude for the wide and lasting impact of his contributions to our field. August 2002
Sue Whitesides Roberto Tamassia
Table of Contents
Papers Sketch-Driven Orthogonal Graph Drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ulrik Brandes, Markus Eiglsperger, Michael Kaufmann, Dorothea Wagner
1
Maintaining the Mental Map for Circular Drawings . . . . . . . . . . . . . . . . . . . . 12 Michael Kaufmann, Roland Wiese Graphs, They Are Changing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Stephan Diehl, Carsten G¨ org Drawing Graphs on Two and Three Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Sabine Cornelsen, Thomas Schank, Dorothea Wagner Path-Width and Three-Dimensional Straight-Line Grid Drawings of Graphs 42 Vida Dujmovi´c, Pat Morin, David R. Wood Drawing Outer-Planar Graphs in O(n log n) Area . . . . . . . . . . . . . . . . . . . . . . 54 Therese Biedl Computing Labeled Orthogonal Drawings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Carla Binucci, Walter Didimo, Giuseppe Liotta, Maddalena Nonato Computing and Drawing Isomorphic Subgraphs . . . . . . . . . . . . . . . . . . . . . . . . 74 Sabine Bachl, Franz-Josef Brandenburg A Group-Theoretic Method for Drawing Graphs Symmetrically . . . . . . . . . . 86 David Abelson, Seok-Hee Hong, Donald E. Taylor A Branch-and-Cut Approach to the Directed Acyclic Graph Layering Problem . . . . . . . . . . . . . . . . . . . . . . . 98 Patrick Healy, Nikola S. Nikolov Geometric Systems of Disjoint Representatives . . . . . . . . . . . . . . . . . . . . . . . . . 110 Jiˇr´ı Fiala, Jan Kratochv´ıl, Andrzej Proskurowski An Efficient Fixed Parameter Tractable Algorithm for 1-Sided Crossing Minimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 Vida Dujmovi´c, Sue Whitesides Simple and Efficient Bilayer Cross Counting . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 Wilhelm Barth, Michael J¨ unger, Petra Mutzel Orthogonal 3D Shapes of Theta Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 Emilio Di Giacomo, Giuseppe Liotta, Maurizio Patrignani
XII
Table of Contents
Separating Thickness from Geometric Thickness . . . . . . . . . . . . . . . . . . . . . . . 150 David Eppstein Book Embeddings and Point-Set Embeddings of Series-Parallel Digraphs . . 162 Emilio Di Giacomo, Walter Didimo, Giuseppe Liotta, Stephen K. Wismath Compact Encodings of Planar Orthogonal Drawings . . . . . . . . . . . . . . . . . . . . 174 Amrita Chanda, Ashim Garg Fractional Lengths and Crossing Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 Ondrej S´ykora, L´ aszl´ o A. Sz´ekely, Imrich Vrt’o Drawing Directed Graphs Using One-Dimensional Optimization . . . . . . . . . . 193 Liran Carmel, David Harel, Yehuda Koren Graph Drawing by High-Dimensional Embedding . . . . . . . . . . . . . . . . . . . . . . 207 David Harel, Yehuda Koren Advances in C-Planarity Testing of Clustered Graphs . . . . . . . . . . . . . . . . . . 220 Carsten Gutwenger, Michael J¨ unger, Sebastian Leipert, Petra Mutzel, Merijam Percan, Ren´e Weiskircher HGV: A Library for Hierarchies, Graphs, and Views . . . . . . . . . . . . . . . . . . . . 236 Marcus Raitner Rectangular Drawings of Planar Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 Md. Saidur Rahman, Takao Nishizeki, Shubhashis Ghosh Extended Rectangular Drawings of Plane Graphs with Designated Corners 256 Kazuyuki Miura, Ayako Miyazawa, Takao Nishizeki RINGS: A Technique for Visualizing Large Hierarchies . . . . . . . . . . . . . . . . . . 268 Soon Tee Teoh, Kwan-Liu Ma Applying Crossing Reduction Strategies to Layered Compound Graphs . . . 276 Michael Forster Crossing Reduction by Windows Optimization . . . . . . . . . . . . . . . . . . . . . . . . . 285 Thomas Eschbach, Wolfgang G¨ unther, Rolf Drechsler, Bernd Becker Geometric Graphs with No Self-intersecting Path of Length Three . . . . . . . 295 J´ anos Pach, Rom Pinchasi, G´ abor Tardos, G´eza T´ oth Two New Heuristics for Two-Sided Bipartite Graph Drawing . . . . . . . . . . . . 312 Matthew Newton, Ondrej S´ykora, Imrich Vrt’o Straight-Line Drawings of Binary Trees with Linear Area and Arbitrary Aspect Ratio . . . . . . . . . . . . . . . . . . . . . . . . . 320 Ashim Garg, Adrian Rusu
Table of Contents
XIII
Some Applications of Orderly Spanning Trees in Graph Drawing . . . . . . . . . 332 Ho-Lin Chen, Chien-Chih Liao, Hsueh-I Lu, Hsu-Chun Yen Improving Walker’s Algorithm to Run in Linear Time . . . . . . . . . . . . . . . . . . 344 Christoph Buchheim, Michael J¨ unger, Sebastian Leipert Semi-dynamic Orthogonal Drawings of Planar Graphs . . . . . . . . . . . . . . . . . . 354 Walter Bachl
Software Demonstrations Graph Layout for Workflow Applications with ILOG JViews . . . . . . . . . . . . 362 Gilles Diguglielmo, Eric Durocher, Philippe Kaplan, Georg Sander, Adrian Vasiliu InterViewer: Dynamic Visualization of Protein-Protein Interactions . . . . . . . 364 Kyungsook Han, Byong-Hyon Ju, Jong H. Park Some Modifications of Sugiyama Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366 Danil E. Baburin A Framework for Complexity Management in Graph Visualization . . . . . . . 368 Ugur Dogrusoz, Burkay Genc A Partitioned Approach to Protein Interaction Mapping . . . . . . . . . . . . . . . . 370 Yanga Byun, Euna Jeong, Kyungsook Han Camera Position Reconstruction and Tight Direction Networks . . . . . . . . . . 372 Ileana Streinu, Elif Tosun Demonstration of a Preprocessor for the Spring Embedder . . . . . . . . . . . . . . 374 Paul Mutton, Peter Rodgers
Graph Drawing Contest Graph-Drawing Contest Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376 Franz J. Brandenburg
Invited Talks Techniques for Interactive Graph Drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380 James Arvo Drawing Venn Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381 Frank Ruskey Author Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
Sketch-Driven Orthogonal Graph Drawing Ulrik Brandes1 , Markus Eiglsperger2 , Michael Kaufmann2 , and Dorothea Wagner1 1 2
Department of Computer & Information Science, University of Konstanz. {Ulrik.Brandes|Dorothea.Wagner}@uni-konstanz.de Wilhelm Schickard Institute for Computer Science, University of T¨ ubingen. {eiglsper|mk}@informatik.uni-tuebingen.de
Abstract. We present an orthogonal graph drawing algorithm that uses a sketchy drawing of the graph as input. While the algorithm produces an orthogonal drawing with few bends in the Kandinsky model it also preserves the general appearance of the sketch. Potential applications for this kind of drawing algorithm include the generation of schematic maps from geographic networks and interactive orthogonal graph drawing.
1
Introduction
Orthogonal drawings of graphs are common in many areas, but especially so in technical and engineering applications where their apparent tidiness seems to be appreciated. Typical examples include circuit schematics, entity-relationship diagrams and system plans. A commonality in these applications is that, quite often, a sketch of the drawing is already available, either because a user has created the graph in an editor, or because the vertices have some natural, e.g. geographic, position. In such cases, standard black-box algorithms for graph layout do not leave sufficient control over the appearance of the drawing with the engineer. We extend a successful approach for orthogonal graph layout to start from a sketch of the graph and produce a tidy, orthogonal drawing with few bends that preserves the overall appearance of the sketch. For the purpose of this paper, a “sketch” of a graph is a drawing that exhibits the main features to be conveyed, but is unsatisfactory from an aesthetic point of view. In practice, a sketch may for instance be a manual layout produced by the user of a database schema editor or a physically realized network, and it may but does not have to be orthogonal. Our approach can thus be viewed as a more general case of dynamic graph drawing, since we do not require that the sketch is drawn by a layout algorithm or even in the same representation as the target drawing. An alternative view is that an existing drawing is to be improved subject to user-supplied constraints or hints for the algorithm. There is a fair amount of research on dynamic graph layout (see [4] for an overview) and on utilizing user interaction for force-directed [22,14], quasivisibility [21] and layered layout [9], and while there are even attempts to learn
Partially supported by DFG under grants Br 2158/1-1 and Ka 812/8-1.
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 1–11, 2002. c Springer-Verlag Berlin Heidelberg 2002
2
Ulrik Brandes et al.
parameters of layout objectives from example drawings [18,19], we know but one instance of a method for explicit clean-up of a given sketch. SCHEMAP is a system generating schematic maps for communication networks that was demonstrated at last year’s Graph Drawing Software Exhibition [17]. This system gradually orthogonalizes a given network layout (“ground plan”) into a schematic map while preserving the embedding (including crossings). Since it is based on a force-directed algorithm there is no guarantee that the result is indeed orthogonal, and running times are apparently far from interactive. We propose an efficient, dedicatedly orthogonal layout algorithm that extends the Kandinsky approach of [13] according to the Bayesian paradigm for dynamic layout of [2]. We therefore review briefly these two approaches in Sect. 2, before we describe our new algorithm in Sect. 3 and provide examples in Sect. 4. We conclude in Sect. 5.
2
Preliminaries
Our algorithm for sketch-driven orthogonal graph layout rests on two pillars: an orthogonal layout algorithm for general planar graphs, and a framework for extending (static) layout algorithms to dynamic graphs. We review briefly these foundations and refer to [8,15] for background reading. 2.1
Orthogonal Graph Layout and Kandinsky Models
We assume that the reader is familiar with the concepts of planarity and network flow. An embedded planar graph G(V, E, F ) is a planar graph with a specific circular order of edges around vertices and a specific external face, admitting a planar drawing that respects the given embedding. Unless otherwise specified, the planar graphs we consider are always embedded. A planar orthogonal box drawing of a planar graph is a planar drawing that maps each vertex to a box and each edge to a sequence of horizontal and vertical segments. We assume for the rest of this work grid drawings, i.e. drawings in which the center of the boxes and the bends along the edges have integer coordinates. An orthogonal shape Q is a mapping from the set of faces F of a graph G to clockwise ordered lists of tuples (ei , ai , bi ), 1 ≤ i ≤ |Q(f )|, where ei is an edge, ai ∈ {1, . . . , 4} represents the angle formed with the following edge inside the appropriate face in multiples of 90◦ , and bi is the list of bends of the edge. A quasi-orthogonal shape is an orthogonal shape with ai = 0 allowed, where a 0◦ angle means that the succeeding edge is adjacent to the same side of the vertex as the preceding edge. We denote with Q(f, i) the i-th tuple of Q(f ), with a(Q, f, i) the value of the angle field of Q(f, i), and with b(Q, f, i) the value of the bend field of Q(f, i). A quasi-orthogonal shape Q is called valid, if there is a planar orthogonal box drawing with quasi-orthogonal shape Q. Note that quasi-orthogonal shape are not related to quasi-orthogonal drawings as described in [16]. Different drawing conventions have been proposed for planar orthogonal box drawings. We will concentrate on Kandinsky models. All Kandinsky models impose
Sketch-Driven Orthogonal Graph Drawing
3
the following two constraints on the drawing which we call Kandinsky properties. The bend-or-end property is defined as follows: Let G=(V, E) be an embedded graph and consider a planar orthogonal box drawing of G. Let e1 and e2 be two edges adjacent to the same side of a vertex v, e1 following e2 in the embedding, and let f be the face to which e1 and e2 are adjacent. Then either e1 must have a last bend with a 270◦ angle in f or e2 must have a first bend with 270◦ angle in f . The non-empty face property forbids some degenerated cases for triangles in the graph. See [13] for a detailed description of the Kandinsky properties. An important consequence is stated in the following lemma. Lemma 1 ([13]). Every 0◦ angle of a Kandinsky drawing has a unique corresponding 270◦ bend. Bends which correspond to a 0◦ angle are called vertex-bends, all other bends are called face-bends. A Kandinsky drawing of a graph can be determined in the topology-shapemetrics framework [?, Ch. 2.3] by planarizing the graph (topology step), computing angles and bends (shape step), and finally determining the length of edge segments and size of vertex boxes (metrics step, also called compaction). Given an embedded planar graph, the shape of a Kandinsky drawing with the minimum number of bends is obtained from a minimum cost flow in a network that extends the well-known approach of [23] to account for 0◦ angles [13]. See Sect. 3 for details. 2.2
Dynamic Graph Layout and the Bayesian Paradigm
In dynamic graph drawing, the input is a sequence of graphs which represent the states of a single graph that is changing over time. Dynamic graphs can be visualized, e.g., in an animation or in a sequence of drawings, but it is important to keep changes between consecutive frames to a minimum in order not to destroy a viewer’s mental map of the graph [10]. Methods for dynamic orthogonal layout are proposed in [20,5,3,7]. The core modeling task of dynamic layout, i.e. the combination of criteria for good (static) layout with the requirement of small change, is therefore very similar to that of sketch-driven layout. For layout algorithms based on the optimization of an objective function, the Bayesian framework [2,1] suggests to incorporate a difference metric [6] as a penalty in the objective function. Optimization of the combined objective function thus naturally results in a trade-off between static layout criteria and stability. Since orthogonal drawing algorithms in the topology-shape-metrics framework heavily depend on the angles and bends computed in the shape step, it seems natural to use the change in angles and bends as a difference metric for orthogonal shapes [3,1].
4
Ulrik Brandes et al.
3
The Algorithm
Throughout this section, let Σ be an admissible drawing (a sketch) of a graph GΣ = (VΣ , EΣ ), where a sketch is admissible if there is no overlap between edges and non-incident vertices, and no more than two edges cross in single point. Any sketch can be transformed into an admissible one. Our objective is to determine an orthogonal box drawing of GΣ with the following properties: – – – –
the topology is preserved, the drawing is in the Kandinsky model, angles in the drawing deviate little from angles in the sketch (stability), and the drawing contains few bends (readability).
Our algorithm follows the topology-shape-metrics approach and proceeds as follows. First, a planarization G = (V, E, F ) of GΣ is determined. by replacing each crossing in the sketch by a dummy node, so that V = VΣ ∪ C where C is the set of dummy nodes. Since we do not change the embedding of G in the following steps, this ensures that the topology of GΣ is preserved. Next, a quasiorthogonal shape of G is determined from Σ by rounding angles in the sketch to the nearest multiple of 90◦ and classifying each edge bend as either a 900 or a 270◦ bend. Note that the resulting quasi-orthogonal shape S need not be valid. A valid quasi-orthogonal shape Q in the Kandinsky model is then determined so as to satisfy a trade-off between stability and bend-number. Finally, a compaction algorithm is applied on Q to compute a Kandinsky drawing of G, from which the final drawing is obtained by replacing dummy nodes with edge crossings. We concentrate on the problem of determining a quasi-orthogonal shape Q, since all other steps in the algorithm can be carried out using standard algorithms. The problem is stated in terms of an optimization problem for which we present a min-cost flow formulation based on [13]. 3.1
Problem Statement
The problem of finding a quasi-orthogonal shape Q is a bi-criteria optimization problem where the two objectives are readability (number of bends) and stability (change in shape). The readability of a shape Q is independent of the given sketch and defined as the total number of bends, namely B(Q) =
1 2
|b| .
f ∈F (e,a,b)∈Q(f )
The stability of an orthogonal shape Q is expressed in terms of the difference between angles in Q and corresponding angles in the shape S of the sketch |a(S, f, i) − a(Q, f, i)| ∆A (Q, S) = f ∈F 1≤i≤|f |
Sketch-Driven Orthogonal Graph Drawing
5
and the difference in edge bends ∆B (Q, S) = ∆(b(S, f, i), b(Q, f, i)) f ∈F 1≤i≤|f |
where ∆(s1 , s2 ) denotes a restricted edit-distance between two strings, in which only insert and delete operations are permitted. This is similar to the shape difference metric used in [6]. From these components we form a weighted compromise between the degree of change with respect to the given sketch and the number of bends in the quasi-orthogonal shape. Our objective function thus reads D(Q|S) = α · ∆A (Q, S) + β · ∆B (Q, S) + γ · (B(Q) − B(S)) stability
readability
where parameters α, β, and γ control the relative importance of angle or bend changes and bend number. We are now ready to state our problem formally. Problem 1. Given a quasi-orthogonal shape S of a planar graph G, find a valid quasi-orthogonal shape Q of G in the Kandinsky model such that D(Q|S) is minimum. 3.2
Bend-Minimum Kandinsky Shapes
Bend-minimum Kandinsky shapes for planar embedded graphs can be obtained by solving a path-based min-cost flow problem [13]. Since it is essential for our algorithm, we briefly review some important properties of the flow network, but assume that the reader is familiar with Tamassia’s min-cost flow formulation for creating bend-minimum drawings of embedded planar graphs with maximum degree four [23]. This formulation contains a node for each vertex (vertex-node), and for each face (face-node) of the input graph. The angle defined inside a face f between to consecutive edges a, b sharing a vertex v is determined by the flow on the network-edge that connects the vertexnode of v with the face-node of f . A flow of 0 defines an angle of 90◦ , a flow of 1 an angle of 180◦ and so forth. This is illustrated in Fig. 1. Since the sum of angles around a vertex must be 360◦ , each vertex-node is connected to the source of the network with an edge of capacity degree(v) − 4. f
1
v g
0
0
h
Fig. 1. A vertex v incident to faces f , g, and h, and the corresponding part of the min-cost flow network where arc labels indicate flow values according to the depicted shape
6
Ulrik Brandes et al.
Since zero flow represents an angle of 90◦ , an angle of 0◦ corresponds to negative flow which is not feasible in the network. In Kandinsky networks, this problem is solved as shown in Fig. 2 by introducing additional vertices and arcs which allow flow coming from a face-node to enter a vertex-node. Before a unit of flow can enter a vertex node, it crosses an edge and thus creates a bend. It follows that each 0◦ angle has the associated bend required by Lemma 1. For each vertex-node v we define the supply(v) as degree(v) − 4. A vertex-node v with positive supply is connected to the network source with capacity supply(v), and a vertex-node v with negative supply is connected to the network sink with capacity −supply(v).
2C+1
2C+1
2C+1
2C+1
2C+1
2C+1
2C+1
2C+1
2C+1
2C+1
Fig. 2. Kandinsky flow network for a node adjacent to five edges. Thick lines depict the original node and edges, thin lines depict network nodes and edges. All capacities are one except at pointed arcs which have capacity three. If not stated explicitly, arcs have zero cost except for dashed circular arcs which have cost −C
3.3
Sketch-Driven Kandinsky Shapes
In this section we describe modifications to the Kandinsky network that yield a network for Problem 1. The first modification concerns angles around a vertex v. We define for each angle defined by two consecutive edges e and e on a vertex v an angle-node ave,e . We create two arcs, one from ave,e to the vertex-node of v and one in the opposite direction. Both arcs have unconstrained capacity and cost α. We denote with UA (v) the set of angle-nodes of a vertex v. Angle-nodes are the only nodes connected to vertex nodes. All arcs which were connected to vertex-nodes in the original formulation are now connected to the corresponding angle-node. For each angle, and therefore for each angle-node w, there is a target angle a(w) defined by the shape S of the sketch. If a(w) > 0, then w is connected to the source with an arc of capacity a(w) and cost zero. If a(w) < 0, then w is
Sketch-Driven Orthogonal Graph Drawing
(1,w)
(2,0)
f
(1,w) g
f
(2,0)
(a) around a vertex
g
(1,0)
(2,0) s
7
(2,0) (1,2C)
s
(b) at regular and vertex-bends
Fig. 3. Modified Kandinsky network. Newly introduced arcs are dashed and labeled with capacity and cost in (b), where w = β − γ. Newly introduced nodes are marked gray. Node s is the global source
connected to the sink with an arc of capacity a(w) and cost zero. Additionally we remove a(w) from the supply of the vertex-node. Therefore the supply of a vertex node is now defined as supply (v) = degree(v) − 4 − w∈UA (v) a(w). Our construction is illustrated in Fig. 3(a). The second modification concerns the modeling of bends. For each bend in S we create the device shown left in Fig. 3(b). A demand of 1 is added to both faces incident to the edge containing the bend. The effect of this device is, that either Q contains the bend at zero cost or the bend is removed at cost β − γ. Additionally we assign arcs between faces the cost β + γ. Note that the first and the last bend on an edge are potential vertex-bends. For this type of bends we create a different device as shown right in Fig. 3(b). This device ensures that vertex-bends can be confirmed at zero cost. Lemma 2. An optimal solution of the above path-based min-cost flow problem yields an optimal solution for Problem 1. Sketch of Proof. Observe that the original Kandinsky network is modified inside of boxes that represent vertices of the input graph. The total amount of supply in a box remains unchanged since supply (v) + UA (v) a(w) = degree(v) − 4 = supply(v). The same holds for bend devices. Therefore the set of quasi-orthogonal shapes that correspond to a feasible flow in the network is the same as in the original formulation, namely the set of all valid quasi-orthogonal shapes. It remains to show that a min-cost flow in the network yields an optimal solution for D(Q|S). Let x be a feasible flow in the network, and Q the valid quasi-orthogonal shape corresponding to x. Consider the arc a(v, w) between an angle-node w and
8
Ulrik Brandes et al.
its vertex-node v in the flow network and a(w, v) the reverse edge. We assume that either x(a(v, w)) = 0 or x(a(w, x)) = 0. The angle-node w represents the angle between an edge e and its following edge in the embedding. Let (e, aS , bS ) be a tuple in S and (e, aQ , bQ ) be the corresponding tuple in Q describing this angle. Then aQ = aS − x(a(v, w)) + x(a(w, v)) and therefore α · |aS − aQ | = α · (a(w, v)) + α(a(v, w)). At bend devices there are two possibilities: either a bend is conserved at cost zero, or it is deleted at cost β − γ. A newly created bend has cost β + γ in x. Let bQ have minimum edit distance to bS with kD deletions and kI insertions. Then kD (β − γ) + kI (β + γ) = β(kD + kI ) + γ(kI − kD ) = ∆(bQ , bS ) + γ · (|bQ | − |bS |).
Lemma 2 and [13] hence yield an efficient algorithm for an optimal trade-off between bend-reduction and sketch-preservation. Theorem 1. Problem 1 can be solved in time O(n2 log n).
4
Examples
While our approach works very well for graphs which are sufficiently connected, graphs with many tree like structures in the outer face are more difficult, because small angle changes result in major differences in appearance. We use an augmentation method in this case to improve the quality of the algorithm. The idea of the augmentation is to put a frame around the graph and connect vertices on the outer face to this frame by straight lines, see Fig. 4. We then execute the algorithm and finally remove the frame together with the augmentation edges. The introduced edges give the drawing a greater stability. We connect only vertices which are on the conex hull of the sketch drawing with the frame to avoid introducing new crossings. An experimental version of our approach has been implemented in Java using yFiles [24]. Figure ?? shows the result of our algorithm applied to the example used in the paper that initiated this work [17]. In contrast to the force-directed approach used there, our network-flow approach has negligible running time and is therefore truly interactive. A second application that we envision is the beautification of ER diagram sketches of which the designer wants certain features to be preserved. An example
Fig. 4. Ground plan from [17] and its framed sketch.
Sketch-Driven Orthogonal Graph Drawing
9
Fig. 5. Schematic map produced by our algorithm for ground plan from [17]. SchName
Schema
AttrName
DataType SchName
SCH_RELS
ATTRIBUTE
Schema
RelName
SCH_RELS
Relation
RelName
REL_ATTRS
Relation
DataType REL_ATTRS
KEY_ATTRS
d Query
AttrName
ATTRIBUTE
KEY_ATTRS
KeyNo
KEY
KEYS
INDEX_ATTRS
KeyNo
INDEX_ATTRS
BASE_RELATION
VIEW_RELATION DEFINES
KEY
BASE_RELATION
KEYS
d
RefRel DEFINES
FKEY
FKEY
VIEW_ATTRS
Indexes
RefRel
VIEW_RELATION
Query
VIEW_ATTRS
AttrName VIEW_ATTRIBUTE
AttrName
VIEW_ATTRIBUTE
AttrNum INDEX
IndexName
IndexName
IndexType
INDEX
Indexes
AttrNum
IndexType
Fig. 6. ER diagram from [?, p. 577]) and an orthogonalized version
is given in Fig. 6. Note that some degree one vertices such as the one labeled “Query” change their relative position in order to avoid vertex-bends, which would have been necessary if the angles had been fixed. This a good example for the trade-off optimization.
5
Discussion
Our approach can be extended to a fully dynamic orthogonal graph drawing algorithm by considering the most recent drawing as a sketch. Note that the structure of the graph may since have changed, i.e. nodes and vertices may have been added or removed. The deletion of graph elements poses no problem, since we can simply remove them from the sketch as well. Additions to the graph require more care, since, e.g., newly created edges split an angle in the sketch drawing into two, and we can not infer the target values for those two angles in the network. We do have, however, a target value for the sum of these angles. Therefore merging the two angle-nodes into one and using the sum of the angles as the target value for the merged node solves this problem. See Fig. 7 for an illustration.
10
Ulrik Brandes et al.
Fig. 7. Edge insertion for dynamic layout
It is worth noting that the globally defined parameters α, β, and γ can be adjusted locally for every angle and bend. This may be useful in dynamic graph drawing, e.g. to give older parts of a drawing increased stability. An issue we have not addressed in this work is the compaction of sketch drawings. In our implementation we use the compaction algorithm described in [11] together with visibility postprocessing. However, sometimes it may be helpful to preserve some distances in the sketch drawing, especially in the dynamic scenario. Our future research will investigate this problem.
References 1. U. Brandes. Layout of Graph Visualizations. PhD thesis, University of Konstanz, 1999. http://www.ub.uni-konstanz/kops/volltexte/1999/255/. 2. U. Brandes and D. Wagner. A Bayesian paradigm for dynamic graph layout. Proc. Graph Drawing ’97. Springer LNCS 1353:236–247, 1997. 3. U. Brandes and D. Wagner. Dynamic grid embedding with few bends and changes. Proc. Algorithms and Computation ’98. Springer LNCS 1533:89–98, 1998. 4. J. Branke. Dynamic graph drawing. In Drawing Graphs: Methods and Models, Springer LNCS Tutorial 2025:228–246, 2001. 5. S. Bridgeman, J. Fanto, A. Garg, R. Tamassia, and L. Vismara. InteractiveGiotto: An algorithm for interactive orthogonal graph drawing. Proc. Graph Drawing ’97. Springer LNCS 1353:303–308, 1997. 6. S. Bridgeman and R. Tamassia. Difference metrics for interactive orthogonal graph drawing algorithms. Journal of Graph Algorithms and Applications, 4(3):47–74, 2000. 7. M. Closson, S. Gartshore, J. Johansen, and S. Wismath. Fully dynamic 3dimensional orthogonal graph drawing. Journal of Graph Algorithms and Applications, 5(2):1–35, 2001. 8. G. Di Battista, P. Eades, R. Tamassia, and I. G. Tollis. Graph Drawing: Algorithms for the Visualization of Graphs. Prentice Hall, 1999. 9. H. do Nascimento and P. Eades. User hints for directed graph drawing. Proc. Graph Drawing ’01. Springer LNCS 2265:124–138, 2002. 10. P. Eades, W. Lai, K. Misue, and K. Sugiyama. Preserving the mental map of a diagram. Proc. Compugraphics ’91, pp. 24–33, 1991. 11. M. Eiglsperger, and M. Kaufmann. Fast Compaction for Orthogonal Drawings with Vertices of Prescribed Size Proc. Graph Drawing ’01. Springer LNCS 2265:124–138, 2002.
Sketch-Driven Orthogonal Graph Drawing
11
12. R. Elmasri and S. Navathe. Fundamentals of Database Systems. Addison-Wesley, 3rd ed., 2000. 13. U. F¨ oßmeier and M. Kaufmann. Drawing high degree graphs with low bend numbers. Proc. Graph Drawing ’95. Springer LNCS 1027:254–266, 1996. 14. J. Ignatowicz. Drawing force-directed graphs using Optigraph. Proc. Graph Drawing ’95. Springer LNCS 1027:333–336, 1996. 15. M. Kaufmann and D. Wagner, editors. Drawing Graphs: Methods and Models. Springer LNCS Tutorial 2025, 2001. 16. G. W. Klau and P. Mutzel. Quasi-orthogonal drawing of planar graphs. TR 98-1013, Max-Planck-Institut f¨ ur Informatik, Saarbr¨ ucken, 1998. 17. U. Lauther and A. St¨ ubinger. Generating schematic cable plans using springembedder methods. Proc. Graph Drawing ’01. Springer LNCS 2265:465–466, 2002. 18. T. Masui. Graphic object layout with interactive genetic algorithms. Proc. IEEE Visual Languages ’92, pp. 74–87, 1992. 19. X. Mendon¸ca and P. Eades. Learning aesthetics for visualization. Anais do XX Semin´ ario Integrado de Software e Hardware, pp. 76–88, 1993. 20. A. Papakostas and I. G. Tollis. Issues in interactive orthogonal graph drawing. Proc. Graph Drawing ’95. Springer LNCS 1027:419–430, 1996. 21. G. Paris. Cooperation between interactive actions and automatic drawing in a schematic editor. Proc. Graph Drawing ’98. Springer LNCS 1547:394–402, 1998. 22. K. Ryall, J. Marks, and S. Shieber. An interactive system for drawing graphs. Proc. Graph Drawing ’96. Springer LNCS 1190:387–394, 1997. 23. R. Tamassia. On embedding a graph in the grid with the minimum number of bends. SIAM Journal on Computing, 16(3):421–444, 1987. 24. R. Wiese, M. Eiglsperger, and M. Kaufmann. yfiles: Visualization and automatic layout of graphs. Proc. Graph Drawing ’01. Springer LNCS 2265:453–454, 2002.
Maintaining the Mental Map for Circular Drawings Michael Kaufmann1 and Roland Wiese1,2 1
Wilhelm-Schickard-Institut f¨ ur Informatik, Universit¨ at T¨ ubingen, 72076 T¨ ubingen [email protected] 2 yWorks GmbH, Sand 13, 72076 T¨ ubingen [email protected]
Abstract. In this paper we present new ideas to extend the framework for circular drawing of networks by Six and Tollis [15] by some new concepts which makes the framework suitable for user interaction. The original approach displays each biconnected component in a circular way, and the blocktree of the graph as a tree drawn radially [9]. We introduce the concept of hicircular drawings, a hierarchical extension of the mentioned framework replacing the circles of single vertices by circles of circular or star-like structures. This concept is inspired by the works of Brandenburg on graph clustering, and the recursive concepts of series-parallel graphs, PQ- resp. SPQR-trees.
1
Introduction
Next to orthogonal layout, Sugiyama-style layout and springembedder-style layout, the circular layout style has gained increasing popularity. The original circular layout style assumes that the graph is partitioned into clusters, the nodes of each cluster are placed on the circumference of an embedding circle, and each edge is drawn with a straight line [16]. It has found more and more applications in network design and development, especially in the area of computer networks and telecommunication, but also in social networking [12]. The layout style has been introduced by Madden et. al [11,7] to the graph drawing community, the method used is a comparably simple heuristic. Six and Tollis [15,16] adapted the style but developed a scientific framework for the approach. The main idea is to display each biconnected component in a circular way, and the blocktree, i.e. the tree of biconnected components, of the graph as a radial tree of such circles. Other works on clustering include the approaches by Brandenburg [2,10], where a certain kind of subgraphs (cliques) are collapsed to nodes of a graph (cycle, tree) on a higher level of abstraction. An overview on clustering methods as well as on drawing clusters can be found in [4]. On the layout side, the basic concept of compound graphs [18] has been proposed to handle clusters. Compound graphs and also clustered graphs have two different representations, an adjacency representation and also an inclusion representation. The latter one is either done by an additional view of the inclusion tree, or a representation of the cluster by nested rectangles. See also [8] for a M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 12–22, 2002. c Springer-Verlag Berlin Heidelberg 2002
Maintaining the Mental Map for Circular Drawings
13
more advanced approach. Such a twofold representation is not very flexible, since it distracts the users attention, if it is not carefully used. Therefore we try to display clusteral structures, and also want to show the way a graph develops in a dynamic setting. While in the area of computer networks the graphs are mostly static, we recently met applications from the area of product management, where the structure is dynamically growing. The following figure shows the need of an interactive extension of the concept of Six and Tollis: First the graph consists of a chain of quadrangles, which are displayed nicely by the layout algorithm “Circular with Radial”. When we add just a single edge connecting the two outermost quadrangles, all the components collaps into one. Circular with Radial places the vertices on a circle, performs a crossing minimization heuristics but cannot avoid at least n/4 crossings, one from each of the quadrangles. Unfortunately, the angles that arise are very tiny such that the previous structure can hardly be recognized. An alternative layout for this graph is given in the next figure, it shows the complete ring of components as it arose from the construction. Since one can assume that the user has this structural view of the closed chain of quadrangles in mind, his mental map is somewhat maintained. Note that there is already extensive work been done on dynamic graph drawing and various concepts of mental maps. For an overview and related references see [3].
Fig. 1. The left figure shows the chain-like layout as constructed by the Six/Tollis’ algorithm. Adding a new edge from the lowest to the topmost node leads to the middle layout, destroying the mental map completely. A better alternative is shown to the right, where the mental map of the structure, namely a circle of smaller circles, is nicely maintained.
Regarding the example, the ring of quadrangles can be viewed as one big component with some subcomponents, which finally leads to a hierarchical concept. In section 3, we will give the ideas for a new more general approach, and explain the necessary operations that lead to hopefully suitable layouts even in a dynamic setting where vertices and edges can be inserted and deleted. We will keep the description on a rather sketchy level. First, we review the framework for circular drawings by Six and Tollis.
14
2
Michael Kaufmann and Roland Wiese
The Framework of Six and Tollis and Its Limitations
The framework of Six and Tollis can be summarized as follows: The graph G = (V, E) is decomposed into the biconnected components which form the resulting block tree. For the articulation nodes v which are not adjacent to a bridge between two components, v is assigned to one of the components. The nodes of each single component are placed on a circle such that the distance between neighboring nodes is fixed. This determines the circumference of each component, which is represented as a single supernode of large size in the following. Next an adaption of the algorithm for radial tree layout [9] taking into account the supernodes, which usually have different sizes, gives the final layout of the whole structure. In radial tree layouts, the non-root nodes are placed in concentric circles around the root. Note that some rotations are also necessary in order to obtain a nice final drawing and that the maintenance of a reasonable connection between two adjacent components is not trivial, but can be solved. Further note that the circular drawing of each single component can be enhanced by various techniques for crossing reduction. For more details on the crossing reduction step as well as on the framework see [14,15]. We have already seen in the introduction, that the concept of Six and Tollis is static, that and features that support user interactivity are not incorporated. The whole scheme works in only two major stages, with a strong focus on the biconnectivity structure, since the superstructure of the blocktree is drawn as a radial tree and the single biconnected components as circles. Furthermore, the drawing of single biconnected components is quite limited, the placement of the nodes on a circle hides structural properties like symmetries, on the other hand, the contingent property of outerplanarity can be displayed [14]. We try to develop a more structured layout of biconnected components especially if it consists of several finer structures, without loosing the benefits of the concept of Six and Tollis. Before we discuss the setting for interactivity, we introduce a slightly more complicated variant for static circular layout, but which provides more flexibility than the previous approach. Later on, we will extend this new approach to support user interactiveness.
3
The New Approach
The main idea is to extend the radial-circular framework by the ability of maintaining the mental map. The layout of the different parts will either stay unchanged, or just stretched or squeezed. The embedding will definitely not be changed. Only essential structural changes should be displayed. 3.1
Our Static Variant of the Approach of Six and Tollis
As before, the idea is to take the block tree of biconnected components and layout the root component R in a circular way. Then recursively layout the subtrees T adjacent to the root R. The layouts of the subtrees are approximately
Maintaining the Mental Map for Circular Drawings
15
represented by round supernodes of a size according of the size of the layout. To find appropriate positions for these supernodes, the available space around the layout of R is partitioned by straight lines starting from the center of the layout of R. These lines define certain sectors, the so-called wedges [15]. The size of the wedges is chosen appropriate to the size of the supernodes, while the position of the wedge relative to the layout of R is chosen such that afterwards the layout of T , here represented by a supernode, can be attached directly to its articulation point in R. This recursive concept gives a lot of flexibility as will be shown later. Note that R can also be a single node, i.e. if the input graph is a tree. Complete binary trees give also a good motivation of our variant, since the constructed layout is the well-known H-tree layout [13] which is linear with respect to the area. The original radial-tree construction covers an area of O(n2 ) in this case. 6
40
23
17
19 12
27
33
20 32
18 10
38
5
16
3
29 21
24
29 31
25
4
9
39
28
7 26
34
7
18
13
20 37
28
Root
11
25
2 8
27
12
13 17
14 2
40
24
36
5
11
8
37
15
23
19
34
3
22
16
6
22
26
14
4
Root
9
21
30 10
38
30
15
35
35
33 31
39
32 36
Fig. 2. A complete ternary tree laid out according to the radial-circular algorithm [15] and according to our alternative method where the subtrees are drawn recursively.
So, compared to the algorithms of Six and Tollis, the construction works very similar and also allows a lot of variations like the application of crossing minimization schemes. The decomposition into biconnected components form the block tree, the biconnected components are mapped to circles. The main difference lies in the interpretation of the (block) tree structure, which we now consider to be a recursive structure. For the subtrees of the root, we draw independent layouts of the same layout style which are then connected to the articulation points of the root components. 3.2
Detailed Hierarchical Structures
Next, we present the new concepts for refined structures. Intuitively, we allow to replace the nodes in the scheme above by supernodes that again represent tree-like or circular structures. We simulate the tree-like structures by the sim-
16
Michael Kaufmann and Roland Wiese
pler concept of stars. A star is a graph with a center component and some leg components adjacent to the center, but not connected otherwise. Each supernode represents an associated underlying subgraph and has a round shape of a size according to the layout size of the associated subgraph. We have two types of supernodes, namely star nodes and circle nodes. The underlying structure of a star node is a star, consisting of a circle node as center component and possibly a further (super)node at each leg of the star. A circle node represents a set of (super)nodes arranged in a circular way. This way, the hierarchical structure of the input graph G can be represented by a tree H consisting of star nodes, circle nodes and normal nodes at the leaves of the tree. We call H the hicircular tree. A convention of H is that the center component of each star node will always be the leftmost child of the corresponding star node in the tree. The elements of the smallest edge subset in E that can be represented by the same hicircular tree as the whole graph G are called structural edges. All other edges do not contribute to the hierarchical structure, they are nonstructural. In Figure 3, we give a graph and two possible representations by hicircular trees, depending on the interpretation of the structure. In this example, all the edges are structural.
S
N
C
C
N
N
C
N
N
N
N
N
N
N
N
C
N
N
N
N
N C
N
N
N
N
N
N
N
N
C
C
N
C
N
S
N
N
N
N
N
C
C
N
S
N
N
S
N
N
N
N
N
N
N
N
N
N
Fig. 3. A graph and two alternatives for its hicircular tree. Circular nodes are denoted by C, star nodes by S and normal nodes by N. In the upper tree, the global structure is a star with a big circular component in the center and six little legs, while the lower structure is a circle, and the legs are on a lower hierarchy level.
Note that similar descriptions of hierarchies have been used in various other concepts like series-parallel graphs [13], PQ-trees [1] or SPQR-trees [6]. For the block tree of biconnected components as in the approach of Six and Tollis, the hicircular tree consists of a tree of star nodes, each with a circle node as the leftmost child (the center) and more star nodes or normal nodes as the
Maintaining the Mental Map for Circular Drawings
17
other children. All children of circle nodes are normal nodes, since circle nodes just represent biconnected components, which are not differentiated any further. From a given hicircular tree, it is natural to derive the corresponding hicircular layout. The layout technique for the underlying structure of a star node is the same as described in the last subsection. For a circle node we arrange the underlying (super)nodes in a circular way, similar as described by Six and Tollis, but having nodes of different sizes. The details are omitted. 3.3
The Dynamic Case
Based on our concepts developed so far, we use the hicircular tree for the actual graph G to represent its hierarchical structure. Our objective is to preserve the tree-like and cyclic structures, that we kept as the mental map of the user over time if possible. To achieve this goal we want to maintain the hierarchical structures as much as possible, keep the original layout as recognizable as possible, and still clearly distinguish between tree and cycle structures. We will now discuss the elementary update operations; more complex operations can be formulated by a concatenation of these elementary operations: 1. Append a new node v to another node w by a new edge e = (v, w) We consider the normal node w in the hicircular tree. w lies either on a circle, or it is the center of a star, or a normal node. In the two latter cases, v is appended as a leg to w. If w is a circle node, we change w’s status to ’star node’, such that it becomes the center of a star and gets the single circle node v as a leg. The actual layout is changed as follows: We determine the position of w, place v next to w and connect both nodes with edge e without changing the embedding besides the new edge. Then we run the layout algorithm again for the structural edges of G. This gives a layout where v is inserted as a ’leg’ of w. The remaining layout does not change considerably. The actual wedges around w are squeezed a bit, and some space for the wedge for v has been created. v has been placed as close as possible (minimal distance) to w within this wedge. Then the nonstructural edges are added as straight lines. Note that the complete relayout of the graph is not really necessary but it keeps the scheme simple. Alternatively, the layouts within the new smaller wedges can be squeezed by a affine transformation of the node positions. 2. Add a new edge e = (v, w). We consider the position of the single nodes v and w in the hicircular tree H, and determine the lowest common ancestor a in H. If a is a circle node, v and w lie already on a common cycle, which is displayed by supernode a. Hence we decide that e has no effect on the structure of G, e is nonstructural. The drawing for the old graph will not change at all, only the new edge will be inserted, possibly by a straight line. If a is a star node, the new edge joins two leaf nodes within H, such that a new node cycle v = vr , . . . , v0 = a = w0 , . . . , ws = w is formed, where vi (0 < i < r) are nodes on the path from a to v and wj (0 < j < s) are nodes on the path from a to w. We now remove all edges from H that lie on that newly formed circle and add a new circle node c to H. Then we relink all nodes on the circle such
18
Michael Kaufmann and Roland Wiese
v
Fig. 4. Appending the new black node to a center of a star node S means a squeezing of the other wedges of the subgraphs of S.
that they become children of c. Finally we remove the edge that connects a with its parent node p and add the edge (p, c) instead. This transformation yields a well-formed hicircular tree again. If a had more than two legs as it is the case in Figure 5, they remain the legs of their centers as before. From the new hicircular tree, a corresponding new layout can be computed. Compared to the previous layout, the new layout might considerably change, although the planar embedding of the structural edges remains the same except of the new edge. The new edge is embedded according to the previous tree structure, it might only cross some nonstructural edges. The supernodes on the new cycle will move such that a circular structure arise. The adjacent wedges have to be squeezed or even stretched depending on the embedding of the legs of the star nodes, that are involved in the operation. Note that some of the subgraphs associated to the legs of the stars nodes of the new circle will be located inside of the circle, others on the outside. Local adjustments help in this case again. 3. Delete a single node v by removing the connecting edge (v, w). This is exactly the reverse operation of operation 1. Eventually, we have to change the state of w from ‘star node’ to ‘circle node’. Furthermore, we have the freedom to widen the wedges around w, since the wedge for v could be removed. There is only a slight effect on the drawing of G. 4. Delete an edge e = (v, w). We assume that v, w lie in the same biconnected component. Otherwise, the operation is easy, since the layout is split into two components. We omit this case here. As in operation 2. we consider the lowest common ancestor a of v and w and determine, if the removal of e breaks a structural cycle C (a cycle which is displayed by a circle node). Otherwise, e is just removed from the drawing, while everything else remains unchanged. If cycle C is broken, the corresponding supernode a is split into two legs that contain either v or w but not both. The supernodes of the legs are again modeled as sequences of star nodes, similar to the original construction for the block tree. The effect is just reverse to that of operation 2., cf. Figure 6.
Maintaining the Mental Map for Circular Drawings
19
e1 e1
e2
e2
Fig. 5. Inserting two edges to the graph from Figure 3. Edge e2 does not change the structure, so it is just drawn straightline across the drawing. Edge e1 closes a cycle between two legs of a star. Note that this is only the case when our interpretation of the structure and its representing hicircular tree is the same as in the upper alternative of Figure 3. In this case, a new cycle has been established and we change the structure of the drawing accordingly.
S
C
N
N
S
N
S
N
N
C
N
N
S
N
S
N
N N
C
N
C
N
S
N
N
N
N
N
N
Fig. 6. The deletion of an edge from the outermost circle (Figure 3) shows a drastic effect of an edge deletion on the drawing and the hicircular tree
4
Extensions
Our scheme that we presented here is efficient and it contains a lot of flexibility. We will comment in this section on some variations: – Assume that we have inserted already many nonstructural edges, such that the more detailed structure cannot be seen anymore just because of the large number of edges. Then the scheme allows to collapse the refinement of the structure and then to display only the coarse structures, just the way as shown in Figure 7. – If a cycle is broken by the deletion of a structural edge, and there are additional nonstructural edges at present, they might become structural. The scheme now allows to just break the cycle and leave all the other edges as they are, or to remove the nonstructural edges at once and insert them
20
Michael Kaufmann and Roland Wiese
Fig. 7. The center component on the left-hand side with the finer resolution contains too many nonstructural edges such that the refined structural resolution is of no help anymore. Hence the user can decide to collapse a hierarchy level and draw the whole component on one circle as shown in the right figure.
again in the same order as before. This way, one of the nonstructural edges might become structural and the cycle or part of it might remain unbroken. This clearly is an expensive way of restructuring. There might be ways for improvements. – If a nonstructural edge is inserted, we have originally proposed to draw it straightline across the whole structure. Very often, there are much better alternatives like splines, and/or a clever rerouting of such an edge helps, especially if the drawing is not too crowded yet and edge overlappings can (largely) be avoided.
5
Concluding Discussion
We have presented ideas for an extension of the scheme for circular layouts proposed by Six and Tollis to support the display of fine-granular structures and maintain the mental map while dynamically changing the graph. We kept the description on a high level, our goal was to present the main concept, obviously, a lot of details have been omitted. The tool we used to represent our hierarchical structure, was inspired by series-parallel graphs, PQ-trees or SPQRtrees. The basic components are trees, which again are represented by stars, and cycles, which are represented by circles. The update operations on the graph are presented as elementary operations ’insert/delete single nodes/edges’. More complex operations can be simulated by splitting them. At several steps of our descriptions, we have advised a complete recomputation of the layout. This is mainly due a simple description of the scheme, more efficient alternatives can be thought. A major property of the approach is that the drawing reflects the way the graphs have evolved. So, the mental map of the user who is focused on treelike and cyclic structures is maintained. But the drawings of the static graphs
Maintaining the Mental Map for Circular Drawings
21
without having the history of operations, or the hicircular tree, might not so easy to be understood, since the layout heavily depends on the order of the operations. This effect is not particular due to our algorithm but because of the nature of dynamic algorithms that always try to reflect the evoluation of a structure over time [3]. As already been shown in Figure 2, the hicircular tree is not unique. Hence later operations like Inserting an edge might have different effects, as it has been shown in figure F. Fortunately, it can be brought into a standard form by some additional rules, which would support the upper alternative from Figure 2. One way would be to compute the blocktree of biconnected components, and represent this by a tree of C-nodes. Each biconnected component can eventually partitioned by identifying a (structural) edge whose removal would provides a chain-like structure of larger components C1 , ..., Ct . C1 , ..., Ct again form the substructures of the cycle, represented by the C-node from above. On the other hand, the hicircular layout is unique for a given hicircular tree. Note that the scheme supports tree- and circular structures, which are planar per se, and the structural edges are always drawn pairwise crossing-free, but it is also robust enough to work for non-planar graphs as indicated in the last section. Each operation can be executed in linear time, but it seems that advanced data structures similar to [6] should enable more efficient implementations, possibly with logarithmic running times per operation. The basics of the proposed scheme have already been integrated in the yFiles library [19]. In the future, we will consider the practicability of the proposed scheme, asking if it is robust enough to be used in practical applications, and which of the variants are worthwhile to be used. We consider this proposal as a first step in the right direction, since there is certainly demand for dynamic graph drawing. And for the circular layout style, nothing has been published yet in this direction.
References 1. Booth, K.S. and Lueker G.S., Testing for the consecutive ones property, intervals graphs and graph planarity testing using PQ-tree algorithms, J. Comput. System Sci.13, pp. 335-379, 1976. 2. Brandenburg F., Graph Clustering 1: Cycles of Cliques, Proc. GD’97, LNCS 1353, Springer, pp. 158-168, 1998. 3. Branke J., Dynamic Graph Drawing, in Kaufmann/Wagner (Eds.) Drawing Graphs: Methods and Models, LNCS 2025, Springer, pp. 228-246, 2001. 4. Brockenauer R. and S. Cornelsen, Drawing Clusters and Hierarchies, in Kaufmann/Wagner (Eds.) Drawing Graphs: Methods and Models, LNCS 2025, Springer, pp. 193-227, 2001. 5. Di Battista, G., Eades P., Tamassia R. and I. G. Tollis, Graph Drawing: Algorithms for the Visualization of Graphs, Prentice Hall, 1999. 6. Di Battista G., and Tamassia R., On-line graph algorithms with SPQR-trees, Proc. ICALP 1990, LNCS 442, Springer, pp. 598-611, 1990. 7. Dogrus¨ oz U., B. Madden and P. Madden, Circular Layout in the Graph Layout Toolkit, Proc. GD’96, LNCS 1190, Springer, pp. 92-100, 1997.
22
Michael Kaufmann and Roland Wiese
8. Duncan Ch., Goodrich M., and Kobourov St., Planarity-Preserving Clustering and Embedding of Large Graphs, Proc. GD’99, LNCS 1731, Springer, pp. 186-196, 2000. 9. Eades P., Drawing Free Trees, Bulletin of the Institute for Combinatorics and its Applications, 5, pp. 10-36, 1992. 10. Edachery, J., Sen A., Brandenburg F., Graph Clustering Using Distance-k Cliques, Proc. GD’99, LNCS 1731, Springer, pp. 98-106, 2000. . 11. Kar G., B. Madden and R. Gilbert, Heuristic Layout Algorithms for Network Presentation Services, IEEE Network, 11, pp. 29-36, 1988. 12. Krebs V., Visualizing Human Networks, Release 1.0: Esther Dyson’s Monthly Report, pp. 1-25, 1996. 13. Lengauer T., Combinatorial Algorithms for Integrated Circuit Layout, WileyTeubner, 1990. 14. Six, J.M. and I.G. Tollis, Circular Drawings of Biconnected Graphs, Proc. Alenex’99, LNCS 1619, Springer, pp. 57-73, 1999. 15. Six, J.M. and I.G. Tollis, A Framework for Circular Drawings of Networks, Proc. GD’99, LNCS 1731, Springer, pp. 107-116, 2000. 16. Six, J.M., Ph.D. Thesis, University of Texas at Dallas, 2000. 17. Sugiyama K., S. Tagawa and M. Toda. Methods for Visual Understanding of Hierarchical System Structures, IEEE Transactions on Systems, Man and Cybernetics, 11(2), pp. 109-125, 1981. 18. Sugiyama K., K. Misue. Visualisation of structural information: Automatic drawing of compound digraphs, IEEE Transactions on Systems, Man and Cybernetics, 21(4), pp. 876-892, 1991. 19. The yFiles library: http://www-pr.informatik.uni-tuebingen.de/yfiles/ and http://www.yworks.de
Graphs, They Are Changing Dynamic Graph Drawing for a Sequence of Graphs Stephan Diehl and Carsten G¨ org University of Saarland, FR 6.2 Informatik, PO Box 15 11 50, D-66041 Saarbr¨ ucken, Germany [email protected], [email protected] Abstract. In this paper we present a generic algorithm for drawing sequences of graphs. This algorithm works for different layout algorithms and related metrics and adjustment strategies. It differs from previous work on dynamic graph drawing in that it considers all graphs in the sequence (offline) instead of just the previous ones (online) when computing the layout for each graph of the sequence. We introduce several general adjustment strategies and give examples of these strategies in the context of force-directed graph layout. Finally some results from our first prototype implementation are discussed.
1
Introduction Optimizing the layout adjustment for a sequence of graph changes, e.g. for an off-line animation, is still an open yet very challenging area – J¨ urgen Branke [3] of research.
Dynamic graph drawing addresses the problem of computing layouts of graphs which evolve over time by adding and deleting edges and nodes. This results in an additional aesthetic criterion known as “preserving the mental map” [13] or dynamic stability. The ad-hoc approach is to compute a new layout for the whole graph after each update using those algorithms developed for static graph layout. In most cases this approach produces layouts which do not preserve the mental map. The common solution is to apply a technique known from key-frame animations called inbetweening to achieve “smooth” transitions between subsequent graphs, i.e. animations show how nodes are moved to their new positions. This approach yields decent results if only a few nodes change their position or whole clusters are moved without substantially changing their inner layout or if the transition is subdivided into several phases [9]. But in most cases the animations are just nice and do neither convey much information nor help to preserve the mental map.
2
Mental Map and Mental Distance
A layout is a mapping of the nodes and edges of a graph onto a plane or into a volume. M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 23–31, 2002. c Springer-Verlag Berlin Heidelberg 2002
24
Stephan Diehl and Carsten G¨ org
The term mental map refers to the abstract structural information a user forms by looking at the layout of a graph. The mental map facilitates navigation in the graph or comparison of it and other graphs. In the context of dynamic graph drawing changes to this map should be minimal, in other words algorithms to draw sequences of graphs should preserve the mental map. Misue et. al. [13] discuss three models for the mental map – Orthogonality: The horizontal and vertical order of nodes should stay the same when changing node positions. – Proximity Relations: The distance to all or at least to all neighboring nodes should be about the same. – Topology: The dual graph should be maintained. Based on each of these models we can define metrics that indicate how close the mental maps of two given layouts are. For the purpose of this paper we call the resulting class of metrics mental distances. Let Layout be the set of all layouts, i.e. in the simplest case mappings from nodes to points in R2 . Definition 1 (Mental Distance). Let l1 , l2 ∈ Layout be two layouts. Then the function ∆ : Layout × Layout → R+ 0 is a metric for how good l2 preserves the mental map of l1 . In particular ∆(l1 , l2 ) = 0 means that l1 and l2 have the same mental map. Most metrics only compare the layouts for the common subgraph of the underlying graphs, but we could also have metrics which additionally consider the layout of those nodes and edges which are only present in one of the layouts. 2.1
Examples of Mental Distances
Many researchers proposed distance metrics, e.g. [12,4]. We give here two which we use in our current implementation. The metrics below are based on node positions only. There are other metrics which take clustering or edge routing into account. For an overview see for example [3]. Definition 2 (Euclidean and Orthogonal Mental Distance). Let l1 , l2 ∈ Layoutbe two layouts. Their Euclidean mental distance is defined as ∆ (l1 , l2 ) = dist(l1 (v), l2 (v)) where dist(p, q) yields the Euclidean disv∈V1 ∩V2
tance of two points. Let sgn(x) ∈ {−1, 0, +1} yield the sign of a (real) number x. Their orthogonal mental distance is ∆⊥ (l1 , l2 ) = |sgn(l1 (v1 ).x − l1 (v2 ).x) − sgn(l2 (v1 ).x − l2 (v2 ).x)| v1 ,v2 ∈V1 ∩V2 +|sgn(l (v ).y − l (v ).y) − sgn(l (v ).y − l (v ).y)| 1 1 1 2 2 1 2 2
3
The Offline Dynamic Graph Drawing Problem
Assume that the quality of a layout could be measured by a function Γ regarding aesthetic goals like compactness, even distribution of nodes, minimal number of edge crossings, etc [15]. Such formal criteria are the computational crutches to substitute real models of human cognition or simply taste.
Graphs, They Are Changing
25
Definition 3 (Layout Quality). Let l ∈ Layout be a layout. Then the function Γ : Layout → R+ 0 is a metric for the quality of a single layout. In particular Γ (l) = 0 means that l has minimal quality. Now we can state the problem of dynamic drawing of a sequence of graphs. In most applications the graphs in such a sequence will result from changes to the preceding graph and thus will share some nodes and edges. Definition 4 (The Offline Dynamic Graph Drawing Problem). Given a sequence of n graphs g1 , . . . , gn . Compute layouts l1 , . . . , ln for these graphs such that 1. ∆ = ∆(li , li+1 ) is minimal 2. Γ = Γ (li ) is maximal 1≤i
1≤i≤n
Unfortunately, the two optimization goals can not be achieved at the same time in general. For the online dynamic graph drawing problem l1 , . . . , ln−1 and gn are given and ln has to be computed. 3.1
Foresighted Layout without Tolerance
In a previous paper we introduced a dynamic graph drawing algorithm which we called Foresighted Layout [7]. Given a sequence of n graphs we compute a global layout which induces a layout for each of the n graphs. In the simplest case this global layout is just the layout of the supergraph of all graphs in the sequence. By forming temporal equivalence classes of nodes and edges Foresighted Layout can also produce more compact global layouts. In a GAP (graph animation partition) nodes with disjoint live times are grouped together. In an RGAP (reduced GAP) also edges with disjoint live times are represented by a single edge. We have proven the N Pcompleteness of computing a minimal GAP respectively RGAP by reduction on the minimal graph coloring problem [6,10]. A unique feature of the above approach is that once they are drawn on the screen neither nodes nor the bends of edges change their positions in graphs subsequently drawn. This algorithm preserves the mental map in a trivial way by using the global layout, but does so at the cost of other aesthetic criteria. Foresighted Layout does not work for all classes of graphs equally well, as it requires that the supergraph, GAP or RGAP of the graphs belongs to the same class as the individual graphs. For example, in general the supergraph of trees is not a tree, and the supergraph of planar graphs is not a planar graph. 3.2
Foresighted Layout with Tolerance
In this paper we extend the above method, such that it can trade aesthetic quality for dynamic stability and vice versa. To this end we use a tolerance value δ and allow such layouts for individual graphs in the sequence for which the mental distance to certain other graphs1 is smaller than δ. As a result we can formulate a weaker problem. 1
The strategies that we are going to present differ particularly with regard to what other graphs are chosen for comparison.
26
Stephan Diehl and Carsten G¨ org
Definition 5 (The Tolerant Offline Dynamic Graph Drawing Problem). Given a sequence of n graphs g1 , . . . , gn and a tolerance value δ. Compute layouts l1 , . . . , ln for these graphs such that 1. ∆(li , li+1 ) < δ for all 1 ≤ i < n 2. Γ = Γ (li ) is maximal 1≤i≤n
As a simple corollary we get that 0 ≤ ∆ < n ∗ δ. In general we can expect that Γ increases for larger values of δ. In other words a small δ enforces dynamic stability, while larger values increase local quality. For efficiency reasons we do not try to compute an optimal solution, but we compute approximations. Algorithm 1 is generic in the sense that it works with different static layout algorithms and related metrics and adjustment strategies. We use the notation l|g to denote the layout which results from restricting l to the nodes and edges in g. In other words l|g is the layout for g induced by the layout l. We use uppercase letters for the global layout L and layouts Li for graphs gi induced by the global layout. For all other layout we use lowercase. Algorithm 1. Foresighted Layout with tolerance δ Compute global layout L for supergraph (resp. GAP or RGAP) of g1 , . . . , gn for i := 1 to n do Li := L|gi // Compute li by adjusting Li li := adjust(. . .) // using one of the strategies discussed in Section 3.3 if i==1 then Draw graph g1 using l1 else Draw graph gi by morphing from li−1 to li end if end for
3.3
Layout Adjustment Strategies
Classical layout adjustment methods adjust(gi , li−1 ) draw a graph gi by adapting the layout li−1 of the preceding graph. Our adjustment strategies also take the global layout into account. We use the supergraph (resp. GAP or RGAP) as a rough abstraction of the whole sequence of graphs. In a sense it contains information about the whole future. In addition the strategies might consider the previous, next or all graphs in the sequence. Instead of the graph gi these strategies get the layout Li for the graph induced by the global layout and try to adjust it while regarding constraints on the mental distance to other layouts. If they can not fulfill the constraints these strategies yield the induced layout. Strategy 1 (Independent Adjustment). li = adjust(Li , δ) This strategy tries to preserve the mental map by ensuring that ∆(Li , li ) < δ. As a result all graphs in the animation stay close to the global layout.
Graphs, They Are Changing
27
Strategy 2 (Predecessor Dependent Adjustment). li = adjust(Li , li−1 , δ) This strategy differs from the above by requiring that the layout stays close to that of the preceding one, i.e. ∆(li−1 , li ) < δ. Note, that there is no constraint for adjusting L1 . As a result l1 can be very far from the induced layout and this can have undesirable effects. The value of ∆(l1 , L2 ) might get greater than δ and all adjustments to L2 might not sufficiently reduce the mental distance. In this case the adjustment will fail and return the induced layout. Strategy 3 (Context Dependent Adjustment). li = adjust(Li , li−1 , Li+1 , δ) This strategy extends the previous one by enforcing that the layout stays close to both the preceding layout as well as the induced layout for the subsequent graph, i.e. ∆(li−1 , li ) < δ and ∆(li , Li+1 ) < δ. In particular, this strategy makes sure that l1 stays close to L2 and thus we do not run into the problem discussed above when adjusting L2 . The above strategies try to adjust a layout as much as possible, before proceeding to the next one. The previous layout can thus impose too much restrictions on the next one and render adjustments impossible. The following strategy strives to evenly adjust all layouts in the sequence. Strategy 4 (Simultaneous Adjustment). (l1 , . . . , ln ) = adjust(L1 , . . . , Ln , δ) This strategy simultaneously adjusts the induced layouts L1 , . . . , Ln such that ∆(li , li+1 ) < δ for all 1 ≤ i < n. An variant of the simultaneous adjustment strategy could also try to preserve the inertia of movements. 3.4
Layout Adjustment for Force-Directed Layout
We show how a simple spring embedder [8,2] can be modified to perform layout adjustment according to the above strategies. Unfortunately once this embedders have computed a layout that does not preserve the mental map further iterations do not resolve the problem. As a result we extended these embedders by simulated annealing. We assume a global temperature T which cools off after each iteration. Algorithm 2. adjust(Li , li−1 , Li+1 , δ) context dependent l := Li for j := 1 to #Iterations do Compute forces for each node in l with global temperature T Compute new layout l by applying forces to nodes in l if ∆(li−1 , l ) < δ and ∆(l , Li+1 ) < δ then l := l end if T := anneal(T, j) end for return l
28
Stephan Diehl and Carsten G¨ org
Algorithm 2 follows immediately from the above general description of the strategies. In Algorithm 3 the iterations of the embedder are performed simultaneously on all layouts. After each step we check whether the mental distances of a layout and the layouts of its previous and next graphs are below the tolerance value. If not the layout is discarded and the layout of the previous iteration is used for the next iteration.
Algorithm 3. adjust(L1 , . . . , Ln , δ) simultaneous (l1 , . . . , ln ) := (L1 , . . . , Ln ) for j := 1 to #Iterations do for i := 1 to n do Compute forces for each node in li with global temperature T Compute new layout l by applying forces to nodes in li if ∆(li−1 , l ) < δ and ∆(l , li+1 ) < δ then li := l end if T := anneal(T, j) end for end for return (l1 , . . . , ln )
4
Examples
In Figure 1 navigation through word collocation graphs is shown, more precisely the sequence consists of the three graphs for the words Lecture, Corbate, Award and Turing. In the first column the supergraph layouts of the graphs are shown. The nodes for the mentioned words have always the same relative position (the three layouts have small mental distances), but the layouts are of poor quality. In the second column context dependent adjustment with orthogonal mental distance and δ = 2 is shown. The layout quality is better, but the mental distance is larger, because the nodes Lecture and Corbate have changed their horizontal order. In the third column simultaneous adjustment with orthogonal mental distance and δ = 2 is shown. The layout of the first graph is even more compact (because more iterations could be performed) and the mental distance is equal to that of context dependent adjustment. We have done experiments with several animations including navigation in the genealogy of the Hohenzollerns (family of German emperors), navigation in word collocation graphs based on data from www.wortschatz.uni-leipzig.de, computation of a full lattice for a given set of pairs of integers, as well as several random animations of graphs and trees. Obviously, these animations are difficult to show in a paper. Therefore a Java applet with examples is available online at http://www.cs.uni-sb.de/˜diehl/ganimation/.
Graphs, They Are Changing
29
Fig. 1. Different adjustment strategies.
5
Implementation
In our first prototype implementation we implemented a spring embedder with polar and parallel magnetic fields, gravity, and simulated annealing similar to the algorithm used in VCG [16] (except that we do not use local temperatures). The prototype implements all strategies discussed in this paper and provides orthogonality and Euclidean distance as mental distances. Smooth transition between two graphs are animated in the following phases. First all deleted edges shrink and disappear. Then all deleted nodes disappear. Next all remaining nodes and edges are moved to their new positions using linear interpolation. Finally all new nodes appear and all new edges expand. We are currently working on adjustment strategies for hierarchical layout and these will be integrated into our original Foresighted Layout implementation that used hierarchical layout [7].
6
Related Work
So far, we have not found any published work on offline dynamic graph drawing. An overview of online dynamic graph drawing has e.g. been given in [3]. The general framework of Brandes and Wagner [1] characterizes the tradeoff between local quality and dynamic stability using conditional probabilities. In their formulation the conditional probability for a layout depends on those of the pre-
30
Stephan Diehl and Carsten G¨ org
ceding ones, i.e. no look-ahead in the sequence is available, but the formulation could be easily adapted to the offline case. Finally there are several papers that suggest layout adjustment algorithms for certain classes of graphs. All these algorithms have in common that they are based on a certain mental map distance built into the algorithm [13,5,12,14].
7
Conclusion and Future Work
We presented a generic algorithm to compute graph animations. We discussed several strategies for layout adjustment. The effectiveness of the resulting animations needs to be studied and evaluations similar to those of Purchase [15] for aesthetic rules must be performed for dynamic stability. For this we plan to implement additional layout algorithms and metrics. The generic nature of our approach allows us to easily combine different layout algorithms, metrics and adjustment strategies. This comes at the cost of performance. One solution is to manually or automatically specialize the generic algorithm with respect to a given layout algorithm, adjustment strategy and metric before computing the layout. In a specialized algorithm the phases could be interleaved and allow more clever adjustment, e.g. only new coordinates are computed for those nodes which violate orthogonality.
References 1. U. Brandes and D. Wagner. A Bayesian paradigm for dynamic graph layout. In Graph Drawing (Proc. GD ’97), volume 1353 of Lecture Notes Computer Science. Springer-Verlag, 1997. 2. Ulrik Brandes. Drawing on physical analogies. In Drawing Graphs [11]. 2001. 3. J¨ urgen Branke. Dynamic graph drawing. In Drawing Graphs [11]. 2001. 4. S. Bridgeman and R. Tamassia. Difference metrics for interactive orthogonal graph drawing algorithms. In Proceedings of 6th International Symposium on Graph Drawing GD’98. Springer LNCS 1457, 1998. 5. R.F. Cohen, G. Di Battista, R. Tamassia, and I.G. Tollis. Dynamic graph drawings: Trees, series-parallel digraphs, and st-digraphs. SIAM Journal on Computing, 24(5), 1995. 6. S. Diehl, C. G¨ org, and A. Kerren. Foresighted Graphlayout. Technical Report A/02/2000, FR 6.2 - Informatik, University of Saarland, December 2000. http://www.cs.uni-sb.de/tr/FB14. 7. Stephan Diehl, Carsten G¨ org, and Andreas Kerren. Preserving the Mental Map using Foresighted Layout. In Proceedings of Joint Eurographics – IEEE TCVG Symposium on Visualization VisSym’01. Springer Verlag, 2001. 8. P. Eades. A heuristic for graph drawing. Congressus Numerantium, 42, 1984. 9. C. Friedrich and M. E. Houle. Graph Drawing in Motion II. In Proceedings of Graph Drawing 2001. Springer LNCS (to appear), 2001. 10. M. R. Garey and D. S. Johnson. Computers and Intractability. A Guide to the Theory of N P-Completeness. Freeman and Company, 1979. 11. M. Kaufmann and D. Wagner, editors. Drawing Graphs – Methods and Models, volume 2025 of Lecture Notes in Computer Science. Springer-Verlag, 2001.
Graphs, They Are Changing
31
12. K.A. Lyons, H. Meijer, and D. Rappaport. Cluster busting in anchored graph drawing. Journal of Graph Algorithms and Applications, 2(1), 1998. 13. K. Misue, P. Eades, W. Lai, and K. Sugiyama. Layout Adjustment and the Mental Map. Journal of Visual Languages and Computing, 6(2):183–210, 1995. 14. A. Papakostas and I.G. Tollis. Interactive orthogonal graph drawing. IEEE Transactions on Computers, 47(11), 1998. 15. H.C. Purchase, R.F. Cohen, and M. James. Validating graph drawing aesthetics. In F. J. Brandenburg, editor, Graph Drawing (Proc. GD ’95), volume 1027 of Lecture Notes Computer Science. Springer-Verlag, 1996. 16. G. Sander. Visualization Techniques for Compiler Construction. Dissertation (in german), University of Saarland, Saarbr¨ ucken (Germany), 1996.
Drawing Graphs on Two and Three Lines Sabine Cornelsen, Thomas Schank, and Dorothea Wagner University of Konstanz, Department of Computer & Information Science {Sabine.Cornelsen, Thomas.Schank, Dorothea.Wagner}@uni-konstanz.de
Abstract. We give a linear-time algorithm to decide whether a graph has a planar LL-drawing, i.e. a planar drawing on two parallel lines. This has previously been known only for trees. We utilize this result to obtain planar drawings on three lines for a generalization of bipartite graphs, also in linear time.
1
Introduction
Let G = (A ∪ B, E) be a partitioned graph, i.e. a graph with a partition of its vertex set into two disjoint sets A and B. We will refer to the vertices of A as A-vertices and to the vertices of B as B-vertices, respectively. The question of drawing partitioned graphs on parallel lines arises from drawing bipartite graphs, i.e. partitioned graphs such that A and B are independent sets. A natural way to draw such graphs is to draw all vertices of A on one – say horizontal – line, all vertices of B on a parallel line, and all edges as straight-line segments between their end-vertices. Such a drawing will be denoted by BA-drawing. If G is planar, a drawing without edge crossings would be desirable. Harary and Schwenk [6] and Eades et al. [3] showed that a bipartite graph G has a planar BA-drawing if and only of G is a caterpillar, i.e. a tree such that the set of all vertices of degree larger than one induces a path. To obtain planar drawings of a larger class of bipartite graphs, F¨ oßmeier and Kaufmann [5] proposed BAB-drawings. Again, every edge is a straightline segment between its end-vertices and all vertices of A are drawn on one horizontal line, but the vertices of B may be drawn on two parallel lines – one above the A-vertices and one below. F¨oßmeier and Kaufmann [5] gave a lineartime algorithm to test whether a bipartite graph has a planar BAB-drawing. Another generalization of planar BA-drawings of bipartite graphs are planar drawings of leveled graphs which are considered by J¨ unger et al. [7]. Planar drawings for non-bipartite partitioned graphs are considered by Biedl et al. [1,2]. A complete characterization of graphs that have a planar BA-drawing is given in [1]. Felsner et al. [4] considered line-drawings of unpartitioned graphs. They gave a linear time algorithm that decides whether a tree has a planar straight line drawing on a fixed number of lines. We will show how to decide in linear time whether an arbitrary graph has a planar LL-drawing, i.e. a straight line drawing on two parallel lines without
This work was partially supported by the DFG under grant BR 2158/1-1.
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 31–41, 2002. c Springer-Verlag Berlin Heidelberg 2002
32
Sabine Cornelsen, Thomas Schank, and Dorothea Wagner
edge crossings. Our algorithm works even if the end-vertices of some edges are constrained to be on different lines. For planar BAB-drawings, we relax the condition of bipartiteness to partitioned graphs with the only constraint that the neighbor of each vertex of B with degree one is in A. Actually, even this restriction is only necessary in very special cases, which are discussed in Section 2.2. Note that LL-drawings of unpartitioned graphs are the special case of BAB-drawings with A = ∅. This paper is organized as follows. In Section 2, we consider planar BABdrawings. First, we decompose the input graph such that the A-vertices of each component induce a path. We then show that we can substitute each of these components by a graph that contains only B-vertices, but simulates the possible planar BAB-drawings of the component. Finally, in Section 3, we show how to decide whether an unpartitioned graph has a planar drawing on two parallel lines.
2
BAB-Drawings
Let G = (A ∪ B, E) be a partitioned graph such that every B-vertex of degree one is adjacent to an A-vertex. Since we want to test planarity, we can reject every graph with more than 3n − 6 edges. So we can assume that the number of edges is linear in the number n := |A ∪ B| of vertices. For a subset S ⊂ A ∪ B we denote by G(S) the graph that is induced by S. 2.1
Decomposition
If G has a planar BAB-drawing, the connected components of G(A) have to be paths. Therefore, the vertex set of a connected component of G(A) will be called an A-path of G. By P(A), we denote the set of A-paths. P(A) can be determined in linear time. Next, we want to decompose G into components. A subdivision B-path between two vertices b1 and bk is a set {b2 , . . . , bk−1 } ⊂ B such that – {bi , bi+1 } ∈ E for i = 1 . . . k − 1 and – degree bi = 2 for i = 2 . . . k − 1. For an A-path P ∈ P(A), the A-path component GP is the graph induced by the union of the following sets of vertices – set P , – set BP of all B-vertices that are incident to P , – all subdivision B-paths between two vertices of BP that are not subdivision B-paths between two vertices of BP for any P ∈ P(A) \ {P }. Similar to the subdivision paths, we also omit edges that would be contained in several A-path components in any of these components. Figure 1 shows a graph with three A-path components. A vertex of an A-path component GP that is adjacent to a vertex of G − GP is called a connection vertex of GP . Given a BAB-drawing of G, we call the first and last vertex of GP on each of the
Drawing Graphs on Two and Three Lines
33
Fig. 1. Decomposition of a graph into three A-path components. White vertices are Avertices, all other vertices are B-vertices. Rectangularly shaped vertices are connection vertices. Dashed edges are not contained in any of the three A-path components.
three lines a terminal of GP . By the restriction on B-vertices of degree one, the following lemma is immediate. Lemma 1. Let P be an A-path of G. 1. All connection vertices of GP are in BP . 2. In any planar BAB-drawing of G, every connection vertex of GP is a terminal of GP . 3. If G has a planar BAB-drawing, GP has at most four connection vertices. Let P, P ∈ P(A) be distinct and b1 , b2 ∈ BP ∩ BP be two connection vertices of both GP and GP . Then b1 and b2 are drawn on different lines in any planar BAB-drawing. In this case, we add edge {b1 , b2 } to G. We will refer to such an edge as a reminder edge. Lemma 2. 1. The sum of the sizes of all A-path components is in O(n). 2. There is a linear-time algorithm that either computes all A-path components and reminder edges or returns an A-path component that has more than four connection vertices. Proof. 1. By definition, each edge is contained in at most one A-path component. The number of A-path components is at most |A| and each A-path component is connected. Thus the sum of the number of vertices in all Apath components is at most |E| + |A| ∈ O(n). 2. First, each subdivision B-path is substituted by a single edge between its two end-vertices and all sets BP are computed. This can be done in linear time, e.g. by depth first search. Then for each P ∈ P(A), we examine the incident edges e of all b ∈ BP . If both end vertices of e are contained in BP ∪ P , we add e to GP , if not, we classify b as a connection vertex and stop the examination of this vertex b. This guarantees that for each vertex, at most one edge that is not in GP is touched. If the number of connection vertices of GP is greater than 4, we can return GP , else we add a ‘pre-reminder’ edge labeled GP between all six pairs of connection vertices of GP to G. In a final walk through the adjacency list of each connection vertex, we can use the pre-reminder edges to determine the reminder edges and those edges of G between connection vertices that have to be added to an A-path component. Finally, subdivision vertices are reinserted into the replacement edges.
34
2.2
Sabine Cornelsen, Thomas Schank, and Dorothea Wagner
Substitution
In this section, we show how to substitute an A-path component GP by a graph that contains only B-vertices, but simulates all possible planar BAB-drawings of GP in which the connection vertices are terminals. We say that two terminals of GP are on the same side of GP in a BAB-drawing if they are both first or both last vertices on their lines. They are on different sides if one is a first and the other one a last vertex. Essentially, there are six questions of interest: #: How many connection vertices are contained in GP ? η: Does the number of connection-vertices equal the number of B-vertices of GP ? τ : Does GP have a planar BA-drawing? τv : For each connection vertex v of GP , is there a planar BAB-drawing of GP that induces a BA-drawing of GP − v? σvw : For each pair v, w of connection-vertices of GP , is there a planar BABdrawing of GP , such that v and w are on the same side of GP ? δvw : For each pair v, w of connection-vertices of GP , is there a planar BABdrawing of GP , such that v and w are on different sides of GP ? Note that τ implies τv and τv implies σvw and δvw for any pair v, w of connection vertices of GP . Thus, provided that there exists some planar BAB-drawing of GP , these six questions lead to the cases listed in Table 1. Note that the listed substitutes contain different kind of edges. There is one case with a parallel edge and one case with a dotted edge. Let G be the graph constructed from G by substituting each A-path component in the way described above. We say that an edge in an LL-drawing is vertical if the end vertices of e are drawn on different lines. Lemma 3. 1. The size of G is linear in the size of G. 2. G has a planar LL-drawing with every multiple edge and every reminder edge drawn vertically and no dotted edge having a parallel edge if and only if G has a planar BAB-drawing. We discuss only, where the precondition on degree one vertices is needed and omit the rest of the proof. If we have a planar BAB-drawing and we want to construct a planar LL-drawing of G by replacing each A-path component GP by its substitute, we have to make sure, that for any two vertices v and w of GP all vertices that are drawn between v and w do also belong to GP . But there might be also subdivision paths S between vertices of degree one and vertices b ∈ BP . If b is not a connection vertex, we can add S to GP , but if b is a connection vertex, there need not exist a suitable substitute any more. There is no problem, if there are at least three subdivision paths between b and vertices of degree one, since then at least one of them has to be drawn on the other line then b and then any of them can be drawn there, thus neither has to be added to GP . Lemma 4. For each component, the six questions that determine the substitute, can be answered in time linear in the size of the component.
Drawing Graphs on Two and Three Lines
35
Table 1. Substitutes for the A-path components. Cases that correspond up to the names of the connection vertices are omitted. A + means that the corresponding question is answered by yes. A ⊕ means that the answer to this property is implied. No entry means that the according property is not fulfilled.
1 connection vertex η τ τv + ⊕ ⊕ + ⊕ +
4 connection vertices
σvx σvy σvz + + + v
v v
•
w
v @ @ • • v •
~~
+
+
• v
+
•
⊕
⊕
+ ⊕ ⊕
⊕
⊕
+ +
⊕
⊕
+
⊕
⊕
+
+
v
x z
•
v
•
x
y
•
z
w
v
v v
x + +
⊕
⊕
+
⊕
⊕
⊕
⊕
+
+
+
+
v w
w
+
v B • B w •
+
||
⊕
w
• v •
+
x
•
•
•
y
•
τv τw τx σvw σvx σwx + + + ⊕ ⊕ ⊕
w
+
3 connection vertices
2 connection vertices
⊕ ⊕
•
•
y
•
η τ τv τw σvw δvw + + ⊕ ⊕ ⊕ ⊕ +
• ? ?
v
|| • x
v
•
•
w
•
•
v
•
•
w
•
•
v
•
•
•
•
w
+
{{
x
•
}}
w
•
x B v B w • v w
• @ • @ ~~ • • • v
• x
•
x +
w
w
v
•
•
w
•
x
Proof. It is obvious how to decide Properties # and η. To decide properties σvw and δvw , suppose, we have an A-path component GP with an A-path P : a1 , . . . , ak . For technical reasons, we add vertices a0 and ak+1 , one at each end, to P . Let W be the set of vertices of a connected component of GP (B). Suppose first that we wouldn’t allow edges between B-vertices on different lines. In this case G(W ) has to be a path and the vertices in W have to occur in the same order as their adjacent vertices in P . Furthermore, let a (ar ) be the A-vertex
36
Sabine Cornelsen, Thomas Schank, and Dorothea Wagner
with lowest (highest) index that is adjacent to W . Then we say that the edges {ai , ai+1 }, i = , . . . , r − 1 are occupied by G(W ). Finally, if a vertex b in G(W ) is a connection vertex of GP then b has to be a terminal. Thus, if a is an A-vertex with the lowest (highest) index that is adjacent to b, then the edges {ai , ai+1 }, i = 0, . . . , (or i = , . . . , k + 1) are also occupied by G(W ). In general, if GP has a planar BAB-drawing, G(W ) might be a path with at most two chords and the A-vertices adjacent to this path may change at most twice between increasing and decreasing order. Thus, there are three reasons for changing the line in W : a chord, a change in the order of the adjacent A-vertices, or a connection vertex. Note also that such a change of lines might occur in at most two connected components of GP (B). If there is a line change between b1 and b2 in W , then similar to the case of connection vertices above, G(W ) also occupies the edges between the adjacent A-vertices of b1 and b2 and one end of the A-path P . Note that in case of a line change some edges in G(P ) might be occupied twice.
0 (a)
2
1
1
1
2
2
2
0 (b)
0 (c)
2
1
1
1
1
0
0
0
1
0
(d)
Fig. 2. Three reasons for changing a line: a) a chord, b) a change in the order of adjacent A-vertices, and c) a connection vertex. d) A connection vertex occupies a part of the A-path. The numbers indicate how many times an edge or a vertex in the A-path is occupied.
We label every edge and every vertex in G(P ) with the number of times it is occupied as indicated in Fig. 2, where the number of times a vertex v ∈ P is occupied by G(W ) is defined as follows. v is occupied k times by G(W ), if both adjacent edges in the A-path are occupied k-times by W and v is not adjacent to an end vertex of W and k − 1 times if it is adjacent to such an end vertex. It is also occupied k − 1-times if one adjacent edge is occupied k-times and the other one k − 1 times. There exists a planar BAB-drawing with the corresponding choice of the direction of the connection vertices, if and only if 1. in total, every edge in G(P ) is occupied at most twice and 2. each vertex v ∈ P that is adjacent to an end vertex of a connected component of GP (B) is occupied at most once. This test works in linear time, since we can reject the graph, as soon as an edge gets a label higher than 2 and because there are at most four connection vertices and at most two components that change lines for which different orientations have to be checked. A similar approach can be used to answer questions τ and τv .
Drawing Graphs on Two and Three Lines
37
The results in the next section show how to test the conditions of Lemma 3,2, which completes the algorithm for deciding whether a planar BAB-drawing exists.
3
LL-Drawings
Given a graph G = (V, E) and a set of edges U ⊂ E, we show how to decide in linear time whether there exists a planar LL-drawing of G with the property that each edge in U is drawn vertically. A long version of the planar LL-drawability test can be found in [8]. We will first discuss trees and then the general case. 3.1
LL-Drawings of Trees
Felsner et al. [4] characterized trees that have a planar LL-drawing and called them strip-drawable. We give a slightly different characterization. Lemma 5. A tree T has a planar LL-drawing, if and only if it contains a spine, i.e. a path S such that T − S is a collection of paths. Proof. ⇒ The unique path between a leftmost and a rightmost vertex of T in a planar LL-drawing is a spine of T . ⇐ An LL-drawing can be achieved by placing the spine on one of the lines and the path components in the order of their adjacency to the spine on the other line.
As indicated in [4], the inclusion minimal spine Smin can be computed in linear time. If a vertex v is required to be an end vertex of a spine, we only have to check if there is a path between v and an end vertex of Smin in T − Smin . We will use this fact when we examine the general case. Finally, the following lemma characterizes whether the edges in a set U ⊂ E can be drawn vertically. Lemma 6. An edge e can be drawn vertically if and only if there exists a spine S that contains at least one end vertex of e. 3.2
LL-Drawings of General Graphs
For general graphs, the existence of a spine is still necessary for the existence of a planar LL-drawing, but it is not necessarily sufficient. For example, see the
Fig. 3. LL-drawings of a tree. The spine is drawn black.
38
Sabine Cornelsen, Thomas Schank, and Dorothea Wagner
graph on the right. To test whether a general graph has a planar LL-drawing, we first split the graph into components like paths, trees and two connected components. We give necessary conditions for these components and show how to test them in linear time. Finally, by constructing a drawing, we show that these necessary conditions are also sufficient. First we make the following observation. Lemma 7. Every graph that has a planar LL-drawing is outer planar. Proof. Since all vertices are placed on two horizontal lines, every vertex is either a top most or bottom most vertex and is thus incident to the outer face.
Suppose now without loss of generality that G is a connected graph. A vertex v is called a connection vertex, if it is contained in a cycle and its removal disconnects G. We denote the set of all connection vertices by Vc . The connection vertices can be determined with depth first search in linear time.
Fig. 4. A graph with a planar LL-drawing. Connection vertices are solid.
A subgraph L of G is called a single line component, if it is maximal with the property that L is an induced graph and there exists a vertex v ∈ Vc such that ¯ we denote a single line component L is a connected component of G − v. By L, ¯ forms a path we call it a strict L including its incident connection vertex. If L single line component, otherwise we call it a fan.
Fig. 5. Fans and a strict single line component, connection vertices are solid.
Simply testing for all v ∈ Vc , whether the connected components of G(V \ {v}) are paths leads to a quadratic time algorithm for finding the single line components. But we can use outer-planarity to do it in linear time. Note that any single line component contains at most two connection vertices (see Fig. 5 for illustration). Thus, we can find them, by storing the three last visited connection vertices on a walk around the outer face and testing, whether the vertices between the first and second occurrence of the same connection vertex induce a path.
Drawing Graphs on Two and Three Lines
39
Let G be the subgraph that results from G by deleting all single line components. The two-lined components of G are the components that we get by splitting G at the connection vertices of G. Two-lined components that do not contain a cycle will be called tree components. All other two-lined components will be denoted by two-lined biconnected components. Figure 6 illustrates the different components of the graph in Fig. 4.
Fig. 6. Components of the graph in Fig. 4. There are two trees, two two-lined biconnected components, two fans, and three strictly single lined components.
We have now defined all components that we need to characterize those graphs that have a planar LL-drawing. Note that a graph that contains no twolined biconnected components has a planar LL-drawing if and only if it contains a spine. Before we formulate the characterization for the general case, consider the set L of all two-lined components. Let P be the graph with vertex set L in which two two-lined components are adjacent if and only if they share a connection vertex. Suppose a planar LL-drawing for G is given. Then all twolined biconnected components require at least two lines. All tree components also require at least two lines or are connected to two components that require two lines. Thus P has to be a path. We will refer to this property by saying that the two-lined components induce a path. Theorem 1. A graph G has a planar LL-drawing if and only if 1. G is outer planar, 2. the two-lined components induce a path, 3. each tree component T has a spine S such that the connection vertices of T are end vertices of S, and 4. for each two-lined biconnected component B there is a drawing with the following properties. (a) Connection vertices are leftmost or rightmost vertices of B on their line. (b) At most one two-sided component is connected to each vertex of B. (c) If a two-sided component or a fan is connected to a vertex of B, then a vertex on the same side is at most connected to a path. The necessity of these conditions follows from Section 3.1, Lemma 7, and the observations mentioned above. To show that these conditions are also sufficient, we sketch how to find a drawing of G in linear time.
40
Sabine Cornelsen, Thomas Schank, and Dorothea Wagner
Drawing and Sufficient Conditions. In this subsection we sketch how to construct in linear time a planar LL-drawing if the conditions in Theorem 1 are fulfilled. We also mention which edges can be drawn vertically. Since a linear order on the two-lined components is given, we only have to show how to draw each component separately. It was already shown in Section 3.1 how to find a spine and that a tree with a spine has a planar LL-drawing. For drawing two-lined biconnected components, first note that a biconnected graph has a unique outer planar embedding. Starting with a connection vertex on any line, we add the others in the order of their appearance around the outer face and switch lines only if necessary, i.e. at a connection vertex or a chord. We do this procedure for each direction around the outer face. Those cases in which lines are switched at most twice, are the possible outer planar drawings of a two-lined biconnected component, with respect to Theorem 1,4. Hence, if a drawing exists, it can be found in linear time. Vertical edges in two-lined biconnected components only yield another condie1 tion for switching lines. Let L be a fan on a single line component L and a connection vertex v. If L is connected to two two-lined components, only edges e2 between v and L can be vertical edges. Else, also edges indicated by dotted lines in the Figure on the right hand side can be drawn upright, but only one of the edges e1 and e2 simultaneously.
4
Conclusion
We showed how to decide in linear time, whether an arbitrary graph has a planar drawing on two parallel lines, even if the input contains edges that have to be drawn vertically. We applied this result to decide in linear time whether a partitioned graph G = (A∪B, E) with the property that every B-vertex of degree one is adjacent to an A-vertex has a planar BAB-drawing. The algorithm worked in three steps. First, the graph was decomposed into A-path components. Then, each of these components was substituted by a graph that contained only Bvertices, but simulates the possible positions of the connection vertices. Finally, we test whether the resulting graph has a planar LL-drawing. We discussed that the restriction on the vertices of degree one is only needed in the following sense: If b is a connection vertex of an A-path component, the number of subdivision B-paths between b and vertices of degree one may not be one or two. For further research, it would be interesting to examine whether our approach could be extended to BAAB-drawings, that is drawings for which there are two parallel middle lines for the A-vertices.
References 1. T. C. Biedl. Drawing planar partitions I: LL-drawings and LH-drawings. In Proceedings of the 14th Annual ACM Symposium on Computational Geometry (SCG ’98), pages 287–296, 1998.
Drawing Graphs on Two and Three Lines
41
2. T. C. Biedl, M. Kaufmann, and P. Mutzel. Drawing planar partitions II: HHdrawings. In J. Hromkovic, editor, Graph Theoretic Cocepts in Computer Science, 24th International Workshop, (WG ’98), volume 1517 of Lecture Notes in Computer Science, pages 124–136. Springer, 1998. 3. P. Eades, B. D. McKay, and N. C. Wormald. On an edge crossing problem. In Proceedings of the 9th Australian Computer Science Conference (ACSC 9), pages 327–334, 1986. 4. S. Felsner, G. Liotta, and S. K. Wismath. Straight-line drawings on restricted integer grids in two and three dimensions. In M. J¨ unger and P. Mutzel, editors, Proceedings of the 9th International Symposium on Graph Drawing (GD 2001), volume 2265 of Lecture Notes in Computer Science, pages 328–342. Springer, 2002. 5. U. F¨ oßmeier and M. Kaufmann. Nice drawings for planar bipartite graphs. In G. Bongiovanni, D. P. Bovet, and G. Di Battista, editors, Proceedings of the 3rd Italian Conference on Algorithms and Complexity (CIAC ’97), volume 1203 of Lecture Notes in Computer Science, pages 122–134. Springer, 1997. 6. F. Harary and A. Schwenk. A new crossing number for bipartite graphs. Utilitas Mathematica, 1:203–209, 1972. 7. M. J¨ unger, S. Leipert, and P. Mutzel. Level planarity testing in linear time. In S. H. Whitesides, editor, Proceedings of the 6th International Symposium on Graph Drawing (GD ’98), volume 1547 of Lecture Notes in Computer Science, pages 224– 237. Springer, 1998. 8. T. Schank. Algorithmen zur Visualisierung planarer partitionierter Graphen. Master’s thesis, Universit¨ at Konstanz, 2001. http://www.inf.uni-konstanz.de/algo/lehre/theses/.
A Group-Theoretic Method for Drawing Graphs Symmetrically David Abelson1 , Seok-Hee Hong2 , and Donald E. Taylor1 1
School of Mathematics and Statistics, University of Sydney, Australia, [email protected], [email protected] 2 School of Information Technologies, University of Sydney, Australia, [email protected]
Abstract. Constructing symmetric drawings of graphs is NP-hard. In this paper, we present a new method for drawing graphs symmetrically based on group theory. More formally, we define a n-geometric automorphism group of a graph that can be displayed as symmetries of a drawing of the graph in n dimensions. Then we present an algorithm to find all 2- and 3-geometric automorphism groups of a graph. We implement the algorithm using Magma [11] and the experimental results shows that our approach is very efficient in practice. We also present a drawing algorithm to display a 2- or 3-geometric automorphism group.
1
Introduction
Symmetry is one of the most important aesthetic criteria that represent the structure and properties of a graph visually. To construct a symmetric drawing of a graph, we need two steps. The first step, called the symmetry finding step, is to find geometric automorphisms of the graph, which can be displayed as symmetries of a drawing of the graph. The second step, called the drawing step, is to construct a drawing that displays these automorphisms. However, the problem of determining whether a graph has a nontrivial strict geometric automorphism in two dimensions is NP-complete [8]; it is probably strictly harder than graph isomorphism. For planar graphs, there is a polynomial time algorithm [5]. The problem of determining whether a graph can be drawn symmetrically in three dimensions is also NP-complete [6] and a polynomial time algorithm is given for planar graphs [6]. In this paper, we present a group-theoretic method to find all 2- and 3geometric automorphism groups of a graph. First we define an n-geometric automorphism group of a graph that can be displayed as symmetries of a drawing of the graph in n dimensions. Next we present an algorithm to find all 2- and 3-geometric automorphism groups of a graph, based on the classification of the 2- and 3-geometric automorphism groups in [1]. This is done by first calculating the automorphism group
This research has been supported by a grant from the Australian Research Council. Full version of this paper is available from http://www.cs.usyd.edu.au/∼shhong/publication.htm [1].
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 86–97, 2002. c Springer-Verlag Berlin Heidelberg 2002
A Group-Theoretic Method for Drawing Graphs Symmetrically
87
Aut(G) of a graph G and then looking for subgroups satisfying the classification. More specifically, we use conjugacy classes of the automorphism group to find the subgroups. The main contribution of this paper is that we provide an algorithm for finding all 2- and 3-geometric automorphism groups of a graph. A heuristic for finding an axial symmetry in two dimensions is presented by de Fraysseix [4]. Buchheim and Junger present a branch and cut approach to find either a rotational symmetry or an axial symmetry in two dimensions [2]. However, our method is the first to find dihedral groups, which have two generators, in two dimensions and fourteen different kinds of groups, with up to three generators, in three dimensions. We implement the algorithm using Magma [11], a computational algebra system for algebra, number theory, geometry and combinatorics, which incorporates nauty [12] for finding automorphism groups of graphs. The worst case time complexity is exponential in theory, but experiments show in practice it is very fast. For example, for our first data set, which consists of graphs with |V | < 50 and | Aut(G)| < 1000, it takes 0.022 seconds to compute all 2-geometric groups and 0.037 seconds to compute all 3-geometric groups on average. For our second data set, which consists of graphs with |V | < 50 and 1, 000 < | Aut(G)| < 51, 000, 000, it takes 0.41 seconds to compute all 2-geometric groups and 2.58 seconds to compute all 3-geometric groups on average. Further, we show that our method is much faster than the branch and cut approach [2]. The average times for the graphs from the same data set of [2] are below 0.015 seconds. The worst case time is 2.60 seconds, whereas the worst case time of [2] was 9197.55 seconds. Finally we present and implement a drawing algorithm to display a 2- or 3-geometric subgroup. Examples of the outputs are illustrated in Figure 1. It shows a drawing of four-cell displaying dihedral symmetry in two dimensions and a drawing of four-cube displaying octahedral symmetry in three dimensions.
Fig. 1.
Examples of our results.
88
David Abelson, Seok-Hee Hong, and Donald E. Taylor
In the next section, we review the background and define n-geometric automorphism group. In Section 3, we describe our methods for finding 2- and 3-geometric automorphism groups. The drawing algorithm is described in Section 4 and Section 5 concludes.
2 2.1
Background Symmetry
Let In (R) be the group of isometries of Rn and let On (R) be the subgroup of In (R) that fixes the origin. A matrix A is orthogonal if and only if A.AT = I. The elements of On (R) are represented by orthogonal matrices and we use SOn (R) to denote the subgroup corresponding to the matrices of determinant 1. A symmetry α of a set of points Q in Rn is an isometry Rn → Rn such that α(Q) = Q. The symmetries of the point set Q form a group S(Q) and by translating Q if necessary we may suppose that S(Q) is a subgroup of On (R). 2.2
Symmetric Graph Drawing and Geometric Automorphism Group
An automorphism of a graph G = (V, E) is a permutation p of V such that if {u, v} ∈ E then {p(u), p(v)} ∈ E. The set of automorphisms of a graph form a group Aut(G). A straight-line drawing D of graph G is an injective function D : V → Rn (n ≥ 0). A vertex v is placed at D(v) and an edge {u, v} is represented as the straight-line segment joining D(u) and D(v). The concept of geometric automorphism group in two dimensions was introduced by Eades and Lin [3]. An automorphism α of a graph G is geometric if there is a drawing D of G which displays α as a symmetry of D. Note that not every automorphism is geometric; see Figure 2(a). A subgroup H of Aut(G) is geometric if there is a single drawing of the graph that displays every element of H. Note that the two geometric automorphism groups may not be combinable; see Figure 2(b) and (c). 1
2
11 00 00 11
3
11 00 00 11
11 00 00 11
1 0 0 1
1 0 0 1
1 0 1 0
1 0 1 0
11 00 00 11 00 11
11 00 00 11
11 00 00 11 00 11
1 0 1 0
5
4 (a)
(b)
11 00 11 00
1 0 1 0
(c)
Fig. 2. (a) The automorphism (1,2,3)(4,5) is not geometric. (b) A drawing of K4 displaying a geometric automorphism group of size 8. (c) A drawing of K4 displaying a geometric automorphism group of size 6.
A Group-Theoretic Method for Drawing Graphs Symmetrically
2.3
89
The n-Geometric Automorphism Group
We generalize the notion of a geometric automorphism group [3] to n dimensions. A group H ⊆ Aut(G) is n-geometric if there is a drawing D that displays all the elements of H in n dimensions. Note that because we always assume that D is centered on the origin, H will be represented as a subgroup of On (R). Lemma 1. A group H ⊆ Aut(G) is n-geometric with respect to a drawing D if and only if there exists a homomorphism φ : H → On (R) such that for all v ∈ V and h ∈ H, D(hv) = φ(h)D(v). A homomorphism φ : H → On (R) is called a representation of H. In matrix terms, each element of H is represented by an orthogonal matrix. The representation is faithful if φ is injective. We use basic terminology from group theory [10]. Let H be a group acting on a set U . For u ∈ U , let Hu = {x ∈ U | x = gu for some g ∈ H} ⊆ U be the orbit of u and Hu = {g ∈ H | g(u) = u} ⊆ H be the stabilizer of u. The orbits divide the set U into equivalence classes, each of which can be specified by a representative element. Two elements a and b of a group H are conjugate if there exists h ∈ H such that b = hah−1 . Conjugacy is an equivalence relation and the equivalence classes of H are called conjugacy classes. We now characterize n-geometric groups. Theorem 1. A group H ⊆ Aut(G) is n-geometric if and only if there is an injective homomorphism θ : H → On (R) such that for a representative v1 , . . . , vk ∈ V of each orbit of H acting on V , there are corresponding distinct points a1 , . . ., ak ∈ Rn such that θ(Hvi ) = θ(H)ai .
3
Finding Geometric Automorphism Groups
We now outline our method of finding all 2- and 3-geometric automorphism groups based on the classification in [1]. It follows from Theorem 1 that a permutation group A acting on a graph is n-geometric if it is isomorphic (as an abstract group) to a finite subgroup H of On (R) and 1. if A fixes more than one vertex, then H fixes a point other than the origin; 2. for every vertex v, the stabilizer Av is isomorphic to the stabilizer in H of a point of Rn . When the value of n is clear from the context we shall simply refer to A as a geometric group. The group H will be referred to as the type of A. Our search for the geometric subgroups of Aut(G) is facilitated by the fortunate fact that all of the finite subgroups of O2 (R) and O3 (R) have very simple presentations. That is, they can be expressed in the form H = X | R , where X is a list of generators for H and R is a list of relations between the generators. Furthermore, there are at most three generators and in many cases the relations simply specify the orders of the generators and the orders of their products.
90
3.1
David Abelson, Seok-Hee Hong, and Donald E. Taylor
The Finding Algorithm
To find the geometric subgroups of the automorphism group Aut(G) of a graph G = (V, E) we look for elements that satisfy the relations of its presentation. We are only interested in finding these subgroups up to conjugacy because, as the next lemma shows, conjugate n-geometric subgroups have essentially the same drawings. Let Sym(V ) be the group of all permutations of V . Lemma 2. Let H be an n-geometric subgroup of Aut(G) with respect to a drawing D and suppose that H = g −1 Hg ⊆ Aut(G), where g ∈ Sym(V ). Then H is n-geometric with respect to the drawing D defined by D (v) = D(gv). Computing the conjugacy classes of a group is a hard problem but highly optimized algorithms for this purpose are part of Magma. Moreover, in searching for geometric automorphisms it is often possible to restrict to a proper subgroup of Aut(G). To take a simple example, if g is a 2-geometric automorphism of order m > 2, then g has at most one fixed point and all the other cycles have length m. Therefore, if we were looking for a 2-geometric automorphism of order 3, say, and if the group had an orbit of length 16, then we could confine our search to the stabilizer of a point in the orbit. These and similar considerations speed up the search considerably but for clarity we leave them out of our descriptions of the algorithms. 2-Geometric Subgroups. In two dimensions the only geometric groups are the cyclic groups Cn of order n and the dihedral groups Dn of order 2n. In all cases, the first step in finding these is to compute the automorphism group Aut(G), in short A, of the graph G. Algorithm for the 2-geometric cyclic groups 1. Use the orbit lengths of Aut(G) to compute an upper bound for the order of a 2-geometric element. 2. Find representatives for the conjugacy classes of Aut(G). 3. Accept all elements of order 2 found in the previous step and all elements of order m > 2 with at most one fixed point and all other cycles of length m. Every pair of elements of order 2 generates a dihedral group. We makes use of the elements found in the previous algorithm, as follows (The normalizer NA (H) of a subgroup H is defined to be set of elements a ∈ A such that a−1 Ha = H). Algorithm for the 2-geometric dihedral groups 1. Find representatives for the conjugacy classes of geometric elements using the previous algorithm. In this case we also require that any elements of order 2 fix at most one point. 2. For each element g found in the previous step, compute the normalizer N of g in Aut(G). 3. Find representatives for the conjugacy classes of elements of order 2 in N . 4. Accept those elements a found in the previous step that satisfy the relation (ga)2 = 1. The group g, a is a 2-geometric dihedral group. 5. Carry out some additional checking to choose a single representative for dihedral groups that are conjugate within N .
A Group-Theoretic Method for Drawing Graphs Symmetrically
91
3-Geometric Subgroups. There are five types of geometric groups that can be represented by rotations in R3 : cyclic groups Cn , dihedral groups Dn , the tetrahedral group T , the octahedral group O, and the icosahedral group I. Furthermore, Dn has presentation x, y | x2 = y 2 = (xy)n = 1 and the groups T , O and I have presentations x, y | x2 = y 3 = (xy)k = 1 , where k is 3, 4 or 5, respectively. Since D1 = C2 , we shall only use the type Dn when n is at least 2. From each rotation group B we get a larger group B ∗ by taking the direct product of B with the central inversion −I. If we have a geometric subgroup H of type B we find candidates for the groups of type B ∗ by looking inside the centralizer CA (H) = { a ∈ A | ah = ha for all h ∈ H } for elements of order 2 with at most one fixed point; such an element will be represented by the central inversion. This step is straightforward (but potentially expensive) and so we omit it from the descriptions that follow. In addition to the groups just described, there are four other types that do not consist entirely of rotations. They can be described by symbols (H | K). This means that the group itself is isomorphic to a group of type H and contains a subgroup (of rotations) of index 2 of type K. The possible types are (C2n | Cn ), (Dn | Cn ), (D2n | Dn ) and (O | T ). We note that it is possible for a permutation group A to be represented as a 3-geometric group in more than one way. For example, a cyclic group of order 4m that fixes at most one point and with all other orbits of length 4m has types C4m and (C4m | C2m ). Algorithm for the 3-geometric groups of types Cn and (C2n | Cn ) 1. Find representatives for the conjugacy classes of A and accept those elements g of order n all of whose cycles have length 1 or n. The group g is 3geometric of type Cn . But if we include the requirement that no vertex in a drawing lies on an edge joining two other vertices, then additional work needs to be done. 2. If n is even, find all elements h ∈ CA (g) with at most one fixed point and whose square is g. The lengths of the cycles of h will be 1, 2 and 2n. The subgroup h is 3-geometric of type (C2n | Cn ).
1. 2. 3. 4. 5. 6.
Algorithm for the 3-geometric groups of types Dn , (Dn | Cn ) and (D2n | Dn ) Find representatives for the conjugacy classes of geometric elements using the previous algorithm. For each element g found in the previous step, compute the normalizer N of g in Aut(G). Find representatives for the conjugacy classes of elements of order 2 in N . Accept those elements a found in the previous step that satisfy the relation (ga)2 = 1. The group H = g, a is a dihedral group. If H fixes more than one point we require all the orbits of H to have lengths 1, n or 2n. Then H is a group of type (Dn | Cn ). If H fixes at most one point and n = 2m, then it is of type (D2m | Dm ).
92
David Abelson, Seok-Hee Hong, and Donald E. Taylor
7. If H fixes at most one point and if the cycles of g have lengths 1 or n, then H is of type Dn and also of type (Dn | Cn ). 8. Carry out some additional checking to choose a single representative for dihedral groups that are conjugate within N . We give the details for type I. The other cases are similar except that a group with presentation x, y | x2 = y 3 = (xy)4 = 1 may correspond to a geometric group of type O or to one of type (O | T ) depending on the nature of its point stabilizers. Algorithm for 3-geometric groups of types T , O, I and (O | T ) 1. Find representative for the conjugacy classes of elements of order 5. These elements are necessarily 3-geometric. 2. For each element g found in the previous step, find representatives for the conjugacy classes of the elements of order 3 in A under the action of the centralizer CA (g); that is, we consider two elements h1 and h2 of order 3 to be equivalent if for some a ∈ CA (g) we have a−1 h1 a = h2 . 3. For elements g of order 5 and h of order 3 found in the previous steps check whether gh has order 2. If so, the group g, h is isomorphic to I. 4. For each group H = g, h found in the previous step, check that it fixes at most one point and check that it is geometric by determining whether the stabilizer of a representative for each of its orbits is of an allowed type. In the case of I the allowed subgroups are those of orders 1, 2, 3 and 5. This excludes the subgroups of orders 4 and 6, 10 and 12. 5. Carry out some additional checking to choose a single representative for groups that are conjugate within Aut(G). 3.2
Experimental Results
We implement the algorithm using Magma Version 2.8 [11], and conduct two types of experiments. The aim of the experiments is to test the runtime of the symmetry finding algorithm described above. The runtime, in general, depends more on the size of Aut(G) than the size of G, and thus we use test data with large automorphism groups. The first experiment is to find all the 2- and 3-geometric groups for a given graph and then find a geometric automorphism group of maximum size. We use three test data sets. The first two test sets are graphs generated from permutation groups. For a permutation group H acting on a set V we obtain a graph G = (V, E) by taking the edge set E to be an orbit of H on unordered pairs of vertices. That is, choose distinct elements u and v of V and set E = { {h(u), h(v)} | h ∈ H }. The graph created from H has an automorphism group that contains H. For each group, we choose at most one graph. We only choose graphs that are connected since disconnected graphs can be handled using similar methods in [7]. The groups were taken from a Magma database of primitive permutation groups of degree (that is, |V |) less than 50. The first test set has 67 graphs with | Aut(G)| < 1, 000 and a second test set has 34 graphs with 1, 000 < | Aut(G)| <
A Group-Theoretic Method for Drawing Graphs Symmetrically
93
51, 000, 000. A third test data was a set of graphs with highly symmetric graphs such as regular graphs, the cage graphs, non-Hamiltonian graphs, the platonic solids and incidence planes from Groups & Graphs [9]. The first experiment was done on DEC Alpha 600 5/333. Tables 1 and 2 display the experimental results from the first experiment with three data sets. First we present the time for Computing Aut(G) and the size of Aut(G). Each row shows the time for finding each of 2- and 3-geometric groups. For each case, we present the average and worst case of time, the average and maximum size of the maximal subgroup. Table 1. Results for 100 graphs |Aut(G)| < 1, 000 Time Aut(G) Ck2 Dk2 Av for 2D Ck3 (C2k |Ck3 ) ∗ Ck3 3 Dk (Dk |Ck3 ) (D2k |Dk3 ) ∗ Dk3 T T∗ (O|T ) O O∗ I I∗ Av for 3D
Av 0.00152 0.017 0.0057 0.022 0.017 0.005 0.002 0.002 0.002 0.002 0.005 0.0002 0.0003 2e-5 2e-5 5e-5 0 0 0.037
Size
Max 0.017 0.1 0.034
Av 238 23.1 46.1
0.1 0.017 0.0125 0.016 0.0202 0.025 0.033 0.016 0.017 0.0005 0.0005 0.001 0 0
23.1 5.3 6 46.1 46.1 46.1 8 12 0 24 0 0 0 0
|Aut(G)| > 1, 000 Time
Size
Max Av Max Av Max 820 0.0042 0.017 1812375 50803200 47 0.11 0.634 8.9 24 94 0.29 3.8 16.1 24 0.41 47 0.11 0.63 8.9 24 20 0.0058 0.033 7.3 24 6 0.34 5.0 8.5 12 94 0.35 5.0 16.1 24 94 0.373 5.26 16.1 24 94 0.362 5.1 16.1 24 8 0.678 8.7 15.7 28 12 0.23 2.9 12 12 0 0.0039 0.067 24 24 24 0.033 0.558 24 24 0 0.033 0.558 24 24 0 0.0029 0.05 48 48 0 0.048 0.617 60 60 0 0 0 120 120 2.58
Experimental results shows that our method is very efficient. In practice, it computes all 2- and 3-geometric automorphism groups very quickly. For example, for the first data set (|V | ≤ 50 with | Aut(G)| < 1, 000), it takes 0.022 seconds to compute all 2-geometric groups and 0.037 seconds to compute all 3-geometric groups on average. When | Aut(G)| becomes larger, then it takes longer. For example, for the second data set (|V | ≤ 50 with 1, 000 < | Aut(G)| < 51, 000, 000), it takes 0.41 seconds to compute all 2-geometric groups and 2.58 seconds to compute all 3-geometric groups on average. In fact, the computation of Aut(G) is very fast using nauty [12] inside of Magma. Most of the runtime is for looking
94
David Abelson, Seok-Hee Hong, and Donald E. Taylor Table 2. Results for highly symmetric graphs
Time Frequency Max Size Found # Non-Conjugate Groups Max Total Av Av Av 51403.0909 Aut(G) 0.3125 6.069 33 30 8.6333 3.9666 Ck2 1.2103 24.05 Dk2 0.1125 2.859 28 17.3571 9.7857 1.2187 24.14 33 8.3030 7.4545 Ck3 (C2k |Ck3 ) 0.0051 0.111 26 7 4.8461 ∗ Ck3 0.1911 2.5675 20 8.4 2.8 17.2413 13.7241 0.2558 4.6785 29 Dk3 (Dk |Ck3 ) 0.3235 5.8675 31 16.3870 29.2580 (D2k |Dk3 ) 0.2489 3.8965 30 18.1333 6.3333 ∗ Dk3 0.3276 6.56 10 17.6 6.2 T 0.1721 4.039 14 12 1 24 1.1111 T∗ 0.0032 0.021 9 (O|T ) 0.0006 0.0055 9 24 1.3333 O 0.0006 0.0055 6 24 1.5 O∗ 0.0026 0.051 5 48 1.2 I 0.0051 0.15 4 60 1 4 120 1 I∗ 0.0015 0.03 Av Total for 3D 2.7568
for the subgroups within Aut(G). This is the reason that the runtime depends more on the size of Aut(G) than the size of G in general. The second experiment is to find a rotational symmetry of maximum order or a reflectional symmetry with the minimum number of fixed points. The aim of this experiment is to compare our method with a branch and cut method [2]. We use three test sets of [2] including the rome test suite with 11529 graphs [13]. The first set aut has 3000 graphs with |V | < 30, designed to have many automorphisms, but few of them are geometric. These are the so-called hard instances of [2]. The second set sym has 8000 graphs with |V | < 80, generated specifically to have rotational symmetries. The second experiment was done on a standard laptop, DELL Latitude C600 (750MHz, 256 MB RAM). Tables 3 and 4 display the experimental results from the second experiment with three test sets. The result shows that in general our method is much faster than the branch and cut method [2]. For example, Table 3(b) displays the result for aut. It takes 0.015 seconds to find best symmetry on average and 2.60 seconds in worst case. Note that it takes 21.6 seconds on average and 9197.55 seconds in worst case using the method of [2] (see Table 3 in [2]). Table 3(a) displays the result for sym. It takes 0.016 seconds to find best symmetry on average and 0.30 seconds in worst case. Table 4 displays the result for rome data. It takes 0.009 seconds to find best symmetry on average and 0.12 seconds in worst case. Note that it takes 4.26 seconds on average and 19.29 seconds in worst case using the method of [2].
A Group-Theoretic Method for Drawing Graphs Symmetrically
95
Table 3. Results for (a) 8000 graphs in sym and (b) 3000 graphs in aut (a) runtimes for sym, 1 ≤ n ≤ 80 (b) runtimes for aut, hard instances
Time (sec) n
Av Max
Time (sec)
1–10 0.0013 0.05
n
Av Max
11–20 0.0038 0.21
1–5
0.0008 0.01
21–30 0.0124 0.30
6–10 0.0027 0.05
31–40 0.0140 0.24
11–15 0.0056 0.22
41–50 0.0177 0.22
16–20 0.0115 0.70
51–60 0.0219 0.25
21–25 0.0362 1.58
61–70 0.0285 0.16
26–30 0.0356 2.60
71–80 0.0351 0.27 Table 4. Results for all 11529 graphs in rome Time Av Aut(G)
Max
4.1
Graph
Av
Max
Graph
0.00102125 0.011 grafo10316.100.lgr 5.0617 1920 grafo8507.75.lgr
BestCycle 0.00909117 0.12
4
Size
grafo5890.48.lgr 1.6825
3
grafo206.12.lgr
Displaying a Geometric Automorphism Group Choosing a Representation
It is possible to construct different drawings which display a given geometric automorphism group H, depending on the choice of the representation. Let H ⊆ Aut(G) be a 2- or 3-geometric group. We now describe how the choice of representation effects the drawing. We may consider only representations of H with a fixed image T ⊆ O2 (R) or O3 (R). Consider two different faithful representations φ, θ : H → T . Then φθ−1 is an automorphism of H. Hence choosing a different representation is equivalent to composing a fixed representation with an automorphism of H. Let G be a cycle of length 5 with a cyclic subgroup H = (12345)) = p . Figure 3 shows four different drawings that display H. Each uses a representation that takes a generator of H (p, p2 , p3 or p4 respectively) to a rotation by 2π/5. Note that Figure 3 1a) and 1d), 1b) and 1c) are the same up to relabeling. This is because p and p4 , and p2 and p3 are conjugate in Aut(G) by (25)(34). Furthermore p and p2 are conjugate by (2345) ∈ S5 \ Aut(G) thus the drawings that display them use the same points for vertices with different edges.
96
David Abelson, Seok-Hee Hong, and Donald E. Taylor 1
1
2
1 3
5 4
3
4 1a)
Fig. 3.
4.2
1 4 5
3
2
5 1b)
5
2 1c)
2
4
3 1d)
Using different representations to display the same group
Symmetric Drawing Algorithm
A simple drawing method for two dimensions is given by [3] where the main idea is to draw each orbit in a circle. We extend this method to three dimensions.
1. 2. 3. 4. 5. 6.
Algorithm to display a 3-geometric group Let v1 , v2 , . . . , vr be representatives for the orbits of H acting on the vertex set V of the graph. For each i: Find the stabilizer Hvi of vi . If Hvi = H, define D(vi ) to be the origin. If the dimension of φ(Hvi ) is one, define D(vi ) to be a vector of length i fixed by φ(Hvi ); that is, an eigenvector of length i for the eigenvalue 1. If the dimension of φ(Hvi ) is two, let r be the reflection generating φ(Hvi ). Choose D(vi ) to be a vector of length i fixed by r and not fixed by any other element in a subgroup of φ(H) containing r. If Hvi is the trivial group, define D(v) to be any vector of length i not in the fixed point space of any non-trivial element of φ(H). (These spaces of fixed points are known in advance and only need to be computed once.) For v in the orbit of vi , choose h ∈ H such that v = hvi and define D(v) to be φ(h)D(vi ).
Note that the points D(v) are not uniquely determined. At step 3, the orbit can be placed at a different radius and at steps 4 and 5 there is considerable choice for the selected point. The drawing algorithm has been implemented using magma, java and jjgraph. For smaple outputs, see Figure 4.
Fig. 4. Four-cube displaying (a) cyclic and (b) dihedral symmetry. (c) six-cube displaying cyclic symmetry (d) the dodecahedron displaying dihedral symmetry.
A Group-Theoretic Method for Drawing Graphs Symmetrically
5
97
Conclusion
In this paper, we present a group-theoretic method to find all 2- and 3-geometric automorphism groups of a graph. We implement the method using Magma and the experimental results show that our approach is very efficient in practice. We also present a simple drawing algorithm to display 2- or 3-geometric automorphism groups. To construct a maximally symmetric drawing of a graph, we need to choose a geometric automorphism group of a maximum size. In fact it is possible to construct different symmetric drawings of a graph, depending on the choice of the 2- or 3-geometric groups, the representation of a given geometric automorphism group, and ordering of the orbits with given representation.
References 1. D. Abelson, S. Hong and D. E. Taylor, A Group-Theoretic Method for Drawing Graphs Symmetrically, Technical Report IT-IVG-2002-01, School of Information Technologies, The University of Sydney, 2002. 2. C. Buchheim and M. J¨ unger, Detecting Symmetries by Branch and Cut, Graph Drawing 2001, Lecture Notes in Computer Science LNCS 2265, pp. 178-188, Springer Verlag, 2002. 3. P. Eades and X. Lin, Spring Algorithms and Symmetries, Theoretical Computer Science, 240, pp. 379-405, 2000. 4. H. Fraysseix, An Heuristic for Graph Symmetry Detection, Graph Drawing’99, Lecture Notes in Computer Science 1731, pp. 276-285, Springer Verlag, 1999. 5. S. Hong, P. Eades and S. Lee, An Algorithm for Finding Geometric Automorphisms in Planar Graphs, Algorithms and Computation, Lecture Notes in Computer Science 1533, pp. 277-286, Springer Verlag, 1998. 6. S. Hong, Drawing Graphs Symmetrically in Three Dimensions, Graph Drawing 2001, Lecture Notes in Computer Science LNCS 2265, pp. 189-204, Springer Verlag, 2002. 7. S. Hong and P. Eades, Drawing Planar Graphs Symmetrically IV: Disconnected Graphs, Technical Report CS-IVG-2001-03, Basser Department of Computer Science, The University of Sydney, 2001. 8. J. Manning, Geometric Symmetry in Graphs, Ph.D. Thesis, Purdue Univ., 1990. 9. Groups & Graphs, http://130.179.24.217/G&G/G&G.html. 10. W. Ledermann, Introduction to Group Theory, Longman, 1973. 11. Magma, http://magma.maths.usyd.edu.au. 12. nauty, http://cs.anu.edu.au/∼bdm/nauty. 13. Rome test suite ALF/CU, http://www.dia.uniroma3.it/∼gdt.
Path-Width and Three-Dimensional Straight-Line Grid Drawings of Graphs Vida Dujmovi´c1 , Pat Morin2 , and David R. Wood2 1 2
School of Computer Science, McGill University, Montr´eal, Canada. [email protected] School of Computer Science, Carleton University, Ottawa, Canada. {morin,davidw}@scs.carleton.ca
Abstract. We prove that every n-vertex graph G with path-width pw(G) has a three-dimensional straight-line grid drawing with O(pw(G)2 ·n) volume. Thus for graphs with bounded path-width the volume is O(n), and it follows that for graphs with bounded tree-width, such as series-parallel graphs, the volume is O(n log2 n). No better bound than O(n2 ) was previously known for drawings of series-parallel graphs. For planar graphs √ we obtain three-dimensional drawings with O(n2 ) volume and O( n) aspect ratio, whereas all previous constructions with O(n2 ) volume have Θ(n) aspect ratio.
1
Introduction
The study of straight-line graph drawing in the plane has a long history; see [37] for a recent survey. Motivated by interesting theoretical problems and potential applications in information visualisation [35], VLSI circuit design [26] and software engineering [36], there is a growing body of research in three-dimensional straight-line graph drawing. Throughout this paper all graphs G are undirected, simple and finite with vertex set V (G) and edge set E(G); n = |V (G)| denotes the number of vertices of G. A three-dimensional straight-line grid drawing of a graph, henceforth called a three-dimensional drawing, represents the vertices by distinct points in 3-space with integer coordinates (called grid-points), and represents each edge as a line-segment between its end-vertices, such that edges only intersect at common end-vertices. If a three-dimensional drawing is contained in an axisaligned box with side lengths X − 1, Y − 1 and Z − 1, then we speak of an X × Y × Z three-dimensional drawing with volume X · Y · Z and aspect ratio max{X, Y, Z}/ min{X, Y, Z}. This paper considers the problem of producing a three-dimensional drawing of a given graph with small volume, and with small aspect ratio as a secondary criterion. Related Work: In contrast to the case in the plane, every graph has a threedimensional drawing. Such a drawing can be constructed using the ‘moment
Research supported by NSERC and FCAR.
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 42–53, 2002. c Springer-Verlag Berlin Heidelberg 2002
Path-Width and Three-Dimensional Straight-Line Grid Drawings of Graphs
43
curve’ algorithm in which vertex vi , 1 ≤ i ≤ n, is represented by the grid-point (i, i2 , i3 ) . It is easily seen — compare with Lemma 4 to follow — that no edges cross. (Two edges cross if they intersect at some point other than a common end-vertex.) Cohen et al. [8] improved the resulting O(n6 ) volume bound, by proving that if p is a prime with n < p ≤ 2n, and each vertex vi is represented by the grid-point (i, i2 mod p, i3 mod p) then there is still no edge crossings. This construction is a generalisation of a twodimensional technique due to Erd¨ os [16]. Furthermore, Cohen et al. [8] proved that the resulting O(n3 ) volume bound is asymptotically optimal in the case of the complete graph Kn , and that every binary tree has a three-dimensional drawing with O(n log n) volume. Calamoneri and Sterbini [5] proved that every 4-colourable graph has a threedimensional drawing with O(n2 ) volume. Generalising this result, Pach et al. [30] proved that every k-colourable graph, for fixed k ≥ 2, has a three-dimensional drawing with O(n2 ) volume, and that this bound is asymptotically optimal for the complete bipartite graph with equal sized bipartitions. If p is a suitably chosen prime, the main step of this algorithm represents the vertices in the ith colour class by grid-points in the set {(i, t, it) : t ≡ i2 (mod p)} . The first linear volume bound was established by Felsner et al. [17], who proved that every outerplanar graph has a drawing with O(n) volume. Their elegant algorithm ‘wraps’ a two-dimensional layered drawing around a triangular prism; see Lemma 5 for more on this method. Poranen [32] proved that seriesparallel digraphs have upward three-dimensional drawings with O(n3 ) volume, and that this bound can be improved to O(n2 ) and O(n) in certain special cases. Recently di Giacomo et al. [11] proved that series-parallel graphs with maximum degree three have three-dimensional drawings with linear volume. Note that three-dimensional drawings with the vertices having real coordinates have been studied by Bruß and Frick [4], Chilakamarri et al. [6], Chrobak et al. [7], Cruz and Twarog [9], Eades and Garvan [15], Garg et al. [18], Hong [22], Hong and Eades [23, 24], Hong et al. [25], Monien et al. [27], and Ostry [29]. Aesthetic criteria besides volume which have been considered include symmetry [22–25], aspect ratio [7, 18], angular resolution [7, 18], edge-separation [7, 18], and convexity [6, 7, 15]. Tree-Decompositions: Before stating our results we recall some definitions. A tree-decomposition of a graph G is a tree T together with a collection of subsets Tx (called bags) of V (G) indexed by the vertices of T such that: – Tx = V (G), x∈V (T )
44
Vida Dujmovi´c, Pat Morin, and David R. Wood
– for every edge vw ∈ E(G), there is a vertex x ∈ V (T ) such that the bag Tx contains both v and w, and – for all vertices x, y, z ∈ V (T ), if y is on the path from x to z in T , then Tx ∩ T z ⊆ T y . The width of a tree-decomposition is the maximum cardinality of a bag minus one. A path-decomposition is a tree-decomposition where the tree T is a path T = (x1 , x2 , . . . , xm ), which is simply identified by the sequence of bags T1 , T2 , . . . , Tm where each Ti = Txi . The path-width (respectively, tree-width) of a graph G, denoted by pw(G) (tw(G)), is the minimum width of a path-decomposition (treedecomposition) of G. A graph G is said to have bounded path-width (tree-width) if pw(G) = k (tw(G) = k) for some constant k. Given a graph with bounded path-width (tree-width), the algorithm of Bodlaender [1] determines a pathdecomposition (tree-decomposition) with width pw(G) (tw(G)) in linear time. Note that the relationship between graph drawings and path-width or tree-width has been previously investigated by Dujmovi´c et al. [13], Hlin˘en´ y [21], and Peng [31], for example. Our Results: Our main result is the following. Theorem 1. Every n-vertex graph G has an O(pw(G)) × O(pw(G)) × O(n) three-dimensional drawing. Since pw(G) < n, Theorem 1 matches the O(n3 ) volume bound discussed above; in fact, the drawings of Kn produced by our algorithm are identical to those produced by Cohen et al. [8]. We have the following corollary since every graph G has pw(G) ∈ O(tw(G) · log n) [2]. Corollary 1. (a) Every n-vertex graph with bounded path-width has a threedimensional drawing with O(n) volume. (b) Every n-vertex graph with bounded tree-width has a three-dimensional drawing with O(n log2 n) volume.
While the notion of bounded tree-width may appear to be a purely theoretic construct, graphs arising in many applications of graph drawing do have small tree-width. For example, outerplanar graphs, series-parallel graphs and Halin graphs respectively have tree-width 2, 2 and 3 (see [2, 12]). Thus Corollary 1(b) implies that these graphs have three-dimensional drawings with O(n log2 n) volume. While linear volume is possible for outerplanar graphs [17], our result is the first known sub-quadratic volume bound for all series-parallel and Halin graphs. Another example arises in software engineering applications. Thorup [34] proved that the control-flow graphs of go-to free programs in many programming languages have tree-width bounded by a small constant; in particular, 3 for Pascal and 6 for C. Other families of graphs having bounded tree-width (for constant k) include: almost trees with parameter k, graphs with a feedback vertex set of size k, partial k-trees, bandwidth k graphs, cutwidth k graphs, planar graphs of radius k, and k-outerplanar graphs. If the size of a maximum clique is a constant
46
Vida Dujmovi´c, Pat Morin, and David R. Wood
The proofs of Theorems 1 and 2 proceed in three steps. First, an ordered layering with no X-crossing is constructed from a given path-decomposition. The second step balances the number of vertices on each layer. The third step, which is essentially the converse of Lemma 1, takes an ordered layering with no X-crossing and assigns coordinates to the vertices to avoid edge crossings. The style of three-dimensional drawing produced by our algorithm, where vertices on a single layer are positioned on vertical ‘rods’, is illustrated in Fig. 1.
Fig. 1. A three-dimensional drawing of K6 .
Our algorithm for constructing an ordered layering makes use of the socalled normalised path-decompositions of Gupta et al. [20]. (The more general notion of normalised tree-decompositions was developed earlier by Gupta and Nishimura [19].) A path-decomposition T1 , T2 , . . . , Tm of width k is normalised if |Ti | = k + 1 for all odd i and |Ti | = k for all even i, and Ti−1 ∩ Ti+1 = Ti for all even i. The algorithm of Gupta et al. [20] normalises a path-decomposition while maintaining the width in linear time. Lemma 2. If a graph G has a normalised path-decomposition T1 , T2 , . . . , Tm of width k − 1, then G has an ordered k-layering with no X-crossing (see Fig. 2). Proof. For every vertex v ∈ V (G), let Tα(v) and Tβ(v) be the first and last bags containing v. Construct an ordered k-layering of G as follows. Let T1 = {v1 , v2 , . . . , vk }, and position each vi as the leftmost vertex on layer i, 1 ≤ i ≤ k. Since the path-decomposition is normalised, for all bags Tj with j even, there is a unique vertex xj ∈ Tj−1 \ Tj ; that is, β(xj ) = j − 1. Similarly, for all bags Tj with j > 1 odd, there is a unique vertex yj ∈ Tj \ Tj−1 ; that is, α(yj ) = j. The remainder of the ordered layering is constructed by sweeping through the bags of the path-decomposition as follows. For all odd j = 3, 5, . . . , m, position yj in the same layer as the vertex xj−1 and immediately to the right of xj−1 .
Path-Width and Three-Dimensional Straight-Line Grid Drawings of Graphs
47
Fig. 2. An ordered 5-layering with no X-crossing produced by Lemma 2.
Clearly, xj−1 was the rightmost vertex in the layer before inserting yj . Since j − 1 = β(xj−1 ) < α(yj ) = j, there is no bag containing both xj−1 and yj , and no edge xj−1 yj ∈ E(G). In general, two vertices in the same layer are not in a common bag and are not adjacent. Suppose there is an X-crossing between edges vw and xy. Without loss of generality, v
The second step of our algorithm is based on the algorithm of Pach et al. [30] for balancing the size of the colour classes in a vertex-colouring. Note that while Lemma 2 produces an ordered layering with no intra-layer edges, the remaining steps of our algorithm are valid in the more general situation that the given ordered layering possibly has intra-layer edges. Lemma 3. If a graph G has an ordered k-layering with no X-crossing, then for every l > 0, G has an ordered l + k-layering with no X-crossing and at most nl vertices in each layer. Proof. For each layer with q > nl vertices, replace it by q/ nl ‘sub-layers’ each with exactly nl vertices except for at most one sub-layer with q mod nl vertices, such that the vertices in each sub-layer are consecutive in the original layer and the original order is maintained. There is no X-crossing between sublayers of the same original layer as there is at most one edge between such sublayers. There is no X-crossing between sub-layers from different original layers as otherwise there would be an X-crossing in the original layering. There are at most l layers with nl vertices. Since there are at most k layers with less than nl vertices, one for each of the original layers, there is a total of at most l + k layers.
The third step of our algorithm is inspired by the generalisations of the moment curve algorithm by Cohen et al. [8] and Pach et al. [30]. Loosely speaking,
Path-Width and Three-Dimensional Straight-Line Grid Drawings of Graphs
45
k then chordal, interval and circular arc graphs also have bounded tree-width. Thus Corollary 1(b) pertains to such graphs. Since a planar graph is 4-colourable, by the results of Calamoneri and Sterbini [5] and Pach et al. [30] discussed above, every planar graph has a threedimensional drawing with O(n2 ) volume. Of course this result also follows from the classical algorithms of de Fraysseix et al. [10] and Schnyder [33] for producing plane grid drawings. All of these methods produce O(1) × O(n) × O(n) drawings, √ which have Θ(n) aspect ratio. Since every planar graph G has pw(G) ∈ O( n) [2] we have the following corollary of Theorem 1. √ √ Corollary 2. Every n-vertex√planar graph has an O( n)×O( n)×O(n) threedimensional drawing with Θ( n) aspect ratio.
2 This result matches the above O(n √ ) volume bounds with an improvement in the aspect ratio by a factor of Θ( n). Our final result examines the trade-off between aspect ratio and volume.
Theorem 2. Let G be an n-vertex graph. For every r, 1 ≤ r ≤ n/(pw(G) + 1), G has a three-dimensional drawing with O(n3 /r2 ) volume and aspect ratio 2r.
2
Proofs
We first introduce a combinatorial structure which is the basis for a twodimensional layered graph drawing. An ordered k-layering of a graph G consists of a partition V1 , V2 , . . . , Vk of V (G) into layers, and a total ordering
48
Vida Dujmovi´c, Pat Morin, and David R. Wood
Cohen et al. [8] allow three ‘free’ dimensions, whereas Pach et al. [30] use the assignment of vertices to colour classes to ‘fix’ one dimension with two dimensions free. We use an assignment of vertices to layers in an ordered layering without X-crossings to fix two dimensions with one dimension free. Lemma 4. If a graph G has an ordered k-layering {(Vi , k. Then p ≤ 2k by Bertrand’s postulate. For each i, 1 ≤ i ≤ k, represent the vertices in Vi by the grid-points {(i, i2 mod p, t) : 1 ≤ t ≤ p · |Vi |, t ≡ i3 (mod p)} , such that the Z-coordinates respect the given linear ordering
Path-Width and Three-Dimensional Straight-Line Grid Drawings of Graphs
49
Since each iα < p, M is a Vandermonde matrix modulo p, and thus det(M ) ≡ (i1 − i2 )(i1 − i3 )(i1 − i4 )(i2 − i3 )(i2 − i4 )(i3 − i4 )
(mod p),
which is non-zero since iα = iβ and p is a prime. This contradiction proves there are no edge crossings. The produced drawing is at most k × 2k × 2k · n .
We now prove the theorems. Proof of Theorem 1. By Lemma 2, G has an ordered k-layering with no Xcrossing, where k = pw(G) + 1. By Lemma 3 with l = k, G has an ordered (2k)-layering with no X-crossing and at most nk vertices on each layer. By Lemma 4, G has a 2k × 4k × 4k · nk three-dimensional drawing, which is at most 2(pw(G) + 1) × 4(pw(G) + 1) × 4(n + pw(G) + 1). The result follows since 1 ≤ pw(G) < n.
Proof of Theorem 2. By Lemma 2, G has an ordered k-layering with no Xcrossing, where k = pw(G) + 1. By Lemma 3 with l = nr , G has an ordered nr + k-layering with no X-crossing and at most r vertices in each layer. By assumption r ≤ n/(pw(G) + 1). Thus k ≤ nr and the number of layers is at most 2n 2n 4n r . By Lemma 4, G has a r × r × 4n three-dimensional drawing, which has volume 32n3 /r2 and aspect ratio 2r.
3
Commentary
Consider the following open problems concerning straight-line grid drawings. 1. A graph with degree bounded by some constant k is (k + 1)-colourable, and thus by the theorem of Pach et al. [30], has a three-dimensional drawing with O(n2 ) volume. Pach et al. [30] ask whether every graph with bounded degree has a three-dimensional drawing with o(n2 ) volume? 2. As discussed in Section 1 every planar graph has a three-dimensional drawing with O(n2 ) volume. Felsner et al. [17] ask whether every planar graph has a three-dimensional drawing with O(n) volume? Even a volume bound of o(n2 ) would be interesting. As a final observation, we show that a generalisation of the ‘wrapping’ algorithm of Felsner et al. [17] can be applied in conjunction with our algorithm, which may be helpful in solving the above open. Note that Felsner et al. [17] prove the case s = 1 (with improved constants in the volume). Lemma 5. Let a graph G have an ordered k-layering {(Vi ,
50
Vida Dujmovi´c, Pat Morin, and David R. Wood
α < β. The given ordering of each Vi is preserved in the new layers. It remains to prove that there is no X-crossing. Consider two edges vw and xy. Let i1 and i2 , 1 ≤ i1 < i2 ≤ k, be the minimum and maximum layers containing v, w, x or y in the ordered k-layering. Firstly consider the case that i2 − i1 > 2s. Then without loss of generality v is on layer i2 and y is on layer i1 . Thus w is on a greater layer than x, and even if x (or y) appear on the same layer as v (or w) in the new t-layering, x (or y) will be to the left of v (or w). Thus these edges do not form an X-crossing in the ordered t-layering. Otherwise i2 − i1 ≤ 2s. Thus any two of v, w, x or y will appear on the same layer in the t-layering if and only if they are on the same layer in the given ordered k-layering (since t > 2s). Hence the only way for these four vertices to appear on exactly two layers in the ordered t-layering is if they were on exactly two layers in the given k-layering, in which case, by assumption vw and xy do not form an X-crossing. Therefore there are no X-crossings. By Lemma 3 with l = t, G has an ordered 2t-layering with no X-crossing and at most nt vertices in each layer. Since n t = 2s + 1, by Lemma 4, G has a 2(2s + 1) × 4(2s + 1) × 4(2s + 1) 2s+1 threedimensional drawing, which is 2(2s + 1) × 4(2s + 1) × 4(n + 2s). The result follows since s ≤ n.
Lemma 5 also shows that small path-width is not necessary √ for√a graph to have a three-dimensional drawing with small volume. The n × n plane √ grid graph has path-width Θ( n), but has an ordered layering with maximum edge span 1. Therefore it has a three-dimensional drawing with O(n) volume by Lemma 5.
Note Added in Proof The results in this paper have recently been extended. In particular, Wood [38] has proved that every graph G from a proper minor-closed family has a O(1) × O(1) × O(n) three-dimensional drawing if and only if G has O(1) queue-number, and Dujmovi´c and Wood [14] have proved that graphs of bounded tree-width have three-dimensional drawings with O(n) volume. Acknowledgements The authors are grateful for stimulating discussions with Prosenjit Bose, Hubert de Fraysseix, Stefan Langerman, Giuseppe Liotta, and Patrice Ossona de Mendez.
References [1] H. L. Bodlaender, A linear-time algorithm for finding treedecompositions of small treewidth. SIAM J. Comput., 25(6):1305–1317, 1996.
Path-Width and Three-Dimensional Straight-Line Grid Drawings of Graphs
51
[2] H. L. Bodlaender, A partial k-arboretum of graphs with bounded treewidth. Theoret. Comput. Sci., 209(1-2):1–45, 1998. [3] F. J. Brandenburg, ed., Proc. International Symp. on Graph Drawing (GD ’95), vol. 1027 of Lecture Notes in Comput. Sci., Springer, 1996. [4] I. Bruß and A. Frick, Fast interactive 3-D graph visualization. In [3], pp. 99–110. [5] T. Calamoneri and A. Sterbini, 3D straight-line grid drawing of 4colorable graphs. Inform. Process. Lett., 63(2):97–102, 1997. [6] K. Chilakamarri, N. Dean, and M. Littman, Three-dimensional Tutte embedding. In Proc. 26th Southeastern International Conf. on Combinatorics, Graph Theory and Computing, vol. 107 of Cong. Numer., pp. 129– 140, 1995. [7] M. Chrobak, M. Goodrich, and R. Tamassia, Convex drawings of graphs in two and three dimensions. In Proc. 12th Annual ACM Symp. on Comput. Geom., pp. 319–328, 1996. [8] R. F. Cohen, P. Eades, T. Lin, and F. Ruskey, Three-dimensional graph drawing. Algorithmica, 17(2):199–208, 1996. [9] I. F. Cruz and J. P. Twarog, 3D graph drawing with simulated annealing. In [3], pp. 162–165. [10] H. de Fraysseix, J. Pach, and R. Pollack, How to draw a planar graph on a grid. Combinatorica, 10(1):41–51, 1990. [11] E. di Giacomo, G. Liotta, and S. Wismath, Drawing series-parallel graphs on a box. In S. Wismath, ed., Proc. 14th Canadian Conf. on Computational Geometry (CCCG ’02), The University of Lethbridge, Canada, 2002. [12] R. G. Downey and M. R. Fellows, Parameterized complexity. Springer, 1999. ´, M. Fellows, M. Hallett, M. Kitching, G. Liotta, [13] V. Dujmovic C. McCartin, N. Nishimura, P. Ragde, F. Rosemand, M. Suderman, S. Whitesides, and D. R. Wood, On the parameterized complexity of layered graph drawing. In F. Meyer auf der Heide, ed., Proc. 5th Annual European Symp. on Algorithms (ESA ’01), vol. 2161 of Lecture Notes in Comput. Sci., pp. 488–499, Springer, 2001. ´ and D. R. Wood, Tree-partitions of k-trees with applica[14] V. Dujmovic tions in graph layout. Tech. Rep. TR-02-03, School of Computer Science, Carleton University, Ottawa, Canada, 2002. [15] P. Eades and P. Garvan, Drawing stressed planar graphs in three dimensions. In [3], pp. 212–223. ¨ s, Appendix. In K. F. Roth, On a problem of Heilbronn. J. [16] P. Erdo London Math. Soc., 26:198–204, 1951. [17] S. Felsner, S. Wismath, and G. Liotta, Straight-line drawings on restricted integer grids in two and three dimensions. In [28], pp. 328–342. [18] A. Garg, R. Tamassia, and P. Vocca, Drawing with colors. In J. Diaz and M. Serna, eds., Proc. 4th Annual European Symp. on Algorithms (ESA ’96), vol. 1136 of Lecture Notes in Comput. Sci., pp. 12–26, Springer, 1996.
52
Vida Dujmovi´c, Pat Morin, and David R. Wood
[19] A. Gupta and N. Nishimura, Sequential and parallel algorithms for embedding problems on classes of partial k-trees. In Proc. 4th Scandinavian Workshop on Algorithm Theory (SWAT ’94), vol. 824 of Lecture Notes in Comput. Sci., pp. 172–182, Springer, 1984. [20] A. Gupta, N. Nishimura, A. Proskurowski, and P. Ragde, Embeddings of k-connected graphs of pathwidth k. In M. M. Halldorsson, ed., Proc. 7th Scandinavian Workshop on Algorithm Theory (SWAT ’00), vol. 1851 of Lecture Notes in Comput. Sci., pp. 111–124, Springer, 2000. ˘ ny ´ , Crossing-critical graphs and path-width. In [28], pp. 102–114. [21] P. Hline [22] S.-H. Hong, Drawing graphs symmetrically in three dimensions. In [28], pp. 189–204. [23] S.-H. Hong and P. Eades, An algorithm for finding three dimensional symmetry in series parallel digraphs. In D. Lee and S.-H. Teng, eds., Proc. 11th International Conf. on Algorithms and Computation (ISAAC ’00), vol. 1969 of Lecture Notes in Comput. Sci., pp. 266–277, Springer, 2000. [24] S.-H. Hong and P. Eades, An algorithm for finding three dimensional symmetry in trees. In J. Marks, ed., Proc. 8th International Symp. on Graph Drawing (GD ’00), vol. 1984 of Lecture Notes in Comput. Sci., pp. 360–371, Springer, 2001. [25] S.-H. Hong, P. Eades, A. Quigley, and S.-H. Lee, Drawing algorithms for series-parallel digraphs in two and three dimensions. In S. Whitesides, ed., Proc. 6th International Symp. on Graph Drawing (GD ’98), vol. 1547 of Lecture Notes in Comput. Sci., pp. 198–209, Springer, 1998. [26] F. T. Leighton and A. L. Rosenberg, Three-dimensional circuit layouts. SIAM J. Comput., 15(3):793–813, 1986. [27] B. Monien, F. Ramme, and H. Salmen, A parallel simulated annealing algorithm for generating 3D layouts of undirected graphs. In [3], pp. 396– 408. ¨nger, and S. Leipert, eds., Proc. 9th International [28] P. Mutzel, M. Ju Symp. on Graph Drawing (GD ’01), vol. 2265 of Lecture Notes in Comput. Sci., Springer, 2002. [29] D. I. Ostry, Some Three-Dimensional Graph Drawing Algorithms. Master’s thesis, Department of Computer Science and Software Engineering, The University of Newcastle, Australia, 1996. ´ th, Three-dimensional grid drawings of [30] J. Pach, T. Thiele, and G. To graphs. In G. Di Battista, ed., Proc. 5th International Symp. on Graph Drawing (GD ’97), vol. 1353 of Lecture Notes in Comput. Sci., pp. 47–51, Springer, 1998. [31] Z. Peng, Drawing Graphs of Bounded Treewidth/Pathwidth. Master’s thesis, Department of Computer Science, University of Auckland, New Zealand, 2001. [32] T. Poranen, A new algorithm for drawing series-parallel digraphs in 3D. Tech. Rep. A-2000-16, Dept. of Computer and Information Sciences, University of Tampere, Finland, 2000.
Path-Width and Three-Dimensional Straight-Line Grid Drawings of Graphs
53
[33] W. Schnyder, Planar graphs and poset dimension. Order, 5(4):323–343, 1989. [34] M. Thorup, All structured programs have small tree-width and good register allocation. Information and Computation, 142(2):159–181, 1998. [35] C. Ware and G. Franck, Viewing a graph in a virtual reality display is three times as good as a 2D diagram. In A. L. Ambler and T. D. Kimura, eds., Proc. IEEE Symp. Visual Languages (VL ’94), pp. 182–183, IEEE, 1994. [36] C. Ware, D. Hui, and G. Franck, Visualizing object oriented software in three dimensions. In Proc. IBM Centre for Advanced Studies Conf. (CASCON ’93), pp. 1–11, 1993. [37] R. Weiskircher, Drawing planar graphs. In M. Kaufmann and D. Wagner, eds., Drawing Graphs: Methods and Models, vol. 2025 of Lecture Notes in Comput. Sci., pp. 23–45, Springer, 2001. [38] D. R. Wood, Queue layouts, tree-width, and three-dimensional graph drawing. Tech. Rep. TR-02-02 (revised), School of Computer Science, Carleton University, Ottawa, Canada, August, 2002.
Drawing Outer-Planar Graphs in O(n log n) Area Therese Biedl
School of Computer Science, University of Waterloo, Waterloo, ON N2L 3G1, Canada, [email protected]
Abstract. In this paper, we study drawings of outer-planar graphs in various models. We show that O(n log n) area can be achieved for such drawings if edges are allowed to have bends or if vertices may be represented by boxes. The question of straight-line grid-drawings of outerplanar graphs in o(n2 ) area remains open.
1
Introduction
A planar graph is a graph that can be drawn without crossing. F´ ary, Stein and Wagner [F´ ar48,Ste51,Wag36] proved independently that every planar graph has a drawing such that all edges are drawn as straight-line segments. De Fraysseix, Pach and Pollack [FPP90], and independently Schnyder [Sch90] established that in fact O(n2 ) area suffices for a straight-line drawing of an n-vertex planar graph, with vertices placed at grid points. This is asymptotically optimal, since there are planar graphs that need Ω(n2 ) area [FPP88]. A number of other graph drawing models (e.g., poly-line drawings, orthogonal drawings, visibility representations) exist for planar graphs. See Section 2 for precise definitions. In all these models, O(n2 ) area can be achieved for planar graphs, see for example [Kan96,FKK97,Wis85]. On the other hand, Ω(n2 ) area is needed, even in these models, for the graph in [FPP88]. Our paper was motivated by the question whether an area of o(n2 ) is possible, at least in some models, for subclasses of planar graphs such as trees, series-parallel graphs, and outer-planar graphs. Every tree has a straight-line drawing in O(n log n) area [Shi76], and in O(n) area if the maximum degree is asymptotically smaller than n [GGT96]. On the other hand, one can easily construct a series-parallel graph that requires Ω(n2 ) area if the planar embedding must be preserved (see also Fig. 11). The question of whether every series-parallel graph can be drawn in o(n2 ) area when the planar embedding may be changed appears to be open. See [DBETT98] for many other upper and lower bounds regarding drawings of trees and series-parallel graphs under special restrictions. Not many drawing results are known for outer-planar graphs. Leiserson [Lei80] showed that outer-planar graphs have an orthogonal point-drawing in O(n) area
Research supported by NSERC. The author would like to thank Erik Demaine, Henk Meijer, Steve Wismath and the Algorithmic Problem Session Group at the University of Waterloo for inspiring discussions.
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 54–65, 2002. c Springer-Verlag Berlin Heidelberg 2002
Drawing Outer-Planar Graphs in O(n log n) Area
55
if the maximum degree is at most 4. By splitting vertices of higher degrees, and combining them in the resulting drawing after replacing each grid-line with ∆ grid-lines (where ∆ is the maximum degree), one can obtain orthogonal boxdrawings of area O(∆2 n). However, this is an improvement over the O(n2 ) bound only if ∆ is small. In another result, any n points in general position can be used for a straightline drawing of any outer-planar graph [CU96]. However, O(n2 ) area is needed to create n grid points in general positions, so this result does not lead to smaller area bounds either. In this paper, we provide the following results: – Every outer-planar graph has an orthogonal box-drawing with area O(nlog n). – By converting this drawing, it follows easily that every outer-planar graph has a poly-line grid drawing in area O(n log n). – Every outer-planar graph has a visibility representation in O(n log n) area; however, not all vertices are necessarily drawn on the outer-face. The question whether o(n2 ) area is possible for straight-line drawing remains open. In fact, not even any lower bounds better than the obvious Ω(n) appear to be known; we provide some partial results for lower bounds as well.
2
Definitions
Let G = (V, E) be a graph with n = n(G) = |V | vertices. We assume that G is simple, i.e., it has no loops and multiple edges. Throughout this paper, we will assume that G is planar, i.e., that G can be drawn without crossing. Such a planar drawing can be characterized by the cyclic order of edges around each vertex. A planar drawing splits the plane into connected pieces; the unbounded piece is called the outer-face, all other pieces are called interior faces. An outer-planar graph is a planar graph that can be drawn such that all vertices are incident to the outer-face. Throughout this paper we will assume that G is outer-planar; in fact, we will assume that it is maximal outer-planar, i.e., no edge can be added to G without destroying simplicity or outer-planarity. (If G is not maximal outer-planar, simply add edges until it is, draw the resulting graph, and delete the extra edges from the drawing.) A maximal outer-planar graph consists of an n-cycle with chords and every interior face is a triangle. We use the following drawing models (see also Fig. 1): – Straight-line drawings: Vertices are points, all edges are straight-line segments. – Poly-line drawings: Vertices are points, all edges are contiguous sequences of straight-line segments. – Orthogonal point-drawings: A poly-line drawing where all edge segments are horizontal or vertical. Such drawings exist only if the maximum degree is at most 4. – Orthogonal box-drawings: Vertices are (axis-parallel) boxes, edges are contiguous sequences of horizontal or vertical segments.1 1
In this paper, the term “box” is referring to an axis-parallel box.
56
Therese Biedl
Fig. 1. The same graph in a straight-line drawing, a poly-line drawing, an orthogonal point-drawing, an orthogonal box-drawing, and a visibility representation.
– Visibility representations: Vertices are boxes, edges are horizontal or vertical segments. For a planar graph, such drawings should be planar, i.e., have no crossing. We also assume that all defining features have integral coordinates; in particular points of vertices and transition-points (bends) in the routes of edges have integral coordinates, and boxes of vertices have integral corner points. We allow boxes to be degenerate, i.e., to be line segments or points. The width of a box is the number of vertical grid lines (columns) that are occupied by it. The height of a drawing is the number of horizontal grid lines (rows) that are occupied by it. A drawing whose minimum enclosing box has width w and height h is called an w × h-drawing, and has area w · h.
3
Orthogonal Box-Drawings
Let G = (V, E) be a maximal outer-planar graph. In this section, we show how to construct an orthogonal box-drawing of G in a grid of area O(n log n). For the remainder of this section, “drawing” will refer to “orthogonal box-drawing”. We use induction on the number of vertices with the following induction hypothesis (see also Fig. 2): Let (u, v) be an edge on the outer-face of G, with v after u in clockwise order on the outer-face. Then G has a drawing such that – – – –
u occupies the top right corner of the drawing, v occupies the bottom right corner of the drawing, vertices have height 1, i.e., each vertex intersects only one row,2 edges that attach horizontally at an endpoint have no bend.
In the base case (n = 2), simply place u atop v; see Fig. 2. The conditions of the induction hypothesis are clearly satisfied. For n ≥ 3, let w be the third vertex on the interior face incident to (u, v). Let G1 be the graph induced by the vertices between w and u in clockwise order on the outer-face (we call this the graph attached to edge (u, w); see also Fig. 3). Let G2 be the subgraph attached to (w, v). Note that G1 or G2 may contain only one edge. We will for now assume that n(G1 ) ≤ n(G2 ); the other case will be treated later. 2
In our drawings, we “fatten” vertices for better visibility.
Drawing Outer-Planar Graphs in O(n log n) Area u
57
u
v
u v
v
Fig. 2. Illustration of the induction hypothesis, and the base case n = 2. u u G1
v
Ga x
w
v
Gb
G2
G2
w
Fig. 3. Breaking the graph into parts (and breaking G1 further in Case 2).
We have two sub-cases: Case 1: If G1 has only two vertices u and w, then recursively draw G2 with respect to edge (w, v). Place u to the right of w, extend v, and draw the new edge as straight line. See Fig. 4. One can easily verify the induction hypothesis. u
v
w
G2
w
u
G2 v
Fig. 4. The case when G1 consists of only one edge.
Case 2: If G1 contains at least three vertices, then let x be the third vertex on the face other than {u, v, w} incident to (u, w). Let Ga and Gb be the two subgraphs attached to edges (u, x) and (x, w); see also Fig. 3. Recursively draw Ga , Gb and G2 , with respect to edges (u, x), (x, w) and (w, v), respectively, and let Γa , Γb and Γ2 be the corresponding drawings. We now modify Γa to achieve an additional property. By the induction hypothesis, vertex x occupies the bottom right corner of Γa . We say that x spans the bottom of Γa if additionally x occupies the bottom left corner, i.e., if x occupies the complete bottom row of Γa . As we show now, we can always modify Γa by adding at most one row so that this holds. For if x does not occupy the bottom left corner of Γa , then add one more row below Γa , move x into it and expand x so that it occupies the whole width of the drawing. Now re-route the incident edges of x. All edges that attach vertically at x can simply be extended.
58
Therese Biedl
If an edge (z, x) attaches horizontally at x, then (by the induction hypothesis) this edge has no bend. Since x only intersects one row by induction hypothesis, this implies that z occupies part of the last row of Γa . Therefore, we can route edge (z, x) vertically from z to x, which is now one row below. See also Fig. 5. u
u
x
x
Fig. 5. Modifying Γa into Γa .
Let Γa be the drawing that we obtain from Γa by making x span the bottom. In a similar fashion, we modify Γb such that x spans the top, i.e., x occupies both top corners. (By induction hypothesis x already occupies the top right corner of Γb .) Call this new drawing Γb . Now we obtain a drawing of G by placing Γ2 , Γb and Γa next to each other. See Fig. 6 for an illustration of the following process. Stretch Γa or Γb , if necessary, until both drawings have the same height. (Note that any orthogonal box-drawing can be stretched by inserting empty rows.) Next, stretch Γ2 , if necessary, such that it is at least two units taller than Γa and Γb . Now place Γ2 , then Γb (turned upside down) and then Γa such that their tops are aligned. By the placement, the two boxes of w are adjacent in the same row and can simply be rejoined. Since Γa and Γb have the same height, and since x spans both drawings Γa and Γb , the boxes of x are also adjacent in the same row and can be rejoined. Since Γ2 is at least two units taller than Γa , there are two empty rows underneath Γa and Γb . We use these to extend v to the right bottom corner and to route edge (w, u) with two bends. Edge (u, v) is a vertical line in the rightmost column. One easily verifies the induction hypothesis. w Γ2
w
u
Γb
Γa
x
x
v
Fig. 6. Combining Γa , Γb and Γ2 .
Thus we are done with the case n(G1 ) ≤ n(G2 ). The case n(G1 ) > n(G2 ) is symmetric; we do not give the details here and refer to Fig. 7.
Drawing Outer-Planar Graphs in O(n log n) Area u
v
G1
u G1
w
w u
59
v
v
u Ga
G1
w
x Gb
Γ1 w
x
x
Γb
Γa
w
v
Fig. 7. The construction if n(G1 ) > n(G2 ).
Theorem 1. Every outer-planar graph has an orthogonal box-drawing such that the following holds: – – – – –
The height is at most 3 log n − 1, the width is at most 52 n − 4, the planar embedding is respected, the total number of bends is at most n − 2, every edge has at most two bends, every edge on the outer-face has no bends.
Proof. The construction is given above. The bounds on the width, height and number of bends are easily verified in the base case and in Case 1 of the recursion, so we will only focus on Case 2. Let G1 , G2 , Ga , Gb , Γ2 , Γa , Γb , Γa and Γb be defined as before. Since n(G1 ) ≤ n(G2 ), we have n(Ga ) ≤ n2 . Therefore by induction Γa has height at most 3 log n(Ga ) − 1 ≤ 3 log n − 4. We add one grid line to obtain Γa , so Γa has height at most 3 log n − 3. Similarly Γb has height at most 3 log n − 3. Finally, Γ2 has height at most 3 log n − 1 by induction. When stretching the drawings to achieve suitable heights, we will not exceed these bounds. Finally, during the merging process (Fig.6), we use two more grid lines near Γa and Γb , resulting in a total height of at most 3 log n − 1. The width of the drawing is the combined width of Γ2 , Γa and Γb , with three more columns added. Since n(G2 ) + n(Ga ) + n(Gb ) = n + 2, and using induction, the width is at most 5 5 5 5 5 3 + n(G2 ) − 4 + n(Ga ) − 4 + n(Gb ) − 4 = 3 + (n + 2) − 12 = n − 4. 2 2 2 2 2 Similarly, the total number of bends is at most 2 + n(G2 ) − 2 + n(Ga ) − 2 + n(Gb ) − 2 = 2 + (n + 2) − 6 = n − 2. Every edge receives at most 2 bends, if it is edge (w, u). Note in particular that this can be the case only for a chord; any edge on the outer-face of G is drawn as a straight line.
60
4
Therese Biedl
Poly-line Drawings
From any orthogonal box-drawing, we can easily obtain a poly-line drawing with asymptotically the same area as follows: Add empty grid-lines until every segment of every edge has length at least 2. Now for every vertex v, create a point for v at an arbitrary grid point inside the box of v. For each incident edge e of v, re-route e to end at this point by placing a new bend (if needed) at the grid-line incident to the box of v. (Such a grid-line must exist, and does not contain any other vertex, since e had length at least 2 by assumption.) See Fig. 8 for an illustration.
Fig. 8. Converting to a point-drawing.
If we start with the orthogonal box-drawing obtained in Section 3, then by analyzing the construction more carefully, we can improve this general construction as follows: – We only need to add log n new rows, since only in the base case and in the construction in Fig. 5 vertical edge segments of length 1 can be created. More precisely, we can show by induction on the number of vertices similarly as before that there exists an orthogonal box-drawing of height 4 log n − 1 and width 52 n − 4 such that all vertical edges segments have length at least 2. This is obtained by adding one extra row with the base case, and one extra row whenever we need to modify the drawing to make a vertex span the bottom or top of a drawing. – We need not add new columns, since every vertex has height 1, and therefore horizontal edge segments can simply be extended without adding a bend. – We can achieve at most three bends per edge with a good choice of grid points for vertices. Note that every edge obtains at most one extra bend at every endpoint, so we only have to be careful for edges that had two bends in the orthogonal drawing. By construction, this happens only for an edge (w, u) added during Case 2 of the recursive construction. If (w, u) is such an edge, with say w as the left endpoint (see also Fig. 6), then place the grid point for w at the column where edge (w, u) attaches to w. Note that every vertex is at most once the left endpoint of an edge with two bends, so this is well-defined. Edge (w, u) now does not receive an extra bend at w, and hence has at most three bends as well. Combining the bounds of Theorem 1 with the above observations, we obtain the following results:
Drawing Outer-Planar Graphs in O(n log n) Area
61
Theorem 2. Every outer-planar graph has a poly-line grid-drawing in a ( 52 n − 4) × (4 log n − 1)-grid such that all vertices are on the outer-face. Every edge has at most 3 bends. For an outer-planar graph G with maximum degree ∆ ≤ 4, we can similarly obtain an orthogonal point-drawing with area O(n log n), by starting with an orthogonal box-drawing, adding rows and columns to make vertex boxes sufficiently big, and then replacing each box with a subgraph to connect all edges to a point. However, note that this is not an improvement over the known O(n) area bound for orthogonal point-drawings of outer-planar graphs with maximum degree 4 [Lei80].
5
Visibility Representations
In this section, we show that by changing the planar embedding we can avoid the bends in Fig. 6 and obtain a visibility representation. The construction is very similar to the one in Section 3. No bends are added in either the base case or Case 1 of the recursion. The only change to the construction thus occurs in Case 2 of the recursion. Define Ga , Gb , G2 , Γa , Γb and Γ2 as in Case 2 of Section 3. Recall that u occupies the top right and x occupies the bottom right corner of Γa . We showed that by adding one row, we can modify Γa such that x spans the bottom of the drawing. By applying this modification twice and adding two rows, we can obtain a drawing such that x spans the bottom of the drawing and u spans the top of the drawing. Call the resulting drawing Γa . Similarly we can modify Γb into Γb by adding at most two rows such that now w spans the bottom and x spans the top of the drawing. Now we combine Γ2 , Γb and Γa similar as before, but route (u, w) with a horizontal segment (see Fig. 9). Note that this removes x from the outer-face of the drawing. We save the two columns needed for edge (w, u) before, and hence have a smaller width. Using induction, one can show that the height is at most 3 log n − 1 as before, and the width is at most 32 n − 1. Theorem 3. Every outer-planar graph has a visibility representation in a ( 32 n− 2) × (3 log n − 1)-grid. w
w Γb
Γ2
x
u Γa x
v
Fig. 9. Combining without bends.
62
6 6.1
Therese Biedl
Towards Lower Bounds The Snowflake Graph
We have shown that O(n log n) drawings are possible in a variety of drawing models. We suspect that this is best-possible, in particular for the graph shown in Fig. 10 (and referred to as the snowflake graph).
Fig. 10. The snowflake graph.
Conjecture 1. Any poly-line drawing of the snowflake graph has Ω(n log n) area. We have not been able to prove this conjecture, but believe it to be true based on the following observations: – It appears to be the case that in any drawing of this graph, at least one dimension is Ω(n). Is this true, and how can this be shown? – It also appears to be the case that in any drawing of this graph, both dimensions are Ω(log n). Is this true, and does the fact that any edge separator (i.e., any set of edges whose removal splits the graph into two graphs that are a constant fraction smaller) has Ω(log n) size help in proving this? Note that if this conjecture is true, then the lower bound would hold orthogonal box-drawings as well by the results in Section 4, and therefore also for visibility representations. Of course, this conjecture would also imply an Ω(n log n) lower bound for straight-line drawings. 6.2
A More Restrictive Model
As a second contributions to lower bounds, we would like to give an Ω(n2 ) lower bound on the area in a special model. One possible criticism of the orthogonal box-drawings obtained with our algorithm is that although all vertices are technically on the outer-face, they are not clearly visible as being on the outer-face. For example, vertex x in Fig. 6 appears removed from the outer-face, because it is far from the boundary of the enclosing rectangle.
Drawing Outer-Planar Graphs in O(n log n) Area
63
Another model for drawing outer-planar graphs would thus be to require all vertices are placed on the boundary of the minimum enclosing rectangle (respectively touch it if they are boxes). It is known that trees may require Ω(n log n) are in this model [Ull83, p.83ff]. We show now that for outer-planar graphs, Ω(n2 ) area is required in this model. Theorem 4. There exists an outer-planar graph G such that any poly-line drawing Γ of G with all vertices on the boundary of the minimum enclosing rectangle of the graph has area Ω(n2 ). Proof. Let G be the outer-planar graph illustrated in Fig. 6.2. It consists of 5 groups of n/5 vertices, connected with chords between them.
Now assume we have a drawing Γ such that all vertices are on the boundary B of the minimum enclosing rectangle. By planarity, and since the outer-face is a cycle, the order of vertices along B must be the same as the order around the outer-face. Therefore, at least one of the five groups of the graph entirely on one side of B, say the top. Consider the subgraph induced by this group of vertices. We can duplicate its drawing and flip it upside down to obtain a drawing of asymptotically the same area. This drawing is a drawing of a multi-graph wellknown to need Ω(n2 ) area in any drawing that preserves this planar embedding (see also Fig. 11). So the area of the original drawing must have been Ω(n2 ) as well.
+
=
Fig. 11. Any poly-line drawing must have Ω(n2 ) area.
We note here without proof that the same graph, with a similar proof, also yields a lower bound of Ω(n2 ) for various other models of “being visible on the outer-face”, such as “having a horizontal or vertical segment that reaches to the boundary of the enclosing rectangle”, or even “having an escape hatch” (see [Lei80]).
64
7
Therese Biedl
Conclusion
In this paper, we studied planar drawings of outer-planar graphs. Using a simple recursive algorithm, we achieved an orthogonal box-drawing in O(n log n) area. This can be converted into a poly-line drawing in O(n log n) area. With a slight variation, we can also obtain visibility representations, at the cost of not having all vertices drawn on the outer-face. Some partial results towards lower bounds were provided as well. Many open problems remain: – What is the correct area bound for straight-line drawings of outer-planar graph? Can we achieve o(n2 ) for all outer-planar graphs? Note that o(n2 ) can be achieved for all outer-planar graphs that are balanced in some sense. The adjacencies between the interior faces of an outer-planar graph form a tree. It is relatively straightforward to show that if this “dual tree” has diameter d, then the graph has a straight-line drawing in a d × ngrid (Erik Demaine and the author, private communication). Unfortunately, there are outer-planar graphs for which the dual tree is a path, and which therefore d = n − 3. While these graphs can be drawn in o(n2 ) area (in fact, in O(n) area), it is not clear how to handle outer-planar graphs for which the dual tree has diameter Ω(n), but is not a path. – We gave visibility representations of area O(n log n), but at the cost of not respecting the planar embedding. Can we obtain visibility representations of area O(n log n) even with all vertices drawn on the outer-face? – As illustrated in the drawing of the snowflake graph in Figure 12, our drawings may have small area, but are somewhat disappointing in other aspects. In particular, the aspect ratio of the drawing is Ω(n/ log n), and the aspect ratio of some boxes may be Ω(n).
Fig. 12. The drawing of the snowflake graph created with our algorithm.
Is it true that any poly-line drawing of aspect ratio O(1) requires Ω(n2 ) area? (We believe this to be true for the snowflake graph.) And what can be said about drawings where vertex boxes may not have arbitrary aspect ratios, e.g., orthogonal box-drawings in the Kandinsky-model [FK96] or the PG-model [BMT98]? – What can be said about series-parallel graphs? Does every series-parallel graph have a drawing in o(n2 ) area if we are allowed to change the planar embedding? (This is not possible if all edges are required to be drawn “upward”, see [BCDB+ 94].)
Drawing Outer-Planar Graphs in O(n log n) Area
65
References BCDB+ 94. P. Bertolazzi, R.F. Cohen, G. Di Battista, R. Tamassia, and I.G. Tollis. How to draw a series-parallel digraph. Intl. J. Comput. Geom. Appl., 4:385–402, 1994. BMT98. T. Biedl, B. Madden, and I. Tollis. The three-phase method: A unified approach to orthogonal graph drawing. In Graph Drawing (GD’97), volume 1353 of Lecture Notes in Computer Science, pages 391–402. SpringerVerlag, 1998. CU96. N. Casta˜ neda and J. Urrutia. Straight line embeddings of planar graphs on point sets. In Canadian Conference on Computational Geometry (CCCG ’96), pages 312–318, 1996. DBETT98. G. Di Battista, P. Eades, R. Tamassia, and I. Tollis. Graph Drawing: Algorithms for Geometric Representations of Graphs. Prentice-Hall, 1998. F´ ar48. I. F´ ary. On straight line representation of planar graphs. Acta. Sci. Math. Szeged, 11:229–233, 1948. FK96. U. F¨ oßmeier and M. Kaufmann. Drawing high degree graphs with low bend numbers. In F. Brandenburg, editor, Symposium on Graph Drawing 95, volume 1027 of Lecture Notes in Computer Science, pages 254–266. Springer-Verlag, 1996. FKK97. U. F¨ oßmeier, G. Kant, and M. Kaufmann. 2-visibility drawings of planar graphs. In S. North, editor, Symposium on Graph Drawing, GD 96, volume 1190 of Lecture Notes in Computer Science, pages 155–168. SpringerVerlag, 1997. FPP88. H. de Fraysseix, J. Pach, and R. Pollack. Small sets supporting fary embeddings of planar graphs. In Twentieth Annual ACM Symposium on Theory of Computing, pages 426–433, 1988. FPP90. H. de Fraysseix, J. Pach, and R. Pollack. How to draw a planar graph on a grid. Combinatorica, 10:41–51, 1990. GGT96. A. Garg, M.T. Goodrich, and R. Tamassia. Planar upward tree drawings with optimal area. International J. Computational Geometry Applications, 6:333–356, 1996. Kan96. G. Kant. Drawing planar graphs using the canonical ordering. Algorithmica, 16:4–32, 1996. Lei80. C. Leiserson. Area-efficient graph layouts (for VLSI). In 21st IEEE Symposium on Foundations of Computer Science, pages 270–281, 1980. Sch90. W. Schnyder. Embedding planar graphs on the grid. In 1st Annual ACMSIAM Symposium on Discrete Algorithms, pages 138–148, 1990. Shi76. Y. Shiloach. Arrangements of Planar Graphs on the Planar Lattice. PhD thesis, Weizmann Institute of Science, 1976. Ste51. S. Stein. Convex maps. In Amer. Math. Soc., volume 2, pages 464–466, 1951. Ull83. J.D. Ullman. Computational Aspects of VLSI. Computer Science Press, 1983. Wag36. K. Wagner. Bemerkungen zum Vierfarbenproblem. Jahresbericht der Deutschen Mathematiker-Vereinigung, 46:26–32, 1936. Wis85. S. Wismath. Characterizing bar line-of-sight graphs. In 1st ACM Symposium on Computational Geometry, pages 147–152, Baltimore, Maryland, USA, 1985.
Computing Labeled Orthogonal Drawings Carla Binucci, Walter Didimo, Giuseppe Liotta, and Maddalena Nonato Universit` a di Perugia {binucci,didimo,liotta,nonato}@diei.unipg.it
Abstract. This paper studies the problem of computing labeled orthogonal drawings. A label is modeled as a rectangle of prescribed size and it can be associated with either a vertex or an edge. Several optimization goals are taken into account. Namely, the labeled drawing can be required to have minimum total edge length, minimum width, minimum height, or minimum area. We present ILP models to compute optimal drawings with respect to the first three objectives and an algorithm exploiting these models which computes a drawing of minimum area (the compaction problem is known to be NP-complete in general).
1
Introduction
The increasing demand of visualization technologies to display maps and schemas with textual or multimedia content associated with vertices and/or edges has been motivating a significant research effort towards designing algorithms and systems that display labeled drawings of graphs. Among the application domains where these technologies are relevant we mention Cybergeography (Web maps and Internet maps), Software Engineering (UML schemas), and Information Systems (data-base schemas, organization charts). (See also [5,9] for more application domains). At a first sight, one might think that computing a labeled drawing of a graph is “yet-another-version” of the well-known labeling placement problem that has attracted a lot of research in the computational geometry and cartography communities (see, e.g. [7,8,10,13,14] and the on-line bibliography of Strijk and Wolff [17]). Namely, one possible approach for solving the problem is that of removing the labels, computing a drawing, and putting back the labels. However, this approach has several drawbacks in practice. For example, most graph drawing algorithms and systems draw all vertices as boxes having the same (usually quite small) size: if labels have to be drawn inside vertices (such as in a UML schema), a global re-scaling of the drawing may be required at each label insertion. Further, if the graph to display is large (such as a portion of the Web graph), then most graph drawing systems would try to draw groups of edges close with each other so to avoid unnecessary wastes of space on the computer screen. However, this strategy may contrast with the necessity of adding large textual labels on the edges in a post-processing phase while maintaining readability and compactness of the diagram. On the other hand, the graph drawing labeling problem allows more flexibility than the labeling placement problem. While in the latter problem the geometry of M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 66–73, 2002. c Springer-Verlag Berlin Heidelberg 2002
Computing Labeled Orthogonal Drawings
67
the map to be labeled is fixed and given as part of the input, in the graph drawing context the geometry is part of the output. This observation has suggested a radically different approach to the problem, based on computing a drawing of the input graph by taking into account also the space needed for adding the labels [2,4,11]. This paper studies the problem of computing labeled orthogonal drawings. A label is modeled as a rectangle of prescribed size and it can be associated with either a vertex or an edge. Several optimization goals are taken into account. The labeled drawing can be required to have minimum total edge length, minimum width, minimum height, or minimum area. Previous papers on this subject include the seminal paper by Klau and Mutzel [11], the first to present an ILP model for orthogonal drawings of minimum total edge length with labeled vertices, and the work in [2] where several heuristics for orthogonal drawings of minimum area with labeled edges are presented. Both problems of computing orthogonal drawings of minimum area and minimum total edge length are NPcomplete, even when edges and vertices are not labeled [16]. The main contributions of this paper are as follows. – An ILP model for orthogonal drawings with labels both on edges and on vertices is presented. Given a labeled orthogonal representation H, the ILP model can be used to compute a labeled orthogonal drawing of H with minimum total edge length. Variants of the model compute a drawing of minimum width or of minimum height. We remark that the model in this paper is the first ILP model for edge labeling of orthogonal representations. Concerning vertex labeling, our model is different from the one proposed by Klau and Mutzel [11] in which a vertex v is mapped to a point and a label of v is drawn as a box whose perimeter includes v. In our model the label of v is also a box, but v can be either a point on the perimeter or a point inside the box. Our choice is motivated by applications in which vertices are identified with labels, such as drawing UML diagrams and ER-diagrams. – We describe a strategy for computing a labeled orthogonal drawing with minimum area among those preserving a given orthogonal representation. Our approach is based on computing several solutions of the ILP model for width minimization under a certain constraint on the height of the drawing. Our solution strategy is markedly different from standard integer quadratic programming techniques, which appear to be not as effective as our method for handling the specific problem of area minimization. We experimentally observe that the number of ILP solutions required by our algorithm is quite small (5 on the average) and that this number does not seem to depend on the number of vertices of the input graph. – As a special case, our algorithm for area minimization can be used for unlabeled drawings. As far as we know, no other algorithm is known in the literature to this aim, except for some specific classes of orthogonal representations [3]. For reasons of space several details are omitted in this abstract. A more complete version including extensive experimental analysis and heuristics for labeled drawings is available at [1].
68
2
Carla Binucci et al.
Labeled Orthogonal Drawings
We assume familiarity with graph theory [6], graph planarity [15], and graph drawing [5,9]. Let G = (V, E) be a 4-planar graph. An orthogonal drawing of G is a drawing of G such that each vertex of G is mapped to a distinct point of the plane and each edge of G is drawn as a sequence of horizontal and vertical segments between its end-vertices. An orthogonal grid drawing of G is an orthogonal drawing such that vertices and bends are mapped to points of the integer grid. An orthogonal representation of G is an equivalence class of planar orthogonal drawings of G, such that: (i) For each edge (u, v) of G all drawings in the class have the same sequence of left and right turns (bends) along (u, v), while moving from u to v. (ii) For each vertex v of G, and for each pair {e1 , e2 } of clockwise consecutive edges incident on v, all drawings in the class determine the same angle between e1 and e2 . Let L = {λ} be a set of rectangular labels of given integer width w(λ) and given integer height h(λ). We assume that each λ is associated with one edge of G and no two labels are associated with the same edge. Each λ is an edge-label. Let N = {ν} be a set of rectangular labels of given integer width w(ν) and given integer height h(ν) such that each ν is associated with one vertex of G and such that no two labels are associated with the same vertex. Each ν is a vertex-label. In the following we shall use the term “label” instead of vertex-label or edge-label when the context does not give rise to ambiguities. Consider the triplet (G, L, N ). A labeled orthogonal drawing Γ of (G, L, N ) is a drawing such that: (i) G is represented as a planar orthogonal drawing and (ii) each label in L ∪ N is represented as a rectangle. The following definitions characterize a good labeling. Definition 1. An edge e ∈ Γ with associated an edge-label λ ∈ L is properly labeled if: (EL1) λ is a rectangle in Γ with height h(λ) and width w(λ) (EL2) λ has only one side s contained in one segment i of e, and s is properly contained in i. We say that λ is drawn on i. Note that (EL2) implies that there is an intersection between λ and the segment on which λ is drawn. Definition 2. A vertex v ∈ V with associated a vertex-label ν ∈ N is properly labeled if: (VL1) ν is a rectangle in Γ with height h(ν) and width w(ν) (VL2) v is a point either on the perimeter or in the interior of ν. We say that ν is drawn on v. Note that (VL2) implies that there is an intersection between ν and each segment incident on the vertex associated with ν. Definition 3. A labeled drawing Γ is properly labeled if:
Computing Labeled Orthogonal Drawings
69
(EL) Each edge of Γ is properly labeled (VL) Each vertex of Γ is properly labeled (NI) There is no overlap between a label and any other element of the drawing, except for the intersections implied by labels drawn on edges or vertices.
3
An ILP Model for Labeled Orthogonal Drawings
Let G be a 4-planar graph and let HG be an orthogonal representation of G. Let L and N be a set of labels for the edges and for the vertices of G respectively. In this section we present an ILP model for computing a properly labeled orthogonal grid drawing Γ of (G, L, N ) of minimum total edge length among all drawings with shape defined by HG . The model can be modified to minimize either the width or the height of the drawing; it can also be used as a basic component for an algorithm that computes a drawing of minimum area among those whose shape is defined by HG (see Section 4). In this abstract we only provide the mathematical foundation and the main ideas behind our model. We first introduce the notation that will be used in the model (Subsection 3.1); then we show a characterization of properly labeled orthogonal drawings and describe the idea behind the ILP model (Subsection 3.2). 3.1
Notation
We need a mathematical formalism for translating the conditions given by Definitions 1, 2, and 3 in the ILP model. We introduce first some notation for segments of Γ representing edges of G. Then we focus on labels and consider relations between labels, vertices and edges. The notation is similar to that introduced in previous works on the same topic [11,12]. Let Γ be a (not necessarily properly) labeled orthogonal drawing of (G, L, N ). Let X h = {χh } and X v = {χv } be the set of the maximal horizontal and vertical chains of edge segments of Γ , respectively. Note that a chain may consist of a single point which we treat as a zero-length segment. Let S h be the union of the segments of all the maximal horizontal chains, and let S v be the union of the segments of all the maximal vertical chains. Let S = S h ∪S v . We enumerate the edge segments of Γ by associating each element i of S with a distinct positive integer number, called index of i. We denote by f irst(χh ) and f irst(χv ) the segment of minimal index in χh and χv , respectively. Given a horizontal (resp. vertical) segment i of Γ , we denote by C(i) its y-coordinate (resp. x-coordinate). Each non-zero length segment i ∈ S is bounded by two maximal chains orthogonal to i denoted by sup(i) and inf (i) with C(f irst(sup(i))) > C(f irst(inf (i))). The length of a segment i is given by C(f irst(sup(i))) − C(f irst(inf (i))). Each vertex u ∈ V belongs to a unique maximal horizontal chain, χh (u) and to a unique maximal vertical chain, χv (u). Let Cx (u) = C(f irst(χv (u))) and Cy (u) = C(f irst(χh (u))) denote the x-coordinate and the y-coordinate of vertex u, respectively.
70
Carla Binucci et al.
Let λ ∈ L be an edge-label associated with an edge e of G. Label λ can be drawn on any of the segments representing e. S(λ) denotes the set of segments of e and S(L) is the set of all candidate segments for edge-labels, i.e. S(L) = ∪ S(λ). We say that λ overlaps a segment i ∈ S(λ) if the intersection between λ∈L
i and one of the two sides of λ parallel to i is not empty. Note that if λ is drawn on i then λ overlaps i (see (EL2) in Definition 1). However, if λ overlaps i but the drawing is not properly labeled, then λ may be not drawn on i. For each edge-label λ and for each edge segment i ∈ S(λ), we define a 4i,λ , σpi,λ , σPi,λ } of segments. Roughly, the elements of Σ i,λ tuple Σ i,λ = {σoi,λ , σO describe the position of the sides of the rectangle representing λ with respect to i. The elements of Σ i,λ are defined as follows (in our notation o, O stand for “orthogonal” and p, P stand for “parallel”): i,λ are the sides of λ orthogonal to i; σpi,λ and – if λ overlaps i, then σoi,λ and σO i,λ i,λ ) > C(σoi,λ ) and C(σPi,λ ) > σP are the sides of λ parallel to i. Also, C(σO C(σpi,λ ). i,λ – if λ does not overlap i, then σoi,λ = σO = σpi,λ = σPi,λ are zero-length segi,λ i,λ ments, C(σP ) = C(σpi,λ ) = C(i), and C(σO ) = C(σoi,λ ) = C(f irst(sup(i))).
We also define Σ L =
∪
i∈S(L)
Σ i,λ .
Similar definitions are given for vertex-labels. Given a vertex v ∈ Γ and its vertex-label ν ∈ N , let S(ν) be the set of edge segments incident on v. Let ν , σpν , σPν } be the 4-tuple of label segments introduced to represent Σ ν = {σoν , σO ν ν on Γ , according to the following convention: σoν and σO are vertical; σpν and σPν ν ν ν ν are horizontal; C(σO ) > C(σo ) and C(σP ) > C(σp ). We define Σ N = ∪ Σ ν . ν∈N
Finally, we need a notation for defining notions like “top”, “bottom”, “left” and “right” to express constraints that avoid intersection between our geometric objects. For an edge-label λ ∈ L, we define a 4-tuple t(λ), b(λ), l(λ), r(λ) where t(λ) is the top-most horizontal side of the rectangle representing λ, b(λ) is the bottom-most, l(λ) is the left-most vertical side, and r(λ) is the right-most. Similar definition for a vertex-label ν ∈ N and corresponding t(ν), b(ν), l(ν), r(ν). For a segment i ∈ S, if i ∈ S h then t(i) = b(i) = i, l(i) = inf (i), r(i) = sup(i); else, if i ∈ S v then t(i) = sup(i), b(i) = inf (i), l(i) = r(i) = i. 3.2
The ILP Model
We provide six properties which translate the definition of properly labeled orthogonal grid drawing by using the notation of Subsection 3.1. The constraints of the ILP model translate each property into a set of linear inequalities and integrality constraints. We use the notion of signed distance δ. For each ordered pair of parallel segments (i, j) in S ∪ Σ L ∪ Σ N let δ(i, j) = C(i) − C(j). Note that, δ(i, j) = −δ(j, i). The six properties are as follows. (PLD1) For each λ ∈ L, there exists exactly one triplet (λ, i, z) (λ ∈ L, i ∈ S(λ), z ∈ {p, P }) such that:
Computing Labeled Orthogonal Drawings
71
i,λ – If i ∈ S(λ) ∩ S v then δ(i, σzi,λ ) = w(λ) and δ(σO , σoi,λ ) = h(λ). i,λ – If i ∈ S(λ) ∩ S h then δ(i, σzi,λ ) = h(λ) and δ(σO , σoi,λ ) = w(λ). We call such a triplet the position of λ. i,λ (PLD2) If i is the segment of the position of λ, then C(f irst(sup(i))) > C(σO ) i,λ and C(f irst(inf (i))) < C(σo ). Also, ∀i ∈ S, C (f irst(sup(i))) − C (f irst(inf (i))) > 0. ν , σoν ) = (PLD3) Let ν ∈ N be the label associated with vertex v ∈ V , then δ(σO ν ν w(ν) and δ(σP , σp ) = h(ν). (PLD4) Let ν ∈ N be the label associated with vertex v ∈ V , then 0 ≤ Cx (v) − C(σoν ) ≤ w(ν) e 0 ≤ Cy (v) − C(σpν ) ≤ h(ν). (PLD5) Let α , β be two elements of S ∪ L ∪ N . At least one of the following conditions is verified: (1) δ (b(β), t(α)) > 0. (2) δ (l(β), r(α)) > 0. (3) δ (b(α), t(β)) > 0. (4) δ (l(α), r(β)) > 0. (5) α is an edge segment and β is a label drawn on α. (6) α is an edge segment incident on a vertex v, and β is the label associated with v. (PLD6) All vertices and bends have integer coordinates. Theorem 1. Let G be a 4-planar graph, L be a set of labels for the edges of G, and N be a set of labels for the vertices of G. A labeled orthogonal grid drawing Γ of (G, L, N ) is properly labeled if and only if Properties (PLD1) - (PLD6) hold. Based on Theorem 1, an ILP model that minimizes the total edge length has the following objective function M in C (f irst(sup(i))) − C (f irst(inf (i))) i∈S
and about fifty groups of constraints which implement Properties (PLD1) (PLD6) (for details see the manuscript at [1]). In the implementation of the ILP problem we can omit the integrality constraints on the coordinates of vertices and bends, which improves the efficiency of the computations. With a technique similar to that presented in [12], it can be proved that the solutions of the resulting MILP problem are always grid drawings. The total number of variables and inequalities of the ILP model is O((n + b)2 ) where n and b are the number of vertices and bends of Γ , respectively. We remark that it is easy to modify the model in order to minimize the width or the height of the drawing. We denote by wΓ and hΓ the width and the height of the bounding box of Γ , expressed in terms of grid points. The model for width minimization is obtained by using the objective function M in(wΓ ) and by adding the following constraints: hmax > C(i) hmin ≤ C(i) ∀i ∈ S h , wmax > C(i) wmin ≤ C(i) ∀i ∈ S v , hΓ = hmax − hmin , wΓ = wmax − wmin .
72
4
Carla Binucci et al.
Optimizing the Area
In order to compute a labeled drawing of minimum area we exploit the ILP model of the previous section. Namely we set up a new objective function: M in(wΓ + 1 Mh · hΓ ) and add a new constraint hΓ < hm where Mh is an upper bound of the height of the drawing with optimal area. This corresponds to computing a drawing Γ with height no greater than Mh + 1 with minimum height among all drawings of minimum width. The algorithm iteratively searches for a new drawing with the same properties as Γ and lower height. The algorithm stops when the search fails. The idea relies on the fact that the minimum area drawing belongs to the set wΓ , where Γ of Pareto optimal solutions of the multiobjective function M in hΓ is a properly labeled orthogonal grid drawing. Our method returns a subset of this set which the optimal solution belongs to. In the following pseudo-code, Min-Width(hm ) is a subroutine that either returns a properly labeled orthogonal grid drawing with minimum width constrained to hm , if any, or it returns null. Algorithm OptArea Input: A triplet (G, L, N ) and an orthogonal representation HG Output: A properly labeled orthogonal grid drawing Γ opt of (G, L, N ) with minimum area within HG begin hm = Mh + 1 let Γ = Γ opt =Min-Width(hm ) hm = hΓ while (Γ is not null) let Γ =Min-Width(hm ) if (Γ is not null) then if (wΓ opt · hΓ opt > wΓ · hΓ ) then Γ opt = Γ hm = hΓ end Theorem 2. Let G be a 4-planar graph and let HG be an orthogonal representation of G. Let L and N be a set of labels for the edges and for the vertices of G respectively. Algorithm OptArea computes a properly labeled orthogonal grid drawing of (G, L, N ) with minimum area within HG . Since the widths of the drawingsiteratively computed by the algorithm are /w instead of hm = hΓ . We increasing, hm can be updated to wΓopt · hopt Γ Γ experimentally observed that in most cases the number of algorithm iterations reduces significantly. Moreover, the number of ILP solutions required by our algorithm is quite small (5 in the average) and this number does not seem to depend on the number of vertices of the input graph.
Computing Labeled Orthogonal Drawings
5
73
Open Problems
There are several open problems that we plan to investigate in the near future. Some of them are: (i) Refine our ILP model by valid inequalities in order to speed up the solution process. (ii) Extend the ILP model to graphs with high degree vertices. (iii) Design new heuristics for the graph drawing labeling problem.
References 1. C. Binucci, W. Didimo, G. Liotta, and M. Nonato. Computing labeled orthogonal drawings, manuscript: http://www.diei.unipg.it/PAG PERS/binucci/binucci.htm. 2. C. Binucci, W. Didimo, G. Liotta, and M. Nonato. Labeling heuristics for orthogonal drawings. In Symposium on Graph Drawing (GD’01), volume 2265 of LNCS, pages 139–153, 2002. 3. S. Bridgeman, G. D. Battista, W. Didimo, G. Liotta, R. Tamassia, and L. Vismara. Turn-regularity and optimal area drawings of orthogonal representations. Computational Geometry: Theory and Applications, 16:53–93, 2000. 4. R. Castello, R. Milli, and I. Tollis. An algorithmic framework for visualizing statecharts. In Symposium on Graph Drawing (GD’00), volume 1984 of LNCS, pages 139–149, 2001. 5. G. Di Battista, P. Eades, R. Tamassia, and I. G. Tollis. Graph Drawing. Prentice Hall, Upper Saddle River, NJ, 1999. 6. F. Harary. Graph Theory. Addison-Wesley, Reading, MA, 1972. 7. K. G. Kakoulis and I. G. Tollis. An algorithm for labeling edges of hierarchical drawings. In Symposium on Graph Drawing (GD’97), volume 1353 of LNCS, pages 169–180, 1998. 8. K. G. Kakoulis and I. G. Tollis. On the complexity of the edge label placement problem. Computational Geometry: Theory and Applications, 18:1–17, 2001. 9. M. Kaufmann and D. Wagner. Drawing Graphs. Springer Verlag, 2001. 10. G. Klau and P. Mutzel. Optimal labeling of point features in rectangular labeling models. Mathematical Programming, Series B, To appear. 11. G. Klau and P. Mutzel. Combining graph labeling and compaction. In Symposium on Graph Drawing (GD’99), LNCS, pages 27–37, 1999. 12. G. Klau and P. Mutzel. Optimal compaction of orthogonal grid drawings. In Integer Programming and Combinatorial Optimization (IPCO’99), volume 1610 of LNCS, pages 304–319, 1999. 13. G. Klau and P. Mutzel. Optimal labelling of point features in the sliding model. In In Proc. COCOON’00, volume 1858 of LNCS, pages 340–350, 2001. 14. S. Nakano, T. Nishizeki, T. Tokuyama, and S. Watanabe. Labeling points with rectangles of various shape. In Symposium on Graph Drawing (GD’00), volume 1984 of LNCS, pages 91–102, 2001. 15. T. Nishizeki and N. Chiba. Planar Graphs: Theory and Algorithms, volume 32 of Annals of Discrete Mathematics. North-Holland, 1988. 16. M. Patrignani. On the complexity of orthogonal compaction. Computational Geometry: Theory and Applications, 19:47–67, 2001. 17. T. Strijk and A. Wolff. The map labeling bibliography. on-line: http://www.mathinf.uni-greifswald.de/map-labeling/bibliography/.
Computing and Drawing Isomorphic Subgraphs Sabine Bachl1 and Franz-Josef Brandenburg2 1
sd&m AG, Thomas Dehler Str. 27, 81737 M¨ unchen, Germany [email protected] 2 University of Passau, 94030 Passau, Germany [email protected]
Abstract. The isomorphic subgraph problem is finding two disjoint subgraphs of a graph which coincide on at least k edges. Then the graph partitions into a large subgraph, its copy and a remainder. The problem resembles the NP-hard largest common subgraph problem. In [1,2] it has been shown that the isomorphic subgraph problem is NP-hard, even for restricted instances. In this paper we present a greedy heuristic for the approximation of large isomorphic subgraphs and introduce a spring algorithm which preserves isomorphic subgraphs and displays them as copies of each other. The heuristic has been tested extensively on four independent test suites. The drawing algorithm yields nice drawings which cannot be obtained by standard spring algorithms.
1
Introduction
Graph drawing is concerned with the problem of displaying graphs nicely. There is a wide spectrum of approaches and algorithms [4]. Nice drawings help in understanding the structural relation modelled by the graph. Bad drawings are misleading. This has been evaluated by HCI experiments [25,26], which have shown that symmetry is an important factor in the understanding of graph drawings and the underlying relational structure. Drawings of graphs in textbooks [27] and also the winners of the annual Graph Drawing Competitions and the logos of the symposia on Graph Drawing are often symmetric. In [5] symmetry is used for nice drawings without defining nice. Symmetry has two directions: geometric and graph theoretic. A graph has a geometric symmetry, if it has a drawing with a rotational or a reflectional invariant. This has first been studied by Manning [22,23], and is NP-hard for general graphs. For some subclasses of planar graphs there are polynomial time solutions [18,22]. As a pre-requisite such graphs need a non-trivial automorphism. This is the graph theoretic access to symmetry. It is less restrictive than the geometric symmetry, and is isomorphism complete. However, almost all graphs from applications have only a trivial automorphism. Hence, more flexibility is needed, and the notions of geometric symmetry and automorphism must be relaxed and generalized. This is achieved by restricting symmetry to subgraphs only. From another viewpoint there is the cut© operation, which first selects a portion of a graph, then creates a new copy thereof, attaches it to the original graph, M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 74–85, 2002. c Springer-Verlag Berlin Heidelberg 2002
Computing and Drawing Isomorphic Subgraphs
75
and connects the copy and the remainder by some edges. The reverse operation leads to the notion of isomorphic subgraphs, which has been investigated in [1,2]. The isomorphic subgraph problem is finding two large disjoint subgraphs of a given graph, such that one subgraph is a copy of the other. The generalization from graph automorphism to isomorphic subgraphs parallels the generalization from graph isomorphism to largest common subgraph. The difference between these problems lies in the number of input graphs. The coincidence or similarity of the subgraphs is measured in the number of common edges, which must be 100% for the automorphism and isomorphism problems, and which may be less for the more flexible generalizations. A related approach on symmetry by Chen et al. [7] reduces a given graph to a subgraph with a geometric symmetry by node and edge deletions and by edge contractions. The isomorphic subgraph problem and the largest common subgraph problem are NP-hard, even when restricted to forests, connected outerplanar graphs and 2-connected planar graphs [1,2,16]. Both problems are tractable, if the graphs have tree-width k and the graphs and the isomorphic subgraphs are k-connected [6]. In particular, isomorphic subtrees [1,2] and the largest common subtree of two rooted trees can be computed in linear time. For arbitrary graphs the isomorphic subgraph problem seems harder than the largest common subgraph problem. For the largest common subgraph problem we must find a matching between pairs of nodes which induce an isomorphism. For the isomorphic subgraph problem we must first partition the graph into two subgraphs and a remainder and then find the isomorphism preserving matching between the subgraphs. Recall that the graph isomorphism problem can be solved in linear time for almost all graphs [3]. The algorithm uses the degree of the nodes as an invariant and distinguishes nodes by their degree sequences. For subgraph isomorphism Ullmann’s algorithm [31] is well-known and is often used in computational biology for the search of molecular structures. Another method uses Levi’s transformation into a clique problem, which is also used for the largest common subgraph problem [19,20]. Our approach to the computation of large isomorphic subgraphs is a greedy heuristic. In fact, there is a collection of algorithms with different weighting parameters. So we capture both, the partition and the isomorphism problems. Our experiments are directed towards the appropriateness of the approach and the effectiveness of the chosen parameters. The measurements are based on more than 100.000 computations conducted by Bachl for her dissertation [2]. As a second step and an application we present a spring algorithm which preserves isomorphic subgraphs and displays them as copies of each other. The algorithm is an extension of the Fruchterman and Reingold approach [15]. Each node and its copy are treated identically by averaging the forces and moves. An additional force is used to separate the two copies of the subgraphs. With a proper setting of the parameters of the forces this gives rather pleasing pictures.
76
2
Sabine Bachl and Franz-Josef Brandenburg
Isomorphic Subgraphs
We consider undirected graphs G = (V, E) with a set of nodes V and a set of edges E. Edges are denoted by pairs e = (u, v). The set of neighbours of a node v is denoted by N (v). For convenience, we exclude self-loops and multiple edges. In applications graphs are generally attributed graphs with labels at the vertices and at the edges. This is discarded here, although labels may be a great help in the selection and association of nodes and edges for the isomorphic subgraph problem. Definition 1 (node- and edge-induced subgraphs). Let G = (V, E) be a graph and let V ⊆ V and E ⊆ E be subsets of nodes and edges. The nodeinduced subgraph G[V ] = (V , E ) consists of the nodes of V and the edges of E between nodes of V such that E = E ∩ V × V . The edge-induced subgraph G[E ] = (V , E ) consists of the edges of E and the incident nodes V such that V = {u, v ∈ V |(u, v) ∈ E }. An isomorphism between two graphs is a bijection on the sets of nodes that preserves adjacency. A common subgraph of two graphs G1 and G2 is a graph H that is isomorphic to G1 [E1 ] and G2 [E2 ]. More precisely, H is an edge-induced common subgraph of size k, where k = |E1 | is the number of edges. Accordingly, one may consider large node-induced common subgraphs. Definition 2 (isomorphic node-induced subgraph, INS). Instance: A graph G = (V, E) and an integer k. Question: Does G contain two disjoint node-induced common subgraphs H1 and H2 with at least k edges? Definition 3 (isomorphic edge-induced subgraph, IES). Instance: A graph G = (V, E) and an integer k. Question: Does G contain two disjoint edge-induced common subgraphs H1 and H2 with at least k edges? For INS and IES the graph G partitions into H1 , H2 , and a remainder R. Let V, V1 , V2 and VR denote the sets of nodes of G, H1 , H2 and R, respectively. Then V1 ∩ V2 = ∅ and VR contains all nodes from V \ (V1 ∪ V2 ). In the node-induced case, INS, the remainder contains all edges between the nodes of H1 and H2 and the edges with at least one endnode in R. In the edge-induced case, IES, R may also contain some edges between nodes from V1 or from V2 . IES is our most flexible version. Notice that also in the node-induced case the size of the common subgraphs must be measured in terms of the common edges. Otherwise, the problem may become meaningless. As an example consider an n × m grid graph with n, m even. If V1 consists of all even nodes in the odd rows and of all odd nodes in the even rows, and V2 = V \ V1 , then V1 and V2 have maximal size. However, their induced subgraphs are discrete with the empty set of edges.
Computing and Drawing Isomorphic Subgraphs
77
The isomorphic subgraph problems INS and IES have been investigated by Bachl [1,2]. These problems are NP-hard, in general. This has been shown by a directed reduction of 3-PARTITION. At present, there are no direct reductions between the isomorphic subgraph and the largest common subgraph problems, although these problems look similar. When restricted to trees, the isomorphic subtree problem is solvable in linear time. However, the isomorphic subtree problem requires trees as common subgraphs of a tree. This is not the restriction of the isomorphic subgraph problem to a tree. If the isomorphic subgraphs of a tree may be disconnected, then these instances of INS and IES become NP-hard. These results are summarized in Theorem 1. In [7] there are quite similar results for a related problem. Theorem 1. The isomorphic subgraph problems INS and IES are NP-hard. These problems remain NP-hard, if the graph G is – a tree and the subgraphs are forests [6] – outerplanar and the subgraphs are connected [1,2] – 2-connected outerplanar and the subgraphs are not 2-connected [6].
3
Computing Isomorphic Subgraphs
The isomorphic subgraph problem is NP-hard almost everywhere. The size of the largest isomorphic subgraphs can be regarded as a measure for the self-similarity of a graph in the same way as the size of the largest common subgraph is regarded as a measure for the similarity of two graphs. The isomorphic subgraph problem is different from the isomorphism, subgraph isomorphism and largest common subgraph problems. There is only a single graph, and it is a major task to locate and separate the two isomorphic subgraphs. Moreover, graph invariants such as the degree and adjacencies of isomorphic nodes are not necessarily preserved, since edges may end in the remainder or in the other subgraph or may be discarded, if they belong to only one of the edge-induced isomorphic subgraphs. Our approach is a greedy algorithm. The core are weighted graph parameters. If the algorithm has identified a pair of nodes as a copy of each other it finds new pairs among their neighbours. The correspondence between the neighbours is computed by a weighted bipartite matching. Let G = (V, E) be the given graph, and suppose that the subgraphs H1 and H2 have been computed as copies of each other. Consider a pair of nodes (v1 , v2 ) which are copies of each other. For each pair the following graph parameters are taken into account: – – – – – –
w1 w2 w3 w4 w5 w6
= degree(v1 ) + degree(v2 ) = |degree(v1 ) − degree(v2 )| = the number of common neighbours = the number of new neighbours of v1 and v2 which are not in H1 ∪ H2 = the graph-theoretical distance between v1 and v2 = the number of new isomorphic edges in (H1 ∪ v1 , H2 ∪ v2 ).
78
Sabine Bachl and Franz-Josef Brandenburg initialize(P ); while (P not empty) do (v1 , v2 ) = next(P); delete (v1 , v2 ) from P ; N1 = new neighbours of v1 ; N2 = new neighbours of v2 ; M = optimal weighted bipartite matching over N1 and N2 ; forall edges(u1 , u2 ) of M ) do if (G[V1 ∪ {u1 }] is isomorphic to G[V2 ∪ {u2 }]) then P = P ∪ {(u1 , u2 )}; V1 = V1 ∪ {u1 }; V2 = V2 ∪ {u2 }; Fig. 1. Heuristic for isomorphic node-induced subgraphs.
These parameters can be combined arbitrarily to a weight W (v1 , v2 ). The weights w2 and w3 are taken negative. Let w0 = wi . The algorithm iteratively selects a pair of nodes (v1 , v2 ) at random, which are identified by the isomorphism, and then matches their new neighbours in the bipartite graph with the sets of nodes N (v1 ) and N (v2 ). For each pair of neighbours (u1 , u2 ) let W (u1 , u2 ) be the weight of the edge (u1 , u2 ). Then compute an optimal weighted bipartite matching. The pairs of matched nodes are new pairs of identified nodes in V1 and V2 , provided that they pass the isomorphism test. The optimal weighted bipartite matching is computed by the Kuhn-Munkres algorithm (Hungarian method) [8], with a running time of O(n2 m) in our implementation. This can be improved, but it does not really matter, since these graphs are generally small. Figure 1 shows the algorithm for the computation of node-induced subgraphs. P consists of the pairs of nodes which have already been identified by the isomorphism. The isomorphism test is only local, since each time only one new node is appended to each subgraph. The matching edges are sorted by decreasing weights and are checked in this order. In the node-induced case, a matched pair of neighbours (w1 , w2 ) is skipped, if their addition to the intermediate subgraphs does not yield isomorphic subgraphs. In the case of edge-induced isomorphic subgraphs, the isomorphism test adds all pairs of matched nodes and all common edges. For each pair of starting nodes the algorithm runs in linear time except for the Kuhn-Munkres algorithm, which is used as a subroutine on bipartite graphs, whose nodes are neighbours of single nodes. In our experiments a single parameter wi or the sum w0 is taken as a weight. The unnormalized sum worked out because the parameters had similar values. The initialization of the algorithm is a critical point. What is the best pair of nodes to start with? We ran our experiments with three cases: – repeatedly for all O(n2 ) pairs of nodes – with the best pair of nodes according to the weighting function and – repeatedly for all pairs of nodes, whose weighting function is at least 90% of the weight of the best pair.
Computing and Drawing Isomorphic Subgraphs
79
With repetitions the largest subgraphs are kept. Clearly, the all pairs version has a O(n2 ) higher running time than the single pair version. The 90% best weighted pairs is a good compromise between the ellapsed time and the size of the computed subgraphs. The experiments were performed on four independent test suites [24]. – – – –
2215 random graphs with a maximum of 10 nodes and 14 edges 243 graphs generated by hand and 1464 graphs selected from the Roma graph library [28] 740 dense graphs.
These graphs where chosen by the following reasoning. For each graph from the first test suite the optimal result has been computed by an exhaustive search algorithm. This is doable only for small graphs. The graphs from the second test suite were constructed by taking a single graph from the Roma library, making a copy and adding some nodes and edges at random. The threshold is the size of the original graph. It is a good bound for the size of the edge-induced isomorphic subgraphs. The goal is to detect and reconstruct the original graph. For INS, the threshold is a weaker estimate because the few added edges may destroy node-induced subgraph isomorphism. Next, 1464 graphs from the Roma graph library were selected and inspected for isomorphic subgraphs with 10 to 60 nodes. These graphs are sparse with |E| ∼ 1.3|V |. The experiments of the first three test suites give a uniform picture. The heuristic finds the optimal subgraphs in the first test suite. In the second test suite the original graphs and their copies are detected almost completely when starting from the 90% best weighted pairs of nodes, see Figure 2. The weights w2 , w3 and w6 produce the best results. The total running time is in proportion to the number of pairs of starting nodes. For the 90% best weighted pairs of nodes it is less than two seconds for the largest graphs with 100 nodes and w0 , w1 , w4 and w5 , 30 seconds for w2 and 100 seconds for w3 and w6 , since in the latter cases the algorithm iterates over many to almost all pairs of starting nodes. In summary, the difference of degree w2 gives the best performance. For the third test suite the heuristic detects very large isomorphic subgraphs. Almost all nodes are contained in one of the node- or edge-induced isomorphic subgraphs which are almost trees. This surprising result is due to the sparsity of the test graphs. Again weight w2 performs best. [2] has the complete list of test results with more than 100 diagrams. Finally, we ran the heuristic on dense graphs with the 90% best weighted pairs of starting nodes. The dense graphs were generated at random. They have 10, 15, . . . , 50 nodes and 25, 50, . . . , 0.4 · n2 edges. For IES the heuristic finds isomorphic subgraphs which together contain almost all nodes and more than 1/3 of the edges. For INS each subgraph contains about 1/4 of the nodes and 1/20 of the edges, see Figure 3.
80
Sabine Bachl and Franz-Josef Brandenburg
threshold all weights (w0) degree (w1) difference of degree (w2) common neighbours (w3) new neighbours (w4) distance (w5) isomorphic edges (w6)
number of nodes in every subgraph
50
40
30
20
10 20
30
40
50 60 70 number of nodes in the graph
80
90
100
Fig. 2. Isomorphic edge-induced subgraphs of the second test suite for the 90% best weighted pairs of starting nodes.
These results are plausible, since for IES the heuristic adds pairs of matching nodes and ignores only isomorphism violating edges. For INS the isomorphic subgraphs turn out to be sparse.
16
all weights (w0) degree (w1) difference of degree (w2) common neighbours (w3) new neighbours (w4) distance (w5) isomorphic edges (w6)
number of nodes in every subgraph
14 12 10 8 6 4 2 10
15
20
25
30
35
40
45
number of nodes in the graph
Fig. 3. Isomorphic node-induced subgraphs of dense graphs
50
Computing and Drawing Isomorphic Subgraphs
81
The running time of one subgraph isomorphism detection from a single pair of nodes takes less than one second for our largest graphs. The total running time multiplies with the number of pairs of starting nodes, and is between two and 100 seconds for the largest graphs.
4
Drawing Isomorphic Subgraphs
In this section, we consider graphs with a pair of isomorphic subgraphs and their drawings. Sometimes, classical graph drawing algorithms preserve isomorphic subgraphs and display them symmetrically. The Reingold and Tilford algorithm [4,29] computes the tree drawing bottom-up, and so preserves isomorphic subtrees rooted at distinct nodes. It is readily seen that this is no more true for arbitrary subtrees. To stress this point, Supowit and Reingold [30] have introduced the notion of eumorphous tree drawings. However, eumorphous tree drawings of minimal width and integral coordinates are NP-hard. Also radial tree of ordered or embedded trees draw isomorphic rooted subtrees the same. The radial tree algorithm of Eades [10] squeezes a subtree into a sector with a wedge in proportion to the number of the leaves of the subtree. Hence, isomorphic subtrees get the same wedge and are drawn identically up to translation and rotation. It is well-known that spring algorithms tend to display symmetric structures. This comes from the nature of spring methods, and has been emphasized by Eades and Lin [12]. For special classes of planar graphs there are efficient algorithms for the detection and display of symmetries of the whole graphs [18]. For hierarchical graphs (DAGs) symmetry preserving drawing algorithms are unknown. This can be resolved by a three-phase method, which is generally applicable in this framework. If a graph G is partitioned into two node-induced isomorphic subgraphs H1 and H2 and a remainder R, first construct a drawing of H1 and take a copy as a drawing of H2 . Then H1 and H2 are replaced by two large nodes and the remainder together with the two large nodes is drawn by some algorithm in phase two. This algorithm must take the area of the large nodes into account. And it should take care of the edges entering the graphs H1 and H2 . Finally, the drawings of H1 and H2 are inserted at the large nodes and the edges to the nodes of H1 and H2 are locally routed on the area of the large nodes. The drawback of this approach is the third phase, and the difficulties in routing edges to the nodes of H1 and H2 . This may lead to bad drawings with node-edge crossings, parallel edges, and the destruction of symmetry. The alternative to the three-phase method is an integrated approach. Here the preservation of isomorphic subgraphs is built into the drawing algorithms. As said before, this goes automatically for some tree drawing algorithms, and is solved here for a spring embedder. Spring algorithms have been introduced to graph drawing by Eades [11]. Fruchterman and Reingold [15] have simplifed the forces to improve the running time, which is a critical factor for spring algorithms. Our algorithm is based on the advanced USE algorithm [13], which
82
Sabine Bachl and Franz-Josef Brandenburg
is included in the Graphlet system and is an extension of GEM [14]. In particular, USE supports individual distance parameters between any pair of nodes. Other spring algorithms allow only a uniform distance. Our goal are identical drawings of isomorphic subgraphs. The input is an undirected graph G and two isomorphic subgraphs H1 and H2 of G together with the isomorphism φ from the nodes of H1 to the nodes of H2 . If v2 = φ(v1 ) then v2 is the copy of v1 . In the initial phase, the nodes of H1 and H2 are placed identically on grid points (up to a translation). Thereafter the spring algorithm averages the forces imposed on each node and its copy and moves both simultaneously by the same vector. This guarantees that H1 and H2 are drawn identically. Large isomorphic subgraph should be emphasized. They should be separated from each other and distinguished from the remainder. The distinction can be achieved by a node colouring. This does not help, if there is no geometric separation between H1 and H2 , which can be enforced by imposing a stronger repelling force between the nodes of H1 and H2 . We use three distance parameters, k1 for the inner subgraph distance, k2 between H1 and H2 , and k3 otherwise, which k1 < k3 < k2 . Additionaly, H1 and H2 are moved by move subgraph(H, f ). The force f is the sum of the forces acting on the subgraph H and an extra repelling force between the barycenters of H1 and H2 . In a round, all nodes of G are selected in random order and are moved according to the emanating forces. The algorithm stops, if a certain termination criterion is accomplished. This is a complex formula with a cooling schedule given by the USE algorithm, see [13,14]. The extra effort for the computation of forces between nodes and their copies leads to a slow down of the USE algorithm by a factor of about 1.5, if the symmetry of isomorphic subgraphs is enforced.
Input: a graph G and its partition into two isomorphic subgraphs H1 and H2 , and a remainder R, and the isomorphism φ : H1 → H2 Initial placement(H1 , H2 ) while (termination is not yet accomplished) { forall nodes at random (v, V (G)) { f = force(v); if (v ∈ V (H1 ) ∪ V (H2 )) then f = force(φ(v)); f = f +f ; 2 move node(φ[v], f ); move node(v, f ); } move subgraph(H1 , f1 ); move subgraph(H2 , f2 ); } Fig. 4. Isomorphism keeping spring embedder.
Computing and Drawing Isomorphic Subgraphs
Fig. 5. 4 × 4-grid.
83
Fig. 6. Complete graph with 10 nodes.
Figure 4 describes the main steps of the isomorphism preserving spring algorithm. For each node v, force(v) is the sum of the forces acting on v and move node applies the computed forces to a single node. The examples shown below are computed by the heuristic and drawn by the spring algorithm. The most exciting drawings of graphs come from the second
Fig. 7. Graph of test suite 2. The original graph with 30 vertices and 35 edges was copied and then 2 nodes and 4 edges were added. Our algorithm has re-computed the isomorphic edge-induced subgraphs. The open nodes belong to the remainder.
84
Sabine Bachl and Franz-Josef Brandenburg
Fig. 8. Graph (number 06549 in [28]) of test suite 3 with 45 nodes, and the computed isomorphic edge-induced subgraphs.
and third test suites, see Figures 7 and 8. Many more drawings can be found in [2] or by using the algorithm in Graphlet. The algorithm produces many nice drawings. However there is space for improvements. In Figure 5, for example, if the left subgraph were reflected the grid were unfolded. The isomorphic subgraphs must therefore be drawn identically up to translation and reflection. This is an extension of isomorphic subgraphs.
References 1. S. Bachl. Isomorphic subgraphs. Proc. Graph Drawing’99, LNCS 1731 (1999), 286296. 2. S. Bachl. Erkennung isomorpher Subgraphen und deren Anwendung beim Zeichnen von Graphen. Dissertation, University of Passau, (2001), http://elib.ub.unipassau.de/index.html. 3. L. Babai and L.Kucera. Canonical labelling of graphs in average linear time. Proc. 20th IEEE FOCS (1979), 39–46. 4. G. Di Battista, P. Eades, R. Tamassia, and I.G. Tollis. Graph Drawing: Algorithms for the Visualization of Graphs. Prentice Hall, (1999). 5. T. Biedl, J. Marks, K. Ryall, and S. Whitesides. Graph multidrawing: Finding nice drawings without defining nice. Proc. Graph Drawing’98, LNCS 1547 (1998), 347-355. 6. F.J. Brandenburg. Pattern matching problems in graphs. Unpublished manuscript, (2000). 7. H.-L. Chen, H.-I. Lu and H.-C. Yen. On maximum symmetric subgraphs. Proc. Graph Drawing’00, LNCS 1984 (2001), 372–383. 8. J. Clark and D. Holton. Graphentheorie - Grundlagen und Anwendungen. Spektrum Akademischer Verlag, (1991). 9. D. Corneil and D. Kirkpatrick. A theoretical analysis of various heuristics for the graph isomorphism problem. SIAM J. Comput. 9, (1980), 281–297. 10. P. Eades. Drawing free trees. Bulletin of the Institute for Combinatorics and its Applications 5, (1992), 10–36.
Computing and Drawing Isomorphic Subgraphs
85
11. P. Eades. A heuristic for graph drawing. Cong. Numer. 42, (1984), 149–160. 12. P. Eades and X. Lin. Spring algorithms and symmetry. Theoret. Comput. Sci. 240 (2000), 379–405. 13. M. Forster. Zeichnen ungerichteter Graphen mit gegebenen Knotengr¨ oßen durch ein Springembedder-Verfahren. Diplomarbeit, Universit¨ at Passau, (1999). 14. A. Frick, A. Ludwig and H. Mehldau. A fast adaptive layout algorithm for undirected graphs. Proc. Graph Drawing’94, LNCS 894 (1995), 388–403. 15. T. Fruchterman and E.M. Reingold. Graph drawing by force-directed placement. Software – Practice and Experience 21, (1991), 1129–1164. 16. M.R. Garey and D.S. Johnson. Computers and Intractability: A Guide to the Theory of NP-Completeness. W.H. Freeman, San Francisco, (1979). 17. A. Gupta and N. Nishimura. The complexity of subgraph isomorphism for classes of partial k-trees. Theoret. Comput. Sci. 164, (1996), 287–298. 18. S.-H. Hong, B. McKay and P. Eades. Symmetric drawings of triconnected planar graphs. Proc. 13 ACM-SIAM Symposium on Discrete Algorithms (2002), 356–365. 19. I. Koch. Enumerating all connected maximal common subgraphs in two graphs. Theoret. Comput. Sci. 250, (2001), 1–30. 20. G. Levi. A note on the derivation of maximal common subgraphs of two directed or undirected graphs. Calcolo 9, (1972), 341–352. 21. A. Lubiw. Some NP-complete problems similar to graph isomorphism. SIAM J. Comput. 10, (1981), 11–21. 22. J. Manning. Geometric symmetry in graphs. Ph.D. thesis, Purdue Univ., (1990). 23. J. Manning. Computational complexity of geometric symmetry detection in graphs. LNCS 507, (1990), 1–7. 24. Passau Test Suite. http://www.infosun.uni-passau.de/br/isosubgraph. 25. H. Purchase, R. Cohen and M. James. Validating graph drawing aesthetics. Proc. Graph Drawing’95, LNCS 1027 (1996), 435–446. 26. H. Purchase. Which aesthetic has the greatest effect on human understanding. Proc. Graph Drawing’97, LNCS 1353 (1997), 248–261. 27. R.C. Read and R.J. Wilson An Atlas of Graphs. Clarendon Press Oxford (1998) 28. Roma Graph Library. http://www.inf.uniroma3.it/people/gdb/wp12/LOG.html. 29. E.M. Reingold and J.S. Tilford. Tidier drawings of trees. IEEE Trans. SE 7, (1981), 223-228. 30. K.J. Supowit and E.M. Reingold. The complexity of drawing trees nicely. Acta Informatica 18, (1983), 377-392. 31. J.R. Ullmann. An algorithm for subgraph isomorphism. J. Assoc. Comput. Mach. 16, (1970), 31–42.
A Branch-and-Cut Approach to the Directed Acyclic Graph Layering Problem Patrick Healy and Nikola S. Nikolov CSIS Department, University of Limerick, Limerick, Republic of Ireland {patrick.healy,nikola.nikolov}@ul.ie
Abstract. We consider the problem of layering Directed Acyclic Graphs, an N P-hard problem. We show that some useful variants of the problem are also N P-hard. We provide an Integer Linear Programming formulation of a generalization of the standard problem and discuss how a branch-and-bound algorithm could be improved upon with cutting planes. We then describe a separation algorithm for two classes of valid inequalities that we have identified – one of which is facet-defining – and discuss their efficacy.
1
Introduction
Drawing graphs in a hierarchical manner is a well-established style of presentation of relationships between entities, and in many disciplines it is the expected format. The most widely used method of drawing graphs hierarchically is, perhaps, the Sugiyama method [6]. Conceptually, the entities (nodes) should be drawn on a series of levels such that no two nodes that are related should be situated on the same layer and every entity relation (represented by a directed edge) should respect the direction of the relation by pointing in a uniform direction. To achieve this, the three main steps of the method are a) partitioning the node set into edgewise independent subsets so that all inter-partition edges can point the same direction; b) ordering the vertices of each subset in order to minimize edge crossings; and, c) determining a location on the level assigned to each vertex that maximizes clarity of the drawing. In this paper we focus on the first step. This is called the layering problem since the objective is to assign each node of the diagram to a (usually horizontal) layer such that all of the directions of the edges point in the same direction and thus preclude assigning to the same layer a pair of vertices that are related viz. connected by an edge. Currently three algorithms, Longest Path, Coffman-Graham and Gansner et al.’s, predominate for layering a graph. Healy and Nikolov [4] performed an experimental study of these three algorithms. Although the algorithms are fundamentally incomparable since they layer according to different objectives, Gans was found to produce the best layerings judged by a variety of measurements in this study. It is our contention that the algorithms currently in use are inadequate because of the simplified model that they assume, and evidence we have gathered M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 98–109, 2002. c Springer-Verlag Berlin Heidelberg 2002
Branch-and-Cut Approach to the Directed Acyclic Graph Layering Problem
99
on the algorithms’ performance supports this view [4]. In the same paper we proposed a polyhedral approach to the layering problem that reflected more of the problem’s complexities and we defined the graph layering polytope. We also proposed a system ULair which used the ILP solver of CPLEX 7.0. ULair in that context was used as a reference point for the other algorithms’ performance and its running time was not a central focus. In this paper we present a new branch-and-cut version of ULair which contains a cutting plane algorithm for generating cuts based on valid inequalities of the graph layering polytope. The next section describes the layering problem formally. In Section 3 we introduce an Integer Linear Programming model and discuss capacity-related facets of the graph layering polytope and a cutting-plane algorithm. Section 4 describes the experiments that we conducted to evaluate the performance of the branch-and-cut version of ULair. We make some concluding remarks in Section 5.
2
The Layering Problem
Consider a directed acyclic graph (DAG) G = (V, E) and a function w : V → Q+ which represents the widths of the smallest enclosing rectangles of the nodes of G. We layer a graph as follows. Partition the node set V of G into χ ≥ 1 layers V1 , V2 , . . . , Vχ , such that if (u, v) ∈ E with u ∈ Vj and v ∈ Vi then i < j. Then for each edge e = (u, v) ∈ E i+2 j−1 to with u ∈ Vj and v ∈ Vi add so-called dummy nodes di+1 e , de , . . . , de layers Vi+1 , Vi+2 , . . . , Vj−1 respectively, replacing edge (u, v) by the directed path (u, dj−1 , . . . , di+1 e e , v). The dummy nodes are normally not presented in the final drawing; their introduction is required by the algorithms applied at the next phases of the Sugiyama’s algorithmic framework. We assign width wed ∈ Q to all the dummy nodes contributed by edge e by extending the node width function w over the dummy nodes. We also consider wed as the width of edge e. Such a partitioning of the nodes of G is known as a layering of G and we denote it by L(G). A DAG with a layering is called a layered digraph. An algorithm that partitions the DAG node set into layers is called a layering algorithm. Once we have separated the nodes of G into layers the width and the height of the final drawing can be approximated by the width and the height of the layering. The height of a layering is the number of layers. We define the layering width as follows. Definition 1. The width of layer Vi is wi = v∈Vi w(v) and the width of layering L(G) is w = max{wi : i = 1, . . . , χ}. Usually, the width of a layering is defined as the maximum number of nodes in a layer [3,1]. Our definition generalizes this by allowing variable node and edge widths but if all the real nodes have unit width, and the edges (i.e. the dummy nodes) have zero width, then our definition for layering width is identical to the conventional one. We call the problem of finding a layering of a DAG with bounded sum of edge spans and bounded dimensions DAG layering. Considered as a decision problem, DAG layering can be formulated as follows.
100
Patrick Healy and Nikola S. Nikolov
DAG Layering Instance: A DAG G(V, E) with a width function w : V ∪ E → Q+ , and three numbers H, S ∈ N, W ∈ Q+ . Question: Is there a layering of G with sum of edge spans at most S, height at most H and width at most W ? DAG layering is N P-complete since the simpler decision problem when edge spans are ignored is N P-complete [3]. There is no known exact algorithm for solving DAG layering. If the widths of edges – and thus, the dummy nodes they generate – are significant then DAG layering becomes even more difficult [2]. The three layering algorithms referred to earlier solve DAG layering approximately by considering the DAG layering constraints only partially. DAG layering remains N P-complete when the relative order of two independent nodes (i.e. nodes without a direct path between them) is given. We consider the following two problems – to which partial solutions will be used later in our cutting-plane generation algorithm. Same-Layer DAG Layering. Instance: A DAG G(V, E) with a width function w : V ∪ E → Q+ , three numbers H, S ∈ N, W ∈ Q+ , and two independent nodes u, v ∈ V . Question: Is there a layering of G on at most H layers, with total sum of edge spans at most S, of width at most W , and with node u placed in the same layer as node v? Theorem 1. Same-layer DAG layering is N P-complete.1 Above DAG Layering. Instance: A DAG G(V, E) with a width function w : V ∪ E → Q+ , and three numbers H, S ∈ N, W ∈ Q+ , and two independent nodes u, v ∈ V . Question: Is there a layering of G on at most H layers, with total sum of edge spans at most S, of width at most W , and with node u placed in a layer above node v, i.e. if u ∈ Vj and v ∈ Vi then i < j? Theorem 2. Above DAG layering is N P-complete.
3
An ILP Model of the DAG Layering Problem
A starting point of our polyhedral approach to DAG layering as an optimization problem is the following ILP model – which we call WHS-Layering (W for width, H for height and S for spans).
1
Proofs of theorems not included here are available upon request.
Branch-and-Cut Approach to the Directed Acyclic Graph Layering Problem
3.1
101
The ILP Model WHS-Layering
Consider a DAG G = (V, E) and let x be the incidence vector of a subset of V × {1, . . . , H} then WHS-Layering is the following ILP model. ρ(u) ρ(v) min (1) kxuk − kxvk (u,v)∈E
k=ϕ(u)
k=ϕ(v)
ρ(v)
Subject to
xvk = 1
∀v ∈ V
(2)
xvi ≤ 1
∀k ∈ L(u) ∩ L(v), ∀(u, v) ∈ E
(3)
∀k = 1, . . . , H
(4)
∀k = 1, . . . , π(G)
(5)
k=ϕ(v) k
ρ(v)
xui +
i=ϕ(u)
v∈Vk∗
i=k
wv xvk + Dk ≤ W
xvk ≥ 1
v∈Vk∗
all xvk are binaries In this formulation W and H are upper bounds on the width and height of the layering respectively; π(G) is the number of nodes in the longest directed path in G; ϕ(v) and ρ(v) are respectively the lowest and the highest layer where node v can be placed in; L(v) = {ϕ(v), . . . , ρ(v)} and Vk∗ = {v ∈ V : ϕ(v) ≤ k ≤ ρ(v)}. The objective minimises the sum of edge spans, i.e. the number of dummy nodes. Equalities (2) force each node to be placed in exactly one layer; we call them assignment constraints. Inequalities (3) force each edge to point downwards; thus we call them direction constraints. Inequalities (5), called fixing constraints, introduce the additional requirement of having at least one node in the first π(G) layers. This reduces the number of identical layerings (but shifted vertically) if the height of the solution is less than the upper bound H. Inequalities (4), called capacity constraints, restrict the width of each layer (including the dummy nodes) to be less than or equal to W : the first term on the left hand side represents the contribution of the real nodes to the width of layer Vk while Dk represents the contribution of the dummy nodes. We set ρ(u) ρ(v) wed xul − xvl Dk = e=(u,v)∈E
l>k
l≥k
where wed is the width of the dummy nodes along edge e. The difference of the two sums in the parentheses is 1 if edge e = (u, v) spans layer Vk and 0 otherwise. We refer to the constraint polytope of WHS-Layering as the DAG layering polytope. To study its properties we relax it by allowing layerings of subgraphs
102
Patrick Healy and Nikola S. Nikolov v0
v1
v1
v1
v2
v2
v4
v3
v0
v5 v3
v6
v7
(a) A random drawing of the DAG G2
v6
v0
k
v3
v4
v7
(b) Node v2 placed above layer Vk
v7
v6
v2
k
v4 v5
(c) Node v2 placed below layer Vk
Fig. 1. Node v1 placed above node v0 in a layering of the DAG G2
of the DAG G. We do this by replacing equalities (2) by “less-than-or-equal” inequalities. In the sections below when we refer to the DAG layering polytope we mean its relaxed version. 3.2
Generation of Valid Inequalities Related to the Layering Width
The upper bound W imposed on the width of the layering gives rise to a set of capacity-related valid inequalities for the DAG layering polytope. In previous work we identified strong relative ordering valid inequalities based on pairs of independent nodes, one of which had to be placed above the other; we called these strong RO inequalities [4]. In this section we show how, on the basis of heuristic algorithms which solve Same-layer DAG layering and Above DAG layering, we can strengthen them. Before we proceed we show an example, which gives an insight on our approach to finding capacity-related valid inequalities of the DAG Layering polytope. Example 1. Let G2 be the DAG depicted in Figure 1(a). Consider the problem of layering G2 of width at most 4 assuming all the nodes (including the dummy nodes) have a unit width. The drawings in Figure 1(b) and (c) show how placing node v1 in a layer above node v0 will affect the width of the layering. Let v0 be placed in layer Vk . Then its successors v3 , v4 , v6 and v7 must be placed in the layers below Vk . Thus the edges connecting v1 to them will cause three dummy nodes in layer vk (the dummy nodes are depicted by small rectangles in Figure 1(b) and (c)). Since node v2 is neither a predecessor nor a successor of v0 and v1 , placing v1 above v0 does not determine the relative position of v2 to layer Vk . There are three different cases which we should consider. The first case is when v2 is placed in layer Vk . Then layer Vk will have width at least 5, which makes this case impossible. Second, let v2 be placed above layer Vk . This case is depicted in Figure 1(b). Then edge (v2 , v6 ) will contribute another dummy node to layer Vk and this way making this case also impossible. The last alternative is to have node v2 placed below layer Vk . Then its successor v5 must be also below layer Vk . This case is depicted in Figure 1(c). Then edge (v1 , v5 ) will contribute
Branch-and-Cut Approach to the Directed Acyclic Graph Layering Problem
103
a dummy node to layer Vk , which shows that this case is not possible either. Thus v1 cannot be placed above node v0 for W ≤ 4. Consider two independent nodes u and v of a DAG G = (V, E) and assume we have a heuristic procedure PSAM E−LAY ER (u, v, S, H, W ) for solving Same-layer DAG layering, which takes a decision by considering only the width of the layer where nodes u and v are placed and the widths of its neighboring layers above and below. If PSAM E−LAY ER detects a layer of width greater than W it returns a negative answer and otherwise it returns a positive answer; clearly it will fail to detect some bad layerings due to its shortsightedness. If PSAM E−LAY ER returns a negative answer we say that it detects the pattern depicted in Figure 2(a) as an infeasible pattern in a layering of G. Similarly, assume we have a heuristic procedure PABOV E (u, v, γ, S, H, W ) for solving Above DAG layering for a given gap, γ, between the layers of u and v. We consider three cases of gaps between layers which correspond to three patterns which PABOV E may detect as infeasible in a layering of G. The three cases are: γ = 1 when u and v are in adjacent layers (illustrated in Figure 2(b)); γ = 2 when there is exactly one layer between the layers of u and v (illustrated in Figure 2(d)); and γ = 3 when there are two or more layers between the layers of u and v (illustrated in Figure 2(h)). PABOV E decides by considering only the widths of the two layers where nodes u and v are placed respectively and the widths of their adjacent layers. In all cases PABOV E considers the two adjacent layers above and below the layer of v and the two adjacent layers above and below the layer of u. Thus, the number of layers whose widths are considered are 4 (γ = 1), 5 (γ = 2), or 6 (γ = 3). We call the four patterns considered by PSAM E−LAY ER and PABOV E basic infeasible patterns. If more than one of the four infeasible basic patterns are detected simultaneously then that gives rise to combined infeasible patterns. Of the 15 possible combinations we consider the 11 illustrated in Figure 2 which correspond to generic types of valid inequalities for the DAG layering polytope. The first seven infeasible combined patterns give rise to the fixed-gap (FG) layering inequalities xuk +
2
αi xvk+i ≤ 1
(6)
i=0
2 with k ∈ L(u), αi ∈ {0, 1}, i=0 αi ≥ 1, and k + i ∈ L(v) if αi = 1. Similarly, the last four infeasible combined patterns give rise to the valid inequalities k i=ϕ(u)
ρ(v)
xui +
xvi ≤ 1
(7)
i=k+γ
with k ∈ L(u), γ ∈ {0, 1, 2, 3}, and k + γ ∈ L(v). These are the inequalities that generalize the strong RO inequalities [4] and we call them simply RO inequalities in the remainder of this paper.
104
Patrick Healy and Nikola S. Nikolov
v u
k
v
k
u
(a) A (γ = 0)
(b) B (γ = 1)
v
v k
u
u
(d) C (γ = 2)
v
ρ(v )
v
u u u u
(h) D (γ = 3)
k
v
v
k+3
k
ϕ(u )
k
(c) AB
v v k
u
(e) AC
v
v v
u
u
v
ρ(v )
v
v
v
v
v
v
v
v
v v
u u
k
u u
ϕ(u )
(i) CD
u u
k
u u
ϕ(u)
(j) BCD
k
(g) ABC
(f) BC
ρ(v )
v v v
u u
v v v
u u
ρ(v )
k
ϕ(u)
(k) ABCD
Fig. 2. The 11 infeasible patterns as a result of combining the four basic infeasible patterns Pattern A, Pattern B, Pattern C and Pattern D. Nodes enclosed in a dashed rectangle represent alternative positions of the same node.
Theorem 3. Let: G = (V, E) be a DAG with a width function w : V ∪ E → Q+ ; H, W ≥ 0; u and v be two independent nodes; and the sum of the widths of any two nodes be not larger than W . Then the RO inequality (7) is facet-defining for the DAG layering polytope. Proof. As background call LH G the derived graph with node set VL ⊆ V × {1, . . . , H} with unique nodes corresponding to each layer that q ∈ V could be placed and edge set EL where (p , q ) ∈ EL ), p , q ∈ VL and (p, q) ∈ E, where p (respectively q ) corresponds to the placement of p (q) on some level 1, . . . , H. The dimension of the DAG Layering polytope is |VL | [5]. Let LH G = (VL , EL ). We construct |VL | subsets of VL which partially represent G, induce subgraphs of the LDAG LH G of width at most W , and whose incidence vectors satisfy (7) with equality and are linearly independent. We do this in five steps by choosing |VL | subsets of VL each corresponding to a different node λ ∈ VL . Step 1. For each node λui with ϕ(u) ≤ i ≤ k we choose the set {λui }, and for node λvj with k + γ ≤ j ≤ ρ(v) we choose the set {λvj }.
Branch-and-Cut Approach to the Directed Acyclic Graph Layering Problem
105
Step 2. If node z ∈ V is incident neither to u nor to v and is different from both u and v, then we can always choose the set {λuϕ(u) , λzi } for each ϕ(z) ≤ i ≤ ρ(z). Step 3. Let z be either u or v and let λzi be a node that has not been considered in a previous step. If z = u then we choose the set {λzi , λvρ(v) }; and if z = v then we choose the set {λzi , λuϕ(u) }. Step 4. Now consider node λzi with z ∈ / {u, v} and z incident to exactly one of nodes u and v. If there is an edge between z and u then we choose the set {λzi , λvρ(v) }. Otherwise if there is an edge between z and v then we choose the set {λzi , λuϕ(u) }. Step 5. Finally let λzi is a node with z incident to both u and v. The two cases are a) both u and v are predecessors of z, or b) both u and v are successors of z. We need to choose sets ensuring that they will not induce a subgraph of the LDAG LH G with an edge that does not point downwards. In case a) since ρ(v) > ρ(z), we can always choose the set {λzi , λvρ(v) }; in case b) since ϕ(u) < ϕ(z), we can always choose the set {λzi , λuϕ(u) }. For each node λui with ϕ(u) ≤ i ≤ k and each node λvj with k +γ ≤ j ≤ ρ(v) at Step 1 we have chosen a single one-element subset of VL containing it. Then at Steps 2-5 we have chosen a two-element subset for each other node of VL with a second element one of the nodes already placed in a one-element subset at Step 1. Clearly the incidence vectors of the chosen sets are linearly independent and satisfy (7) with equality. Moreover, we have chosen them to represent G partially and induce subgraphs of LH G of width at most W , given that the sum of the widths of any two nodes does not exceed W . The branch-and-cut algorithm for solving DAG layering which we propose consists of solving WHS-Layering in a branch-and-bound framework employing a cutting-plane algorithm at each node of the branch-and-bound tree for generating violated fixed-gap layering and RO inequalities. The cutting-plane algorithm consists of two parts: first, as a preprocessing step of the branch-and-cut algorithm we compute a list, c-list, of triples of two independent nodes u and v and the identifier of a pattern which is infeasible for u and v and any choice of k; then at each branch-and-bound node we simply scan c-list generating cuts based on violated fixed-gap layering and RO inequalities for a specific value of k. The computational time needed for building c-list is O(|V |2 ) and so is the size of c-list in the worst case. The main part of the preprocessing step for building c-list is a boolean function IsInfeasible which combines implementations of both PABOV E and PSAM E−LAY ER discussed above. IsInfeasible takes as input an ordered pair of independent nodes (u, v) and a number γ ∈ {0, 1, 2, 3} of a basic pattern. It returns true if it detects that basic pattern γ for nodes u and v leads to a layering of width greater than the upper bound W . Otherwise it returns false. In order to give a fast answer IsInfeasible considers only the widths of the layers where nodes u and v are placed and their adjacent layers as discussed above. IsInfeasible simply scans all DAG edges and all DAG nodes. For each edge whose both endpoints are related to (or coincide with) either u
106
Patrick Healy and Nikola S. Nikolov
or v IsInfeasible adds the width of the dummy nodes along it to the widths of the considered layers. Similarly for each node which is either u or v or a node related to any of u and v IsInfeasible adds their contribution to the widths of the considered layers. IsInfeasible works as a heuristic, i.e. it may not detect that a particular pattern would lead to a too wide pattern and return false. This is due to the fact that both problems Same-layer DAG layering and Above DAG layering are N P-complete. an infeasible pattern for the node pair (u, v) and IsInfeasible returns true. Otherwise IsInfeasible returns false.
4
Experimental Procedures and Results
The layering algorithm we have developed, ULair2 , follows the general framework of an ABACUS-based branch-and-cut algorithm to which we have added the cutting-plane algorithm discussed in the previous section. For computational evaluation of ULair we used a machine with an 800 MHz Intel Pentium III CPU. The LP solver required by ABACUS was the one of CPLEX 7.0. In all tests we assume that all real and dummy nodes have unit width. All the running times we report are in centiseconds (the time unit adopted by ABACUS). We applied ULair to the 1277 AT&T DAGs3 . To each test DAG we first applied Gansner et al.’s layering algorithm to compute a layering with minimum number of dummy nodes and stored its width and height as WGans (taking the dummy nodes into account) and HGans respectively. Then for each test DAG we ran ULair several times, each time with a different pair of upper bounds on the width and the height. Each pair of upper bounds had the form (fW WGans , fH HGans ) with fW , fH ∈ {0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4}. We observed that the running time of ULair is too long for some test DAGs and combinations of upper bounds, and we took 158 (12.37%) “hard-to-layer” DAGs out of the Test Set leaving 1119 DAGs. In the remainder of this section we present results of applying ULair to these 1119 AT&T DAGs. We experimented with disabling the cutting-plane generation in ULair. By doing this, we observed that for the majority of DAGs it took the same computational time (or slightly better) to solve DAG layering, but there were a few instances which could not be optimized in reasonable time. The number of such “bad” instances increases when the width bound becomes tighter and the height bound becomes larger. We have collected complete results for fH = 1.0 and fH = 1.1 and partial results for fH = 1.2 when cutting-plane generation is disabled. When fH ≥ 1.2 the running times for optimizing the “bad” instances becomes too long and much too resource-consuming, which shows that 2
3
In what follows, mention of ULair refers to the present branch-and-cut system, as opposed to a previous version of the system that relied on CPLEX’s mixed integer programming solver. We obtained the AT&T DAG set from http://www.graphdrawing.org.
Branch-and-Cut Approach to the Directed Acyclic Graph Layering Problem 600
1800 ULair without cutting-plane generation ULair with cutting-plane generation
ULair without cutting-plane generation ULair with cutting-plane generation
1600 Running Time (centiseconds)
500 Running Time (centiseconds)
107
400
300
200
1400 1200 1000 800 600 400
100 200 0
0 10
20
30
40
50 60 Node Count
70
80
90
100
(a) W = 0.9WGans , H = 1.1HGans
10
20
30
40
50 60 Node Count
70
80
90
100
(b) W = 0.7WGans , H = 1.2HGans
Fig. 3. Average running times of ULair with and without cutting-plane generation.
the generation of cutting planes in such cases is important for completing the computation in reasonable time. Two typical cases of how ULair runs with and without generation of cutting planes are illustrated in Figure 3. It can be seen how the cutting-plane generation eliminates some peaks in the average running time, which are present when the cutting-plane generation is disabled. We excluded from consideration one test DAG (attg.56.5) in Figure 3(a) and one test DAG (attg.94.0) in Figure 3(b), because the running times for layering them without generation of cutting planes were too large and did not fit nicely in the plots. The table in Figure 4 compares the running times of ULair with and without generation of cutting planes to the running times of the mixed integer programming solver (MIP) of CPLEX 7.0 for five DAGs which are hard to layer without generation of cutting planes. In order to build this table we constructed the
AT&T fH /fW attg. 23.37 1.2 / 0.7 1.2 / 0.8 29.2 1.2 / 0.7 1.2 / 0.8 32.1 1.2 / 0.7 1.2 / 0.8 56.5 1.2 / 0.7 1.2 / 0.8 94.0 1.2 / 0.7 1.2 / 0.8
Running time (centisec.) no cuts MIP cuts 45 11 15 330 9 17 235 174 29 172 186 115 16,919 85 24 524 78 137 9,852 60,000+ 945 60,000+ 60,000+ 945 38,478 4,237 585 9,009 3,882 631
Cutting planes A:1, AB:1, BC:3, ABC:4 A:6, AB:1, C:1, BC:4, ABC:9 AC:1, ABCD:17 A:3, BC:5, ABC:15, BCD:7 AB:1, ABC:8, ABCD:7 A:1, AB:9, AC:2, BC:2, ABC:1, ABCD:5 ABCD:94 ABCD:95 ABCD:157 ABCD:203
Fig. 4. Some DAGs which are hard to layer without cutting-plane generation.
108
Patrick Healy and Nikola S. Nikolov
WHS-Layering ILP model for each of the five DAGs and ran MIP for solving it, accepting its default settings. The first column contains the number of the DAG; the second column, fH /fW , contains the values of fH and fW respectively. The next three columns represent the CPU time for solving DAG layering (eventually reporting that there is no feasible solution) in centiseconds. Running times over 60,000 centiseconds (10 min) are presented as 60,000+. Column no cuts contains the running times of ULair when the generation of cutting planes is disabled. The next column, MIP, displays the running times of CPLEX’s MIP. Column cuts contains the running times of ULair when our cutting-plane strategy is applied. With a few insignificant exceptions the running times in column cuts are the best, which is a further evidence that our cutting-plane generation strategy helps for optimizing “hard” instances of DAG layering. The last column in Table 4, Cutting planes, contains for each infeasible pattern the number of generated cutting planes by ULair (when the cutting-plane generation is enabled). For example “AC:1, ABCD:17” means that one cutting plane corresponding to infeasible Pattern AC was generated and 17 cutting planes corresponding to infeasible Pattern ABCD were generated. The average number of cutting planes tends to be bigger for bigger values of fW and fixed fH when there is no optimal solution (on average up to 80 cutting planes per DAG with node count between 70 and 100), while in the case that an optimal solution was found average numbers of cutting planes greater than or equal to 2 appear only for tight bounds on the width and large height bounds. This suggests to us that our infeasible solution detection and cutting plane generation algorithms are in need of further development. It might be fruitful to consider triples of nodes instead of pairs as we currently do. While this implies a larger list of candidates to consider, the running time of checking a triple involves only a constant number of pairwise infeasibility checks. In Figure 5 we compare Gansner’s layering on a 62-node, 79-edge DAG to ULair’s layering with dimension bounds equal to 0.7 and 1.0 times Gansner’s width and height, respectively. Gansner’s layering has 39 dummy nodes (depicted as tiny rectangles along the edges), while ULair’s layering has 7 more dummy nodes, caused by tightening the width bound. After the layering phase, we applied exact crossing minimization and at the end manually adjusted the final position of the nodes and the final shape of the edges. Gansner’s layering resulted in 33 edge crossings, while ULair resulted into 30 edge crossings. Both drawings are drawn over the same drawing area. Because ULair’s layering has a smaller width, this allows larger distances between the nodes and as a result, ULair’s clearly has a better distribution of the nodes over the drawing area.
5
Conclusions
We have developed and implemented a branch-and-cut layering algorithm, ULair, which computes high quality layerings from aesthetic point of view. On the basis of our computational experience we conclude that ULair runs reasonably fast for DAGs having up to 100 nodes and it can be applied successfully when the quality
Branch-and-Cut Approach to the Directed Acyclic Graph Layering Problem
(a)
109
(b)
Fig. 5. (a) Gansner’s layering: height 10, width 23, 39 dummy nodes; (b) ULair’s layering: height 10, width 16, 46 dummy nodes
of a drawing is more important than fast computation. ULair can also provide a good initial layering for further manual adjustments and local improvements. With the current cutting-plane generation algorithm that considers only pairs of independent nodes, we have identified a number of DAGs where ULair performs faster than the mixed integer programming solver of CPLEX 7.0. By extending the cutting-plane generation algorithm, we believe that ULair can be made faster still. The performance of ULair can be further improved by employing tighter upper bounds on the sum of edge spans in bounded dimensions.
References 1. O. Bastert and C. Matuszewski. Layered drawings of digraphs. In M. Kaufman and D. Wagner, editors, Drawing Graphs: Method and Models, volume 2025 of LNCS, pages 87–120. Springer-Verlag, 2000. 2. J. Branke, S. Leppert, M. Middendorf, and P. Eades. Width-restriced layering of acyclic digraphs with consideration of dummy nodes. Information Processing Letters, 81(2):59–63, January 2002. 3. P. Eades and K. Sugiyama. How to draw a directed graph. Journal of Information Processing, 13(4):424–437, 1990. 4. P. Healy and N. S. Nikolov. How to layer a directed acyclic graph. In P. Mutzel, M. J¨ unger, and S. Leipert, editors, Graph Drawing: Proceedings of 9th International Symposium, GD 2001, volume 2265 of LNCS, pages 16–30. Springer-Verlag, 2002. 5. P. Healy and N. S. Nikolov. Facets of the directed acyclic graph layering polytope. In Ludˇek Kuˇcera, editor, Graph Theoretical Concepts in Computer Science: WG2002, LNCS. Springer-Verlag, (To appear.). 6. 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, February 1981.
Geometric Systems of Disjoint Representatives Jiˇr´ı Fiala1 , Jan Kratochv´ıl1, , and Andrzej Proskurowski2, 1
2
Institute for Theoretical Computer Science† and Department of Applied Mathematics, Charles University, Prague {fiala,honza}@kam.mff.cuni.cz Department of Computer and Information Science, University of Oregon, Eugene [email protected]
Abstract. Consider a finite collection of subsets of a metric space and ask for a system of representatives which are pairwise at a distance at least q, where q is a parameter of the problem. In discrete spaces this generalizes the well known problem of distinct representatives, while in Euclidean metrics the problem reduces to finding a system of disjoint balls. This problem is closely related to practical applications like scheduling or map labeling. We characterize the computational complexity of this geometric problem for the cases of L1 and L2 metrics and dimensions d = 1, 2. We show that for d = 1 the problem can be solved in polynomial time, while for d = 2 we prove that it is NP-hard. Our NP-hardness proof can be adjusted also for higher dimensions.
1
Introduction
Take a universe X and a family of its subsets M = {Mi | i ∈ I, Mi ⊆ X}. The System of Distinct Representatives (SDR) for M selects from each Mi an element, such that sets are represented by distinct elements. Such assignment can be formally described by an injective mapping f : I → X satisfying the property f (i) ∈ Mi for all i ∈ I. Observe that such system can be equivalently formulated as a matching in bipartite graph, where vertices of the first block of the bi-partition correspond to the elements of X, the other vertices stand for the sets Mi and edges describe the incidence relation. The theory of Systems of Distinct Representatives is well known and very important for discrete optimization problems. Namely, in the case when the
†
The authors acknowledge support of joint Czech U.S. grants KONTAKT ME338 and NSF-INT-9802416 during visits of the first two authors to Eugene, OR, and of the third author to Prague. Research partially supported by Czech Research grant GAUK 158/99. Supported in part by the grant NSF-ANI-9977524. Supported by the Ministry of Education of the Czech Republic as project LN00A056.
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 110–117, 2002. c Springer-Verlag Berlin Heidelberg 2002
Geometric Systems of Disjoint Representatives
111
family M and all its sets Mi are finite, the elegant Hall theorem [5] describes necessary and sufficient conditions for the existence of an SDR, and if it exists it can be found by a polynomial time algorithm (either the algorithm involving augmenting paths or the matching algorithm of Edmonds [3]). Though several generalizations of the concept have been studied, we believe that the concept of distant representatives is new. We assume that the universe X is equipped by a metric dist(a, b) and therefore we may ask for representatives that are sufficiently spaced in X. More formally: Definition 1. Given a parameter q > 0 and a family M = {Mi | i ∈ I} of subsets of X, a mapping f : I → X is called a System of q-Distant Representatives (Sq-DR) if (1) f (i) ∈ Mi for every i ∈ I, (2) dist(f (i), f (j)) ≥ q for every i, j ∈ I, i = j. The metric on the space X could be defined in several ways, for example: – The trivial metric: For arbitrary universe X we set dist(a, b) = 0 if a = b, and dist(a, b) = 1 otherwise. – The integral metric: X = N, dist(a, b) = |a − b|. – The graph metric: Take X = V (G) and set dist(a, b) to the length of the shortest path connecting vertices a and b in a graph G. – The plane Euclidean metric: X = R2 , distance is the length of the segment joining the points a and b in the plane. – The plane Manhattan distance is defined as the sum of coordinate differences |ax − bx | + |ay − by |. The universe X = R2 as in the previous case. Observe that in the case of trivial or integral or graph metric the System of q-Distant Representatives is equivalent to System of Distinct Representatives as far as q ≤ 1. This holds in slightly more general setting: Consider any universe X equipped by any metric for which dist(a, b) ≥ 1 whenever a = b. Then for q ≤ 1 the condition (2) merely says that f (i) = f (j), i.e., a System of q-Distant Representatives is a System of Distinct Representatives. For this case any further metric structure on X becomes irrelevant and in such a case an Sq-DR could be found by a polynomial-time algorithm. We address the computational complexity of the Sq-DR problem in [4] and show several NP-hardness results, mainly for the discrete spaces. Some cases provide a natural counterpart to the results of Aharoni and Haxell [1] who studied a more general concept of Systems of Disjoint Representatives on Hypergraphs. Though they derive necessary and sufficient conditions for the existence of such system on finite families M, the problem whether these conditions are satisfied is still NP-hard as we show in [4]. The aim of this paper is to show that for unit balls in the Euclidean plane the S1-DR problem is NP-hard for both Euclidean an Manhattan metrics. This is in contrast with the complexity of the corresponding Sq-DR problem for balls in the one dimensional Euclidean space, where it allows a polynomial-time algorithm.
112
2
Jiˇr´ı Fiala, Jan Kratochv´ıl, and Andrzej Proskurowski
Systems of Distant Representatives in the Euclidean Space
In this section we consider the case when the universe X is the d-dimensional Euclidean space Rd equipped with the Lp metric for some fixed p. (The Lp d metric is defined by the formula: distLp (a, b) = p j=1 |aj − bj |p ). Clearly, the collection M consists of sets of points. If all sets Mi are finite, we can transform such instance to a finite graph G (here vertices represent points, and pairs of them are adjacent when the corresponding points are at distance less than q) and look for 2-distant representatives in the graph metric. We omit for the moment this case and focus our attention on infinite sets Mi , namely unit diameter balls in Rd . From the computational complexity it is important that such infinite sets can be described in constant space, e.g. by the coordinates of the centers of the balls. Observe that in any Lp metric, two points a and b are at distance smaller than q, iff the two open balls of diameter q, one centered at a and the other at b, intersect. The Sq-DR problem for closed unit balls in Rd then has a nice geometric representation: replace each closed unit ball Mi of M by an open ball Mi of diameter 1+q and ask, whether each Mi can be assigned as a representative a ball of diameter q, completely placed inside Mi , all these representatives being pairwise disjoint. In the rest we use this representation M of the Sq-DR problem, rather than the original collection M. The reason is that in this representation we do not need to operate with the underlying distance: all essential properties are captured by the inclusion relation. A similar situation was considered for finite sets by Aharoni and Haxell in [1]. It is clear that such problems can naturally arise in practical applications like map labeling (for d = 2), where the sets Mi correspond to the possible label placement, and the disjoint representatives of diameter q correspond to the reserved places for labels. See [7,2] for hardness results on similar map labeling problems. The one-dimensional version of finding an Sq-DR for (unit) balls in R is equal to the following scheduling problem: Let a set I of tasks be given. These tasks require to be scheduled on one processor without preemption, such that each task is processed for the same time (q) and within the predetermined time bounds — the release date and the due date — that form intervals (ri , di ) (Mi = (ri + 2q , di − 2q )). The question is whether a feasible schedule exists. Clearly, the polynomial-time algorithm solving the scheduling problem due to Simons [8] provides also a solution for the Sq-DR problem on R with any Lp metric (the parameter p is irrelevant in the one-dimensional Euclidean space). We show in the next section that in the two-dimensional space (and hence in higher dimensions as well) the problem becomes NP-hard for both the Euclidean (L2 ) and the Manhattan (L1 ) metrics.
Geometric Systems of Disjoint Representatives
3
113
Systems of Distant Representatives in the Plane
In the Euclidean metric, balls correspond to disks, while in the Manhattan metric we get squares of diagonal length equal to the required diameter, and diagonals are parallel with the coordinate axes. For convenience, in the case of the Manhattan metric we consider that the plane and all its objects are rotated by π4 √ and scaled by the factor 2, hence all squares involved have side length 1 + q (in M ) or q (the representatives), and squares are oriented in the usual way. Theorem 1. The S1-DR problem is NP-hard for closed unit squares in the Manhattan metric. Proof. We show a reduction from the planar 3-SAT problem, whose NP-completeness was proved in [6]. An instance for this version of the satisfiability problem consists of a formula Φ = (V, C) in the conjunctive normal form, where each variable has one positive and two negative occurrences, each clause consists of two or three literals, and the incidence graph G of Φ is planar. The graph G has vertex set V (G) = V ∪ C and an edge (x, c) belongs to E(G) iff the clause c contains x or ¬x as a literal. The family M contains squares of side length 2. It can be split into three parts: one part represents clauses, the next variables, and the third part are connectors joining clause and variable gadgets together. The three-literal clause gadget consists of two squares of the same placement. It is clear, that only two of the four quadrants could be completely free whenever an S1-DR exists. Similarly, for a clause with only two literals we use three squares in the same position. The variable gadget is schematically depicted in Fig. 1. The dashed lines represent the unit grid in the plane. By black lines we depict 16 squares which we call active, the bold lines indicate two squares at the same position. The halftoned area cannot be used for a possible representative of an active square — it is fully occupied e.g. by four squares at the same position (hence each of them is represented by a different quadrant). The important property of the variable gadget is, that if any S1-DR exists, then either squares P1 and P2 or N1 and N2 will be partly occupied by the representatives for the vertex gadget. For example, if neither P1 nor P2 is hit by the representatives, then both N1 and N2 are, as depicted in Fig. 2. The small squares are representatives for the active squares of the gadget, their numbering corresponds to left-to-right ordering of the active squares from Fig. 1. The connector gadget corresponds to a chain of squares. These squares are grouped to triples and all squares in a triple have the same position (so Fig. 3 represents in fact 18 squares). Two consecutive triples in the chain share one quadrant. If we select two quadrants at the ends of the chain, like A and B in the figure, then at least one of them is fully occupied, if the chain has an S1-DR. The collection M contains for each clause c ∈ C a disjoint copy of the clause gadget placed on a grid according to the planar drawing of G. Similarly we place the variable gadgets for each variable x ∈ V . If a variable x occurs positively
114
Jiˇr´ı Fiala, Jan Kratochv´ıl, and Andrzej Proskurowski
P1 P2
N1 N2
Fig. 1. Variable gadget.
P1 P2
1 2 3 4 5 6
11 7 8 9 10
12 13 14 15 16
N1 N2
Fig. 2. S1-DR for the variable gadget corresponding to the truth assignment.
A B
Fig. 3. Connector gadget.
in a clause c, we include into M a connector joining a unique quadrant of the clause gadget representing c with a lower right quadrant of the square P1 related to the variable gadget of x. We similarly use left corners of N1 and N2 for the two (possible) occurrences of ¬x. The placement of all these objects in the plane follows the planar drawing of the graph G on the unit grid. All squares except those in the construction of the variable gadget coincide with the grid, so the entire collection M can be constructed such that its size is polynomial in the size of the formula Φ.
Geometric Systems of Disjoint Representatives
115
Assume that an S1-DR for M exists. No clause gadget cannot serve all its literals by a free quadrant, hence at least one these literals is forced to fully occupy the square P1 (for a positive literal) or some Ni (otherwise) of the corresponding variable gadget. As it was mentioned above, it is impossible to occupy both P1 and some Ni of the same gadget at the same time. Hence, we may define an assignment x = true if P1 is not occupied by the representatives for the active squares of the variable gadget for x and we put x = false otherwise. Such assignment is well defined and satisfies Φ. The construction of an S1-DR from a truth assignment of Φ is then straightforward. In the proof of Theorem 1 only few squares were placed out of the unit grid. We show, that in the case if all unit squares respect the grid, than the problem is solvable by a polynomial-time algorithm. Corollary 1. For any q of form k1 , k ∈ N it holds that the Sq-DR problem for closed unit squares can be solved in polynomial time, if all sides of squares in M coincide with the grid of span q. Proof. If any Sq-DR exists, then shift all the representatives to the left&downmost position. The resulting Sq-DR has the property that all representatives coincide with the grid points. Then we can without loss of generality restrict the universe X only to the grid points and solve the problem by finding a System of Distinct Representatives. We conclude this section by proving an analogous result for disks, i.e., for the Euclidean metric. Theorem 2. The S1-DR problem is NP-hard for unit disks in the Euclidean metric. Proof. The proof mimics the proof of the case of squares. We represent a planar formula Φ by a collection of disks that are partitioned into clause and variable gadgets, and connectors. As above we use the representation M , where representatives correspond to disks of diameter 1, while the disks in M have diameter 2. The first tool involved in the construction is the reserved halftoned area. Observe that the four disks depicted in Fig. 4 a) allow an S1-DR only as the four halftoned disks. The connectors are depicted in Fig. 4 b). In no S1-DR of the connector gadget both disks A and B may remain simultaneously empty. The vertex gadget is illustrated in the part c). As in the previous proof, it is impossible to find representatives for the vertex gadget where some Pi remains free together with some Nj . Similarly, if the disk P1 remains empty, the corresponding variable will be assigned the true value. Finally, clause gadgets are shown in the section d). At least one of the three or two, resp., dashed disks cannot be left free to saturate the adjacent connector’s end.
116
Jiˇr´ı Fiala, Jan Kratochv´ıl, and Andrzej Proskurowski
B a)
c)
b)
P1
N1
P2
N2
d) A Fig. 4. Gadgets for the S1-DR problem on disks.
The entire discussion follows in the exactly same manner as in the case of squares.
4
Conclusion
In higher dimensions, the construction of connectors and variable and clause gadgets is similar as in the plane. We avoid it here due to space limitations and a somewhat technical aspect of the argument. We also believe that both above constructions can be adjusted for other fixed values of q < 1. We present as an open problem what is the computational complexity for the Sq-DR geometric problem with the Euclidean or Manhattan metrics for q in the range (1, ∞). Finally, we believe that a uniform proof can be derived for the NP-hardness of the Sq-DR problem for unit balls in the d-dimensional Euclidean space for all Lp metrics (q > 0, d ≥ 2, p ≥ 1), It also remains as an open question whether the Sq-DR problem for unit balls belongs to the class NP. It is not straightforward to see whether the coordinates of the representatives — if they exist — can be described and verified in polynomial space and time.
References 1. Aharoni, R., P. Haxell, Hall’s theorem for hypergraphs, J. Graph Th. 35, (2000), pp. 83–88. 2. Doddi S., M. V. Marathe, A. Mirzaian, B. M. E. Moret, B. Zhu, Map labeling and its generalizations. Proc. 8th ACM-SIAM Symp. on Discrete Algorithms, (1997), pp. 148–157. 3. Edmonds, J., Paths, trees and flowers, Can. J. Math. 17, (1965), pp. 449–467. 4. Fiala, J., J. Kratochv´ıl, A. Proskurowski, Systems of sets and their representatives, manuscript 2002.
Geometric Systems of Disjoint Representatives
117
5. Hall, P., On representatives of subsets, J. London Math. Soc. 10, (1935), pp. 26– 30. 6. Kratochv´ıl, J., A special planar satisfiability problem and a consequence of its NP-completeness, Discrete Appl. Math. 52, (1994), pp. 233–252. 7. Marks, J., S. Shieber, The computational complexity of cartographic label placement, Technical Report TR-05-91, Harvard CS, 1991. 8. Simons, B., A fast algorithm for single processor scheduling, Proc. 19th Symp. Foundations of Computer Science, (1978), pp. 246–252.
An Efficient Fixed Parameter Tractable Algorithm for 1-Sided Crossing Minimization Vida Dujmovi´c and Sue Whitesides School of Computer Science, McGill University, 3480 University St., Montreal, Qu´ebec, Canada H3A 2A7, {vida, sue}@cs.mcgill.ca
Abstract. We give an O(φk · n2 ) algorithm for the 1-Sided Crossing Minimization problem, thus showing that the problem is Fixed Parameter Tractable. The constant φ in the running time is the golden ratio √ φ = 1+2 5 ≈ 1.618. The constant k is the parameter of the problem: the number of allowed edge crossings.
1
Introduction
A common method for drawing directed acyclic graphs is to produce layered drawings or hierarchical drawings as introduced by Tomii et al. [17], Carpano [1], and Sugiyama et al. [16]. In these drawings, the vertices are arranged on two or more “layers”, i.e. on parallel horizontal lines, and edges are drawn straight between vertices on adjacent layers. Edges between vertices on the same layer are not permitted, and no point between layers may lie on more than two edges. Layouts of this kind have applications, for example, in visualization, in DNA mapping, and in row-based VLSI layout. The readability of layered drawings is believed to depend crucially on the number of edge crossings. Once vertices have been assigned to layers, this number is determined by the orderings of the vertices within the layers. Unfortunately, the problem of choosing vertex orderings that minimize the number of edge crossings in layered drawings is in fact an NP-complete problem [12] even if there are only two layers [11]. The problem of choosing vertex orderings that minimize the number of edges whose removal leaves the graph planar is also NP-complete, even for two layers [10]. Most techniques for producing layered drawings first assign vertices to layers (sometimes this is determined by the context), and then do a layer-by-layer sweep. A permutation π1 for the vertices in the top layer L1 is chosen and fixed. Then for each succeeding layer Li , a permutation πi is sought that keeps to a minimum the number of edge crossings among the edges between Li−1 and Li . A key step in this method is to minimize crossings between two adjacent layers when the ordering on one layer is fixed. This problem is called 1-Sided Crossing Minimization. Unfortunately, the 1-Sided Crossing Minimization problem is also NP-complete [11]. The problem is NP-complete even for
Research supported by FCAR and NSERC.
M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 118–129, 2002. c Springer-Verlag Berlin Heidelberg 2002
A Fixed Parameter Tractable Algorithm for 1-Sided Crossing Minimization
119
graphs with only degree-1 vertices in the fixed layer and vertices of degree at most 4 in the other layer [14], i.e. for a forest of 4-stars. The 1-Sided Crossing Minimization problem is the focus of this paper. Many heuristics have been proposed (e.g. [19,16,9,11,6,2,18]). J¨ unger and Mutzel [13] gave an exact integer linear programming algorithm for the 1-Sided Crossing Minimization problem. They also surveyed heuristics and made performance comparisons with optimal solutions generated by their methods. They reported that the iterated barycentre method of Sugiyama et al. [16] performs best in practice. However, from a theoretical point of view the median heuristic of Eades and Wormald [11]√is a linear 3-approximation algorithm, whereas the barycentre heuristic is a Θ( n)-approximation algorithm. When only a small number, k, of edge crossings is acceptable, then an algorithm for 1-Sided Crossing Minimization whose running time is exponential in k but polynomial in the size of the graph may be useful. The theory of parameterized complexity [5] addresses complexity issues of this nature, in which a problem is specified in terms of one or more parameters. Such a problem with input size n and parameter size k is fixed parameter tractable, or in the class FPT, if there is an algorithm to solve the problem in f (k) · nα time, where α is a constant independent of k and n, and f is an arbitrary function dependent only on parameter k. A problem in FPT is thus solvable in polynomial time for any fixed value of k. The more general h-Layer Crossing Minimization problem as well as the related h-Layer Planarization problem have been studied from the fixed parameter tractability point of view in [8]. Here h represents the number of layers and planarization means to remove some number k of edges so that the remaining graph can be drawn without crossings (see [10]). It has been proven in [8], using bounded pathwidth techniques, that both these general problems (which include 1-Sided Crossing Minimization) are in the class FPT. Unfortunately, the pathwidth-based approach is only of theoretical interest, since the running 3 time of the algorithms is O(232(h+2k) n). In [7], other FPT techniques are used k to derive an O(k · 6 + |G|) time algorithm for 2-Layer Planarization of a graph G, and an O(3k · |G|) time algorithm for 1-Layer Planarization. In this paper, we give an algorithm for 1-Sided Crossing Minimization that runs in O(φk |L2 |2 + |L1 ||L2 |) time, where L2 is the set of vertices on the free layer where the permutation π2 of vertices is to be chosen, L1 is the set of vertices on the fixed layer where the permutation π1 of vertices is fixed, and the constant φ is the golden ratio. The algorithm is based on the FTP technique called Bounded Search Tree. This technique relies on exploring some search space, and then proving that its size depends only upon the parameter k. The search space thus becomes constant size and the algorithm is then polynomial time for each fixed k. The remainder of this paper is organized as follows. After definitions and preliminary results in Section 2, we study properties of optimal drawings in Section 3. Our algorithm for the 1-Sided Crossing Minimization problem is then given in Section 4.
120
2
Vida Dujmovi´c and Sue Whitesides
Problem Statement, Notation, and Some Facts
A graph G = (V, E) with vertex set V and edge set E ⊆ V × V is called bipartite if there isa partition of V into two disjoint non-empty sets L1 and L2 such that V = L1 L2 and E ⊆ L1 × L2 . The number of vertices and edges of G are respectively denoted by n = |V | and m = |E|. Let dv denote the degree of a vertex v. We assume dv ≥ 1. In a 2-layer drawing of a graph G = (L1 , L2 ; E), the vertices in L1 and L2 are positioned on two distinct parallel lines (layers), and the edges are drawn straight. Since edges are not allowed within a layer, G must be bipartite. Let L1 denote the top, fixed layer, whose vertex ordering π1 is fixed. Let L2 denote the bottom, free layer, whose vertices are free to be permuted. We study the following problem: Problem:1-Sided Crossing Minimization Instance: a bipartite graph G = (L1 , L2 ; E), an integer k, and a fixed ordering π1 for the vertex set L1 on the top layer. Question: Is there a 2-layer drawing of G that respects π1 and that has at most k crossings?
L1 , π1 f ixed
L2 , π2 f ree Fig. 1. A 2-layer drawing. The ordering π1 of L1 is fixed. Vertices of L2 are free.
From now on, we assume that input graphs are bipartite, with minimum degree at least 1, and that an ordering π1 has been specified for the top layer. We do not consider multiple edges, although these are easy to handle. Let G, π1 , k denote an instance of the 1-Sided Crossing Minimization problem, and let (G, π1 , π2 ) denote a combinatorial representation of a 2-layer drawing of G, with π1 and π2 giving the permutations for the vertices on layers L1 and L2 , respectively. Let the number of crossings in the drawing (G, π1 , π2 ) be denoted by cr(G, π1 , π2 ), and let the minimum possible number of crossings subject to the vertices of L1 being ordered by π1 be denoted by cr(G, π1 , πopt ). Note that cr(G, π1 , πopt ) = minπ2 {cr(G, π1 , π2 ) }, where π2 ranges over all permutations for L2 . Let v < w denote an ordered pair of vertices on the same layer, and let v, w denote an unordered pair of vertices. Sometimes it is convenient to denote unordered pairs of vertices by (v, w), which is also used to denote an edge. The meaning will be clear from the context. Throughout the paper, the term “pair” refers to a pair of distinct objects.
A Fixed Parameter Tractable Algorithm for 1-Sided Crossing Minimization
121
Fact 1. [4] Two edges (v, v ) and (w, w ), where v, w ∈ L2 and v , w ∈ L1 , cross in a 2-layer drawing if and only if v < w and w < v , or w < v and v < w . Fact 2. [4] For vertices v and w in the free layer L2 , the number of crossings of the edges incident to v with the edges incident to w is completely determined by the relative ordering of v and w. Definition 1. Consider a problem instance G, π1 , k , and let v and w be vertices in L2 . The crossing number cvw is the number of crossings that edges incident with v make with edges incident with w in drawings having v < w; the crossing number cwv is for w < v. Fact 3. [4] The total number of crossings in a 2-layer drawing (G, π1 , π2 ) is: cvw , (1) cr(G, π1 , π2 ) = ∀v<w∈π2
where the summation is over all ordered pairs v < w of elements of π2 ; furthermore, min(cvw , cwv ) ≤ cr(G, π1 , πopt ) ≤ max(cvw , cwv ), (2) v,w∈L2
v,w∈L2
where the summations are over all unordered pairs v, w of vertices of L2 .
3
Properties of Optimal Drawings
In this section, we establish a property of optimal drawings (G, π1 , πopt ) (see Lemma 1) that will be fundamental for our algorithm in the next section. For each vertex v in L2 , let lv denote the leftmost neighbor of v in L1 , and let rv denote the rightmost neighbor of v in L1 . Note that if v ∈ L2 has degree 1, then lv = rv . Now consider two vertices v and w in L2 . We say that v and w are a suited pair if rv ≤ lw , or if rw ≤ lv ; otherwise we call the pair unsuited. For example, in Fig. 2 v, u is a suited pair and so is pair w, u; pair v, w is not suited. If v and w each have degree 1 and have the same neighbor in L1 (i.e. lv =rv =lw =rw ), we say that v and w are a trivial suited pair. The following fact, which is an immediate consequence of Fact 1 and the definition of unsuited pair, indicates the importance of the notion of suitable pairs. Fact 4. A pair of vertices v, w ∈ L2 is unsuited if and only if cvw ≥ 1 and cwv ≥ 1. On the other hand, the edges of a suited pair v, w do not cross if v and w appear in their natural ordering in π2 , i.e., if v < w when rv ≤ lw , and w < v when rw ≤ lv . If v, w is a trivial suited pair, then cvw = 0 and cwv = 0, and we say that both v < w and w < v are natural orderings for the pair v, w. The notion of natural ordering leads to a useful fact for our algorithm.
122
Vida Dujmovi´c and Sue Whitesides
lv
v
L1 , π1 f ixed
rv
u
w
L2 , π2 f ree
Fig. 2. Pair v, w is unsuited, while v, u and w, u are suited pairs.
Fact 5. Suppose v, w is a suited pair for π1 with natural ordering v < w. Then for any π2 , the drawing (G, π1 , π2 ) satisfies: (i) cvw =0; (ii) if rv = lw , then cwv = dv · dw ; (iii) if rv = lw , then cwv = (dv · dw ) − 1; and finally, (iv) unless v and w are a trivial suited pair, cwv > 0. Note that natural ordering is only defined for pairs of suited vertices. For general pairs, we say that v < w is the preferred ordering for a pair v, w if cvw < cwv . Thus the natural ordering is the preferred ordering for non-trivial suited pairs. The following Lemma is the basis for our algorithm. Lemma 1. For fixed π1 , let Γopt = (G, π1 , πopt ) be a drawing with the minimum possible number of crossings. Then all suited pairs appear in πopt in their natural ordering. To prove Lemma 1 the following straight forward lemma will be useful. Lemma 2. For 1 ≤ i ≤ |L2 |, let vi denote the vertex in the ith position in π2 of some drawing (G, π1 , π2 ) with π1 fixed. Moving any vertex vi ∈ L2 from its starting position i across the t consecutive vertices vi+1 , vi+2 , . . . , vi+t to the right creates a new drawing (G, π1 , π2 ) with: cr(G, π1 , π2 ) = cr(G, π1 , π2 ) +
t
(cvi+j vi − cvi vi+j ).
(3)
j=1
Similarly, if vi is moved to the left over t consecutive vertices, then the above summation is from j = −1 to j = −t and the sign in front of the summation is “−”. Proof. Assume, without loss of generality, that vertex vi moves to the right across t consecutive vertices in (G, π1 , π2 ). This creates a new drawing (G, π1 , π2 ). The only pairs of vertices in (G, π1 , π2 ) whose relative ordering changes in (G, π1 , π2 ) are the pairs vi , vj for i + 1 ≤ j ≤ i + t. Hence by Fact 2, these are the only pairs whose crossing number might change. In particular, the crossing number for a pair vi , vj for j in the range [i + 1, i + t] changes from cvi vj to cvj vi . Substituting these changes into Equation 1 of Fact 3 gives Equation 3 above. ✷ Now we give the proof of Lemma 1. Proof of Lemma 1: The proof is by contradiction. Assume that in Γopt = (G, π1 , πopt ) there is a suited pair v, w whose ordering in πopt is not its natural
A Fixed Parameter Tractable Algorithm for 1-Sided Crossing Minimization
123
ordering. Note that v and w are not degree-1 vertices with a common neighbor, as both orderings would be natural in that case. Assume that v < w is the (unique) natural ordering of v, w. By Fact 5 the crossing number cvw = 0 and the crossing number cwv > 0. For a contradiction, we now prove that either v or w can be moved in Γopt such that the resulting drawing Γnew = (G, π1 , πnew ) satisfies cr(Γnew ) < cr(Γopt ). Let i and j denote the positions of w and v, respectively, in πopt . Here i < j since v and w appear in the order w < v in πopt . If |j − i| = 1, we can interchange v and w without affecting any other pair of vertices in Γopt . Equation 3 in Lemma 2 gives the number of crossings in the resulting drawing Γnew : cr(Γnew ) = cr(Γopt ) − cwv + cvw = cr(Γopt ) − cwv + 0. Since cwv > 0, we have cr(Γnew ) < cr(Γopt ), which contradicts the optimality of Γopt . If |j − i| > 1, let ui+1 , ui+2 , . . . , uj−1 denote the vertices between w and v in πopt , listed in order of appearance in πopt . Regard these vertices as a frozen block U inside which no changes are made. See Fig. 3. rv
lv
L1 , π1 f ixed
L2 , π2 f ree w
U
v
Fig. 3. Proof of Lemma 1
According to Lemma 2, moving v or w from one side of block U to the other may only affect the crossing number contributions of pairs of the form u, w and u, v for u ∈ U . Let cU p denote the number of crossings that the edges incident to vertices in U have with the edges incident to a vertex p to the right of U : cU p = Σu∈U cup . Similarly, let cpU denote this number of crossings when p lies to the left of U . Since Γopt is optimal, we claim we have the strict inequality (4) cU v < cvU . Otherwise, we could move v to the left side of U and then interchange v with w to obtain a drawing with the following total number of crossings: cr(Γnew ) = Γopt − cU v + cvU − cwv + 0. Since cwv > 0, if cU v ≥ cvU , then cr(Γnew ) < cr(Γopt ), a contradiction. observation: To conclude the case |j − i| > 1, and hence the proof of the lemma, it suffices to show that cU v < cvU implies cwU ≥ cU w , for this means
124
Vida Dujmovi´c and Sue Whitesides
we can move w to the right side of U without increasing the total number of crossings in the resulting drawing and then interchange w and v to produce a drawing with fewer crossings than Γopt . This gives a contradiction, and so proves that the assumption that πopt contains a suited pair not ordered by its natural ordering cannot hold. To establish the desired inequality cwU ≥ cU w , we first derive some intermediate inequalities for cU v , cvU , cwU , and cU w in terms of sizes of the following sets: ER = the set of edges in Γopt with one endpoint in U and the other endpoint strictly greater than rv in the ordering π1 ; EL = the set of edges with one endpoint in U and the other endpoint strictly less than rv in the ordering π1 ; Nv = the neighbors of v; and Nw = the neighbors of w. By the definition of ER , all the vertices in Nv occur in π1 strictly before the L1 endpoint of each edge in ER . By the definition of EL and by the fact that v, w is a suited pair with the natural ordering v < w, the vertices in Nw occur in π1 strictly after the L1 endpoints of the edges in EL . Fact 2 implies the following inequalities for crossing numbers: cU v ≥ dv · |ER | : The edges incident to v and the edges in ER all pairwise intersect, creating dv · |ER | crossings. Since ER is a subset of the edges incident to U , cU v ≥ dv · |ER |. cvU ≤ dv · |EL | : This holds because no edge incident to v crosses any edge incident to U that is not in EL . cwU ≥ dw · |EL | : The edges incident to w and the edges in EL all pairwise intersect, so cwU ≥ dw · |EL |. cU w ≤ dw · |ER | : This holds because no edge incident to w intersects any edge incident to U that is not in ER . Recall inequality (4), that cU v < cvU . Since cU v ≥ dv ·|ER | and cvU ≤ dv ·|EL |, we have dv · |ER | ≤ cU v < cvU ≤ dv · |EL |, which implies that |ER | < |EL |. This, and the fact that cwU ≥ dw · |EL |, and the fact that cU w ≤ dw · |ER | together imply that cwU > cU w . By the observation above, this completes the proof. ✷
4 4.1
An Efficient FPT Algorithm The Bounded Search Tree Approach for the Algorithm
One of the basic methods for developing FPT algorithms is the method of bounded search trees (BST) (see Downey and Fellows [5, Chapter 3.1]). In this method one builds a search tree which is exhaustively traversed for a solution. The critical observation for many parameterized problems is that, while the computation done at each node of the tree may depend on the problem size, the size of the tree itself depends only on the parameters. In this section we present an FPT algorithm for the 1-Sided Crossing Minimization problem based on the bounded search tree approach. The key observations for building a BST for this problem lie in Lemma 1 and Fact 4. Here is an overview of our algorithm.
A Fixed Parameter Tractable Algorithm for 1-Sided Crossing Minimization
125
Lemma 1 allows us, at the start, to fix the relative ordering of each nontrivial suited pair of vertices in L2 according to its unique natural ordering. The remaining unordered pairs of vertices in L2 are either trivial suited pairs, or unsuited pairs which will each, by Fact 4, create a crossing no matter which relative ordering is chosen. We build a bounded search tree (i.e., a BST) based on the unsuited pairs. (It turns out that the trivial pairs neighbours can be dealt with later in the algorithm.) The input to every node of the BST is a budget B giving the remaining number of allowed edge crossings, and a relation D containing all pairs of L2 ordered thus far. We will formally define relation D shortly. At each node of the BST some unordered pair (v, w) is chosen (i.e. a pair not in D) such that cvw = cwv . Then the node branches to two recursive subproblems. In one branch, the ordering of (v, w) is fixed to v < w and the budget B is reduced by cvw . In the other branch the ordering of (v, w) is fixed to w < v and B is reduced by cwv . Since we only work with unsuited pairs in building the tree, we know that cvw ≥ 1 and cwv ≥ 1. Therefore, since the initial budget B = k, the height of the BST is at most k. As a matter a fact the situation is better than that, for two reasons. Firstly, since cvw = cwv , then either cvw or cwv is at least 2, so one of the two branches of the BST node reduces B by at least 2. Secondly, since < is a transitive relation, fixing an ordering of the pair (v, w) at a node of the BST may in fact impose an ordering of another as yet unordered pair (p, q) in the relation D at that node. Hence B can be reduced not only by cvw but also by either cpq or cqp , depending on which relative ordering is imposed on (p, q). 4.2
The Algorithm
The following definitions will be useful for the description of the algorithm. Let D be a directed acyclic graph (digraph) that represents a binary relation “ < ” on the set of vertices L2 . In particular, the vertices of L2 are represented by nodes of a digraph D and an ordered pair of vertices v < w is represented by a directed edge from v to w (denoted henceforth by vw) in D. The digraph D is stored as an |L2 | × |L2 | matrix. We use D to denote both the set of pairs in the current binary relation “ < ” and the associated acyclic directed graph that represents these pairs as directed edges. The algorithm labels nodes in the BST with digraphs. The digraph associated with the root will be transitively closed, acyclic, and directed. As the algorithm progresses, it computes a digraph label for each child node it generates in the BST by choosing a directed edge to add to the digraph of the parent and then taking the transitive closure of this. The following algorithm solves the 1-Sided Crossing Minimization problem. Algorithm: 1-Sided Crossing Minimization Input: G, π1 , k Output: πopt if G, π1 , k is a YES instance, else NO
126
Vida Dujmovi´c and Sue Whitesides
Step 0. Computing crossing numbers: Compute the crossing numbers cvw and cwv for all pairs of vertices in L2 , stopping the computation of a particular crossing number as soon as it is known to exceed k. Step 1. Checking for extreme values: Compare k with the upper and lower bound as per Fact 3. if k < Σ(v,w) min(cvw , cwv ) then output NO and HALT; if k ≥ Σ(v,w) max(cvw , cwv ) then output an arbitrary π2 and HALT. Step 2. Initialization: Precompute the following information required by the bounded search tree. C = {(v, w)|cvw = cwv }; D0 = a directed acyclic graph (V, E), where V = L2 , and the directed edges vw ∈ E correspond to the naturally ordered pairs (v, w) that satisfy cvw = 0 and cwv = 0. (It is easy to check that D0 is transitively closed.); B0 = initial budget = k−Σvw∈D0 cvw −Σ(v,w)∈C cvw . Note that Σvw∈D0 cvw = 0. Also note that we reduce the budget k by the eventual cost of the pairs in C even though these pairs do not appear in D0 . Step 3. Building the search tree: A node of the search tree has at most two children. Each node has a label (D, B). The label D of a node represents a “possible” partial solution, i.e. a partial ordering of vertices of L2 . The label B represents the remaining budget for crossings. For instance the label of the root is: D= D0 and B = B0 . We now build the search tree as follows. Label the root of the tree with (D, B) where D = D0 and B = B0 . In general, for a non-leaf node labeled (D, B), choose a pair (v, w) such that D contains no edge joining v and w and such that cvw = cwv . A pair (v, w) is thus an unordered pair not in C. In any ordering π2 , the pair (v, w) is ordered as either vw or wv, so we create at most two children (D1 , B1 ) and (D2 , B2 ) of the non-leaf node (D, B) corresponding to these two possibilities. No child is created if its budget would be negative. Thus a node labeled (D, B) is a leaf if and only if, either it does not have an unordered pair (v, w) ∈ C; or there remains any pair (v, w) for which both B1 and B2 are negative. For a non-leaf node (D, B), we label one of its two children by (D1 , B1 ) where: D1 = transitive closure of D ∪ vw, and B1 = B − cvw − pq cpq . Here D ∪vw represents the addition of directed edge vw to D. The summation in B1 is over the directed edges that are added to D ∪ vw by the transitive closure and that have cpq = cqp . That is, the sum is over pq s.t. pq ∈ D1 and pq ∈ D ∪vw and cpq = cqp . B2 ), where: Similarly, we label the other child of node (D, B) with (D2 , D2 = transitive closure of D ∪ vw, and B2 = B − cvw − pq cpq . If a leaf is created whose label D has the property that ∀(v, w) if vw ∈ D and wv ∈ D then (v, w) ∈ C, then output π2 = topological sort of D. Also, update the minimum number of crossings found so far to k − B, where B is the budget of the leaf, and update the best ordering so far to π2 . We call such a node a solution leaf.
A Fixed Parameter Tractable Algorithm for 1-Sided Crossing Minimization
127
If after exploring the entire tree, no solution leaf is found, output NO and HALT; otherwise, output the best ordering found, which is πopt , and HALT. Remarks. In Step 0, we stop computing cvw as soon as it becomes k + 1, even though cvw may be bigger than that. This is because a child with v < w would have a negative budget. Hence it suffices to know that cvw ≥ k + 1. Step 3 of the algorithm effectively creates and explores the search tree simultaneously. This can be done by depth-first search, or by breath-first search. The depth-first way requires less space and is thus the preferred choice. Also notice that, when creating a child by choosing, say, to order v and w as vw, we reduce the budget for the child by an amount computed not only for the ordered pair vw, but also for the pairs that are newly ordered by the transitive closure of D ∪ vw. However, we only do this for newly ordered pairs whose two crossing numbers are not the same. Those whose crossing numbers are the same have already been accounted for in B0 . Theorem 6. Given a bipartite graph G = (L1 , L2 ; E), a fixed permutation π1 of L1 , and an integer k, algorithm 1-Sided Crossing Minimization(G, π1 , k) determines in O(φk · |L2 |2 + |L1 ||L2 |) time if cr(G, π1 , πopt ) ≤ k and if yes produces a 2-layer drawing (G, π1 , π2 ) with the optimum number of crossings. The constant √ φ in the running time is the golden ratio φ = 1+2 5 ≈ 1.618. Proof. Step 3 of the algorithm creates and explores the search tree simultaneously. For every node (D, B) of the search tree we maintain the following two invariants: (i) D is a transitively closed, directed, acyclic graph; (ii) The budget B at node (D, B) is B = k − vw∈C cvw − vw∈D&vw∈C cvw . This is true for the root node (D0 , B0 ). Suppose this is true for a node labeled (D, B). At this node, the algorithm chooses an unordered pair (v, w) with cvw = cwv . This pair is used to create up to two child nodes. We claim that both D ∪ vw and D ∪ wv are acyclic. Suppose, on the contrary, that D ∪ vw contains a directed cycle. Then D must contain a directed path from w to v. Since D is transitively closed, it contains edge wv, contradicting the fact that (v, w) is unordered in D. Similarly for D ∪ wv. Since the transitive closure of a directed acyclic graph is again acyclic, the graph labels D1 , D2 for any child nodes created at a node labeled D are again transitive and acyclic. Thus all the graph labels in the search tree are directed, acyclic, and transitively closed. The fact that labels B1 and B2 agree with formula (ii), follows directly from the formulas used to compute these two labels from the parent label B in Step 3 of the algorithm. As the tree is built, either a solution leaf is found, or the tree is completely explored without finding such a leaf. A solution leaf (D, B) has, by definition, a non-negative budget B. By the invariant (ii), the cost of all the crossings arising from the ordered pairs in D has been taken into account. By the definition of a solution leaf, all pairs (v, w) not ordered by directed edges in D are in C and satisfy cvw = cwv ; hence the total cost directly attributable to them has already been deducted from the initial budget k. Hence any topological sort of D produces a total ordering consistent with D and having total cost k−B, where
128
Vida Dujmovi´c and Sue Whitesides
0 ≤ B ≤ k. By the invariant (i), the label D of every node of the search tree is an acyclic graph and it necessarily has a topological sort. Based on this argument, a solution leaf (D, B) encodes an ordering π2 such that cr(G, π1 , π2 ) ≤ k. It is not difficult to verify that the solution leaves of the BST implicitly store all the orderings π2 for which cr(G, π1 , π2 ) ≤ k and in which all the suited pairs are ordered by their natural ordering. Lemma 1 implies that in order to decide if G, π1 , k is a YES or NO instance it is enough to consider only such orderings π2 . Therefore, if there is an ordering π2 such that cr(G, π1 , π2 ) ≤ k the algorithm finds one. In fact, since the algorithm updates the best solution found so far, when it terminates it outputs an optimal ordering πopt . We now discuss the running time of the algorithm. Only for an unordered unsuited pair v, w that has cvw = cwv are child nodes created, of which there are at most two. Therefore, in one child node the budget is reduced by at least 1 and in the other by at least 2. A node with B = 0 must be a leaf node, because any child of such a node would have a negative budget. Therefore, no further branching is allowed. At a node for which budget B = 1, at most one child can have a budget B1 that is non-negative, and in this case, B1 = 0 and the child must be a leaf. Thus a recurrence relation that generates an upper bound for the number of nodes in this search tree is: sB = sB−1 + sB−2 + 1 for k ≥ 2; s0 = 1, s1 = 2. It can be verified by induction that for B ≥ 0, sB = FB+2 + FB+1 − 1 where FB is the B-th Fibonacci number. From the bound on Fibonacci numbers and k+2 k given that B0 ≤ k, it follows that sB0 < φ√5 + φ√+1 − 1 < 1.9 · φk . Thus the 5 search tree has O(φk ) nodes. The time taken at each node of the search tree is dominated by updating a transitive closure of its label D after insertion of one ordered pair v < w (or w < v). Updating the transitive closure after one insertion can be done in O(|L2 |2 ) time [3]. These updates are needed to generate the labels for the children, of which there are at most two. Thus the time taken in the third step of the 1-Sided Crossing Minimization algorithm is O(φk · |L2 |2 ). It can be shown that the time taken in steps 0 - 2 of the algorithm is no more than O(k · |L2 |2 + |L1 ||L2 |). Thus the total running time of the algorithm is O(φk · |L2 |2 + |L1 ||L2 |). ✷
5
Conclusion
We have proved that the 1-Sided Crossing Minimization problem is fixed parameter tractable by presenting a very easy-to-implement FPT algorithm for its solution. Moreover, the algorithm finds a drawing with the smallest possible number of crossings in the case that this number does not exceed k. The exponential part of the running time of the algorithm is 1.618k . In many instances the base of this exponent will be even smaller. The reason is that a pair of vertices v, w will often have both crossing numbers cvw and cwv bigger than 1, or at least one of them bigger than 2. Each time a node of the BST branches on such a pair of vertices, the resulting search tree will be even smaller.
A Fixed Parameter Tractable Algorithm for 1-Sided Crossing Minimization
129
An interesting investigation for future research would be to compare experimentally the performance of the two known methods for optimal 1-Sided Crossing Minimization, namely, integer linear programming [13] versus our FPT algorithm.
References 1. M. J. Carpano. Automatic display of hierarchized graphs for computer aided decision analysis. IEEE Trans. Syst. Man Cybern., SMC-10(11):705– 715, 1980. 2. C. Catarci. The assignment heuristic for crossing reduction. IEEE Trans. on Systems, Man, and Cybernetics, 25(3), 1995. 3. T. Corman, C. Leiserson, and R. Rivest. Introduction to Algorithms. MIT Press, 1990. 4. G. Di Battista, P. Eades, R. Tamassia, and I. G. Tollis. Graph Drawing: Algorithms for the Visualization of Graphs. Prentice-Hall, 1999. 5. R. G. Downey and M. R. Fellows. Parametrized complexity. Springer, 1999. 6. S. Dresbach. A new heuristic layout algorithm for directed acyclic graphs. In U. Derigs, A. Bachem, and A. B. A. Drexl, editors, Operations Research Proceedings (1994), pages 121–126. Springer, 1995. 7. V. Dujmovi´c, M. Fellows, M. Hallett, M. Kitching, G. Liotta, C. McCartin, N. Nishimura, P. Ragde, F. Rosemand, M. Suderman, S. Whitesides, and D. R. Wood. A fixed-parameter approach to two-layer planarization. In Mutzel [15], pages 1–15. 8. V. Dujmovi´c, M. Fellows, M. Hallett, M. Kitching, G. Liotta, C. McCartin, N. Nishimura, P. Ragde, F. Rosemand, M. Suderman, S. Whitesides, and D. R. Wood. On the parameterized complexity of layered graph drawing. In Proc. 9th European Symposium on Algorithms (ESA 2001), volume 2161 of Lecture Notes in Comput. Sci., pages 488–499. Springer, 2001. 9. P. Eades and D. Kelly. Heuristics for drawing 2-layered networks. Ars Combin., 21(A):89–98, 1986. 10. P. Eades and S. Whitesides. Drawing graphs in two layers. Theoret. Comput. Sci., 131(2):361–374, 1994. 11. P. Eades and N. C. Wormald. Edge crossings in drawings of bipartite graphs. Algorithmica, 11(4):379–403, 1994. 12. M. R. Garey and D. S. Johnson. Crossing number is NP-complete. SIAM J. Algebraic Discrete Methods, 4(3):312–316, 1983. 13. M. J¨ unger and P. Mutzel. 2-layer straightline crossing minimization: performance of exact and heuristic algorithms. J. Graph Algorithms Appl., 1(1):1–25, 1997. 14. X Mu˜ noz, U Unger, and I Vrˇto. One sided crossing minimization is np-hard for sparse graphs. In Mutzel [15]. to appear. 15. P. Mutzel, editor. Proc. Graph Drawing: 9th International Symposium (GD’01), volume 2265 of Lecture Notes in Comput. Sci. Springer, 2001. 16. K. Sugiyama, S. Tagawa, and M. Toda. Methods for visual understanding of hierarchical system structures. IEEE Trans. Systems Man Cybernet., 11(2):109– 125, 1981. 17. N. Tomii, Y. Kambayashi, and S. Yajima. On planarization algorithms of 2-level graphs. Papers of tech. group on elect. comp., IECEJ, EC77-38:1–12, 1977. 18. V. Valls, R. Marti, and P. Lino. A branch and bound algorithm for minimizing the number of crossing arcs in bipartite graphs. J. Operational Res., 90:303–319, 1996. 19. J. N. Warfield. Crossing theory and hierarchy mapping. IEEE Trans. Systems Man Cybernet., SMC-7(7):505–523, 1977.
Simple and Efficient Bilayer Cross Counting Wilhelm Barth1 , Michael J¨ unger2 , and Petra Mutzel1 1
Institut f¨ ur Computergraphik und Algorithmen, Technische Universit¨ at Wien Favoritenstraße 9–11, A-1040 Wien, Austria {barth, mutzel}@ads.tuwien.ac.at http://www.ads.tuwien.ac.at/ 2 Institut f¨ ur Informatik, Universit¨ at zu K¨ oln Pohligstraße 1, D-50969 K¨ oln, Germany [email protected] http://www.informatik.uni-koeln.de/ls juenger/
Abstract. We consider the problem of counting the interior edge crossings when a bipartite graph G = (V, E) with node set V and edge set E is drawn such that the nodes of the two shores of the bipartition are drawn as distinct points on two parallel lines and the edges as straight line segments. The efficient solution of this problem is important in layered graph drawing. Our main observation is that it can be reduced to counting the inversions of a certain sequence. This leads to an O(|E| + |C|) algorithm, where C denotes the set of pairwise interior edge crossings, as well as to a simple O(|E| log |Vsmall |) algorithm, where Vsmall is the smaller cardinality node set in the bipartition of the node set V of the graph. We present the algorithms and the results of computational experiments with these and other algorithms on a large collection of instances.
1
Introduction
Let G = (N, S, E) be a bipartite graph with disjoint node sets N and S and let all edges in E have one end node in N and one in S. Furthermore, let LN , LS ∈ IR2 be two disjoint parallel lines, a “northern” and a “southern” line. A bilayer drawing BLD(G) assigns all nodes ni ∈ N = {n0 , n1 , . . . , np−1 } to distinct points P (ni ) on LN and all nodes sj ∈ S = {s0 , s1 , . . . , sq−1 } to distinct points P (sj ) on LS . The edges ek = (ni , sj ) ∈ E = {e0 , e1 , . . . , er−1 } are assigned to straight line segments with end points P (ni ) and P (sj ), see Fig. 1 for an example. Given a bilayer drawing BLD(G) of a bipartite graph G = (N, S, E), the bilayer cross count is the number BCC (BLD(G)) of pairwise interior intersections of the line segments corresponding to the edges. The example in Fig. 1 has a bilayer cross count of 12. It is a trivial observation that BCC (BLD(G)) only depends on the relative positions of the node points on LN and LS and not on their exact coordinates. Therefore, BCC (BLD(G)) is determined by permutations πN of N and πS of S. Given πN and πS , we wish to compute BCC (πN , πS ) efficiently by a simple algorithm. For ease of exposition, we assume without loss of generality that there are no isolated nodes and that q ≤ p. M.T. Goodrich and S.G. Kobourov (Eds.): GD 2002, LNCS 2528, pp. 130–141, 2002. c Springer-Verlag Berlin Heidelberg 2002
Simple and Efficient Bilayer Cross Counting
131
Fig. 1. A bilayer drawing
In automatic graph drawing, the most important application of bilayer cross counting occurs in implementations of Sugiyama-style layout algorithms [11]. Such a procedure has three phases. In the first phase, the nodes are assigned to m parallel layers for some m ∈ IN such that all edges join two nodes of different layers. Edges that connect non-adjacent layers are subdivided by artificial nodes for each traversed layer. In the second phase, node permutations on each layer are determined with the goal of achieving a small number of pairwise interior edge crossings. In the third phase, the resulting topological layout is transformed to a geometric one by assigning coordinates to nodes and edge bends. See Fig. 2 for a typical Sugiyama-style layout in which an artificial node is assumed wherever an edge crosses a layer. In this example, the artificial nodes co¨ıncide with the edge bends.
Fig. 2. A typical Sugiyama-style layout
In phase two, popular heuristics approximate the minimum number of crossings with a layer by layer sweep. Starting from some initial permutation of the nodes on each layer, such heuristics consider pairs of layers (Lfixed , Lfree ) = (L0 , L1 ), (L1 , L2 ), . . . , (Lm−2 , Lm−1 ), (Lm−1 , Lm−2 ), . . . , (L1 , L0 ), (L0 , L1 ), . . . and try to determine a permutation of the nodes in Lfree that induces a small bilayer cross count for the subgraph induced by the two layers, while keeping Lfixed
132
Wilhelm Barth, Michael J¨ unger, and Petra Mutzel
temporarily fixed. These down and up sweeps continue until no improvement is achieved. The bilayer crossing minimization problem is NP-hard [4] yet there are good heuristics and it is even possible to solve this problem very quickly to optimality for instances with up to about 60 nodes per layer [6]. A common property of most algorithmic approaches is that a permutation of the nodes of the free layer is determined by some heuristic and then it must be decided if the new bilayer cross count is lower than the old one. This is the bilayer cross counting problem that we address in this paper. It has been observed in [12] that bilayer cross counting can be a bottleneck in the overall computation time of Sugiyama-style algorithms. Of course, it is easy to determine if two given edges in a bilayer graph with given permutations πN and πS cross or not by simple comparisons of the relative orderings of their end nodes on LN and LS . This leads to an obvious algorithm with running time O(|E|2 ). This algorithm can even output the crossings rather than only count them, and since the number of crossings is Θ(|E|2 ) in the worst case, there can be no asymptotically better algorithm. However, we do not need a list of all crossings, but only their number. The bilayer cross counting problem is a special case of a core problem in computational geometry, namely counting (rather than reporting) the number of pairwise crossings for a set of straight line segments in the plane. Let C be the set of pairwise crossings. The best known algorithm for reporting all these crossings is by Chazelle and Edelsbrunner [2] and runs in O(|E| log |E| + |C|) time and O(|E| + |C|) space; the running time is asymptotically optimum. The best known algorithm for counting the crossings is by Chazelle [1] and runs in O(|E|1.695 ) time and O(|E|) space. For the bilayer cross counting problem, a popular alternative in graph drawing software is a sweep-line algorithm by Sander [10] that runs in O(|E| + |C|) time and O(|E|) space. This algorithm is implemented, e.g., in the VCG tool [9] or the AGD library [5]. A breakthrough in theoretical and practical performance is an algorithm by Waddle and Malhotra [12] that runs in O(|E| log |V |) time and O(|E|) space, where V = N ∪ S. The authors report on computational experiments that clearly show that the improvement is not only theoretical but leads to drastic time savings in the overall computation time of a Sugiyama-style algorithm that is implemented in an internal IBM software called NARC (Nodes and ARC) graph toolkit. Their algorithm consists of a sweep-line procedure that sweeps the bilayer graph once, say from west to east, and maintains a data structure called accumulator tree that is similar to the range tree data structure that is common in computational geometry, e.g., when a finite set of numbers is given and the task is to determine the cardinality of its subset of numbers that lie in a specified interval, see Lueker [8]. The sweep-line procedure involves complicated case distinctions and its description takes several pages of explanation and pseudo-code. In Section 2 we give a simple proof of the existence of O(|E| log |V |) algorithms for bilayer cross counting by relating the bilayer cross count to the number of inversions in a certain sequence. This observation immediately leads to a bilayer cross counting algorithm that runs in O(|E| + |C|) time and O(|E|)
Simple and Efficient Bilayer Cross Counting
133
space like the algorithm by Sander [10] and another algorithm that runs in O(|E| log |V |) time and O(|E|) space like the algorithm by Waddle and Malhotra [12]. In Section 3, we present an even simpler algorithm that runs in O(|E| log |Vsmall |) time and O(|E|) space, where Vsmall is the smaller cardinality set of N and S. This algorithm is very easy to understand and can be implemented in a few lines of code. The question how the old and the new algorithms perform in direct comparison is addressed empirically in Section 4. It turns out that the algorithm presented in detail in Section 3 outperforms the others not only in terms of implementation effort, but in most cases also in terms of running time.
2
Bilayer Cross Counts and Inversion Numbers
In a sequence π = a0 , a1 , . . . , at−1 of pairwise comparable elements ai (i = 0, 1, . . . , t − 1), a pair (ai , aj ) is called an inversion if i < j and ai > aj . The inversion number INV (π) = |{(ai , aj ) | i < j and ai > aj }| is a well known measure of the degree of sortedness of the sequence π. In a bilayer graph with northern layer permutation πN = n0 , n1 , . . . , np−1 and southern layer permutation πS = s0 , s1 , . . . , sq−1 let πE = e0 , e1 , . . . , er−1 be sorted lexicographically such that ek = (nik , sjk ) < (nil , sjl ) = el in πE iff ik < il or ik = il and jk < jl . In Fig. 1, the edges are sorted like this. Let π = j0 , j1 , . . . , jr−1 be the sequence of the positions of the southern end nodes in πE . In our example, we have π = 0, 1, 2, 0, 3, 4, 0, 2, 3, 2, 4. Each inversion in π is in a 1-1 correspondence to a pairwise edge crossing in a bilayer graph drawing BLD(G) according to πN and πS . Therefore, BCC (πN , πS ) is equal to the number of inversions in π. It is well known that the number of inversions of an r-element sequence π can be determined in O(r log r) time and O(r) space, e.g., Cormen, Leiserson, and Rivest [3] suggest an obvious modification of the merge sort algorithm in exercise 1-3d. Since the lexicographical ordering that leads to π can be computed in O(|E|) time and space, this implies immediately the existence of an O(|E| log |V |) time and O(|E|) space algorithm for bilayer cross counting. More precisely, the (modified) merge sorting algorithm requires O(r log RUN (π)) time and O(r) space, where RUN (π) is the number of runs, i.e., the number of sorted subsequences in π. This appears attractive when RUN (π) is expected to be small. We will test this empirically in Section 4. The number of inversions of a sequence π can also be determined with the insertion sort algorithm with O(r + INV (π)) time and O(r) space consumption, and this immediately gives an O(|E| + |C|) time and O(|E|) space algorithm for bilayer cross counting. We will work out this idea in detail in the following section, and develop another algorithm with O(|E| log |Vsmall |) running time. An algorithm for counting the inversions of an r-element sequence π with elements in {0, . . . , q − 1}, q ≤ r, with running time better than O(r log r) would immediately improve the bilayer cross counting approaches based on counting inversions. We do not know if such an algorithm exists.
134
3
Wilhelm Barth, Michael J¨ unger, and Petra Mutzel
A Simple O(|E| log |Vsmall |) Algorithm
Our task is the efficient calculation of the number of inversions of the sequence π coming from a bilayer graph drawing according to πN and πS as described in Section 2. We explain our algorithm in two steps. In step 1, we determine the bilayer cross count by an insertion sort procedure in O(|E|2 ) time, and in step 2, we use an accumulator tree to obtain O(|E| log |Vsmall |) running time. We use the example of Fig. 1 to illustrate the computation. Here is step 1: (a) Sort the edges lexicographically according to πN and πS by radix sort as described in Section 2. This takes O(|E|) time. In Fig. 1, this step has already been performed and the edges are indexed in sorted order. (b) Put the positions of the southern end nodes of the edges into an array in sorted order of (a). In the example, we obtain 0, 1, 2, 0, 3, 4, 0, 2, 3, 2, 4. (c) Run the insertion sort algorithm (see, e.g. [3]) on the array and accumulate the bilayer cross count by adding the number of positions each element moves forward. In the illustration on our example in Fig. 3 we also show the nodes of N and the edges of E. This additional information is not needed in the algorithm, it just helps visualizing why the procedure indeed counts the crossings. In our example, the answer is 2 + 4 + 2 + 1 + 3 = 12 crossings. The correctness of this algorithm follows from the fact that whenever an element is moved, the higher indexed elements are immediately preceding it in the current sequence. This is the important invariant of the insertion sort algorithm. So the total number of positions moved is equal to the number of crossings. Insertion sort takes linear time inthe number of edges plus the number inversions in the worst case, we have of inversions, and since there are |E| 2 described an O(|E|2 ) algorithm for bilayer cross counting. Now in step 2 of our explanation we use an accumulator tree as in [12] in order to obtain an O(|E| log |Vsmall |) algorithm. Namely, let c ∈ IN be defined by 2c−1 < q = |S| ≤ 2c , and let T be a perfectly balanced binary tree with 2c leaves whose first q are associated with the southern node positions. We store the accumulator tree T in an array with 2c+1 −1 entries in which the root is in position 0 and the node in position i has its parent in position i−1 2 . All array entries are initialized to 0. Our algorithm accumulates the number of the associated southern nodes in each tree leaf and the sum of the entries of its children in each internal tree node. It builds up this information by processing the southern end node positions in the order given by π. For each such position, we start at its corresponding leaf and go up to the root and increment the entry in each visited tree position (including the root) by 1. In this process, whenever we visit a left child (odd position in the tree), we add the entry in its right sibling to the number of crossings (which is initialized to 0). In Fig. 4, we demonstrate this for our example: Inside each tree node, we give its corresponding tree index, and to the right of it, we give the sequence of entries as they evolve over time. An entry vj indicates that value v is reached when the j-th element of the sequence π
Simple and Efficient Bilayer Cross Counting
135
Fig. 3. Counting crossings via insertion sort
is inserted. The bilayer cross count becomes 2, 6, 8, 9, and 12, when the southern end node positions of e3 , e6 , e7 , e8 , and e9 , respectively, are inserted. By our reasoning above, the correctness of the algorithm is obvious and, if we assume without loss of generality that |S| ≤ |N |, i.e., Vsmall = S, we have a running time of O(|E| log |Vsmall |). Fig. 5 displays a C-program fragment that implements the algorithm. The identifier names correspond to the notation
136
Wilhelm Barth, Michael J¨ unger, and Petra Mutzel
Fig. 4. Building the accumulator tree and counting the crossings
we have used above, or are explained in comments, respectively. The identifier southsequence points to an array corresponding to the sequence π of the southern end node positions after the radix sorting (not shown here) has taken place.
/* build the accumulator tree */ firstindex = 1; while (firstindex0) { 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 fo