Journal of Graph Algorithms and Applications http://www.cs.brown.edu/publications/jgaa/ vol. 6, no. 1, pp. 3–5 (2002)
Graph Drawing and Representations Special Issue on Selected Papers from the Seventh International Symposium on Graph Drawing, GD’99 Guest Editors’ Foreword Hubert de Fraysseix CNRS UMR 8557 — E.H.E.S.S. 54 Bd Raspail, 75006 Paris, France http://www.ehess.fr/centres/cams/person/hf
[email protected]
Jan Kratochv´ıl Department of Applied Mathematics and Institute for Theoretical Computer Science Charles University Malostransk´e n´ am. 25, 188 00 Praha 1, Czech Republic http://www.ms.mff.cuni.cz/acad/kam/kratochvil
[email protected]
GD’99 was supported in part by DIMATIA Charles University and Czech Research ˇ 201/99/0242. Editorial work on this volume was partially supported grant GACR by the Institute for Theoretical Copmputer Science of Charles University (project LN00A056 of the Ministry of Education of the Czech Republic).
H. de Fraysseix and J. Kratochv´ıl, Foreword , JGAA, 6(1) 3–5 (2002)
1
4
A few words about the conference
This special issues features contributions based on five of the papers and one of the invited talks presented at GD’99 at Stirin Castle in the vicinity of Prague, Czech Republic. The conference brought together researchers, practitioners, developers and users working on all aspects of graph visualization and representations. The issues considered in graph drawing range from geometry, topology, partially ordered sets and graph theory, through algorithms and complexity theory to practical systems and applications. The interaction between theoretical advances and implemented solutions has always been an important part of the graph drawing field and of the Graph Drawing Symposia. In a recently restored baroque castle 30 km out of Prague, the participants were less distracted by the numerous opportunities of day- and night-life attractions of the fabulous city. The English style gardens of the castle provided opportunities for walks and discussions, the artistic atmosphere of the castle was enhanced by the conference concert given by Jiˇr´ı Stiv´ın, a prominent Czech jazz musician, and by the invited talk “Art of drawing” by Jaroslav Neˇsetˇril, who is also a prominent Prague painter. It is our pleasure to include a paper based on this talk in our volume. In total 38 papers were accepted and presented during the conference. Five of these papers were invited for this special volume. All of them went through further rigorous refereeing process. Also because of this, but from other reasons as well, the papers in this volume differ substantially from their proceedings versions. Most of them are presented in more detail, and therefore became significantly longer. In one case, on the other hand, the new version became considerably shorter than the conference one. This is because a stronger and more general theorem was proven by the author in the meantime. We believe that both publishing new stronger results as well as including more details to other papers’ results and proofs will be welcome and appreciated and justifies the 2 year span between the conference and the appearance of this special volume. We would like to thank the authors for their patience and the referees for their hard work.
2
A few words about the papers
The first and last papers of the volume are devoted to geometrical representations of graphs or partially ordered sets. The question if every planar graph allows a representation as an intersection graph of straight line segments has now become a well known problem in the area, with names as Fellows, Pach, Pollack, Scheinerman and Erd¨ os attached to various partial results and variants of the problem. It is well known that planar bipartite graphs are even contact graphs of segments. The result stating that planar triangle-free graphs are intersection graphs of segments in three directions in the plane proved in Triangle-free planar graphs and segment intersection graphs by de Castro, Cobos, Dana, Marquez and Noy is still today, 2 years after the GD’99 conference,
H. de Fraysseix and J. Kratochv´ıl, Foreword , JGAA, 6(1) 3–5 (2002)
5
the strongest result in the area. The paper Planar Graphs with Topological Constraints by Dornheim considers the question of drawing graphs under certain topological constraints, namely of the form that a vertex is inside or outside a particular cycle in the graph. This novel approach is treated very thoroughly and a number of NP-completeness results and polynomial time algorithms are presented. J¨ unger and Leipert in their paper Level Planar Embedding in Linear Time provide a second step towards automatic drawing of level planar graphs. At GD’98, J¨ unger, Leipert and Mutzel presented a linear time algorithm for recognizing level planar graphs. The step from recognition to actual construction of an embedding, which is definitely not straightforwardly linear time, is presented in this paper. Drawing planar graphs on a prescribed locations of vertices is an important question, both from theoretical and practical points of view. The paper Embedding Vertices at Points: Few Bends suffice for Planar Graphs by Kaufmann and Wiese show (among other results) that every 4-connected planar graph can be embedded on any given point set with at most one bend per edge, while this question is NP-complete for general planar graphs. The invited talk of Jarik Neˇsetˇril about “Art of drawing” was very well accepted by the participants of GD’99. It is true that the speaker talked slightly more about art and drawings than about graphs, but the audience learned a lot from this talk about the meaning and significance of drawings. After the recent development in the area, namely the talk of the author at the symposium Graph Drawing 2001 in Vienna (coauthored by J. Adamec), we have asked Neˇsetˇril to prepare a paper stemming from his earlier presentation which would, however, reflect and comment on the new notion of fractal length or combinatorial entropy of drawings. We appreciate very much that he was willing to prepare this contribution in such a short time, so that it is possible to include it in the present volume. The last paper of the volume, Realization of Posets by Ossona de Mendez is another paper on geometric representations. It presents a very general result on representations of partially ordered sets which, among others, generalizes a famous result of Schnyder about incidence posets of planar graphs.
Journal of Graph Algorithms and Applications http://www.cs.brown.edu/publications/jgaa/ vol. 6, no. 1, pp. 7–26 (2002)
Triangle-Free Planar Graphs as Segment Intersection Graphs Natalia de Castro
Francisco Javier Cobos Alberto M´ arquez
Juan Carlos Dana
Departamento de Matem´ atica Aplicada I Universidad de Sevilla http://www.ma1.us.es/ {natalia, cobos, dana, almar}@us.es
Marc Noy ∗ Departamento de Matem´ atica Aplicada II Universitat Polit`ecnica de Catalunya http://www.upc.es/
[email protected] Abstract We prove that every triangle-free planar graph is the intersection graph of a set of segments in the plane. Moreover, the segments can be chosen in only three directions (horizontal, vertical and oblique) and in such a way that no two segments cross, i.e., intersect in a common interior point. This particular class of intersection graphs is also known as contact graphs.
Communicated by H. de Fraysseix and and J. Kratochv´ıl: submitted October 1999; revised February 2001 and July 2001.
∗
Partially supported by projects SEUI-PB98-0933 and CUR Gen. 1999SGR00356.
Cat.
N. de Castro et al., Segment Intersection Graphs, JGAA, 6(1) 7–26 (2002)
1
8
Introduction
Given a set S of segments in the plane, its intersection graph has a vertex for every segment and two vertices are adjacent if the corresponding segments intersect. Intersection graphs of segments and other geometrical objects have been widely studied in the past. For instance, if the segments are contained in a straight line then we have the interval graphs [5], a well-known family of perfect graphs. If the segments are chords of a circle then the intersection graph is called a circle graph, see for instance [8, 10]. An interesting result, due to de Fraysseix, Osona de Mendez and Pach [4], and independently to Ben-Arroyo Hartman, Newman and Ziv [2], says that every planar bipartite graph is the contact graph (a particular case of intersection graph, where no two segments cross) of a set of horizontal and vertical segments and, in a different formulation, Tamassia and Tollis proved in [11] almost the same result. On the other hand, it is known that the recognition of such graphs is an NP-complete problem (see [6], [7] and recently [3]). This result provides a partial answer to a question of Scheinerman [9]: Is every planar graph the intersection graph of a set of segments in the plane? The main result in this paper, which is a significant extension of [4], is that every triangle-free planar graph is the intersection graph of a family of segments. Moreover, the segments can be drawn in only three directions and in such a way that they do not cross, i.e. the segments do not have any interior point in common. This particular class of intersection graphs is also known as contact graphs. We call such a representation a segment representation of the graph.
v1
h1
o1
h1 o2
v2 v4
v3
v5
v1
v2
v3
v5
v4
o2
h2
h3
h5 h4
h3
h2
o3
h4
v7
o1
v6 h6
v6
o3 h5 v7
h6
Figure 1: A segment representation of a planar graph.
Our technique is similar in spirit to the one used in [2] for bipartite planar graphs with some transformations. A key point in our proof is Gr¨ otzsch’s Theorem [12], which guarantees that every planar triangle-free graph is 3-colorable.
N. de Castro et al., Segment Intersection Graphs, JGAA, 6(1) 7–26 (2002)
9
The sketch of the proof is as follows. Fixing an embedding of a given triangle-free planar graph G, adding new vertices and (induced) paths between the vertices of the graph we can obtain a new triangle-free graph embedded in the plane which is a subdivision of a 3-connected graph. Starting with a 3-coloring, a segment representation in three directions is obtained for this new graph using several technical lemmas. Finally, removing the dummy vertices and paths, we obtain a segment representation of the graph G. The three directions considered are horizontal, vertical and oblique (parallel to the bisector of the second quadrant of the plane).
2
Pseudo-convex faces with three directions
In this section we present some preliminaries and we indicate the basic techniques that are used. Let G be a planar graph, and consider a fixed embedding of G in the plane. The embedding divides the plane into a number of regions that we call faces of the graph. Let IG be a segment representation of G. We assume throughout the paper that no segment continues beyond its last intersection with a segment in another direction. The segment representation also partitions the plane into regions which we call faces of the representation, whose are simple n-polygons (if n ≥ 4, there is no pair of non-consecutive edges sharing a point). The proof of our main result is based on adapting the concept of “convex polygon” for segments in three directions. A segment path of length n is a sequence of horizontal, vertical and oblique segments P = {s1 , . . . , sn } such that segment si intersects si−1 and si+1 , for 1 < i < n. A segment path P = {s1 , . . . , sn } is said to be monotone with respect to a straight line l if any line orthogonal to l intersects P in exactly one point. We consider monotone paths of the segment representation with respect to the following two lines: the bisector of the second quadrant of the plane (l1 = {x + y = 0}) and the line (l2 = {x − 2y = 0}). Since we can draw a monotone path rightward or leftward, we distinguish four different kinds of monotone paths: • A path P is an increasing monotone path to the right (IMPR) if its horizontal segments are drawn rightward, its vertical segments are drawn upward, and its oblique segments are drawn rightward and downward. • A path P is a decreasing monotone path to the right (DMPR) if its horizontal segments are drawn rightward, its vertical segments are drawn downward, and its oblique segments are drawn rightward and downward. • A path P is a decreasing monotone path to the left (DMPL) if its horizontal segments are drawn leftward, its vertical segments are drawn downward, and its oblique segments are drawn leftward and upward.
N. de Castro et al., Segment Intersection Graphs, JGAA, 6(1) 7–26 (2002)
10
• A path P is an increasing monotone path to the left (IMPL) if its horizontal segments are drawn leftward, its vertical segments are drawn upward, and its oblique segments are drawn leftward and upward.
s1
DMPL sn IMPL
DMPR
sn
IMPR s1
Figure 2: Monotone paths. Let IG be a segment representation of a plane triangle-free graph G. Recall that the face boundaries of the representation correspond to closed walks in G. A face F of a segment representation is pseudo-convex if its boundary can be divided into an IMPR, a DMPR, a DMPL and an IMPL (clockwise). It can be seen that the partition of a pseudo-convex face into monotone paths is not unique, but there are only a few possibilities and this does not modify the proofs of the theorems. From now on, we consider the boundary of a pseudo-convex face clockwise.
IMPR DMPR
F
IMPL
DMPL
Pseudo-convex Face
Non Pseudo-convex Face
Figure 3: The four paths of a pseudo-convex face.
Given a pseudo-convex face, we define the upper subpath as the union of its IMPR and its DMPR and, the lower subpath as the union of its DMPL and IMPL subpath. Analogously, we define the right subpath as the union of the DMPR and DMPL, and the left subpath as the union of the IMPL and IMPR. In this way the boundary of a pseudo-convex face can be considered as the
N. de Castro et al., Segment Intersection Graphs, JGAA, 6(1) 7–26 (2002)
11
union of the upper and lower subpaths, and also as the union of the right and left subpaths. We say that the upper and lower subpaths are opposite subpaths to each other (analogously with the right and the left subpaths).
Left subpath Right subpath
Upper subpath
F Lower subpath
Figure 4: The upper, lower, right and left subpaths of a pseudo-convex face. Note that if F is a pseudo-convex face, and P is a monotone path inside F connecting two segments in its boundary, then P partitions F into two new pseudo-convex faces. Moreover, if two segments on the boundary of F can be extended inside F until they cross, those extended segments also would split F into two new pseudo-convex faces. In order to build a segment representation of a plane graph G, we proceed by representing the boundary of the outerface of G by contact segments, using a pseudo-convex representation. If two vertices of the outerface are joined in G by a path, we represent this path as a monotone segment path inside the representation of the outerface, obtaining two pseudo-convex faces. Recursively we represent monotone paths of G until the representation of the graph is completed. We see then that in order to represent a graph by contact segments it is necessary to join segments by segment paths inside the faces of the representation. We need to extend segments of the boundary of the faces inside them to contact the segments. However it is not always possible to extend segments inside a pseudo-convex face. A segment of a pseudo-convex is extensible along one of its ends if and only if its angle inside the face is concave. Thus, a segment of a pseudo-convex face is extensible by one of its ends, or by both or by none, depending on the adjacent segments (see Figure 5).
N. de Castro et al., Segment Intersection Graphs, JGAA, 6(1) 7–26 (2002)
12
Non-extensible Extensible by one Extensible end by both ends
Figure 5: Extensible segments.
It is obvious that in order to join two segments inside a pseudo-convex face, one of them must be extended, but this is not sufficient in general as we can see in Figure 6: segment r2 can be extended inside F , but we can not join it with r1 because r2 intersects other segments of the face. The segment r3 can be also extended inside the face, but we cannot join r1 with r3 because they never contact.
r1
r2 r3
Figure 6: Extension of segments.
According to the above remark, we have two different problems when we try to join segments inside a pseudo-convex face; when the segments can be extended inside the face, but they find some “obstacle” before the intersection (other segments of the face), and on the other hand when the segments cannot be extended or they never contact. To solve these problems we define two basic operations in the segment representation. The first operation is enlarging a segment of the representation, and the second one is changing the sense of drawing of some segments. Although we are interested in some specific segments, these operations will transform other segments of the representation.
N. de Castro et al., Segment Intersection Graphs, JGAA, 6(1) 7–26 (2002)
13
Enlarging a segment means to increase its length, and obviously we also need to increase the length of other segments of the representation and make a translation of other segments without modifying their length. With this operation we can keep away the obstacles and to overlap parallel segments, if we want to join them by a segment path. The other operation allows us to extend a segment by one of its ends, if it was not possible before. It changes the sense of drawing of its adjacent segment and the other segments of its monotone path, to preserve the pseudo-convexity of the face.
Figure 7: Transforming the segment representation. The following technical lemmas allow us to construct a topological equivalent representation where we modify some segments, allowing to join the segments by a path of any length. Lemma 1 Let IG be a segment representation of a subdivision of a 3-connected plane graph G such that all its faces are pseudo-convex, let k be a positive real number and let s be a segment on the boundary of a face F of IG . Then IG can be transformed into another segment representation IG satisfying: 1. IG is topologically equivalent to IG (that is, the faces of IG and IG have the same facial walks), and the faces of IG are pseudo-convex; 2. it is possible to enlarge s (and at most two segments on the opposite subpath of F ), such that the length of s in IG is k + l.
N. de Castro et al., Segment Intersection Graphs, JGAA, 6(1) 7–26 (2002)
14
Proof: The proof is by induction on the number of faces of the graph G. Firstly, we suppose that F is just the boundary of IG , and let s be the segment of F that we want to enlarge. We can distinguish three cases depending on the direction of s. Case 1 Let s be a horizontal segment. If s is a horizontal segment in the upper subpath of F (analogously if s is in the lower subpath) we look for a horizontal segment s0 in the lower subpath of F . If there exists such segment we enlarge s and s0 by the same amount and we make a translation of all the segments between s and s0 , transforming F into another pseudo-convex face (see Figure 8 (a)). If there does not exist a horizontal segment s0 in the lower subpath of F , there must exist a vertical segment s0 and an oblique segment s00 which are adjacent in the lower subpath of F , because the boundary of F is a closed path. In this case, we increase the length of s, s0 and s00 and we make a translation of the rest of the segments (see Figure 8 (b)).
s
s
(a)
s'
s
s'
s
s' s''
s' (b)
s''
Figure 8: How to enlarge a segment of a pseudo-convex face by any amount, using parallel segments (a), using three segments (b).
Case 2 If s is a vertical segment, the proof is as Case 1, considering the boundary of F as the union of the right and left subpaths. Case 3 If s is an oblique segment, the proof is similar to the other cases, considering the boundary of F as the union of the upper and lower subpaths.
N. de Castro et al., Segment Intersection Graphs, JGAA, 6(1) 7–26 (2002)
15
Suppose that G has two bounded faces and let us denote by u1 , . . . , un the vertices of G which are in both faces. Let {s1 , . . . , sn } be the segments of IG corresponding to u1 , . . . , un , respectively, and let us denote by F1 and F2 the boundary of the bounded faces in IG .
s1 s
F2 s2
F1
s3 s4 s'
Figure 9: The adjacent segments are s1 , . . . , s4 . Let s be the segment of F1 we want to enlarge. By considerations given above, this transformation will enlarge other segments of F1 , but if none of these segments belong to F2 , we can reduce to Case 1 because the transformations does not modify F2 . If we have selected two (or three) segments in F1 to enlarge them, they will modify F2 if and only if F1 and F2 share more than one point of those segments. Thus, we can suppose that F1 ∩ F2 ∩ s1 is not just one point, and neither is F1 ∩ F2 ∩ sn . Otherwise, we do not consider the segments s1 and sn in the subpath {s1 , . . . , sn }. According to that, the path {s1 , . . . , sn } is monotone because the faces of IG are pseudo-convex. Suppose that s is in F1 . As in the case where G had only one bounded face, in the opposite subpath of F1 we look for a parallel segment or two contiguous segments non-parallel to s. If these segments are not in F2 we only modify F1 according to the first case. Let us suppose that s belongs to F1 and we have found a parallel segment s0 in the opposite part of F1 . Since F1 ∩ F2 is a monotone path and the segments are in opposite parts of F1 , just one of them belongs to F2 . Now, the task is to find a parallel segment in the opposite part of F2 , and we are sure that this new segment does not belongs to F1 , so enlarging all selected segments, a new representation IG0 equivalent to IG is obtained. The same proof remains valid if we choose two contiguous segments s0 and 00 s in F1 and they belong also to F2 . Suppose now that IG has n bounded pseudo-convex faces with boundaries F1 , . . . , Fn , and let s be a segment in the boundary of a face F . Since G is a subdivision of a 3-connected graph, there exists a face (for example Fn ) adjacent
N. de Castro et al., Segment Intersection Graphs, JGAA, 6(1) 7–26 (2002)
16
to the unbounded face (i.e., the boundary of the face in G corresponding to Fn has an edge in the unbounded face H of G) and such that s is not in Fn ∩ H. Thus, if we construct the graph G1 as the graph obtained from G by deleting all the edges of the face of G corresponding to Fn which are contained in the outerface, then we can assure that s belongs to G1 .
v1 v2 Fn v
3
v
4
v5 G
G1
s1 s
2
s
3
s s
4
5
IG
IG
1
Figure 10: Induction. Let v1 , . . . , vk be the vertices of G, corresponding to the segments s1 , . . . , sk of Fn , which are also on the outerface, where v2 , . . . , vk−1 are of degree two. By removing the segments of IG corresponding to the vertices v2 , . . . , vk−1 , we obtain a segment representation IG1 of G1 . Since IG1 has n − 1 faces, enlarging in any amount some of the segments, we can transform its segment representation into another one which has the same convex faces. To obtain this new representation, we have to enlarge other segments in IG1 besides s, but we have preserved the structure of the segments in the representation. So, we are able to represent again the segments corresponding to v2 , . . . , vk−1 enlarging the length of one (or two) of them, if it is necessary, to obtain a segment representation of G. 2 We can see, using Lemma 1, that by enlarging some segments, a segment representation with pseudo-convex faces can be transformed into another one preserving the topology of the embedding. But this is not sufficient to join segments inside a face, so we need another kind of transformation.
N. de Castro et al., Segment Intersection Graphs, JGAA, 6(1) 7–26 (2002)
17
Changing the sense of drawing of the segments of a monotone path of a pseudo-convex face F (for instance, the segments which were drawn to the left are drawn to the right) it is possible to draw a new pseudo-convex face F where these segments belong now to another monotone path. The remaining paths of F only change in the length of some of the segments (see Figure 11).
F
F s3
s2
s2 s1
s1
s4
s3
s4
Figure 11: How to restructure a face through a path. In the segment representation, the change of the face F to F produces some changes in the faces adjacent to F along the monotone path, and we obtain another segment representation with pseudo-convex faces as in the proof of Lemma 1 (see Figure 12). When we change the drawing in the manner described above, we say that the face F is restructured through the monotone path. Lemma 2 Let IG be a segment representation of a subdivision of a 3-connected plane graph G such that all its faces are pseudo-convex. Let F be a face of IG . Then, IG can be transformed into another segment representation IG satisfying: 1. IG is topologically equivalent to IG (that is to say, the faces of IG and IG have the same facial walks), and the faces of IG are pseudo-convex; 2. the face F corresponding to F has been restructured through a monotone path. Proof: We first suppose that F is just the boundary of IG . It is easily seen that we can change the drawing of the segments so that they belong to the previous or the following monotone path. Suppose now that IG has n bounded pseudo-convex faces. Let F be the face that we want to restructure through the monotone path s1 , . . . , sn . It is necessary to change the sense of drawing of all the segments of the restructured path, thus the other faces that contain in their boundaries the segments s1 , . . . , sn will be also restructured, but they will preserve their pseudo-convexity. The main idea is that no other face of the representation will be modified, except for the length of some segments, but by Lemma 1 it is possible to increase the length of the segments of the representation preserving the pseudo-convexity.
N. de Castro et al., Segment Intersection Graphs, JGAA, 6(1) 7–26 (2002)
18
In fact, we can consider the faces adjacent to F . The union of these faces determines a region of the plane, R, whose boundary is also a pseudo-convex face. Since restructuring F only modifies the segments in the interior of R but never in its boundary, the faces of the representation that are not adjacent to F will keep their structure. For instance, in Figure 12, we have restructured the face F and this transformation forces restructuring the shaded face. Other faces of the segment representation have been transformed in the length of some segments of their boundaries, but by Lemma 1 they preserve their pseudo-convexity.
F F
Figure 12: How to restructure the faces adjacent to the restructured face F . 2
3
Triangle-free graphs
We need the following result proved by Barnette [1]: Theorem 1 If G is a subdivision of a 3-connected graph, there exists a family Q1 , . . . , Qn−1 of paths in G such that the family of subgraphs defined as G1 = G, G2 = G1 − Q1 , . . . , Gn = Gn−1 − Qn−1 satisfies the properties 1. Each Gk is a subdivision of a 3-connected graph. 2. Gn is a subdivision of K4 . Moreover, if we fix a subgraph of G which is a subdivision of K4 , G can be reduced, by deleting edges and paths, to this subgraph. An easy consequence is that every planar triangle-free graph which is a subdivision of a 3-connected graph can be reduced, by deleting edges and paths with internal vertices of degree two, to a subdivision of a fixed complete subgraph K4 in such a way that in each step we have a subdivision of a 3-connected graph.
N. de Castro et al., Segment Intersection Graphs, JGAA, 6(1) 7–26 (2002)
19
This result will allow us to build a segment representation in three directions of subdivisions of 3-connected graphs as follows. Firstly we build a segment representation of a subdivision of K4 and then insert, in reverse order, the edges and paths that were removed to obtain from G the subdivision of K4 . In order to do this, we need two basic operations: (1) insert a segment path between two segments of the same face and (2) join two segments of the same face. The second operation is, at least, as difficult as the first one, so we will concentrate only in the second operation. As we see in Figure 6, we can find some problems in the segment representation to join two segments inside a face. Most of the cases can be solved by changing the drawing of the segments of the representation with the basic operations “enlarge segments” and “restructure faces”, but there are four rare cases that need an special operation. We need at this point some new definitions. Given a 3-colored plane graph G with colors {h, o, v}, a path P = {u1 , . . . , un } of G is rare if it verifies one of the following conditions: Case 1. u1 is colored as h, u2 as o, and un as v. Case 2. u1 is colored as v, un−1 as h, and un as o. Case 3. u1 is colored as h, u2 as o, un−1 as h, and un as o. Case 4. u1 is colored as o, u2 as v, un−1 as v, and un as h.
sn
v1
s
1
vn-1
s2
vn
rn r2 r1
w2
wn
w1 wn-1
Figure 13: Rare face (four rare paths). A face of a graph is called rare if there exists a monotone path containing a rare subpath (see Figure 13). We say that a rare face is repaired if we subdivide its rare path with a new vertex colored as v between u1 and u2 in the first and the third case, and between un−1 and un in the second case, or a new vertex colored as h between u1 and u2 in the fourth case.
N. de Castro et al., Segment Intersection Graphs, JGAA, 6(1) 7–26 (2002)
20
In the following lemma, when we say that two segments s and t can be joined by a segment path of length k, we mean a path {s, s1 , s2 , . . . , sk , t}. Lemma 3 Let IG be a segment representation of a plane graph G and let s1 and s2 be two distinct non adjacent segments in a pseudo-convex non-rare face F . Then IG can be transformed into another segment representation IG satisfying 1. IG and IG have the same faces and face boundaries as G, and the faces of IG are pseudo-convex; 2. s1 can be joined to s2 by a segment path of length k, for all k > 0, or directly if s1 and s2 have not the same direction inside the pseudo-convex face F , corresponding to F . Proof: The proof falls naturally into two cases: the segments have the same direction, or they do not.
s1
s2
s1
(a)
s2
s1
(b)
(c) s2
s2
s1
s1 s2
Figure 14: Joining segments Case 1: s1 and s2 do not have the same direction. Suppose the segments cannot be joined inside F directly. The lines containing
N. de Castro et al., Segment Intersection Graphs, JGAA, 6(1) 7–26 (2002)
21
s1 and s2 indicate us which end has to be extended for the segments to intersect. Let us mark these ends. 1. At least one of the segments is extensible by the marked end but it intersects other segments of F (Figure 14 (b)). Then we can enlarge some segments of F using Lemma 1 and save the obstacle. 2. No segment is extensible by the marked end (Figure 14 (c)). Then we have to restructure the face through the path containing s1 (or s2 ) to make it extensible. Note that there exists exactly four configurations where the segments are not extensible and restructuring the face does not solve the problem, but these are the rare paths which are excluded.
S1 S2
Non pseudo-convex face
Non pseudo-convex face
Figure 15: Segments s1 and s2 cannot be adjacent. We need that s1 and s2 are non adjacent segments because we cannot join them by a segment path inside F if their angle inside F is concave. Note that in this case F will split into two faces, but one of them will not be pseudo-convex (see Figure 15). Case 2: s1 and s2 have the same direction. In this case, it suffices to join the segments by a segment path of length one, because this path can be substituted by any path of length greater than one. Again there are two subcases: 1. If the segments belong to opposite subpaths (they are drawn in opposite sense). By Lemma 1, we can enlarge s1 and s2 until there exists a perpendicular line that crosses both segments, and a segment path of any length can be drawn inside the face.
N. de Castro et al., Segment Intersection Graphs, JGAA, 6(1) 7–26 (2002)
s
22
s1
1
s2
s2
(a) s1
s1
s2
s
2
(b)
Figure 16: Joining segments.
2. If the segments are drawn in the same sense and they cannot be extended, we have to restructure the face through the path containing s1 (or s2 ) to make it extensible. 2 The interest of these Lemmas is that they allow us to proof the following. Lemma 4 Any triangle-free plane graph which is a subdivision of a 3-connected graph can be represented by segments in three directions. Proof: As G is a triangle-free plane graph, in virtue of Gr¨otzsch’s Theorem [12], G admits a 3-coloring with the colors h, v and o (horizontal, vertical and oblique, respectively). Since G is a subdivision of a 3-connected graph, we can find a vertex, not in the outerface of G, connected by three disjoint paths to three vertices in the outerface. These paths and the outerface determine a graph K, which is a subdivision of K4 . Using Theorem 1 [1] it is possible to build a sequence of graphs G1 , . . . , Gn and a sequence of paths Q1 , . . . , Qn−1 such that G1 = G, Gi is a subdivision of a 3-connected plane graph, Gi is obtained from Gi−1 by deleting the path Qi−1 , and the graph obtained from Gn−1 deleting Qn−1 is K. When the path Qi is deleted, a new face F appears in Gi+1 as the union of two faces in Gi . The boundary of F can be divided into two paths; on the one hand the path beginning in the first vertex of Qi and ending in the last one and, on the other hand, the rest of the boundary. If one of them is rare, we must
N. de Castro et al., Segment Intersection Graphs, JGAA, 6(1) 7–26 (2002)
23
repair F by subdividing an edge with a new vertex (that we label as a repaired vertex), to make the face F non-rare. So, we can construct another sequence G01 , . . . , G0n where G0i is Gi with a new repaired vertex, if necessary.
sn s1
v1 v
s
n-1
2
rn r2 r1
vn
u
u
w2 wn
w1
u u
wn-1 Rare face (four rare paths)
Repaired face
Figure 17: Repairing rare paths. It is easy to give a segment representation of K 0 with all its faces pseudoconvex. It suffices to represent pseudo-convexly the outerface of K 0 and proceed according to the above remark. Using Lemma 3 it is possible to add the path Qi to the segment representation of G0i+1 to obtain a pseudo-convex face representation of G0i . Since every subgraph is a subdivision of a 3-connected graph, the path Qi cannot join adjacent vertices and so we can apply Lemma 3. In order to obtain a segment representation of the graph G, we must remove the repaired vertices. These segments cannot be removed directly, because we must change the drawing of one of the segments adjacent to the repaired vertex, so it is necessary to modify the representation. Since this is the last operation of the representation, and the repaired vertex is not adjacent to any other segment, it is possible to remove it, as illustrated in Figure 18. Notice that we could not remove the repaired vertices if the rare path would have exactly three segments u1 , u2 and u3 , but this case is not possible because joining u1 with u3 it will be form a triangle, and G was a triangle-free graph. 2 We can now formulate our main result as follows. Theorem 2 Every triangle-free planar graph is the contact graph of a set of segments in three directions. Proof: Let G be a triangle-free plane graph. Since G has no triangles, we can obtain a 3-coloring of G using Gr¨otzsch’s Theorem [12]. The colors will be labeled as h, v and o (horizontal, vertical and oblique, respectively). We can build a new triangle-free plane graph G1 , subdivision of a 3-connected graph, which contains G as a subgraph, by adding new vertices and edges joining the
N. de Castro et al., Segment Intersection Graphs, JGAA, 6(1) 7–26 (2002)
F'
F'
F'
F
F
F'
F
F'
F'
u F
F
F
F'
u F
F'
F
F'
u F
u
F'
F
F'
u
F
F'
F'
u
u F
24
F
u F
F'
F'
F'
F
F
Figure 18: How to remove the repaired vertex u in the four cases.
blocks of G. If this is the case, these vertices are labeled as dummy vertices. When an added edge produces a triangle, we subdivide it, and when a new edge joins two vertices with the same color, we subdivide it too. We call these new vertices and edges virtual. All the new vertices (dummy and virtual) can be colored so that the 3-coloring is preserved. By Lemma 4, G1 admits a segment representation. Out of this segment representation we must remove all the vertices and edges added. A virtual edge (or a path built with virtual edges and vertices) in the segment representation of G1 is an adjacency between two segments (or a virtual path joining two segments). It suffices to break this adjacency and to shorten these segments (note that the segments do not cross, they only contact). The dummy vertices are removed as the repaired vertices in Lemma 4 (see Figure 18). 2
4
Concluding remarks
The hypothesis that the graph has no triangles can be relaxed in some cases. No doubt there exist planar graphs with triangles that admit segment rep-
N. de Castro et al., Segment Intersection Graphs, JGAA, 6(1) 7–26 (2002)
25
resentations (see Figure 1). The problem lies in the fact that we have followed a constructive proof to obtain a segment representation using the pseudo-convex faces representation of a subdivision of a 3-connected graph. This construction would not be possible in general if the graph contains triangles, because if we fix the three directions of the segments we can observe that the graph in Figure 19 cannot be represented by non-crossing segments.
v1
o1
v2 h1
v1 o2
h1
o1 o2
h2
h2
v2
Figure 19: Two segments must cross. In this example we see the intersection graph of a family of segments, but this representation by segments of the graph contains regions that do not correspond to faces of the embedding of the graph. So, the topology of the embedding of the plane graph cannot be preserved and inductive arguments are no longer possible. This problem admits a partial solution as follows. A 3-coloring of a plane graph G with colors {h, v, o} is good if all the triangles of G are colored (clockwise), as h − v − o. The proof of Theorem 2 can be adapted yielding the following result: Theorem 3 Let G be a 3-colored plane graph. The coloring is good if and only if there exists a segment representation IG verifying that the faces of G correspond to faces of IG , and the boundaries of the faces are preserved.
N. de Castro et al., Segment Intersection Graphs, JGAA, 6(1) 7–26 (2002)
26
References [1] D.W. Barnette. On Steinitz’s theorem concerning convex 3-polytopes and on some properties of planar graphs In The many facets of graph theory. Lectures Notes in Mathematics Springer, Berlin, 110:27–39, 1969. [2] I. Ben-Arroyo Hartman, I. Newman and R. Ziv. On grid intersection graphs. In Discrete Math., 87:41–52, 1991. [3] P. Hlineny. Contact graphs of line segments are NP-complete. In Discrete Math., 235:95–106, 2001. [4] H. de Fraysseix, P. Osona de Mendez and J. Pach. Representation of planar graphs by segments. In Colloquia Mathematica Societatis J´ anos Bolyai, Intuitive Geometry, Szeged (Hungary), 1991. [5] M.C. Golumbic. Algorithmic Graph Theory and Perfect Graphs. Academic Press, 1980. [6] J. Kratochv´ıl. A special planar satisfiability problem and a consequence of its NP-completeness. In Discrete Applied Math., 52:233–252, 1994. [7] J. Kratochv´ıl and J. Matouˇsek. Intersection graphs of segments. In J. of Comb. Theory, Serie B, 62:289–315, 1994. [8] W. Naji. Reconnaisance des graphes de cordes. In Discrete Math., 54:329– 337, 1985. [9] E.R. Scheinerman. Intersection classes and multiple intersection parameters of graphs. Ph D. thesis,, Princeton University, 1984. [10] J. Spinrad. Recognition of circle graphs. In J. of Algorithms, 16:264–282, 1994. [11] R. Tamassia and I.G. Tollis. A unified approach to visibility representation of planar graphs. In Discrete and Computational Geometry, 1:321–341, 1986. [12] C. Thomassen. Gr¨ otzsch’s 3-colour theorem and its counterparts for the torus and the projective plane. In J. Comb. Theory B, 62:268–279, 1994.
Journal of Graph Algorithms and Applications http://www.cs.brown.edu/publications/jgaa/ vol. 6, no. 1, pp. 27–66 (2002)
Planar Graphs with Topological Constraints Christoph Dornheim Institut f¨ ur Informatik Albert-Ludwigs-Universit¨ at D-79110 Freiburg, Germany http://www.informatik.uni-freiburg.de/~dornheim
[email protected] Abstract We address in this paper the problem of constructing embeddings of planar graphs satisfying declarative, user-defined topological constraints. The constraints consist each of a cycle of the given graph and a set of its edges to be embedded inside this cycle and a set of its edges to be embedded outside this cycle. Their practical importance in graph visualization applications is due to the capability of supporting the semantics of graphs. Additionally, embedding algorithms for planar graphs with topological constraints can be combined with planar graph drawing algorithms that transform a given embedding into a topology preserving drawing according to particular drawing conventions and aesthetic criteria. We obtain the following main results on the planarity problem with topological constraints. Since it turns out to be NP-complete, we develop a polynomial time algorithm for reducing the problem for arbitrary planar graphs to a planarity problem with constraints for biconnected graphs. This allows focussing on biconnected graphs when searching for heuristics or polynomial time subproblems. We then define a particular subproblem by restricting the maximum number of vertices that any two distinct cycles involved in the constraints can have in common. Whereas the problem remains NP-complete if this number exceeds 1, it can otherwise be solved in polynomial time. The embedding algorithm we develop for this purpose is based on the reduction method.
Communicated by H. de Fraysseix and and J. Kratochv´ıl: submitted May 2000; revised March 2001.
This research was supported by the Deutsche Forschungsgemeinschaft (DFG) as part of the graduate school on Human and Machine Intelligence.
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
1
28
Introduction
Most research in the graph drawing field has focussed so far on developing algorithms that produce drawings of graphs according to particular drawing conventions and aesthetic criteria (see [5], [6], [11] and [23]). Common drawing conventions require, for instance, the vertices to have integer coordinates, the edges to be polylines or straight lines or to be composed of straight line segments parallel to one of the coordinate axes. Aesthetic criteria are in general optimization goals such as minimizing the number of edge crossings, maximizing the minimum distance between vertices or, in case of polyline drawings, minimizing the number of bends. Both drawing conventions and aesthetic criteria are intended to ensure readability of the drawings. They can be seen as geometric constraints implicit to the drawing algorithms. Many applications, however, need a visualization of graphs satisfying userdefined constraints to emphasize certain semantical aspects. Visual languages [27], for instance, may require some subgraphs to be drawn with a predefined shape to support their semantics. And in VLSI design [14] it is often necessary to have a graph layout where certain vertices are arranged in a group or cluster [21]. Although “the study of constraints is a strategic research direction for the graph drawing field” [22], there are only few graph drawing approaches allowing the user to define constraints. A survey of these approaches and those drawing algorithms that can be modified to support some sort of constraints is given in [22]. Again, the resulting constraints are primarily geometric and most of them are covered by the approach of [15] which supports the specification of arithmetic linear equality and inequality constraints on the coordinates of the vertices. These approaches to constrained graph drawing have often the disadvantage of not drawing a planar graph without crossings, i.e. as a planar embedding. For graph planarity without constraints there are many testing and embedding algorithms developed so far: from conceptually simple procedures such as [4] (also briefly described in [1]) to more involved linear time procedures such as the path addition embedding algorithm presented by Mehlhorn and Mutzel [18] based on the planarity testing procedure of Hopcroft and Tarjan [16] or the vertex addition embedding algorithm presented by Chiba et al. [3] based on the planarity testing procedure of Booth and Lueker [2]. However, the problem of constructing a planar embedding according to explicit constraints has obtained only little attention so far, despite its impact to planar graph theory and practice. An interesting approach to constrained graph embedding presented in [19] is the problem of finding a planar embedding such that the user’s preferences for facial cycles are satisfied. The preferences, or constraints, are specified by a cost function on the cycles of the graph. In an embedding that satisfies these constraints the overall costs of its facial cycles are minimized. Another approach is the construction of planar embeddings for clustered graphs [12]. A clustered graph is a graph with a user-defined hierarchical structure over the vertices such that each level decomposes the graph into disjoint clusters. In a planar drawing of a clustered graph a cluster is represented by a simple region
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
29
containing exactly the vertices that belong to this cluster. Additionally, edges are allowed to intersect the boundaries of the regions only once; in particular, edges connecting vertices of the same cluster must be inside the corresponding region. The embedding algorithm developed in [12] requires the vertices of each cluster to induce a connected graph. As shown in [9] and [10], these embeddings can be further transformed into drawings according to specific drawing conventions while preserving their cluster structure. Since many drawing procedures for planar graphs need a particular embedding (more precisely, a combinatorial representation of an embedding) as input and produce drawings of the same topology, the construction of embeddings satisfying given constraints can be used as a preprocessing step for a wide range of planar graph drawing algorithms. This paper is devoted to planar graph embedding with topological constraints; it considerably extends the previous work in [8]. We define a topological constraint for a graph to consist of some of its cycle and a set of its edges to be embedded inside this cycle and a set of its edges to be embedded outside this cycle. These constraints are clearly topological since topological transformations of the plane preserve their validity. Note that we build constraints by sets of edges instead of sets of vertices. If some vertex is to be embedded inside or outside a given cycle, the corresponding topological constraint can be defined by using an edge incident to this vertex (if the vertex is isolated, it must be replaced by some new edge for the time of the embedding process). To see that in some situations vertex sets would be insufficient, think of, e.g., Hamilton cycles: the diagonals of a Hamilton cycle can be embedded inside or outside, but there is no vertex left to constitute a topological constraint. The topological constraints are useful in graph embedding whenever the inner and outer regions of cycles have an intrinsic or user-defined semantics. Graphs whose vertices and edges represent spatial entities such as road maps or subway maps often induce some natural meaning to the faces and regions of their embeddings as well. In this case, topological constraints can be defined to ensure that the embedded graph preserves some important topological relationships. Generally, these constraints can be used to impose some structure on the embedding to be constructed. Consider in Fig. 1 the transition diagram of a finite automaton accepting the language (a(cde)∗ bz + f(hij)∗ gz)∗ . The main components of this expression are a(cde)∗ bz and f(hij)∗ gz, each representing a cyclic walk starting and ending in q0 . Moreover, each component contains a subcomponent (cde)∗ and (hij)∗ representing cyclic walks starting and ending in q1 and q6 , respectively. To reflect this structure in the diagram, it makes sense to draw the cycles q0 , q1 , q7 and q0 , q6 , q7 representing the main components into disjoint regions, but to draw the cycles q1 , q3 , q2 and q6 , q5 , q4 representing the corresponding subcomponents inside q0 , q1 , q7 and q0 , q6 , q7 , respectively. These requirements can be expressed exactly by topological constraints. Last but not least, a topological constraint allows one to specify a cycle to be an inner or outer facial cycle just by postulating the former or latter set, respectively, to consist of all edges not belonging to that cycle. The outline of the paper is as follows. Recalling in Sect. 2 the required defi-
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
30
q1 a
b
q4
c d q 3 z i q5
j
h
g
e
q2
q0 f
q7
q6 Figure 1: A transition diagram of a finite automaton with the language (a(cde)∗ bz + f(hij)∗ gz)∗ . The structure of this expression is reflected in the drawing by the topological relationships of the cycles. nitions and results of planar graph theory, we show in Sect. 3 NP-completeness of the problem of deciding whether a graph has an embedding satisfying a given set of topological constraints. In contrast, we present a linear time embedding algorithm for triconnected graphs. Section 4 is concerned with developing a polynomial time procedure for reducing the embedding problem with topological constraints to biconnected graphs. This can be particularly useful in searching for tractable subproblems. We introduce in Sect. 5 a particular subproblem defined by the maximum number of vertices two distinct cycles involved in the constraints have in common. Whereas this problem remains NP-complete if this number exceeds 1, we develop a polynomial time algorithm for generating a required embedding if this number is 0 or 1. Finally, we conclude with Sect. 6.
2
Preliminaries
Assuming familiarity with basic graph terminology (see [1] and [7]), we recall in this section the required fundamentals on planar graphs. For a thorough presentation of planar graph theory we refer the reader to [24], [7] and [20]. Unless otherwise stated, all graphs are finite, simple and undirected. The set of vertices and edges of a graph G are denoted V (G) and E(G), respectively. Paths and cycles in a graph are always simple, i.e. their inner vertices are pairwise distinct. A cycle C in G is induced if any edge of G joining two vertices of C is already an edge in C. Moreover, C is non-separating if the number of components of G does not increase when deleting C from G. A block means a maximal connected subgraph without a cutvertex, i.e. a maximal 2-connected subgraph or a bridge or an isolated vertex. If A denotes the set of cutvertices of G and B denotes the set of its blocks, then the block graph of G is defined on A ∪ B by the edges aB with a ∈ B for a ∈ A and B ∈ B. Note that the block graph of a connected graph is always a tree. A plane graph (V, E) consists of a finite set V ⊆ R2 and a finite set E of Jordan curves connecting two points of V such that any two points are connected
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
31
by at most one curve and the interior of a curve contains no point of V and no point of any other curve. These points and curves are again called vertices and edges, respectively, since all graph notions can also be applied to plane graphs. e we If there is an isomorphism between an abstract graph G and a plane graph G, e an embedding of G in the plane. A graph is planar if it has an embedding call G e always denotes an embedding of the graph G and in the plane. In the sequel, G e to H simply by H. e for subgraphs H ⊂ G we often denote the restriction of G Every plane graph G divides R2 \ G into disjoint open arcwise connected regions called faces of G; the unbounded one is the outer face and the bounded ones are the inner faces. If a cycle C of G is the boundary of some face, we call C a facial cycle; depending on whether C is the boundary of an inner or outer face, we call C an inner or outer facial cycle, respectively. Any cycle C divides R2 \ C into two open arcwise connected regions; the bounded one is the interior of C, denoted by int C, and the unbounded one is the exterior of C, denoted by ext C. The closure of int C and ext C is denoted by Int C and Ext C, respectively. Given a graph G = (V, E) the edge space E(G) of G is the vector space over the 2-element field F2 = {0, 1} formed by the set of all subsets of E and the sum A ⊕ B = (A \ B) ∪ (B \ A) for A, B ⊆ E. The cycle space C(G) is the subspace of E(G) generated by the cycles of G – more precisely, by their edge sets. The elements of C(G) are unions of edge-disjoint cycles of G. Suppose e is an embedding of a 2-connected planar graph G and F 0 is the set of all G e Then, as follows from MacLane’s planarity criterion [17], facial cycles of G. F = F 0 \ {F } forms a basis of C(G) for any F ∈ F 0 and F is the sum of all cycles in F . There is always an embedding of G where F is the set of inner facial cycles and F the outer facial cycle. We often make use of the fact that the edges e contained in Int C e for some cycle C ⊂ G are exactly the edges of those of G e whose sum is C. Moreover, any two embeddings of G are inner facial cycles of G topologically equivalent if they coincide in their outer facial cycle and their set of inner facial cycles (see [7]). We can thus represent a particular 2-connected embedding up to topological equivalence just by its outer facial cycle and the set of its inner facial cycles. If in addition G is 3-connected, the facial cycles of e can be identified combinatorially as the induced non-separating cycles in G, G as proved by Tutte [26]. This allows representing any embedding of G just by its outer facial cycle because all these embeddings have the same facial cycles. Finally, we introduce a notion that plays a fundamental role in graph embedding algorithms following the principle of path addition. Suppose H is a subgraph of G. Then an H-component of G is either an edge (together with its ends) in E(G) \ E(H) joining two vertices of H or it is a connected component of G− H together with all edges (and their ends) of G joining this component to H.1 The vertices of an H-component in H are its vertices of attachment. Suppose C is a cycle in G. Vertices of attachment of a C-component, provided that there are at least two, divide C into edge-disjoint paths, called segments. We say 1 This definition follows [24]. One can find elsewhere in the literature various notions for H-components, e.g. bridges in [1].
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
32
that two C-components avoid each other if either one of them has fewer than two vertices of attachment or all vertices of attachment of one C-component lie in a single segment of the other C-component; otherwise they overlap. The overlap graph GC of C in G is defined as the graph whose vertices are the C-components of G such that two vertices are adjacent iff the corresponding Ccomponents overlap. Overlap graphs can be used even for characterizing planar graphs: by Tutte’s theorem [25] a graph is planar iff the overlap graph of each of its cycle is bipartite.
3
Topological Constraints
In this section we introduce topological constraints and present a criterion for graphs having an embedding that satisfies such constraints. We also show some basic properties of the computational problem of finding these embeddings: whereas this problem is in general NP-complete, it can be solved in linear time for 3-connected graphs. Definition 1 Let G be a graph and T be a set of triples Ti = hCi , Ini , Outi i such that Ci is a cycle in G, Ini , Outi ⊂ E(G) \ E(Ci ), Ini ∪ Outi 6= ∅ and Ini ∩ Outi = ∅. These triples are called topological constraints for G. e of G satisfies T if for each constraint Ti ∈ T all edges of An embedding G fi and all edges of Outi are contained in ext C fi ; such Ini are contained in int C an embedding is called a T -embedding. Moreover, G is T -planar if G has a T -embedding. Obviously, T -planar graphs are necessarily planar; thus we only consider planar graphs. Given a planar graph G and a set T of topological constraints for G, n always denotes the number of vertices of G, m denotes the number of edges where m ≤ 3n−6 and t denotes the number of constraints in T . Note that t can be exponential in n. The relevant parameters of the problem of finding a T -embedding of G are therefore n and t. Since each constraint Ti consists of at most m edges, the input length of any instance can be assumed to be O(nt). For convenience, if C is a cycle Ci occurring in some constraint, we often write InC and OutC instead of Ini and Outi , respectively. Due to the additional requirements on embeddings, one cannot hope for a simple Kuratowski-like criterion for T -planarity. In contrast to classical planarity, T -planarity of a graph cannot be simply reduced to its components or blocks either; even the required topological relationships between its components can get complex as we will see in the next section. To characterize T -planarity in Theorem 1, we make use of some properties of 3-connected planar graphs given in Sect. 2. This theorem is illustrated in Fig. 2. Theorem 1 Let G be a graph and T be a set of topological constraints. Then, G is T -planar iff there is a 3-connected planar graph G0 with G ⊆ G0 and V (G) = V (G0 ) and a basis F of C(G0 ) consisting of induced non-separating cycles of G0 such that for any hC, InC , OutC i ∈ T and FC ⊆ F defined by
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
33
S S L C = F ∈FC F it holds that x ∈ F ∈FC F for any x ∈ InC and y 6∈ F ∈FC F for any y ∈ OutC . e is a T -embedding of G. Triangulating G e in the plane Proof: (⇒) Suppose G 0 f leads to an embedding G of a maximal planar and thus 3-connected graph G0 . f0 are induced non-separating cycles and form a basis The inner facial cycles of G 0 F of C(G ). Let be hC, InC , OutC i ∈ T and FC be the set of cycles in F whose e of G, e and thus of G f0 , it sum is C. Since any edge of InC is contained in Int C belongs to some cycle in FC . Analogously, any edge of OutC is contained in e of G f0 and therefore does not belong to some cycle of FC . Ext C (⇐) Let G0 be the supergraph of G satisfying the required properties. Then f0 of G0 with L there is an embedding G F ∈F F as the outer facial cycle and all F ∈ F as inner facial cycles. For any hC, InC , OutC i ∈ T we have that all edges e in G f0 and all edges of OutC are contained in Ext C e of InC are contained in Int C 0 0 e f f 2 in G . Thus, we get a T -embedding G by restricting G to G. G
G0
C x1
F3
y x2
F2
F1 F4
F6
F5
F7
F8 T = hC, {x1 , x2 }, {y}i
(a)
F = {F1 , . . . , F8 } FC = {F1 , F2 , F4 , F5 , F6 , F8 } (b)
Figure 2: Illustration of Theorem 1: (a) Graph G with constraint T . (b) Supergraph G0 of G with basis F of C(G) and set FC of those cycles in F whose sum is C. In case of 3-connected graphs, this criterion leads directly to an algorithm for finding a T -embedding. To ensure linear time complexity, we use dual graphs to represent the relationships between facial cycles (see [7]). Suppose G is a 3connected planar graph and F the unique set of facial cycles of some embedding of G. Any two facial cycles have at most one edge in common and each edge belongs to exactly two facial cycles. We define the dual graph G∗ on F such that two facial cycles are adjacent iff they share an edge. Since edges of G are in a one-to-one correspondence to edges of G∗ , let C ∗ denote the set of edges in G∗ that correspond to the edges of C ⊆ E(G). G∗ has the interesting property that C ⊆ E(G) is a cycle in G iff C ∗ is a minimal cut in G∗ , i.e. removing C ∗ from G∗ separates G∗ intoLtwo components U ∗ , W ∗ ⊂ G∗ . These components L satisfy C = F ∈U ∗ F = F ∈W ∗ F . Thus, in any embedding of G U ∗ is the
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
34
set of facial cycles inside C and W ∗ is the set of facial cycles outside C, or vice versa. Figure 3 illustrates the relationship between G and G∗ . G∗
G F1
F2
F3
F4
C
F5
F1 F2 F3 F4
F6 F5
F6 (a)
(b)
Figure 3: (a) A 3-connected planar graph G with a cycle C and unique (b) The dual Graph G∗ of G with minimal cut faces F1 , . . . , F6 . ∗ C = {F1 F6 , F2 F5 , F4 F5 , F3 F6 } corresponding to C and the sets U ∗ = {F1 , F2 , F3 , F4 }, W ∗ = {F5 , F6 }. To find a T -embedding, we only have to decide for each C whether U ∗ or W ∗ is the set of facial cycles outside C and to search for a facial cycle F0 belonging to each of these sets. Then F0 can be chosen as the outer facial cycle. We describe the algorithm in Fig. 4 and prove its correctness in Theorem 2. Algorithm embed triconnected graph Input : G, T Output : outer facial cycle F0 of some T -embedding 1. 2. 3.
4.
Find the set F of facial cycles of some embedding of G. Construct the dual graph G∗ . ∗ ∗ ∗ ∗ For each hC, In SC , OutC i ∈ T find the S components UC , WC of G − C . Let be UC = F ∈U ∗ F and WC = F ∈W ∗ F . C C ∗ = WC∗ ; If InC ⊂ UC and OutC ⊂ WC , define ZC ∗ = UC∗ ; else stop. else if InC ⊂ WC and OutC ⊂ UC , define ZC ∗ , return F0 . If there is some cycle F0 ∈ F belonging to each ZC Figure 4: Embedding algorithm for 3-connected graphs
Theorem 2 Given a 3-connected graph G and a set T of topological constraints for G, algorithm embed triconnected graph generates a T -embedding represented by its outer facial cycle iff G is T -planar. Moreover, it has time complexity O(nt). Proof: (⇒) Suppose the algorithm returns some F0 . There is some embedding e of G with inner facial cycles F 0 = F \ {F0 } and outer facial cycle F0 . By G ∗ ∗ , we have for any hC, InC , OutC i ∈ T and FC := F \ZC ⊆ F0 definition of the ZC
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
35
S that F ∈FC F contains all edges of InC but no edge of OutC . Thus, by Theorem e is a T -embedding. 1, G e with the set F 0 of inner (⇐) Conversely, assume G to have a T -embedding G 0 facial cycles and outer facial cycle F0 . We have to show that the algorithm always generates a cycle F0 as required. Let for any hC, InC , OutC i ∈ T FC denote the sum of those cycles in F 0 that sum up to C. FC and (F 0 ∪SF00 ) \ FC are exactly the components UC∗ , WC∗ of G∗ − C ∗ and, by Theorem 1, F ∈FC F ∗ contains all edges of InC but no edge of OutC . Thus, the algorithm defines ZC 0 0 0 ∗ to be (F ∪ F0 ) \ FC . At least T F0∗ belongs to each ZC such that the algorithm . can return some cycle F0 ∈ C ZC Finally, this algorithm can be implemented as an O(nt) procedure: generating the facial cycles of G by embedding G takes O(n) time as well as the construction of the dual graph G∗ . Since finding the components UC∗ and WC∗ of G∗ − C ∗ and testing the required conditions can both be done in O(n) time, step 3 takes all in all O(nt) time. The last step also needs only O(nt) time. 2 Basically, this polynomial time T -planarity algorithm depends on the simple topological properties of 3-connected planar graphs. The next theorem shows that in the general case we cannot hope for such a polynomial time solution. This also holds for some natural restrictions of the problem. Theorem 3 The problem of T -planarity is NP-complete. Proof: Membership in NP follows immediately from Theorem 2: we only have to guess a 3-connected planar supergraph G0 of G and verify in polynomial time G0 to be T -planar. Next we show the problem to be NP-hard by transformation from the NPcomplete problem BETWEENNESS (see [13]) defined as: given a finite set A and a set S of ordered triples of distinct elements from A, is there a oneto-one function f : A −→ {1, . . . , |A|} such that for each (a, b, c) ∈ S either f (a) < f (b) < f (c) or f (c) < f (b) < f (a) holds? Let A = {a1 , . . . , an } and S be an arbitrary instance of BETWEENNESS. We associate with A the graph GA defined by V (GA ) = {x, y, a1 , . . . , an } and E(GA ) = {xai , ai y | i ∈ {1, . . . , n}}. For any i, j with 1 ≤ i < j ≤ n let Ci,j denote the cycle (x, ai , y, aj , x) illustrated in Fig. 5. Then, S is encoded by a set TS of topological constraints for GA : let InCi,j be the set {xak | (ai , ak , aj ) ∈ S or (aj , ak , ai ) ∈ S} and TS be the set of triples hCi,j , InCi,j , ∅i with nonempty InCi,j . We show that GA is TS -planar iff there is some function f satisfying the fA is a TS -embedding of GA where a0 requirements given above. Suppose G fA . and a00 are the two vertices of GA belonging to the outer facial cycle of G We define a linear order f on A by f (a0 ) = 1, f (a00 ) = n and inductively fA where the f (a) = i if a 6= a00 and a belongs to the outer facial cycle of G −1 −1 vertices f (1), . . . , f (i − 1) are removed. It follows immediately that for each (a, b, c) ∈ S f (b) is between f (a) and f (c). Conversely, suppose f has the required property. Then GA can be embedded while preserving the order of f , i.e. f −1 (i) and f −1 (i + 1) belong to the same
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
36
x
a1
ai
Ci,j
aj
an
y Figure 5: Graph GA defined in the proof of Theorem 3 inner facial cycle and f −1 (1) and f −1 (n) belong to the outer facial cycle. Thus, 2 all edges of InCi,j are inside Ci,j . According to the special properties of GA and TS defined in the proof, we can draw some further conclusions. Since GA is 2-connected and has treewidth 2, T -planarity remains NP-complete for the class of graphs having these properties. Thus, unlike many other graph problems, a bounded treewidth does not result in a polynomial time solution in case of T -planarity. With respect to the connectivity number κ of graphs, we get the exact boundary between P and NP: the problem is NP-complete for κ ≤ 2 while allowing a polynomial time solution for κ ≥ 3. T -planarity remains also NP-complete for Eulerian graphs since GA is Eulerian (if |A| is odd, we have to add the edge xy to E(GA )). Interestingly, NP-completeness holds for topological constraints of the form hC, InC , ∅i. Since in the proof any xak ∈ InCi,j can be expressed equivalently by xai ∈ OutCk,j and xaj ∈ OutCi,k , this is also valid for constraints of the form hC, ∅, OutC i.
4
Reduction to Biconnected Graphs
As far as classical planarity is concerned, the planarity problem of a graph can be simply reduced to its blocks. Correspondingly, many graph embedding algorithms, e.g. [3] and [18], require the input graph to be 2-connected. The embedded blocks can be easily merged to an embedding of the whole graph. A corresponding reduction for T -planarity, however, must involve all the topological constraints between the components and blocks. In this section we develop a polynomial time algorithm providing such a reduction in two steps: first, T planarity for a graph is reduced to its components and second, connected graphs with constraints are reduced to their blocks. Thus, it is sufficient to focus on 2connected graphs when searching for polynomial time subproblems or heuristics to cope with the general NP-complete problem.
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
4.1
37
Reducing a Graph to Its Components
Topological constraints for an arbitrary planar graph can considerably differ from those for a 2-connected graph: this is due to the fact that topological constraints between its components or blocks imply yet another sort of constraints not subsumed by Definition 1. Suppose we have two components H and H 0 of a graph G and three constraints meaning that x ∈ E(H 0 ) must be embedded inside cycles C1 and C2 , but outside cycle C3 of H. To find an embedding of e of H with an G satisfying these constraints, we have to find an embedding H f f f inner face inside C1 and C2 , but outside C3 in which we can embed H 0 . Thus, we get a new constraint between cycles of the same component that cannot be equivalently expressed by topological constraints. Although again topological by nature, we call constraints of this sort overlap constraints. More formally: Definition 2 Let G be a graph and L be a set of pairs Li = hC-Ini , C-Outi i such that C-Ini and C-Outi are sets of cycles of G. These pairs are called overlap constraints for G. e of G satisfies L if for each constraint Li ∈ L there is a face An embedding G e in the interior of all cycles of C-Ini and in the exterior of all cycles of of G C-Outi ; such an embedding is called an L-embedding. Moreover, G is L-planar if G has an L-embedding. We only consider overlap constraints that are induced by topological constraints though they might be of general interest. If a graph has an embedding satisfying both topological constraints T and overlap constraints L, we call it T L-planar and its embedding T L-embedding for short. If H is a subgraph of G, we denote with T |H the set of topological constraints which T induces on H, i.e. hCi , Ini ∩ E(H), Outi ∩ E(H)i if Ci is a cycle in H and hCi , Ini , Outi i ∈ T . Suppose G is a planar graph, T is a set of topological constraints for G and H is the set of components of G to which we want to reduce T -planarity. To represent the induced constraints between distinct components H, H 0 ∈ H, we define the following sets: C-InH,H 0 C-OutH,H 0
= {C ⊂ H | hC, InC , OutC i ∈ T with InC ∩ E(H 0 ) 6= ∅}, = {C ⊂ H | hC, InC , OutC i ∈ T with OutC ∩ E(H 0 ) 6= ∅}.
The sets C-InH,H 0 define moreover a relation ≺ on H by H 0 ≺ H iff C-InH,H 0 6= ∅. This relation means that we have to find an embedding of H that has a face inside all cycles of C-InH,H 0 and outside all cycles of C-OutH,H 0 , thus satisfying the overlap constraint hC-InH,H 0 , C-OutH,H 0 i. However, there are much more overlap constraints for H. Consider the set H0 of all successors of H, i.e. {H 0 | H 0 ≺ H}, and let K be a component of (the undirected graph of) ≺ restricted to H0 . of H. The stronger Then all H 0 ∈ K must lie in the same S S face of an embedding overlap constraints for H are thus h H 0 ∈K C-InH,H 0 , H 0 ∈K C-OutH,H 0 i for all such K. e of G and the induced ordering < on H by Now consider an embedding G e H 0 is in some inner face of G| e H . It can be easily seen, that < is H 0 < H iff G|
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
38
a strict partial order with the additional property that H 0 < H and H 0 < H 00 imply either H < H 00 or H = H 00 or H 00 < H due to planarity. In other words, e is a < is the transitive closure of a disjoint union of rooted trees. If moreover G T -embedding, the relation ≺ defined above is a subrelation of <. An example of both relations is given in Fig. 6.2 G
H1 C1
C2
H2 C4
C5
C3
C6
H3
H4
C-InH1 ,H3 C-InH1 ,H4 C-InH2 ,H3 C-InH2 ,H4 C-OutH1 ,H2 C-OutH2 ,H1 (a)
e G H3 H4 C1 C 4 C6 C5
C3
H3 <
C2
≺
H1
= {C1 } = {C2 } = {C4 } = {C5 } = {C3 } = {C6 }
H2
H4 H1 H2
H3
H4
(b)
Figure 6: (a) A graph G consisting of components H1 , . . . , H4 and topological constraints between them represented by the sets C-InHi ,Hj and C-OutHi ,Hj ; e satisfying these constraints these sets define the relation ≺. (b) An embedding G e and the relation < induced by G. The method of reducing T -planarity of G to its components consists just in finding such an extention < of ≺ and appropriate embeddings of the components of G. Instead of the strict partial ordering <, it is more convenient to construct its transitive reduction which is a disjoint union of rooted trees. When first considering subsets H0 ⊂ H such that ≺ |H0 is a connected relation, we can easily formulate a recursive procedure order components shown in Fig. 7 for constructing the transitive reduction of < w.r.t. to H0 . It makes use of an algorithm A for generating an embedding of a connected graph satisfying given topological and overlap constraints; we also assume that the faces corresponding to the overlap constraints are returned. Such an algorithm A is provided by the reduction to blocks developed in the next section. The procedure order components returns e to H f0 is labelled a tree of embedded components in H0 where an edge from H e in which H f0 must be embedded. Figure 8 shows the only two with a face of H possible labelled trees that can result from the graph and constraints given in 2 Note
that we visualize relations like ≺ by drawing an arrow from H to H 0 if H 0 ≺ H.
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
39
e to H f0 by the overlap constraint Fig. 6 (a). Here we have labelled an edge from H e instead of its corresponding face. The first labelled tree corresponds to for H the embedding shown in Fig. 6 (b). Algorithm order components Input : H0 ⊂ H such that ≺ |H0 is connected Output : labelled tree of embedded components of H0 1. 2.
3. 4.
Determine the set M of components maximal in ≺ |H0 . e Use algorithm A to find an H ∈ S M with an embedding S H satisfying TH and set LH of constraints Li = h H 0 ∈Ki C-InH,H 0 , H 0 ∈Ki C-OutH,H 0 i for components Ki of ≺ |H0 \{H} . e corresponding to Li , else stop. If this succeeds, let Fi be the faces of H For all Ki compute order components(Ki ) resulting in labelled trees Ri . e by adding edges from H e to the Merge the Ri to a new tree with root H roots of Ri labelled with Fi . Finally, return this new tree. Figure 7: Algorithm for ordering components f1 H
f2 H h{C1 , C2 }, {C3 }i
f2 H h{C4 }, ∅i f3 H
h{C5 }, ∅i f4 H
h{C4 , C5 }, {C6 }i f1 H h{C1 }, ∅i f3 H
h{C2 }, ∅i f4 H
Figure 8: Two labelled trees that can result from procedure order components for the graph and constraints given in Fig. 6. Instead of faces, the edges are labelled with the corresponding overlap constraints. The complete reduction algorithm reduce to components is given in Fig. 9. To obtain a T -embedding of G, we only have to embed the components of G according to the structure of the generated trees. Finally, we prove correctness and the time complexity for this algorithm in Theorem 4. We therefore assume that an algorithm A is available for embedding a component H with topological constraints TH and overlap constraints LH . Its time complexity is assumed to be O(p(nH , kH , tH , lH )) for some polynomial p with parameters nH = |H|, tH = |TH |, lH = |LH | and the number kH of all cycles occurring in the constraints of TH and LH . Note that each overlap constraint consists then of at most kH cycles. Theorem 4 Let G be a planar graph and T be a set of topological constraints for G. Then, algorithm reduce to components generates a T -embedding of G iff
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
40
Algorithm reduce to components Input : G, T Output : T -embedding of G 1. 2. 3. 4.
Determine the set H of components of G. Determine the sets C-InH,H 0 and C-OutH,H 0 , the induced constraints TH := T |H and the relation ≺. If ≺ is cyclic, stop. For each component Ki of ≺ compute order components(Ki ) resulting in labelled trees Ri . f0 Construct the embedding of G as described by the Ri , i.e. embed H e iff there is an edge from H e to H f0 labelled with F . into face F of H Figure 9: Reduction of T -planarity of a graph to its components
G is T -planar. Moreover, it takes O n4 + n2 t + n · p(n, t, t, n) time provided that the time complexity of A is given by p. e is an embedding of G generated by the algorithm and < Proof: (⇒) Suppose G e is indeed a T -embedding. is the induced relation on H. We have to show that G e be the generated embedding of the component Let be hC, InC , OutC i ∈ T and H H ∈ H with C ⊂ H. First, consider an x ∈ InC belonging to component H 0 ∈ H. If H = H 0 , x is e in H e since H e is a TH -embedding. Otherwise we have H 0 ≺ H. When inside C choosing H for embedding in step 2 of algorithm order components, H 0 belongs to some component Ki of ≺ |H0 \{H} . Thus, the overlap constraint Li ensures e of H. e that all H 0 ∈ Ki are embedded in a face inside C Second, consider an x ∈ OutC belonging to component H 0 ∈ H. Again, if e in H e since H e is a TH -embedding. Otherwise we have H = H 0 , x is outside C 0 e H 0 must be in some component Ki C ∈ C-OutH,H 0 . If H < H holds in G, of ≺ |H0 \{H} determined in step 2 of algorithm order components. Thus, the overlap constraint Li ensures that all H 0 ∈ Ki are embedded in a face outside e H f0 is obviously outside C e of G. e e of H. e If H 0 < H does not hold in G, C (⇐) Conversely, we show that the algorithm indeed finds an embedding of G if G is T -planar. By the first part of the proof, such an embedding always e be a T -embedding of G and < be its induced relation on satisfies T . So let G H. Since < is an extention of ≺, ≺ is in particular acyclic. For a connected e 0 |H0 the restriction of some T -embedding subrelation ≺ |H0 of ≺ we denote with G 0 0 e of G to the components in H . Note that each G e0 |H0 has a unique maximal G component in < |H0 . We must show that for each call of procedure order components the search for an appropriate maximal component H always succeeds. For this purpose e H0 for each call order components(H0 ) we define inductively a T -embedding G eH0 |H0 is a possible choice in step 2. Let such that the maximal component of G 0 e Ki be the components of ≺ and let G be the embedding of G built by placing
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
41
e0 satisfies T again. e Ki into different regions of the plane. Obviously, G all G| e0 . Thus, for each call order components(Ki ) the eKi to be G We define each G e maximal component of GKi |Ki is a possible choice for H in step 2. eH0 be already deConsider now some call order components(H0 ) and let G 0 fined. By assumption, the search in step 2 for an H ∈ H succeeds; however, H e H0 |H0 . Let Ki be is not necessarily identical with the maximal component of G the components of ≺ |H0 \{H} and Fi be the corresponding faces of the generated e in which the components in Ki must be embedded. Transform embedding H e e 0 of G by replacing G e H0 |H with H e and placing each 0 GH into a new embedding G 0 e e e e Ki to be GH0 |Ki into the face Fi of H. Again, G satisfies T . We define each G 0 e . Consequently, for each call order components(Ki ) the maximal component G e Ki |Ki is a possible choice for H in step 2. This completes the proof that of G the algorithm never stops irregularly if G is T -planar. Finally, we derive the time complexity of reduce to components from algorithm A. As can be easily seen, step 1, 2 and 4 of reduce to components takes O(n), O(nt) + O(n2 ) and O(n) time, respectively. To establish the time needed by step 3, we consider the call order components(H0 ) for some H0 ⊂ H. First, the set M of maximal components of ≺ |H0 can be determined in O(n) time. For some Hj ∈ M let be nj = |Hj |, tj = |THj |, lj = |LHj | and kj be the number of cycles occurring in THj and LHj , i.e. the number of cycles in Hj occurring in T . Then, computing the lj components of ≺ |H0 \{Hj } can be done in O(n2 ) time and determining the constraints LHj needs O(nkj ) time. By assumption, testing if Hj is THj LHj -planar can be done in O(p(nj , kj , tj , lj )) time. P In the ∈ M must be checked. It is clear that nj = n, worst case, however, all the H j P P P P tj ≤ t. Additionally, we have lj ≤ 2n since lj is largest if kj = t and ≺ |H0 is a tree and for a tree the sum is twice the number of edges. Thus, step 2 of order components can be done in X O(n2 ) + O(nkj ) + O(p(nj , kj , tj , lj )) X X X X X X nkj + p kj , tj , lj nj , = O n2 + = O n3 + nt + p(n, t, t, n) . is bounded by n, we get the overall Since the number of calls of order components complexity O n4 + n2 t + n · p(n, t, t, n) for algorithm reduce to components. 2
4.2
Reducing a Component to Its Blocks
The second part of reducing T -planarity of a graph G consists of reducing its components H with induced topological constraints TH and overlap constraints LH to its blocks. Again, this reduction step leads to a new sort of constraints between blocks which are similar, but not entirely equivalent with overlap constraints. Consider two blocks B and B 0 of H having a cutvertex v in common and suppose we have constraints in TH meaning that B 0 must be embedded inside cycles C1 and C2 , but outside cycle C3 of B. A corresponding embedding
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
42
e of B must clearly satisfy the overlap constraint h{C1 , C2 }, C3 i. However, due B to the way these blocks are connected to each other, the topological constraints e inside C1 imply additional requirements: first, the boundary of the face in B and C2 , but outside C3 must contain the cutvertex v, and second, v must belong e f0 of B 0 in order to merge B to the boundary of the outer face of the embedding B 0 0 f to an embedding of B ∪ B satisfying the constraints given above. Since and B these constraints are an extention of overlap constraints, we call them extended overlap constraints. Definition 3 Let G be a graph and X be a set of triples Xi = hC-Ini , C-Outi , vi such that C-Ini and C-Outi are sets of cycles of G and v is a vertex of G. These triples are called extended overlap constraints for G. e of G satisfies X if for each constraint Xi ∈ X there is a face of An embedding G e in the interior of all cycles of C-Ini and in the exterior of all cycles of C-Outi G and whose boundary contains v; such an embedding is called an X -embedding. Moreover, G is X -planar if G has an X -embedding. We are again only interested in those extended overlap constraints that are f0 derived in the reduction step. It can easily be seen that the requirement for B to have v at the boundary of the outer face can be expressed by the extended overlap constraint h∅, C-Out, vi where C-Out denotes the set of all cycles occurring in the constraints for B 0 . This is because taking the face corresponding to this extended overlap constraint as the outer face results in the required embedding where v is on the outer face boundary and all other constraints are preserved. The reduction of TH LH -planarity of H to its blocks works much like the first reduction step of G to its components. This is due to the fact that any embedding of H induces again an ordering < on the set B of blocks of H with the same properties as defined in the previous section. Thus we can adopt the key idea of constructing an appropriate ordering of the blocks. However, some minor modifications are necessary to cope with both the overlap constraints LH and the extended overlap constraints derived during the reduction process. We use the block graph Hb of H, as defined in Sect. 1, to represent the complete decomposition of H into its blocks and cutvertices. Note that Hb is a tree because H is connected. Analogously to the previous section, we represent the constraints between distinct blocks B, B 0 ∈ B by the sets C-InB,B 0 and C-OutB,B 0 . By defining them in terms of C-components, many constraints between B and further blocks are inferred. For the sake of a uniform representation, we transform the overlap constraints Li ∈ LH into the sets C-InB,Li and C-OutB,Li . C-InB,B 0 = {C ⊂ B | hC, InC , OutC i ∈ TH with InC ∩ E(Z) 6= ∅ for some C-component Z containing B 0 }, C-OutB,B 0 = {C ⊂ B | hC, InC , OutC i ∈ TH with OutC ∩ E(Z) 6= ∅ for some C-component Z containing B 0 }, C-InB,Li = {C ⊂ B | Li = hC-Ini , C-Outi i ∈ LH with C ∈ C-Ini }, C-OutB,Li = {C ⊂ B | Li = hC-Ini , C-Outi i ∈ LH with C ∈ C-Outi }.
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
43
The sets C-InB,B 0 and C-InB,Li define again a relation ≺ on B ∪ LH by B 0 ≺ B iff C-InB,B 0 6= ∅ and Li ≺ B iff C-InB,Li 6= ∅. The reason for including the constraints of LH is that this ensures all blocks B with Li ≺ B to be embedded in a linear order of < as must be the case in any embedding of H satisfying LH (see for example Fig. 12). The algorithm reduce to blocks providing the second reduction step is presented in Fig. 10. Again, the resulting embedding of H is obtained from a labelled tree that is generated by the procedure order blocks given in Fig. 11. This procedure assumes that some block B0 is selected from those blocks that are maximal in ≺ to serve as a maximal block in the relation < induced by the TH LH -embedding of H to be generated. Thus, contrary to the reduction algorithm in the previous section, finding a TH LH -embedding of H possibly requires several complete reduction processes if necessary until a proper B0 leads to the required embedding. This is due to the fact that the generated extended overlap constraints for the blocks are partially depending on the choice of B0 ; for instance, all other blocks B with cutvertex q in the path B0 , . . . , q, B of Hb are to be embedded with q at the outer face boundary. Instead of relation ≺, procedure order blocks uses for technical reasons an extention ≺0 of ≺ by adding B 0 ≺0 B iff B0 , . . . , B, q, B 0 is a path in Hb . This enforces the search of which block to consider next in step 2 of order blocks to take those blocks that are nearest to B0 in the tree Hb . Note that in general, however, ≺0 is no longer a subrelation of < induced by some TH LH -embedding of H. Algorithm order blocks works similarly to its corresponding procedure order components except for those parts where the block graph must be taken into account. Algorithm reduce to blocks Input : component H with constraints TH and LH Output : TH LH -embedding of H 1. 2. 3.
4.
Determine the set B of blocks of H and the blockgraph Hb of H. Determine the sets C-InB,B 0 , C-OutB,B 0 , C-InB,Li and C-OutB,Li , the constraints TB := TH |B and the relation ≺. If ≺ is cyclic, stop. Find a block B0 maximal in ≺ such that order blocks(B ∪ LH ) results in a labelled tree R using the extention ≺0 of ≺ by B 0 ≺0 B iff B0 , . . . , B, q, B 0 is a path in Hb . If this fails, stop. Construct the embedding of H as described by R, i.e. for any edge e to B f0 labelled with F and for the cutvertex p with path from B 0 f0 into face F at p of B. e Additionally, return B, p, B in Hb embed B the faces corresponding to the overlap constraints Li ∈ LH , i.e. the labels of the edges to Li in R.
Figure 10: Reduction of TH LH -planarity of a connected graph to its blocks Figure 12 illustrates this reduction step with a simple connected graph H whose blocks B1 , . . . , B4 are cycles C1 , . . . , C4 , respectively, and B5 is a bridge.
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
44
Algorithm order blocks Input : B 0 ⊂ B ∪ LH such that ≺0 |B0 is connected Output : labelled tree of embedded components of B 0 1. 2.
3. 4.
Determine the set M of components maximal in ≺0 |B0 . Use algorithm A0 to find some B ∈ M such that: (i) for any component Ki of ≺0 |B0 \{B} there is at most one cutvertex pi ∈ B in Hb separating B from Ki , e where (ii) B has a TB LB XB -embedding B LB is the set of overlap constraints L0i = hC-InB,Ki , C-OutB,Ki i for all Ki ∈ LH , XB is the S set of extendedSoverlap constraints Xi = h B 0 ∈Ki C-InB,B 0 , B 0 ∈Ki C-OutB,B 0 , pi i for all Ki 6∈ LH . If B 6= B0 , XB contains the additional constraint that q satisfying the path B0 , . . . , q, B in Hb must be at the outer face boundary. e corresponding to L0 and Xi , If this succeeds, let Fi be the faces of B i respectively, else stop. For all Ki 6∈ LH compute order blocks(Ki ) resulting in labelled trees Ri . For any Ki ∈ LH define Ri to be Ki . e by adding edges from B e Merge the Ri to a new tree with root B to the roots of Ri labelled with Fi . Finally, return this new tree. Figure 11: Algorithm for ordering blocks
The topological constraints and the overlap constraint L for H are directly encoded in the relation ≺. As can easily be seen, the only correct choice for B0 among the candidates B1 and B3 is B0 = B1 . This is because B0 = B3 is separated in Hb by two cutvertices from B2 = C2 and B4 = C4 which inhibits embedding one of these cycles into the other and thus contradicts the overlap constraint L. To establish in Theorem 5 correctness and time complexity of algorithm reduce to blocks, we assume an algorithm A0 to be available for embedding a block B with topological constraints TB , overlap constraints LB and extended overlap constraints XB . The time complexity of A0 is assumed to be O(p0 (nB , kB , tB , lB , xB )) for some polynomial p0 with parameters nB = |B|, tB = |TB |, lB = |LB |, xB = |XB | and the number kB of all cycles occurring in the constraints of TB , LB and XB . Consequently, each overlap constraint and each extended overlap constraint consists of at most kB cycles. Theorem 5 Let H be a connected planar graph and TH be a set of topological constraints and LH be a set of overlap constraints for H. Then, algorithm reduce to blocks generates a TH LH -embedding of H iff H is TH LH -planar. Moreover, it takes O n5 + n4 l + n3 k + n2 kl + nt + n2 · p0 (n, k, t, l, n + l) time provided that the time complexity of A0 is given by p0 and n = |H|, t = |TH |,
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002) B1
C1 p1
p1
C2
p2
C4
f1 B B3
B4 L
≺0
B4
≺
h{C1 }, ∅, p1 i
f2 B B5
h∅, {C2 }, p1 i h{C2 }, ∅, p1 i h∅, {C3 }, p1 i
f3 B
B5
L
Hb (a)
B1 B2
B2 B4
B5 H
B3
B2
B3
p2
C3
B1
45
h{C3 }, ∅, p2 i h∅, {C3 }, p2 i f B4 h{C4 }, ∅i L
h∅, ∅, p2 i h∅, ∅, p2 i f5 B R
C1 C2 C3 C4
e H
(b) Figure 12: (a) A connected graph H with its block graph Hb and the relation ≺ determined by C-InB1 ,B2 = {C1 }, C-InB3 ,B4 = {C3 }, C-InB2 ,L = {C2 } and C-InB4 ,L = {C4 }. (b) The relation ≺0 , the labelled tree R and its corresponding e when B1 is chosen as B0 . embedding H
l = |LH | and k is the number of all cycles occurring in the constraints of TH and LH . e is an embedding of H generated by the algorithm and Proof: (⇒) Suppose H e is indeed a TH LH < is the induced relation on B. We have to show that H embedding. Analogously to the proof of Theorem 4, it can easily be seen that the induced topological constraints TB and the extended overlap constraints Xi e satisfies TH . produced in step 2 of algorithm order blocks guarantee that H e To show that H also satisfies LH , we consider an overlap constraint L = e corresponding to L and BF is hC-In, C-Outi ∈ LH . Suppose F is the face in H the block with an edge to L labelled with F in the tree R resulting from step 3 of reduce to blocks. That is, BF appears as the minimal block in < containing cycles from C-In. When choosing BF for embedding in step 2 of order blocks, the generated overlap constraint L0i = hC-InBF ,Ki , C-OutBF ,Ki i for Ki = L clearly ensures that F is a face inside all cycles of C-In in BF and outside all cycles of C-Out in BF . Let C ∈ C-In belong to some block B 6= BF . Since L and
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
46
BF belong to the same component Ki determined in step 2 of order blocks, the e corresponding to the extended overlap constraint Xi is guaranteed to face of B be inside C. Thus, BF is embedded inside C. Next, consider some C ∈ C-Out e BF must be in a belonging to a block B 6= BF . If BF < B holds in H, component Ki . Then, the constraint Xi ensures again its corresponding face in e to be outside C. Otherwise, BF is obviously outside C in H. e B (⇐) Conversely, we show that the algorithm never stops irregularly if H is e is an embedding of H satisfying the constraints TH TH LH -planar. Suppose H and LH and < is the induced relation on B. Clearly, the restriction of ≺ to B is a subrelation of <; thus ≺ must be acyclic. Since in step 3 of reduce to blocks possibly all maximal blocks in ≺ are considered, it is sufficient to show that the choice of a block B0 which is maximal in < succeeds. So let ≺0 be the extention of ≺ defined in step 3 which is also acyclic. In analogy to the proof of Theorem e B0 for each call order blocks(B 0 ) such that the 4 we define a TH LH -embedding H e B0 |B0 is a possible choice in step 2. maximal component of H e such that for the call order blocks(B ∪ LH ) B0 e First we define HB∪LH := H is an appropriate choice in step 2; moreover, B0 is the only candidate because it is the unique maximal block in ≺0 . Consider now some call order blocks(B 0 ) e B0 be already defined. By assumption, the search in step 2 for some and let H B ∈ B 0 succeeds; however, B is not necessarily identical with the maximal block e B0 |B0 . Let Ki be the components of ≺0 |B0 \{B} and Fi be the corresponding of H e in which the blocks in Ki must be embedded. faces of the generated embedding B Moreover, let pi ∈ B be the cutvertex in Hb separating B from Ki . Then e 0 of H by replacing H e B0 |B with B e and e B0 into a new embedding H transform H 0 e e e placing each HB0 |Ki into face Fi of B at cutvertex pi . Again, H satisfies TH e Ki is defined to be H e 0 , we assure that for each call and LH . When each H e Ki |Ki is a possible choice in step 2. order blocks(Ki ) the maximal block of H This completes the proof that this algorithm never stops irregularly if H is TH LH -planar. Finally, we derive the time complexity of reduce to blocks from algorithm A0 . As can be easily seen, step 1 and 4 of reduce to blocks takes O(n) and O(n + l) time, respectively. The construction of the sets C-InB,B 0 and C-OutB,B 0 in step 2 depends on the C-components which can be determined in O(nt) time. Then the four sets can be determined in O(nt) + O(kl) time. Moreover, defining the sets TB can be done in O(nt) time and the relation ≺ can be computed and checked in O(n2 + nl) time. We consider next the call order blocks(B 0 ) for some B 0 ⊂ B ∪ LH . The set M of maximal components in ≺0 |B0 can be determined in O(n) time. For some Bj ∈ M let be nj = |Bj |, tj = |TBj |, lj = |LBj |, xj = |XBj | and kj be the number of all cycles occurring in TBj , LBj and XBj , i.e. the number of all cycles in Bj occurring in TH and LH . Then, determining the lj + xj components Ki of ≺0 |B0 \{Bj } needs O(n2 + nl) time and determining the cutvertices pi needs O(n) time. Moreover, the constraints XBj can be found in O((n + l)kj ) time whereas the constraints LBj consists of sets already generated. By assumption, a TBj LBj XBj -embedding, if any, can be found in O(p0 (nj , kj , tj , lj , xj )) time.
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
47
In the worst P case, however, P all the Bj ∈PM must be checked. It is clear that P kj = k, tj ≤ t and lj P = l. By the argument given in nj ≤ 2n, the proof of Theorem 4, we additionally get xj ≤ 2(n + l). Thus step 2 of order blocks can be done in X (O(n2 + nl) + O((n + l)kj ) + O(p0 (nj , kj , tj , lj , xj ))) X X X X X X X (n + l)kj + p0 kj , tj , lj , xj nj , = O (n2 + nl) + = O n3 + n2 l + nk + kl + p0 (n, k, t, l, n + l) . Since for a fixed B0 the number of calls is bounded by n, the time needed can by the call order blocks(B ∪ LH ) in step 3 of algorithm reduce to blocks be estimated by n O(n) + O n3 + n2 l + nk +kl + p0 (n, k, t, l, n + l) , that is O n4 + n3 l + n2 k + nkl + n · p0 (n, k, t, l, n + l) . In the worst case, however, all maximal blocks B0 in ≺ must be checked. Thus we finally obtain the overall complexity O nt + kl + n2 + nl + n O n4 + n3 l + n2 k + nkl + n · p0 (n, k, t, l, n + l) = O n5 + n4 l + n3 k + n2 kl + nt + n2 · p0 (n, k, t, l, n + l) . 2 As an immediate consequence, we get the complexity of this algorithm when only topological constraints TH are given. In this case we have l = 0 and k = t = |TH |. Moreover, the reduction to blocks leads only to extended overlap constraints, but not to overlap constraints. Corollary 1 For a connected planar graph H with n = |H| and a set TH of topological constraints for H with t = |TH |, the algorithm reduce to blocks takes O n5 + n3 t + n2 · p0 (n, t, t, 0, n) time. The combination of the algorithms developed in this and the previous section leads to the complete reduction method of T -planarity of a graph G to its blocks. When replacing algorithm A with algorithm reduce to blocks in Theorem 4 (and matching the corresponding parameters), the following time complexity of the complete reduction can easily be verified. Corollary 2 Suppose G is a planar graph with n = |G| and T is a set of topological constraints for G with t = |T |. Then, algorithm reduce to components com- bined with algorithm reduce to blocks takes O n6 + n4 t + n3 · p0 (n, t, t, n, 2n) time provided that the time complexity of A0 is given by p0 . We finally note that extended overlap constraints can often be simplified in the following way. Consider some constraint Xi = hC-Ini , C-Outi , vi and a cycle C ∈ C-Ini . In case of v 6∈ C we can remove C from C-Ini and create the topological constraint meaning that v is to be embedded inside C instead. If this constraint is satisfied, any face with v at its boundary is certainly in the interior of C. The cycles of C-Outi containing v can be treated analogously. Thus, this simplification results in extended overlap constraints whose vertex is contained in all cycles involved.
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
5
48
Restricted Topological Constraints
The NP-completeness result of planarity with topological constraints opens the search for interesting tractable subproblems. Such subproblems can be defined in terms of various restrictions on graphs or constraints. For instance, one can study the effect of restricting the degree of graphs to the time complexity of T -planarity. Instead of graph parameters, we are concerned in this section with a particular parameter inherent to topological constraints which we call cycle intersection order. Definition 4 Given a graph G and a set C of cycles in G, the maximum number of vertices two distinct cycles of C have in common is called the cycle intersection order of C. For a set T of topological constraints for G we denote the set of cycles occurring in T by CT . The cycle intersection order of T is the cycle intersection order of CT . If d is the cycle intersection order of T , we also write Td for T . In other words, the cycle intersection order of T is the maximum order of all graphs Ci ∩ Cj for distinct Ci , Cj ∈ CT . We consider it a natural parameter of topological constraints since it captures an important aspect of the relationships between cycles of CT which is worth studying. In particular, we are interested in finding the exact boundary between P and NP w.r.t. this parameter. Recalling the proof of Theorem 3, we can immediately conclude that Td planarity remains NP-hard for all d ≥ 3. This is because any two distinct cycles involved in the defined constraints share either 2 or 3 vertices. By a minor modification of encoding a BETWEENNESS instance, we obtain NP-hardness even for d ≥ 2. Theorem 6 The problem of Td -planarity is NP-complete for all d ≥ 2. Proof: It is sufficient to show NP-hardness of Td -planarity for d = 2. Consider an instance of BETWEENNESS, i.e. a set A = {a1 , . . . , an } and a set S = {s1 , . . . , sr } of ordered triples sj = (aj1 , aj2 , aj3 ) of distinct elements of A. We transform the graph GA defined in the proof of Theorem 3 into a graph G0A by replacing each vertex ai by the path ai,1 , . . . , ai,r (with an edge from each of these vertices to x and y) and adding some cycle C which meets all these vertices involved exactly in x and y. This construction is illustrated in Fig. 13. For any sj = (aj1 , aj2 , aj3 ) let Cjj1 ,j3 denote the cycle (x, aj1 ,j , y, aj3 ,j , x). We define TS0 to contain the constraints hCjj1 ,j3 , {xaj2 ,j }, ∅i for all triples sj and, additionally, the constraint hC, {xai,j | 1 ≤ i ≤ n, 1 ≤ j ≤ r}, ∅i. This last constraint ensures any embedding of G0A to induce some linear order of the paths ai,1 , . . . , ai,r . Obviously, all these cycles have exactly x and y in common such that the cycle intersection order of TS0 is 2. Then it can be proved analogously to Theorem 3 that G0A is TS0 -planar iff hA, Si is a positive instance; however, we omit the details. 2
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
49
x C
a1,1
a1,r
an,1
an,r
1 C1,n
y Figure 13: Graph G0A defined in the proof of Theorem 6 Interestingly, the remaining problem of T1 -planarity turns out to have a positive solution. The next sections are devoted to the development of a polynomial time algorithm for generating a T1 -embedding. Thus, the boundary of Td -planarity between P and NP will be proved to be d = 1. Due to the polynomial time reduction method presented in the previous section, it is sufficient to find a polynomial time embedding algorithm for 2-connected graphs and constraints that are derived from topological constraints with cycle intersection order 1. Expectedly, such an algorithm depends primarily on certain structural properties of sets of cycles in a 2-connected graph with cycle intersection order 1. The next section explores these properties as far as required for developing the T1 -embedding algorithm.
5.1
Decomposition of Biconnected Graphs by Cycles of Intersection Order 1
Suppose we are given a nonempty set C of cycles in a planar 2-connected graph G such that C has cycle intersection order 1. Moreover, let n denote |G| and k denote |C|. Since any edge of G belongs to at most one cycle of C and each cycle = n − 2. consists of at least three edges, we immediately get that |C| ≤ 3n−6 3 This also holds obviously for planar graphs with a smaller connectivity number than 2. Nevertheless, we continue to use parameter k when analyzing time complexity. The main purpose of this section is to present a method of decomposing G into subgraphs with respect to C having certain desirable properties which support the construction of an embedding of G satisfying given constraints. This decomposition is described in terms of C-components of G for cycles C ∈ C. The fact that G admits such a decomposition is mainly due to the cycle intersection order 1 of C; in particular, nonplanar graphs admit the same decomposition. We denote the set of C-components in G for all C ∈ C with HC and often write HC for C-components H of G. As a simple consequence of cycle
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
50
intersection order 1 of C, we have that C 0 must be entirely contained in some C-component of G for any distinct C, C 0 ∈ C; this C-component is denoted by HC,C 0 . The following lemma describes a frequently used relationship between C-components for different cycles of C. Lemma 1 Let G be a 2-connected graph, C be a set of cycles in G with cycle intersection order 1 and C1 , C2 , C3 ∈ C. Then, if C2 and C3 belong to different C1 -components, C1 and C3 belong to the same C2 -component. Proof: We show that there is a path p in G from some vertex a ∈ V (C1 )\V (C2 ) to some vertex b ∈ V (C3 ) \ V (C2 ) such that p does not meet C2 . Then, since p is entirely contained in some C2 -component, both C1 and C3 necessarily belong to that C2 -component, too. The C1 -component H of G containing C3 has at least 2 vertices of attachment, but by assumption |C1 ∩ C2 | ≤ 1, at most one of them belongs to C2 . So let a ∈ V (C1 )\V (C2 ) be the other attachment vertex. Since C2 is not contained in H, C2 can only meet H at its attachment points. Then let H 0 ⊂ H be the component of G − C1 which contains vertices of C3 and let b be such a vertex. Thus we have H 0 ∩ C2 = ∅ and b ∈ V (C3 ) \ V (C2 ). Finally, if a already belongs to C3 , we define p to be the trivial path a. Otherwise, if e is an edge joining a to some z ∈ H 0 and p0 is a path in H 0 from z to b, then p = e ∪ p0 is the required 2 path from a to b without meeting C2 . Any cycle C ∈ C with more than one C-component divides G into just these C-components. It is more appropriate for our purpose, however, to take the union of these C-components with C as the subgraphs into which C divides G. Having in mind the way how cutvertices divide a connected graph into blocks, one can ask whether there is a similar decomposition of G into maximal subgraphs that cannot be further divided by cycles of C. This motivates the following definition of parts. Definition 5 A subset C 0 of C with |C 0 | ≥ 2 is called separable if there is some C ∈ C with at least two C-components in G each of which containing cycles from C 0 . Otherwise, C 0 is called inseparable. T An inseparable C 0 defines the subgraph PC 0 = C∈C 0 C ∪ HC of G where HC is the C-component containing all cycles from C 0 \ {C}. We call the subgraphs PC 0 defined by some maximal inseparable C 0 and the subgraphs C ∪ HC for a C-component HC not containing cycles from C parts of G w.r.t. C. The set of all parts is denoted by P. The decomposition graph D is defined on C ∪ P by the edges CP iff C ⊂ P for C ∈ C and P ∈ P. To illustrate these definitions, consider the graph G and its decomposition graph D shown in Fig. 14. For instance, {C5 , C8 } is separable since C5 and C8 belong to different C1 -components. {C1 , C8 } is inseparable, but not maximal inseparable since {C1 , C8 , C7 } is also inseparable. This set, however, is maximal inseparable, thus defining a part. As we will see, the decomposition graph is always a tree.
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002) G
D
C6
C6 C5
C5
C7
C7 C1 C3 C4
51
C2
C1
C8
C8 C3
C2
C4
Figure 14: A 2-connected graph G (drawn nonplanar) and its decomposition graph. The cycles of C with intersection order 1 are drawn as circles and the parts are marked by dashed outlines and square nodes, respectively. The definition of maximal inseparable subsets and parts, however, is nonconstructive. Thus we develop next an effective method for finding all maximal inseparable subsets of C which then can be transformed into a procedure for computing the parts of G. For this purpose we define in Proposition 1 the relation on C depending on some fixed root cycle Cr . It is called weakly linear if C C 0 and C C 00 imply C 0 C 00 or C 0 = C 00 or C 00 C 0 . Proposition 1 Let be Cr ∈ C and the relation be defined on C by C Cr and C 0 C iff C 0 6⊂ HC,Cr for all distinct C, C 0 ∈ C \ {Cr }. Then, is a weakly linear, strict partial order. Proof: It is sufficient to consider only cycles distinct from Cr . Obviously, is asymmetric since C 0 C implies by Lemma 1 that Cr and C are in the same C 0 -component, i.e. C 6 C 0 . To show transitivity, assume that C 00 C 0 and C 0 C holds and suppose that C 00 6 C. Since C 00 and Cr are in the same C-component, but not C 0 and Cr , we conclude that C and C 00 are in the same C 0 -component. In connection with C 00 C 0 we then get C C 0 in contradiction to asymmetry. Thus C 00 C must hold. To prove that is weakly linear, assume that C C 0 and C C 00 and further suppose that C 0 6= C 00 and C 0 6 C 00 . The latter means that C 0 and Cr are in the same C 00 -component, thus from C C 00 follows that C and C 0 are in different C 00 -components. Then, by Lemma 1, C 00 and C are in the same C 0 -component. In connection with C C 0 this means that C 00 and Cr are in 2 different C 0 -components, thus C 00 C 0 . In other words, the transitive reduction of is a rooted tree with root Cr . For the example graph of Fig. 14 with C1 chosen for Cr , is shown in Fig. 15.
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
52
C1 C2 C5 C6 C7 C8 C3 C4 Figure 15: Relation for the graph given in Fig. 14 and root cycle Cr = C1 . Using the relation , we are able to determine the maximal inseparable subsets C 0 of C, no matter which cycle is the root cycle. We show in Theorem 7 that we get all maximal inseparable sets C 0 by choosing some cycle C and all direct successors C 0 of C in belonging to the same C-component of G. The cycle C 0 is a successor of C if C 0 C holds, and a direct successor if there is no C 00 with C 0 C 00 C. The proof of this theorem makes use of the following lemma on maximal inseparable sets. Lemma 2 Let C 0 ⊂ C be maximal inseparable and B ∈ C be a cycle not belonging to C 0 . Then, there is some C 0 ∈ C 0 dividing B from C 0 \ {C 0 }. Proof: Since C 0 ∪ {B} is separable, there is a B1 ∈ C, B1 6= B, dividing B from all cycles of C 0 \ {B1 }. If B1 ∈ C 0 , we are finished. Otherwise, since C 0 ∪ {B1 } is also separable, there is some B2 ∈ C, B2 6= B1 , dividing B1 from C 0 \ {B2 }. We show that B2 also divides B from C 0 \{B2 }. By Lemma 1, B2 and all cycles of C 0 are in the same B1 -component, thus B and B2 are in different B1 -components. Again by Lemma 1, B and B1 are in the same B2 -component. Then we get that B2 also divides B from C 0 \ {B2 }. If B2 ∈ C 0 , we are finished. Otherwise, one can find again a B3 ∈ C dividing B2 , and thus B, from C 0 \ {B3 }, and so forth. This process results in some Bi belonging to C 0 that divides B from C 0 \ {Bi }. 2 Theorem 7 Let C 0 be a subset of C with |C 0 | ≥ 2. Then, C 0 is maximal inseparable iff there is a C ∈ C 0 such that C 0 \ {C} is a set of all direct successors C 0 C belonging to the same C-component in G. Proof: (⇒) Suppose C 0 is maximal inseparable. By Proposition 1, there is a cycle C ∈ C 0 that is maximal in |C 0 . Let H be the C-component containing all the other cycles of C 0 . We first prove that all C 0 ∈ C 0 \ {C} are successors of C. If Cr ∈ C 0 , we have C = Cr and, by definition, C 0 C for all C 0 ∈ C 0 \ {C}. Otherwise we have Cr 6∈ C 0 . We show that Cr is not contained in H; then all C 0 ∈ C 0 \ {C} are in a different C-component than Cr , thus it follows that C 0 C. So suppose that Cr ⊂ H. Since C 0 is maximal inseparable, from Lemma 2 follows that there is some C ∗ ∈ C 0 , C ∗ 6= Cr , dividing Cr from C 0 \ {C ∗ }. C ∗ must be identical with C: otherwise the maximality of C implies C 6 C ∗ , i.e. C ∗ does not divide Cr from C 0 \ {C ∗ }. However, C = C ∗ means
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
53
that Cr is in a different C-component than all C 0 ∈ C 0 \ {C}, contrary to the assumption that Cr ⊂ H. Next we show that all C 0 ∈ C 0 \{C} are direct successors of C in . Suppose that there is some C ∗ with C 0 C ∗ C. From C ∗ C follows by Lemma 1 that C and Cr are in the same C ∗ -component. In connection with C 0 C ∗ we get that C 0 and C are in different C ∗ -components. Then, however, C 0 would not be inseparable. Finally, we have to show that any direct successor C 0 of C belonging to H is already contained in C 0 . Suppose that C 0 6∈ C 0 . By Lemma 2, there is some C ∗ ∈ C 0 , C ∗ 6= C 0 , dividing C 0 from C 0 \ {C ∗ }. From C ∗ C follows that Cr and C are in the same C ∗ -component, and C 0 6 C ∗ means that Cr and C 0 are in the same C ∗ -component. Then, C ∗ does not divide C 0 from C and, thus, from C 0 \ {C ∗ }. This shows that C 0 must belong to C 0 . (⇐) Suppose C 0 satisfies the requirements where C is the maximal cycle. Let H be the C-component containing all other cycles of C 0 . We first show that C 0 is inseparable. So let C ∗ be some cycle of C. If C ∗ 6⊂ H, C ∗ is in a different C-component than all C 0 ∈ C 0 \ {C}. By Lemma 1, all C 0 ∈ C 0 are in the same C ∗ -component. Suppose C ∗ ⊂ H, thus in particular C ∗ 6= C and C ∗ 6= Cr . If C ∗ ∈ C 0 , we have C ∗ C, i.e. Cr and C are in the same C ∗ -component. Since for all C 0 ∈ C 0 \ {C} we have C 0 C, and in particular C 0 6 C ∗ , Cr and C 0 are in the same C ∗ -component. Thus, all C 0 ∈ C 0 belong to the same C ∗ component. Otherwise, if C ∗ 6∈ C 0 , C ∗ must be a successor of some C 0 ∈ C 0 \{C} according to the assumption. From C ∗ C 0 C follows that Cr , C 0 and C are in the same C ∗ -component. Since for all other C 00 ∈ C 0 \ {C, C 0 } we have C 00 6 C ∗ , it follows that Cr and C 00 are in the same C ∗ -component. Thus, all C 0 ∈ C 0 again belong to the same C ∗ -component. Next we prove that C 0 is maximal inseparable. Suppose that for some C ∗ 6∈ C 0 0 C ∪ {C ∗ } is also inseparable. Then C ∗ must be contained in H. By assumption, C ∗ must be a successor of some C 0 ∈ C 0 \ {C}, i.e. C ∗ and Cr are in different C 0 -components. From C 0 C follows that C and Cr are in the same C 0 component. Thus, C ∗ and C are in different C 0 -components such that C 0 ∪ {C ∗ } is separable. 2 From the results shown above we get some immediate consequences characterizing parts and decomposition graphs in more detail. We summarize them in Corollary 3 and 4. Corollary 3 Let P be the set of parts of G w.r.t. C. Then the following propositions hold: (i) Any part PC 0 ∈ P contains exactly the cycles C 0 from C. (ii) Any cycle C ∈ C in some part P ∈ P has exactly one C-component in P . (iii) For any part P ∈ P and cycle C ∈ C we have P ⊂ C ∪ HC for some C-component HC of G. (iv) Two distinct parts P, P 0 ∈ P have at most one cycle of C in common.
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
54
(v) Any part P ∈ P is 2-connected. S (vi) P ∈P P = G. Corollary 4 Let P be the set of parts and D be the decomposition graph of G w.r.t. C. Then the following propositions hold: (i) D is a tree with |D| < n. (ii) If HC is a C-component of G for C ∈ C and P is the part of G with C ⊂ P ⊂ C ∪ HC , then C ∪ HC is the union of all parts belonging to the component of D − C which contains P . (iii) G has less than n C-components, i.e. |HC | < n. The usefulness of decomposing G into its parts for the embedding algorithm to be developed comes in particular from proposition (ii) of Corollary 3: it guarantees that any cycle of C in some part P is a facial cycle of any embedding of P . As we will see in Sect. 5.2, this allows controlling the satisfaction of constraints during the embedding process. By proposition (ii) of Corollary 4, we have a one-to-one correspondence ε between C-components of G and edges of D: each edge CP ∈ E(D) represents the C-component HC with C ⊂ P ⊂ C ∪ HC , thus we define ε(HC ) = CP . This correspondence ensures the decomposition graph D to be a complete representation of the structure of G w.r.t. C. The method for finding the maximal inseparable subsets of C provided by Theorem 7 leads directly to an efficient procedure for computing the parts of G. The order in which the cycles are processed plays a crucial role in this procedure. Suppose is defined by some fixed cycle Cr and the cycles of C are in the reverse order C1 , . . . , Ck of some topological sorting, i.e. Cj Ci implies j < i. Thus, we always have Ck = Cr . Define G0 = G and Pi , Gi and Ei for 1 ≤ i ≤ k as follows: = {Ci ∪ H | H is a Ci -component of Gi−1 with Cr 6⊂ H}, = Ci ∪ Hr , for the Ci -component Hr of Gi−1 with Cr ⊂ Hr , = {C 0 P | C 0 ∈ C and C 0 ⊂ P ∈ Pi }. S S Defining PCr = Pi and the graph DCr on C ∪ PCr by the edge set Ei , it can easily be seen in Proposition 2 that PCr is in fact the set of all parts of G and DCr is its decomposition graph. Pi Gi Ei
Proposition 2 For any Cr ∈ C PCr is the set P of parts and DCr is the decomposition graph D of G w.r.t. C. Moreover, P and D can be computed by an O(nk) procedure. Proof: By the definition of the Ei , DCr = D follows from PCr = P. Due to the particular order of the cycles Ci , the successors Cj of Ci contained in Gi−1 are exactly the direct successors of Ci . Moreover, each Cj has only one Cj component in Gi−1 , namely that one which contains Ci and Cr . By Theorem 7, Pi contains exactly the parts built by Ci and its direct successors Cj belonging
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
55
to the same Ci -component and also the parts built by Ci and a Ci -component not containing any other cycle of C. Finally, it can easily be seen that a procedure can be implemented for generating P and D which takes O(nk) time. The relation can be determined for some fixed Cr by computing all C-components in HC which needs O(nk) time. The topological sorting can be done in O(k 2 ) = O(nk) time. And in each step i the determination of all Ci -components of Gi−1 takes O(n) time. Thus the overall complexity is O(nk). 2 Figure 16 illustrates the stepwise construction of the parts of graph G given in Fig. 14. The sequence of cycles is C3 , C4 , C2 , C5 , C6 , C7 , C8 , C1 which is the reverse order of some topological sorting of the relation shown in Fig. 15. i=1
i=2
i=3
i=4 C5
C3
C2
C4 i=5
i=6
i=7
i=8
C6 C7 C8
C1
Figure 16: Construction of parts of the graph given in Fig. 14 using the ordering C3 , C4 , C2 , C5 , C6 , C7 , C8 , C1 . For each step i Gi is colored black and the parts in Pi are the grey-colored subgraphs in connection with the cycle of step i. 5.1.1
Representing Embeddings by Labelled Decomposition Graphs
Decomposition graphs are particularly interesting for the planarity problem with topological constraints. We show in this section that labelled decomposition graphs can represent, in a sense, embeddings of 2-connected planar graphs up to topological constraints, i.e. all embeddings corresponding to the same labelled decomposition graph satisfy the same topological constraints involving cycles from C. e of G. Due to the correspondence between edges Consider an embedding G of D and C-components of G, we can label each edge CP with the binary information on which side of C the C-component HC corresponding to CP is
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
56
e If Pe ⊂ Int C e holds in G, e we label CP with 1 and otherwise, embedded in G. e we label CP with 0. Obviously, edges representing overlapping if Pe ⊂ Ext C, e defines a weakly linear, C-components have complementary labels. Since G f0 ⊂ Int C, e there is at least one strict partial order < on C by C 0 < C iff C maximal Cr ∈ C w.r.t. < contained in the exterior of any other cycle of C. As a consequence, for any path Cr , . . . , P, C in D the edge P C is labelled with 0. e induces a labelling of D according to the following definition. Thus G Definition 6 Let D be the decomposition graph of G w.r.t. C. A labelling λ of D is a function λ : E(D) −→ {0, 1} satisfying the following conditions: (1) λ(ε(HC )) + λ(ε(HC0 )) = 1 for overlapping C-components HC and HC0 . (2) There is a Cr ∈ C such that for all paths Cr , . . . P, C in D: λ(P C) = 0. A labelling of D together with D is called a labelled decomposition graph. e and G e 0 are embeddings of G inducing the same labelling of D. Suppose G e iff it is inside C in G e0 , i.e. G e and Then any C-component HC is inside C in G 0 e e G satisfy the same topological constraints involving cycles from C. However, G 0 e and G need not necessarily be topologically equivalent, they can differ in the particular embeddings of the C-components. Conversely, if two embeddings of G induce different labellings of D, they must be distinguished by at least one topological constraint. For this reason labelled decomposition graphs represent embeddings up to topological constraints. For the example graph G of Fig. 14 an embedding of G together with its labelled decomposition graph is shown in Fig. 17. C1 1
C5
P1 C7
C6
C8 C1
C4 C3
P2
1 P3
P4
0
0
C2
C5
C6
C7
1
1
1 C2
0
0
P5 0 C3
(a)
0
P6
0
0 C8
P7
0 C4 (b)
Figure 17: (a) An embedding of the graph G given in Fig. 14. (b) The decomposition graph D of G with a labelling induced by this embedding. Given a labelling λ of D, one can easily construct an embedding of G which induces exactly λ: one has only to embed Cr and then attach in a depth-first
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
57
manner all parts P to the already embedded cycle C for edges CP ∈ E(D) according to the label of CP . Algorithm embedding shown in Fig. 18 describes this embedding procedure more precisely. Depending on the labelling λ, it generates a set F of pairs hF, SF i where F is a cycle in G and SF ⊆ C; the cycles F are called cycles of F and SF are called their labels. If we choose some hF0 , ∅i from F , which is guaranteed to exist, F0 is the outer facial cycle and the cycles of F are the facial cycles of some embedding of G that induces λ. In this case the inner facial cycles of any C ∈ C are exactly those cycles F of F with C ∈ SF . The procedure must be called with C = Cr and F = {hCr , ∅i, hCr , {Cr }i}; the cycles of F represent the two facial cycles of the embedded Cr . Algorithm embedding Input : labelling λ, C ∈ C, F ⊂ C(G) × 2C Output : F For each edge CP ∈ E(D) do: 1. Let H be the (unique) C-component in P . Find some pair hF, SF i ∈ F such that F contains all vertices of attachment of H and C ∈ SF iff λ(CP ) = 1. 2. Determine the set F 0 of facial cycles of some embedding of H ∪ F . 3. Remove hF, SF i from F and add hF 0 , SF i to F for all F 0 ∈ F 0 \ {F }. 4. For any edge P C 0 ∈ E(D) set SC 0 := SC 0 ∪ {C 0 } for cycle C 0 of F and compute embedding(λ, C 0 , F ). Return F . Figure 18: Algorithm for generating an embedding corresponding to a labelled decomposition graph To illustrate the construction of an embedding, Fig. 19 shows the sequence of partial embeddings of the example graph according to the labelling given in Fig. 17 (b). This sequence corresponds to the sequence of the sets F of facial cycles generated by some depth-first search of D. For each visited edge CP H is the grey-colored subgraph and F is the face cycle it is attached to. The correctness of this algorithm is proved in Proposition 3. Proposition 3 Let λ be a labelling of the decomposition graph of G w.r.t. C. Then algorithm embedding generates a set F of pairs hF, SF i with cycle F ⊆ G and SF ⊆ C. F satisfies the following conditions (where F (C) denotes {F | hF, SF i ∈ F with C ∈ SF }): (i) {F | hF, SF i ∈ F} is the set of facial cycles of some embedding of G. (ii) There is some hF0 , ∅i ∈ F. L (iii) C = F ∈F (C) F for all C ∈ C. S (iv) P ⊂ F ∈F (C) F iff λ(CP ) = 1 for CP ∈ E(D).
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002) C1
C1 P1
C2 P5
C1 P2
C1 P3
C6 P6
C1 P4
C7 P7
58
Figure 19: Illustration of algorithm embedding for the labelled decomposition graph D of Fig. 17 (b). For each edge CP H is the grey-colored subgraph and F the face cycle it is attached to. Moreover, the algorithm takes O(n2 ) time. Proof: Define F0 = {hCr , ∅i, hCr , {Cr }i} and for i = 1, . . . , |P| Fi to be the sets F generated by the depth-first search of the algorithm. Note that the number of visited edges CP ∈ E(D) is identical with the number of parts of G. Let Fi (C) denote {F | hF, SF i ∈ Fi with C ∈ SF }. We show by induction that the following propositions hold for all i ≥ 0; then, since G is the union of all of its parts, F|P| satisfies the claim. (i) S {F | hF, SF i ∈ Fi } is the set of facial cycles of some embedding of 0 F 0 ∈Fi F . (ii) There is some hF0 , ∅i ∈ Fi . L (iii) C = F 0 ∈Fi (C) F 0 if Fi (C) 6= ∅. S S (iv) If for CP ∈ E(D) P ⊂ F 0 ∈Fi F 0 , then P ⊂ F 0 ∈Fi (C) F 0 iff λ(CP ) = 1. Clearly, F0 satisfies all these conditions. We assume them to hold for all j ≤ i for some i. Let CP be the currently visited edge of D and H be the Ccomponent of P . Due to condition (1) of Definition 6 and (i), there is some pair hF, SF i ∈ Fi such that F contains the vertices of attachment of H and C ∈ SF iff λ(CP ) = 1. Let F 0 be the generated set of facial cycles of some embedding of H ∪ F . By Corollary 3 (ii), F and all C 0 ∈ C with P C 0 ∈ E(D) are facial cyclesLof this embedding and, thus, are contained in F 0 . Moreover, we have F = F 0 ∈F 0 \{F } F 0 .
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
59
By the definition of Fi+1 := Fi \ {hF, SF i} ∪ {hF 0 , SF i | F 0 ∈ F 0 , F 0 6= F } and SC 0 := SC 0 ∪ {C 0 }, the conditions (i)–(iv) can be easily verified. Condition (i) holds since F 0 \ {F } is a refinement of F and (ii) holds because of cycle intersection order 1 of C. Condition (iii) is shown for C 0 with P C 0 6∈ E(D) by M M M M F0 = F0 ⊕ F0 = F 0 = C0 F 0 ∈Fi+1 (C 0 )
F 0 ∈Fi (C 0 )\{F }
F 0 ∈F 0 \{F }
F 0 ∈Fi (C 0 )
and for C 0 with P C 0 ∈ E(D) by Fi+1 (C 0 ) = {C 0 }. The last condition (iv) follows immediately from the choice of F depending on λ(CP ) and condition (2) of Definition 6. Finally, we note that this algorithm can be implemented as an O(n2 ) procedure since G has less than n parts and steps 1 to 4 can be done in O(n) time. 2
5.2
A Polynomial Time T1 -Embedding Algorithm
Provided with the analysis of the previous sections, we are now able to present a polynomial time algorithm for generating T1 -embeddings of planar graphs. This algorithm is a combination of the reduction algorithms given in Sect. 4 and the procedure for generating T LX -embeddings of 2-connected graphs which we develop next. So let G denote a 2-connected planar graph and T , L and X denote a set of topological constraints, overlap constraints and extended overlap constraints for G, respectively, such that the set C of all cycles involved in these constraints is of cycle intersection order 1. Moreover, we denote n = |G|, t = |T |, l = |L|, x = |X | and k = |C|. The main idea for generating a T LX -embedding of G is finding an appropriate labelling of the decomposition graph D of G w.r.t. C depending on T , L and X that can be transformed by algorithm embedding into a T LX -embedding. For this purpose, we determine edges of D whose labels can be deduced from the constraints and, thus, necessarily belong to this labelling. To find labels according to condition (1) of Definition 6, we make use of overlap graphs GC of cycles C ∈ C. Consider a component Z of GC with at least two C-components. ˙ 2 such that both Z1 Since GC is bipartite, Z has a unique partition Z = Z1 ∪Z and Z2 contain no overlapping C-components. Then, a label for CP ∈ E(D) with CP = ε(HC ) for some C-component HC ∈ Z clearly determines the labels of edges representing all the other C-components in Z. We denote with [CP ] the set of edges representing all the C-components belonging to the same part of the partition as CP and denote with [CP ]− the set of edges representing all the C-components belonging to the other part. Thus, two edges of [CP ] and [CP ]− , respectively, must have complementary labels. We call [CP ] the equivalence class of CP and [CP ]− its complement. With the following definitions we determine equivalence classes of edges of D whose labels can be easily deduced from the constraints. E1 (T ) and E0 (T ) are the sets of equivalence classes whose edges must have label 1 and 0, respectively, due to the topological constraints in T . The sets E1 (L), E0 (L) and
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
60
E1 (X ), E0 (X ) are to be interpreted analogously. Note, however, that these sets are not meant to cover all labels that can be deduced. E10 (T ) E00 (T ) E1 (T ) E0 (T )
= = = =
E0 (L) E1 (L)
= {[ε(HC,C 0 )] | C ∈ C-Outi , C 0 ∈ C-Ini for hC-Ini , C-Outi i ∈ L} = {[CP ]− | [CP ] ∈ E0 (L)}
E00 (X ) E000 (X ) E10 (X ) E1 (X ) E0 (X )
= = = = =
{[ε(HC )] | HC ∩ InC 6= ∅ for HC ∈ HC , hC, InC , OutC i ∈ T } {[ε(HC )] | HC ∩ OutC 6= ∅ for HC ∈ HC , hC, InC , OutC i ∈ T } E10 (T ) ∪ {[CP ]− | [CP ] ∈ E00 (T )} E00 (T ) ∪ {[CP ]− | [CP ] ∈ E10 (T )}
{[ε(HC,C 0 )] | C ∈ C-Outi , C 0 ∈ C-Ini , hC-Ini , C-Outi , vi ∈ X } {[ε(HC )] | v 6∈ C ∈ C-Outi , v ∈ HC ∈ HC , hC-Ini , C-Outi , vi ∈ X } {[ε(HC )] | v 6∈ C ∈ C-Ini , v ∈ HC ∈ HC , hC-Ini , C-Outi , vi ∈ X } E10 (X ) ∪ {[CP ]− | [CP ] ∈ E00 (X ) ∪ E000 (X )} E00 (X ) ∪ E000 (X ) ∪ {[CP ]− | [CP ] ∈ E10 (X )}
As a result, we define E1 = E1 (T ) ∪ E1 (L) ∪ E1 (X ) and E0 = E0 (T ) ∪ E0 (L) ∪ E0 (X ). Next we consider overlap constraints and extended overlap constraints in more detail. By their semantics and cycle intersection order 1 of C, the cycles of C-Ini belonging to some Li ∈ L or Xi ∈ X are embedded in any T LX -embedding of G in a linear order w.r.t. the induced relation < on C. Thus, they must necessarily belong to a path of D if G is T LX -planar. If this holds for Li = hC-Ini , C-Outi i, we denote w(Li ) the smallest path containing all cycles of C-Ini and say that Li induces w(Li ); the constraints of X are treated analogously. Suppose such a path is of the form C1 , P1 , . . . Pj , Cj , Pj0 , . . . , Ps , Cs with C1 , Cj and Cs belonging to a set C-Ini . Then in a T LX -embedding either C1 < . . . < Cj < . . . < Cs or Cs < . . . < Cj < . . . < C1 holds. We define the set E∗ of equivalence classes whose edges potentially get label 1, due to these two cases, during the search for an appropriate labelling: E∗
=
{[CP ] | CP ∈ E(w(Li )), C ∈ C-Ini if Li ∈ L induces w(Li )} ∪ {[CP ] | CP ∈ E(w(Xi )), C ∈ C-Ini if Xi ∈ X induces w(Xi )}.
To construct an appropriate labelling, we have to find in particular a Cr ∈ C satisfying condition (2) of Definition 6. For each edge CP ∈ E(D) let RCP be the set {C 0 ∈ C | C 0 6⊂ ε−1 (CP )}, i.e. the set of cycles not contained in the C-component represented by CP . We can restrict the set of candidates for Cr with the help of RCP : suppose CP has label 1, then no cycle in C \ RCP can satisfy condition (2). Moreover, consider a path w(Li ) whose first and last edges are CP and C 0 P 0 , respectively. Then we can restrict the set of candidates to RLi := RCP ∪ RC 0 P 0 ; RXi is defined analogously. From what is considered so far, we have the following set of candidates: \ \ \ RCP ∩ RLi ∩ RXi . R= [CP ]∈E1
Li ∈L
Xi ∈L
In Definition 7 we establish the criterion of being an appropriate labelling that respects the constraints T , L and X , thus we call it T LX -labelling.
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
61
Definition 7 A T LX -labelling λ of D is a labelling satisfying the following additional conditions: (1) λ(CP ) = 1 if [CP ] ∈ E1 . (2) λ(CP ) = 0 if [CP ] ∈ E0 . (3) Cr ∈ R; each Li ∈ L and Xi ∈ X induces in particular a path in D. (4) For all paths Cr , . . . , C, P with [CP ] ∈ E∗ : λ(CP ) = 1. Clearly, any T LX -embedding of G induces a T LX -labelling on D. It can also easily be verified by Proposition 3 that the converse holds as well: given a T LX -labelling of D, algorithm embedding generates some hF, SF i such that each F0 with hF0 , ∅i is the outer facial cycle and the cycles of F are the facial cycles of some T LX -embedding of G. The algorithm find labelling in Fig. 20 generates a T LX -labelling of D iff G is T LX -planar. Its main part is a depth-first search of D beginning at a candidate Cr ∈ R that labels the visited edges. We consider D a directed tree with root Cr such that each edge is uniquely denoted by CP or P C depending on whether Cr , . . . , C, P or Cr , . . . , P, C is a path in D. When attaching labels to edges, labelling an edge with 0 or 1 fails if this edge already has the complementary label 1 or 0, respectively. Proposition 4 establishes the correctness of the algorithm. Algorithm find labelling Input : decomposition graph D of G, constraints T , L, X Output : T LX -labelling λ with the particular Cr ∈ C 1.
2. 3. 3.1 3.2 3.3 4.
Determine E1 and E0 . If E1 ∩ E0 6= ∅, stop. Check if each Li ∈ L and Xi ∈ X induces a path in D; if not so, stop. Determine E∗ and R. If R = ∅, stop. Label any edge CP of D with 1 if [CP ] ∈ E1 , and with 0 if [CP ] ∈ E0 . Then label any edge CP not labelled so far with ∗ if [CP ] ∈ E∗ . Find a Cr ∈ R such that the following operations executed during a depth-first search of D beginning at Cr are successful: If edge P C is visited, label all edges in [P C] with 0 and all edges in [P C]− with 1. If edge CP with label ∗ is visited, label all edges in [CP ] with 1 and all edges in [CP ]− with 0. If edge CP without any label is visited, label all edges in [CP ] with 0 and all edges in [CP ]− with 1, or vice versa. If this succeeds, return Cr and labelling λ defined by the labels of D.
Figure 20: Algorithm for generating a T LX -labelling of the decomposition graph
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
62
Proposition 4 Given constraints T , L and X for G, algorithm find labelling generates a T LX-labelling iff G is T LX -planar. Moreover, the algorithm takes O n2 k + kl + kx time. Proof: (⇒) It can easily be seen that the set of labels generated by the algorithm defines in fact a T LX -labelling λ of D. Since for any edge CP ∈ E(D) the edges in [CP ] and in [CP ]− have complementary labels and, moreover, each edge has a unique label 0 or 1, condition (1) of Definition 6 is satisfied. Condition (2) is guaranteed by step 3.1, thus λ is a labelling. Conditions (1) and (2) of Definition 7 are ensured by step 2 and (3) is checked in step 1 and 3. The last condition (4) holds because of step 3.2. Thus λ is a T LX -labelling and G is T LX -planar. (⇐) Suppose G has a T LX -embedding. Then there is a T LX -labelling λ0 induced by this embedding. In particular, we have that E1 ∩ E0 = ∅, each Li ∈ L and Xi ∈ X induces a path in D and R 6= ∅. Since for any edge CP of D labelled in step 2 with 0 or 1 it necessarily holds that λ0 (CP ) = 0 or λ0 (CP ) = 1, respectively, and the cycle Cr is searched exhaustively in R, it is guaranteed that the algorithm finds a complete set of labels for D which defines a T LX -labelling as shown above. Finally, we estimate the time complexity of this algorithm. To determine the sets in step 1, it is necessary to find the overlap graphs of cycles of C which can be done in O(kn2 ) time. Then, determining the sets E1 (T ), E0 (T ) and E1 (L), E0 (L) and E1 (X ), E0 (X ) needs O(nt), O(kl) and O(kx) time, respectively. Finding the paths induced by the constraints in L and X and determining E∗ can be done in O(nl + nx) time. Moreover, the set R can be computed in O(nk + lk + xk) time. Next, labelling edges in step 2 and during the depth-first search of D needs O(n) time, thus step 3 takes O(kn) time. The resulting time 2 complexity is therefore O(n2 k + kl + kx). Consider again the example graph of Fig. 14 and suppose we have a topological constraint meaning that cycle C6 should be embedded inside cycle C1 and an overlap constraint meaning that C1 and C3 should include a common face. The first constraint determines the set E1 (T ) = {[C1 P3 ]} and, thus, E0 (T ) = {[C1 P2 ] = [C1 P4 ]}. The other sets for L and X are empty. Because of the second constraint we get E∗ = {[C1 P1 ], [C2 P1 ], [C2 P5 ], [C3 P5 ]} indicating that C1 , C2 and C3 are to be embedded in some linear inclusion order. The set of candidates is R = {C1 , C3 , C5 , C7 , C8 }. Algorithm find labelling encodes these sets by the partial labelling shown in Fig. 21 (a). In figure (b) we see some complete labelling that can result from this partial labelling when C1 is chosen for Cr ; it corresponds to the embedding shown in Fig. 17. The complete T LX -embedding algorithm is shown in Fig. 22. Its correctness and complexity can be easily obtained from what is developed so far.
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
63
C1 C6
P2
P3 0 C1 P1
C4
1 P1
C5
C3
P6
∗ C2 ∗ P5
C7 1 ∗ ∗
P7
0 P4
1
0
P2
P3
0
0
C2
C5
C6
C7
1
1
P5 0 C3
(a)
P4
0
1
C8
0
P6
0
0 C8
P7
0 C4 (b)
Figure 21: Illustration of algorithm find labelling: (a) A partial labelling encoding a topological constraint and an overlap constraint. (b) A complete labelling produced by the algorithm. Algorithm embedding with constraints Input : G, constraints T , L, X Output : T LX -embedding of G 1. 2. 3. 4.
Determine the decomposition graph D of G. Compute find labelling(D, T , L, X ) resulting in a labelling λ and cycle Cr if G is T LX -planar; otherwise stop. Compute embedding(λ, Cr {hCr , ∅i, hCr , {Cr }i}) resulting in hF, SF i. Embed G such that the cycles of F are the facial cycles and F0 is the outer facial cycle for some hF0 , ∅i ∈ F. Figure 22: Algorithm for generating a T LX -embedding
Proposition 5 Given T , L, X for G, algorithm embedding with constraints generates a T LX -embedding iff G is T LX -planar. Moreover, it takes O(n2 k + kl + kx) time. The combination of algorithm embedding with constraints with algorithm reduce to blocks and algorithm reduce to components leads to the complete T1 embedding procedure for planar graphs. Using Corollary 1 and 2 of Theorem 5, we get the complexity of this procedure depending on whether G is disconnected, connected or 2-connected. Theorem 8 Suppose G is a planar graph with n = |G| and T is a set of topological constraints for G of cycle intersection order 1 with t = |T |. Then the following propositions hold:
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
64
(i) If G is disconnected, a T -embedding can be found in O(n6 ) time. (ii) If G is connected, a T -embedding can be found in O(n5 ) time. (iii) If G is 2-connected, a T -embedding can be found in O(n2 t) time.
6
Conclusions
This paper contributes to the relatively new research direction on planar graph embedding with user-defined constraints. We introduced a special sort of constraints, called topological constraints, and studied the problem of finding an embedding satisfying a given set of topological constraints. As this problem turned out to be NP-complete, we developed a polynomial time procedure for reducing the problem for arbitrary planar graphs to a problem for biconnected graphs which allows to focus on biconnected graphs when searching for heuristics or tractable subproblems. This reduction, however, results in another two types of constraints one has to cope with in developing embedding algorithms. We then used this reduction for studying a particular subproblem defined by a parameter called cycle intersection order. With respect to this parameter, we proved the exact boundary between P and NP by showing that this subproblem remains NP-complete if the cycle intersection order exceeds 1 and by presenting a polynomial time embedding algorithm for cycle intersection order 0 or 1.
Acknowledgments The author wish to thank the referees for several useful suggestions.
References [1] J.A. Bondy, U.S.R. Murty. Graph Theory with Applications, MacMillan, 1976 [2] K. Booth, G. Lueker. Testing for the consecutive ones property, interval graphs, and graph planarity using PQ-tree algorithms. J. Comput. Syst. Sci., 13: 335–379, 1976 [3] N. Chiba, T. Nishizeki, S. Abe, T. Ozawa. A linear algorithm for embedding planar graphs using PQ-trees. J. Comput. Syst. Sci., 30: 54–76, 1985 [4] G. Demoucron, Y. Malgrange, R. Pertuiset. Graphes planaires: reconnaissance et construction de repr´esentations planaires topologiques. Revue Fran¸caise de Recherche Op´erationelle, 8: 33–47, 1964 [5] G. Di Battista, P. Eades, R. Tamassia, I.G. Tollis. Algorithms for drawing graphs: An annotated bibliography. Comp. Geom., 4(5): 235–282, 1994
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
65
[6] G. Di Battista, P. Eades, R. Tamassia, I.G. Tollis. Graph Drawing: Algorithms for the Visualization of Graphs, Prentice Hall, 1999 [7] R. Diestel. Graph Theory, Springer, 1997 [8] C. Dornheim. Graph embedding with topological cycle-constraints. In J. Kratochvil (ed.), Graph Drawing, Proc. 7th Int. Symp. GD’99, LNCS 1731, 155–164, 1999 [9] P. Eades, Q.W. Feng. Multilevel visualization of clustered graphs. In S. North (ed.), Graph Drawing, Proc. 4th Int. Symp. GD’96, LNCS 1190, 101–112, 1997 [10] P. Eades, Q.W. Feng, H. Nagamochi. Drawing clustered graphs on an orthogonal grid. J. Graph Algorithms Appl., 3(4): 3–29, 1999 [11] P. Eades, P. Mutzel. Graph drawing algorithms. In M.J. Atallah (ed.), Algorithms and Theory of Computation Handbook, CRC Press, 1999 [12] Q.W. Feng, R.F. Cohen, P. Eades. Planarity for clustered graphs. In P.G. Spirakis (ed.), Algorithms – ESA’95, Proc. 3rd European Symp., LNCS 979, 213–226, 1995 [13] M.R. Garey, D.S. Johnson. Computers and Intractability – A Guide to the Theory of NP-Completeness, Freeman, 1979 [14] D. Harel. On visual formalisms. Communications of the ACM, 31(5): 514– 530, 1988 [15] W. He, K. Marriott. Constrained graph layout. In S. North (ed.), Graph Drawing, Proc. 4th Int. Symp. GD’96, LNCS 1190, 217–232, 1997 [16] J. Hopcroft, R.E. Tarjan. Efficient planarity testing. J. Assoc. Comput. Mach., 21:549–568, 1974 [17] S. MacLane. A combinatorial condition for planar graphs. Fundam. Math., 28: 22–32, 1937 [18] K. Mehlhorn, P. Mutzel. On the embedding phase of the Hopcroft and Tarjan planarity testing algorithm. Algorithmica, 16: 233–242, 1996 [19] P. Mutzel, R. Weiskircher. Optimizing over all combinatorial embeddings of a planar graph. In G. Cornuejols, R.E. Burkard, G.J. Woeginger (eds.), Integer Programming and Combinatorial Optimization, Proc. 7th Int. IPCO Conf., LNCS 1610, 361–376, 1999 [20] T. Nishizeki, N. Chiba. Planar Graphs: Theory and Algorithms. Annals of Discrete Mathematics (32), North-Holland Mathematics Studies, 1988 [21] K. Sugiyama, K. Misue. Visualization of structured information: Automatic drawing of compound digraphs. IEEE Trans. Syst., Man and Cybernetics, 21(4): 876–892, 1991
C. Dornheim, Planar Graphs with Constraints, JGAA, 6(1) 27–66 (2002)
66
[22] R. Tamassia. Constraints in graph drawing algorithms. Constraints, 3(1): 87–120, 1998 [23] R. Tamassia. Advances in the theory and practice of graph drawing. Theor. Comp. Sci., 217(2): 235–254, 1999 [24] C. Thomassen. Planarity and duality of finite and infinite graphs. J. Comb. Theory, Ser. B, 29: 244–271, 1980 [25] W.T. Tutte. Matroids and graphs. Trans. Am. Math. Soc., 90: 527–552, 1959 [26] W.T. Tutte. How to draw a graph. Proc. Lond. Math. Soc., III. Ser. 13: 743–768, 1963 [27] C. Williams, J. Rasure, C. Hansen. The state of the art of visual languages for visualization. Visualization ’92, Proc., IEEE Computer Society Press, 202–209, 1992
Journal of Graph Algorithms and Applications http://www.cs.brown.edu/publications/jgaa/ vol. 6, no. 1, pp. 67–113 (2002)
Level Planar Embedding in Linear Time Michael J¨ unger Institut f¨ ur Informatik Universit¨at zu K¨ oln, Germany http://www.informatik.uni-koeln.de/
[email protected]
Sebastian Leipert Stiftung caesar Bonn, Germany http://www.caesar.de/
[email protected] Abstract A level graph G = (V, E, φ) is a directed acyclic graph with a mapping φ : V → {1, 2, . . . , k}, k ≥ 1, that partitions the vertex set V as V = V 1 ∪ V 2 ∪ · · · ∪ V k , V j = φ−1 (j), V i ∩ V j = ∅ for i 6= j, such that φ(v) ≥ φ(u) + 1 for each edge (u, v) ∈ E. The level planarity testing problem is to decide if G can be drawn in the plane such that for each level V i , all v ∈ V i are drawn on the line li = {(x, k − i) | x ∈ R}, the edges are drawn monotonically with respect to the vertical direction, and no edges intersect except at their end vertices. In order to draw a level planar graph without edge crossings, a level planar embedding of the level graph has to be computed. Level planar embeddings are characterized by linear orderings of the vertices in each V i (1 ≤ i ≤ k). We present an O(|V |) time algorithm for embedding level planar graphs. This approach is based on a level planarity test by J¨ unger, Leipert, and Mutzel (1998).
Communicated by H. de Fraysseix and and J. Kratochv´ıl: submitted November 1999; revised March 2001.
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
1
68
Introduction
A fundamental issue in Automatic Graph Drawing is to display hierarchical network structures as they appear in software engineering, project management and database design. The network is transformed into a directed acyclic graph that has to be drawn with edges that are strictly monotone with respect to the vertical direction. Many applications imply a partition of the vertices into levels that have to be visualized by placing the vertices belonging to the same level on a horizontal line. The corresponding graphs are called level graphs. Using the P Q-tree data structure, J¨ unger, Leipert, and Mutzel (1998) have given an algorithm that tests in linear time whether such a graph is level planar, i.e. can be drawn without edge crossings. In order to draw a level planar graph without edge crossings, a level planar embedding of the level graph has to be computed. Level planar embeddings are characterized by linear orderings of the vertices in each level. We present a linear time algorithm for embedding level planar graphs. Our approach is based on the level planarity test and it augments a level planar graph G to an st-graph Gst , a graph with a single sink and a single source, without destroying the level planarity. Once the st-graph has been constructed, we compute a planar embedding of the st-graph. This is done by applying the embedding algorithm of Chiba et al. (1985) for general graphs, obeying the topological ordering of the vertices in the st-graph. Exploiting the planar embedding of the st-graph Gst , we are able to determine a level planar embedding of G. This paper is organized as follows. After summarizing the necessary preliminaries in the next section, including the P Q-tree data structure we give a short introduction to the level planarity test presented by J¨ unger et al. (1998) in the third section. In the fourth section, we present the concept of the linear time level planar embedding algorithm. Sections 5 to 8 contain the details of the embedding algorithm. We close the paper with some remarks on how to produce a level planar drawing using the result of our algorithm. A short glossary of terms is given as an appendix.
2
Preliminaries
A level graph G = (V, E, φ) is a directed acyclic graph with a mapping φ : V → {1, 2, . . . , k}, k ≥ 1, that partitions the vertex set V as V = V 1 ∪ V 2 ∪ · · · ∪ V k , V j = φ−1 (j), V i ∩ V j = ∅ for i 6= j, such that φ(v) ≥ φ(u) + 1 for each edge (u, v) ∈ E. A vertex v ∈ V j is called a level-j vertex and V j is called the j-th level of G. For a level graph G = (V, E, φ), we sometimes write G = (V 1 , V 2 , . . . , V k ; E). A drawing of a level graph G in the plane is a level drawing if the vertices of every V j , 1 ≤ j ≤ k, are placed on a horizontal line lj = {(x, k − j) | x ∈ R}, and every edge (u, v) ∈ E, u ∈ V i , v ∈ V j , 1 ≤ i < j ≤ k, is drawn as a monotonically decreasing curve between the lines li and lj . A level drawing of G is called level planar if no two edges cross except at common endpoints. A level graph is level planar if it has a level planar drawing. A level graph G is obviously level planar if and only if all its components are level planar. We therefore may assume in the following without loss of generality that G is connected. A level drawing of G determines for every V j , 1 ≤ j ≤ k, a total order ≤j of the vertices of V j , given by the left to right order of the vertices on lj . A level embedding consists of a permutation of the vertices of V j for every j ∈ {1, 2, . . . , k} with respect to a level drawing. A level embedding with respect to a level planar drawing is called level planar. A level graph G = (V, E) is said to be proper, if every edge e ∈ E connects only vertices
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
69
belonging to consecutive levels. Usually, a level graph G has sinks and sources placed on various levels of the graph. Figure 1 shows a proper level graph. 1 2 3 4 5 Figure 1: An example of a level graph. Sources are drawn black. A P Q-tree is a data structure that represents the permutations of a finite set U in which the members of specified subsets occur consecutively. This data structure has been introduced by Booth and Lueker (1976) to solve the problem of testing for the consecutive ones property (see, e.g., Fulkerson and Gross (1965)). A P Q-tree is a rooted and ordered tree that contains three types of nodes: leaves, P -nodes, and Q-nodes. The leaves are in one to one correspondence with the elements of U . The P - and Q-nodes are internal nodes. In subsequent figures, P -nodes are drawn as circles while Q-nodes are drawn as rectangles. The frontier of a P Q-tree T , denoted by frontier (T ), is the sequence of all leaves of T read from left to right, and the frontier of a node X, denoted by frontier (X), is the sequence of its descendant leaves read from left to right. The frontier of a P Q-tree is a permutation of the set U . We use the notion frontier (T ) and frontier (X) also to denote the set of elements in frontier (T ) and frontier (X), respectively, its meaning being evident by context. An equivalence transformation specifies a legal reordering of the nodes within a P Q-tree. The only legal equivalence transformations are (i) any permutation of the children of a P -node, and (ii) the reverse permutation of the children of a Q-node. Two P Q-trees T and T 0 are equivalent if and only if their underlying trees are equal and T can be transformed into T 0 by a sequence of equivalence transformations. The equivalence of two P Q-trees is denoted T ≡ T 0 . The set of consistent permutations of a P Q-tree is the set of all frontiers that can be obtained by a sequence of equivalence transformations and is denoted by PERM(T ) = {frontier (T 0 ) | T 0 ≡ T } . If two nodes X and Y of a P Q-tree have the same parent, they are siblings. The nodes are called adjacent or direct if they are siblings and appear consecutively in the order of children of their parent. Let Π := {π | π is a permutation of U } and for any subset S ⊆ U let ΠS := {π ∈ Π | all elements of S are consecutive within π}. Given any P Q-tree T over U , the function
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
70
REDUCE(T, S) computes a P Q-tree T 0 such that PERM(T 0 ) = PERM(T ) ∩ ΠS . The function REDUCE applies a sequence of templates to the nodes of a P Q-tree starting at the leaves, and proceeding upwards until the root of the pertinent subtree is reached. Each template has a pattern and a replacement. If a node matches the pattern of a template, the pattern is replaced within the tree by the replacement of the template. The return value of REDUCE is a new P Q-tree. It is the null tree, a tree with no nodes at all, if the original tree could not be reduced for the specified set S. If a null tree is returned, the set of permissible permutations on the set U is empty and the null tree represents an empty set of permutations. Therefore it is convenient to denote the null tree by ∅. A node X in T is said to be full if frontier (X) ⊆ S. A node X is said to be empty if frontier (X) ∩ S = ∅. A node X is partial if it is neither empty nor full. Nodes are said to be pertinent if they are either full or partial. Each template specifies a local change within the tree. Only the node X that has to be matched and its children are altered. The patterns to which nodes are matched depend upon the set S and the frontier of the subtree rooted at the particular node X. The matched pattern is selected by examining the node X and its children after the children themselves have been matched. Depending on the situation in the frontier of X the node is labeled indicating whether X is empty, full, or partial. This bottom-up strategy ensures that all information on the situation in the frontier of the children of X is available when processing X. In Figure 2 and Figure 3 we illustrate two of the template matchings, the templates Q2 and Q3 (see Booth and Lueker (1976) for the templates P1 – P6 and Q1). The pattern at the left hand side is to be transformed into a pattern at the right hand side. A full node or a full subtree is hatched, and a partial Q-node that roots a pertinent subtree is hatched partially. We use a triangle for symbolizing a subtree. A subtree is either full or empty, so its precise form has no effect on the templates.
...
...
... ...
...
...
...
...
Figure 2: Template Q2.
...
... ...
...
... ...
...
...
...
...
...
...
...
...
Figure 3: Template Q3.
Theorem 2.1 (Booth and Lueker (1976)). The data structure P Q-tree and the template matchings can be implemented such that the class of permutations in which the elements of each set Si of a family S = {S P1n, S2 , . . . , Sn } of subsets of U occur as a consecutive sequence can be computed in O(|U | + n + i=1 |Si |) time.
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
71
One result that is achieved in the proof of Theorem 2.1 is the following corollary that is needed later when proving the correctness of a level planar embedding algorithm. Corollary 2.2 (Booth and Lueker (1976)). Let X be a child of a Q-node Y . Throughout the template matching algorithm X remains a child of a Q-node.
3
A Linear-Time Level Planarity Test
In this section we give a short introduction to a level planarity test as it has been presented in J¨ unger et al. (1998, 1999). Let Gj denote the subgraph of G induced by V 1 ∪ V 2 ∪ · · · ∪ V j . The basic idea is to perform a top-down sweep, processing the levels in the order V 1 , V 2 , . . . , V k . The graph Gj , 1 ≤ j < k, is not necessarily connected, and a separate P Q-tree is introduced for every component F of Gj to represent the set of permutations of the vertices of F in V j that appear in some level planar embedding of Gj . The P -nodes of such a P Q-tree correspond to cut vertices in F , the Q-nodes to connected components with a fixed embedding that can only be reversed. The leaves correspond either to level-j vertices or to incoming edges of level-l vertices, with l > j. Performing the top-down sweep, standard P Q-tree techniques are applied, as long as different components of Gj are not adjacent to a common vertex on level j. If two components are adjacent to a common vertex v on level j, they have to be merged and a new P Q-tree has to be constructed from the two corresponding P Q-trees. The new P Q-tree then represents all level planar embeddings of the merged component. Applying a combination of reduce operations and merge operations for combining P Q-trees, we maintain for every level V j and for every component F of Gj the set of permutations of the vertices of F in V j that appear in some level planar embedding of Gj . If the set of permutations for Gk is not empty, the graph G = Gk is obviously level planar. Before we describe our algorithm, called LEVEL-PLANARITY-TEST, let us introduce some new terminology. Let X be a Q-node in T corresponding to a subgraph B of Gj , 1 ≤ j ≤ k. The children of X each correspond to a cut vertex on the border of the outer face of B (see also Booth and Lueker (1976); Leipert (1998)). If X is not the root, then there exists an extra cut vertex on the border of the outer face of B that separates the subgraph G0 induced by the subtree rooted at X from Gj − G0 . This cut vertex is called the connective cut vertex of B. Since Gj is not necessarily connected, let mj denote the number of components of Gj and let j Fi , i = 1, 2, . . . , mj , denote the components of Gj . Figure 4 shows a G4 with m4 = 2 components F14 and F24 . The set of vertices in Fij is denoted by V (Fij ). Define LL(Fij ), the low indexed level, to be the smallest d such that Fij contains a vertex in V d and maintain this integer at the root of the corresponding P Q-tree. The height of a component Fij in the subgraph Gj is j − LL(Fij ). The LL-value merely describes the size of the component. The LL-values of the two components shown in Figure 4 are LL(F14 ) = 1 and LL(F24 ) = 2. Let Hij be the graph arising from Fij as follows: For each edge e = (u, v), where u is a vertex in Fij and v ∈ V l , l ≥ j + 1, we introduce a virtual vertex with label v and a virtual edge that connects u and this virtual vertex. Thus there may be several virtual vertices with the same label, adjacent to different components of Gj and each with exactly one entering edge. The form Hij is called the extended form of Fij and the set of virtual vertices of Hij is denoted by frontier (Hij ). Figure 5 shows possible extended forms H14 and H24 of the example in Figure 4. The virtual vertices on level 5 are denoted by their labels. The frontier of H14 consists of one virtual vertex labeled u,
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
72
two vertices labeled v, and two vertices labeled w. The set of virtual vertices of Hij that are labeled v ∈ V j+1 is denoted by Siv . 1 2 3 4 F14
F24
Figure 4: A G4 with m2 = 2 components F14 and F24 .
1 2 3 4 5 w
w
v H14
v
u
x
v
x
H24
Figure 5: Two extended forms H14 and H24 of Figure 4. The graph that is created from an extended form Hij by identifying all virtual vertices with the same label to a single vertex is called a reduced extended form and denoted by Rij . To construct R14 from the example component H14 , the vertices labeled w have to be identified and the vertices labeled v have to be identified. In order to identify the two vertices labeled x in H24 for the construction of R24 , it is necessary to permute the left most vertex labeled x and the vertex labeled v. Both forms R14 and R24 then have exactly one vertex labeled v. The set of virtual vertices of Rij is denoted by frontier (Rij ). If Siv of Hij is not empty, we denote the vertex with label v of Rij (i.e., the vertex that arose from identifying all virtual vertices of Siv )
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
73
by vi and update Siv = {vi }. The graph arising from the identification of two virtual vertices vi and vl (labeled v) of two reduced extended forms Rij and Rlj is denoted Rij ∪v Rlj . We call Rij ∪v Rlj a merged reduced form. The vertex arising from the identification of vi and vl is denoted by v{i,l} (and labeled by v of course). If LL(Rij ) ≤ LL(Rlj ) we say Rlj is v-merged into Rij . The form that is created by v-merging Rlj into Rij and identifying all virtual vertices with the same label w 6= v is again a reduced extended form and denoted by Rij (thus renaming Rij ∪v Rlj with the name of the “higher” form). Figure 6 shows the resulting merged reduced extended form R14 ∪v R24 after R24 (the smaller form) has been v-merged into R14 (the higher form). Since R14 is the higher form, R14 ∪v R24 is renamed into R14 . 1 2 3 4 5 w
v
x
u
Figure 6: A merged reduced extended form R14 ∪v R24 after R24 has been v-merged into R14 . The former vertices of R24 are drawn shaded. We omit scanning for leaves with the same label after we have v-merged several reduced extended forms. This is done in order to achieve linear running time. However, this strategy results in improper reduced extended forms, possibly having several virtual vertices with the same label. These forms are called partially reduced extended forms. If any reduced extended form has been v-merged into Rij , the form Rij is called v-connected , otherwise Rij is called v-unconnected. The form R14 shown in Figure 6 is v-connected. A reduced extended form Rij that is v-unconnected for all v ∈ V j+1 is called primary. A reduced extended form Rij that is v-connected for at least one v ∈ V j+1 is called secondary. Again, R14 shown in Figure 6 is secondary. Let Rij be a reduced extended form such that Siv 6= ∅ for some v ∈ V j+1 and Siw = ∅ for all w ∈ V l − {v}, j + 1 ≤ l ≤ k, then Rij is called v-singular. Let T (Gj ) be the set of level planar embeddings of all components of Gj . In case that Gj is level planar, the set of permutations of level-j vertices in level planar embeddings of each component Fij of Gj as well as its extended form Hij can be described by a P Q-tree T (Fij ) or T (Hij ), respectively (J¨ unger et al. (1998, 1999)). The leaves of T (Hij ) correspond to the virtual vertices of Hij and we
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
74
label the leaves of T (Hij ) as their counterparts in Hij . By construction, T (Gj ) is a set of P Q-trees. Considering a function CHECK-LEVEL that computes for every level j, j = 2, 3, . . . , k, the set T (Gj ) of level planar embeddings of the components Gj , the algorithm LEVEL-PLANARITYTEST can be formulated as follows. Bool LEVEL-PLANARITY-TEST(G = (V 1 , V 2 , . . . , V k ; E)) begin Initialize T (G1 ); for j := 1 to k − 1 do T (Gj+1 ) = CHECK-LEVEL(T (Gj ), V j+1 ); if T (Gj+1 ) = ∅ then return “false”; return “true”; end. The procedure CHECK-LEVEL is divided into two phases. The First Reduction Phase constructs the P Q-trees corresponding to the reduced extended forms of Gj . Every P Q-tree T (Fij ) that represents all level planar embeddings of some component Fij is transformed into a P Q-tree T (Hij ) representing all level planar embeddings of the extended form Hij . We continue to reduce in every P Q-tree T (Hij ) all leaves with the same label, thereby constructing a new P Q-tree, representing all level planar embeddings of Hij , where leaves with the same label occupy consecutive positions. If one of the reductions fails, G cannot be level planar. Leaves with the same label v are replaced by a single representative vi (see also Booth and Lueker (1976)). P Q-trees of different components are merged in the Second Reduction Phase if the components are adjacent to the same vertex v on level j + 1. Given the set of leaves labeled v, we first determine their corresponding P Q-trees. If some leaves labeled v are in the frontier of the same P Q-tree, we reduce them and replace them by a single representative. The P Q-trees are then merged pairwise in the order of their sizes. Using this ordering a P Q-tree T (F ) is constructed that represents all possible level planar embeddings of the merged components. Even though v may not be the only common vertex in the merged components, we do not reduce leaves with label w 6= v in the P Q-tree in order to obtain a linear time algorithm. If one of the reduce or merge operations fails while applied in this phase, the graph G is not level planar. The function REPLACE removes all leaves with a common label v after these leaves have been reduced (and therefore are consecutive in all permissible permutations) and replaces them by a single representative (Booth and Lueker (1976)). Finally we add for every source of V j+1 its corresponding P Q-tree. Thus the set of P Qtrees constructed by the function CHECK-LEVEL represents all level planar embeddings of every unger et al. (1998, 1999)). component of Gj+1 (see J¨ A short description of the pairwise merge operations of Heath and Pemmaraju (1995, 1996) for non singular forms is now given. Singular components are handled by examining certain information on interior faces and regions of the outer face (see J¨ unger et al. (1999)). Let G = (V, E) be a klevel graph and R1j and R2j be two components of Gj , 1 ≤ j < k, both being adjacent to the same vertex v ∈ V j+1 . Let T1 and T2 be the P Q-trees of R1j and R2j , both representing all level planar embeddings of their corresponding forms after the application of the first reduction phase for the level j + 1. Identifying the vertices labeled v of the forms R1j and R2j constructs a new form
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
75
R1j ∪v R2j . For this new component R1j ∪v R2j a new P Q-tree T is needed that represents all level planar embeddings of R1j ∪v R2j . The construction of the P Q-tree T (R1j ∪v R2j ) is is based on the trees T1 and T2 . The merge operation is accomplished using information that is stored at the nodes of the P Qtrees. For any subset S of the set of vertices in V j+1 ∪ V j+2 ∪ · · · ∪ V k that belongs to a form Hij or Rij , define ML(S) to be the greatest d ≤ j such that V d , V d+1 , . . . , V j induces a subgraph in which all nodes of S occur in the same connected component. The level ML(S) is said to be the meet level of S. For a Q-node Y in the corresponding P Q-tree T (Hij ) or T (Rij ) with ordered children Y1 , Y2 , . . . , Yt , integers denoted by ML(Yi , Yi+1 ), 1 ≤ i < t, are maintained satisfying ML(Yi , Yi+1 ) = ML(frontier (Yi ) ∪ frontier (Yi+1 )). For a P -node X a single integer denoted by ML(X) that satisfies ML(X) = ML(frontier (X)) is maintained. Figure 7 shows the P Q-trees corresponding to the forms H1j and H2j of Figure 5 together with the ML-values that are stored at the nodes. The maintenance of the ML-values during the pattern matching algorithm REDUCE is straightforward.
1 u 3 w
3
3
3
4
w
x v
v
x
v
Figure 7: P Q-trees corresponding to H14 and H24 shown in Fig. 5. For describing how to merge T1 and T2 corresponding to R1j and R2j we may assume without loss of generality that LL(T1 ) ≤ LL(T2 ). Thus the form R2j is the smaller form and an embedding of R1j has to be found such that R2j can be nested within the embedding of R1j . This corresponds to adding the root of T2 as a child to a node of the P Q-tree T1 and constructing a new P Q-tree T 0 . In order to find an appropriate location to insert T2 into T1 , we start with the leaf labeled v in T1 and proceed upwards in T1 until a node X 0 and its parent X are encountered satisfying one of the following five conditions. Merge Condition A The node X is a P -node with ML(X) < LL(T2 ). Attach T2 as child of X in T1 . Merge Condition B The node X is a Q-node with ordered children X1 , X2 , . . . , Xt , X 0 = X1 , and ML(X1 , X2 ) < LL(T2 ). Replace X 0 in T1 by a Q-node Y having two children, X 0 and the root of T2 . The case where X 0 = Xt and ML(Xt−1 , Xt ) < LL(T2 ) is symmetric. Merge Condition C The node X is a Q-node with ordered children X1 , X2 , . . . , Xt , X 0 = Xi , 1 < i < t, and ML(Xi−1 , Xi ) < LL(T2 ) and ML(Xi , Xi+1 ) < LL(T2 ). Replace X 0 by a Q-node Y with two children, X 0 and the root of T2 .
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002) Merge Condition D 1 < i < t, and
76
The node X is a Q-node with ordered children X1 , X2 , . . . , Xt , X 0 = Xi , ML(Xi−1 , Xi ) < LL(T2 ) ≤ ML(Xi , Xi+1 ) .
Attach the root of T2 as child of X between Xi−1 and X 0 . In case that ML(Xi , Xi+1 ) < LL(T2 ) ≤ ML(Xi−1 , Xi ) , attach the root of T2 as child of X between X 0 and Xi+1 . Merge Condition E The node X 0 is the root of T1 . Reconstruct T1 by inserting a Q-node Y as new root of T1 with two children X 0 and the root of T2 . Based on the following theorem, we develop a linear time algorithm for embedding a level planar graph. Theorem 3.1 (J¨ unger, Leipert, and Mutzel (1998)). The algorithm LEVEL-PLANARTEST tests any (not necessarily proper) level graph G = (V, E, φ) in O(n) time for level planarity.
4
Concept of the Embedding-Algorithm
One can easily obtain the following naive embedding algorithm for level planar graphs. Choose any total order on V k that is consistent with the set of permutations of V k that appear in level planar embeddings of Gk = G. Choose then any total order on V k−1 that is consistent with the set of permutations of V k−1 that appear in level planar embeddings of Gk−1 and that, together with the chosen order of V k implies a level planar embedding on the subgraph of G induced by V k−1 ∪ V k . Extend this construction one level at a time until a level planar embedding of G results. However, to perform this algorithm, it is necessary to keep track of the set of P Q-trees of every level l, 1 ≤ l ≤ k. Besides, an appropriate total order of the vertices of V j , 1 ≤ j < k, can only be detected by reducing subsets of the leaves of Gj , where the subsets are induced by the adjacency lists of the vertices of V j+1 . More precisely, for every pair of consecutive edges e1 = (v1 , w), e2 = (v2 , w), v1 , v2 ∈ V j , in the adjacency list of a vertex w ∈ V j+1 , we have to reduce the set of leaves corresponding to the vertices v1 , v2 in T (Gj ). This immediately yields an Ω(n2 ) algorithm for non-proper level graphs, with Ω(n2 ) dummy vertices for long edges traversing one or more levels, since we are forced to consider for every long edge its exact position on the level that is traversed by the long edge. Instead, we proceed as follows: Let G = (V, E, φ) be a level planar graph with leveling φG : V → {1, 2, . . . , k}. We augment G to a planar directed acyclic st-graph Gst = (Vst , Est , φGst ) where Vst = V ] {s, t} and E ⊂ Est such that every source in G has exactly one incoming edge in Est \ E, every sink in G has exactly one outgoing edge in Est \ E, φGst (s) = 0, φGst (t) = k + 1, (s, t) ∈ Est , and for all v ∈ V we have φGst (v) = φG (v). This process, in which two vertices and O(n) edges are added to G, is the nontrivial part of the algorithm that will be explained in Sections 6 - 8.
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
77
We compute a topological sorting, i.e., an onto function f : Vst → {1, 2 . . . , n + 2}. The function f is comparable with φGst in the sense that for every v, w ∈ Vst we have f (v) ≤ f (w) if and only if φGst (v) ≤ φGst (w). Obviously f is an st-numbering of Gst (see, e.g., Even and Tarjan (1976)). Using this st-numbering, we can obtain a planar embedding Est of Gst with the edge (s, t) on the boundary of the outer face by applying the algorithm of Chiba et al. (1985). From the planar embedding we obtain a level planar embedding of Gst by applying a function “CONSTRUCT-LEVEL-EMBED” that uses a depth first search procedure starting at vertex t and proceeding from every visited vertex w to the unvisited neighbor that appears first in the clockwise ordering of the adjacency list of w in Est . Initially, all levels are empty. When a vertex w is visited, it is appended to the right of the vertices assigned to level φGst (w). The restriction of the resulting level orderings to the levels 1 to k yields a level planar embedding of G. It is clear that the described algorithm runs in O(n) time if the nontrivial part, namely the construction of Gst can be achieved in O(n) time. After adding the vertices s and t we augment G to a hierarchy by adding an outgoing edge to every sink of G without destroying level planarity using a function AUGMENT, processing the graph top to bottom. Using the same function AUGMENT again, we process the graph bottom to top and augment Gst to an st-graph by adding the edge (s, t) and an incoming edge to every source of G without destroying the level planarity. Thus our level planar embedding algorithm can be sketched as follows. El LEVEL-PLANAR-EMBED(G = (V 1 , V 2 , . . . , V k ; E)) begin ignore all isolated vertices; expand G to Gst by adding V 0 = {s} and V k+1 = {t}; if LEVEL-PLANARITY-TEST(Gst ) then AUGMENT(Gst ); else return El = ∅; //Gst is now a hierarchy; orient the graph Gst from the bottom to the top; AUGMENT(Gst ); orient the graph Gst from the top to the bottom; add edge (s, t); //Gst is now an st-graph; compute a topological sorting of Vst ; compute a planar embedding Est according to Chiba et al. (1985) using the topological sorting as an st-numbering; El = CONSTRUCT-LEVEL-EMBED(Est, Gst ); return El ; end. Augmenting a level graph G to an st-graph Gst is divided into two phases. In the first phase an outgoing edge is added to every sink of G. Using the same algorithmic concept as in the first phase, an incoming edge is added to every source of G in the second phase. In order to add an outgoing edge for every sink of G without destroying level planarity, we need to determine the position of a sink v ∈ V j , j ∈ {1, 2, . . . , k − 1}, in the P Q-trees. This is done by inserting an indicator as a leaf into the P Q-trees. The indicator is ignored throughout the
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
78
application of the level planarity test and will be removed either with the leaves corresponding to the incoming edges of some vertex w ∈ V l , l > j, or it can be found in the final P Q-tree. The idea of the approach can be explained best by an example. Figure 8 shows a small part of a level graph with a sink v ∈ V j and the corresponding part of the P Q-tree. Since v is a sink, the leaf corresponding to v will be removed from the P Q-tree before testing the graph Gj+1 for level planarity. Instead of removing the leaf, the leaf is kept in the tree ignoring its presence from now on in the P Q-tree. Such a leaf for keeping the position of a sink v in a P Q-tree is called a sink indicator and denoted by si (v). v v Figure 8: A sink v in a level graph G and the corresponding P Q-tree. As shown in Fig. 9 the indicator of v may appear within the sequence of leaves corresponding to incoming edges of a vertex w ∈ V l . The indicator of v is interpreted as a leaf corresponding to an edge e = (v, w) and G is augmented by e. Adding the edge e to G does not destroy the level planarity and provides an outgoing edge for the sink v. v w
v
w
e
w Figure 9: Adding an edge e = (v, w) without destroying level planarity. When replacing a leaf corresponding to a sink by a sink indicator, a P - or Q-node X may be constructed in the P Q-tree such that frontier (X) consists only of sink indicators. The presence of such a node is ignored in the P Q-tree as well. A node of a P Q-tree is an ignored node if and only if its frontier contains only sink indicators. By definition, a sink indicator is also an ignored node.
5
Sink Indicators in Template Reductions
In order to achieve linear time for the level planar embedder, we have to avoid searching for sink indicators that can be considered for augmentation. Consequently, only those indicators si (v), v ∈ V , that appear within the pertinent subtree of a P Q-tree with respect to a vertex w ∈ V
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
79
are considered for augmentation. We show that every edge added this way does not destroy level planarity. The first lemma considers sink indicators appearing within the sequence of pertinent leaves. Lemma 5.1. Let si (v) be a sink indicator of a vertex v ∈ V j , 1 < j < k, in a P Q-tree T corresponding to an extended form H. Adding the edge e = (v, w) to G does not destroy level planarity if one of the following two conditions holds. (i) si (v) is a descendant of a full node in the pertinent subtree with respect to a vertex w ∈ V l , j < l ≤ k. (ii) si (v) is a descendant of a partial Q-node in the pertinent subtree with respect to a vertex w ∈ V l , j < l ≤ k, and si (v) appears within the pertinent sequence. Proof: Since si (v) is the child of a full node or appears at least within a pertinent sequence of full nodes, adding the edge e = (v, w) does not destroy level planarity of the reduced extended form R corresponding to H. Thus it remains to show that adding the edge has no effect on merge operations. For every embedding E of R, the edge e is embedded either between two incoming edges of w or next to the consecutive sequence of incoming edges of w. If e is embedded between two incoming edges, the edge e obviously does not affect the level planar embedding of any nonsingular form and u-singular form with u 6= w. If e is embedded next to the consecutive sequence of incoming edges of w, then si (v) must be a descendant of a full node X. If X is a P -node, there exists an embedding of R such that the edge e can be embedded between two incoming edges of w. Thus adding the edge does not affect the level planar embedding of any nonsingular form and any u-singular form, with u 6= w. Consider now a full Q-node X. By construction, si (v) is a descendant leaf at one end of X. The Q-node X corresponds to a subgraph B. The vertex v must be on the boundary of the outer face of the subgraph B and there exists a path P = (v = u1 , u2 , . . . , uµ = w), µ ≥ 2, on the boundary of the outer face of B such that φ(ui ) < l for all i = 1, 2, . . . , µ − 1. Thus none of the nodes ui , i = 1, 2, . . . , µ − 1, is considered for a merge operation. Hence, replacing the path P by an edge (v, w) at the boundary of the outer face does not affect the level planar embedding of any nonsingular form and any u-singular form, with u 6= w. Figure 10 illustrates the insertion of an edge e = (v, w) if si (v) is the endmost child of a Q-node.
si (v)
11 00 00 11
w
111 000 000 111
v
w
w Figure 10: The sink indicator si (v) is an endmost child of a Q-node. The path P is drawn shaded, the edge e = (v, w) is drawn as a dotted line.
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
80
Considering w-singular forms, adding the edge e produces one more face but the height of the largest interior face or the largest region of the outer face with w being adjacent to this region remains valid. Thus a w-singular form that has to be embedded within an interior face or within a w-cavity can be embedded level planar after the insertion of e. 2 Lemma 5.1 allows us to consider an edge for insertion if a sink indicator is a descendant of a full node or a descendant of a partial Q-node within the sequence of full children of the Q-node. The lemma does not consider a sink indicator si (v) that appears as a child of a partial Q-node X such that si (v) is a sibling to the pertinent sequence. Although the following lemma shows that edges corresponding to sink indicators that are endmost children at the full end of a partial Q-node can be added without destroying level planarity, the case where sink indicators are between the sequence of full and the sequence of empty children reveals problems. Lemma 5.2. Let si (v) be a sink indicator of a vertex v ∈ V j , 1 < j < k, in a P Q-tree T and let si (v) be a descendant of an ignored node X that is a child of a partial Q-node Y in the pertinent subtree with respect to a vertex w ∈ V l , j < l ≤ k. If X appears at the full end of the partial Q-node, the edge e = (v, w) can be added without destroying level planarity. Proof: Analogous to the proof of Lemma 5.1 for the case in which si(v) is a descendant of a full Q-node. 2 Consider now the situation of an extended reduced form R as shown in Figure 11. The sink indicator si (v) is a child of a partial Q-node in the pertinent subtree of some vertex w ∈ V l , j < l ≤ k, and si (v) is adjacent to a full and an empty node. Adding the edge e does not a priori destroy level planarity in R, but it creates a new interior face, such that the large space between w and the rightmost vertex of the subgraph corresponding to the subtree rooted at X is destroyed. Now assume that a nonsingular form R0 has to be w-merged into R, applying merge operation D. Although the ML-value between the leaf w and the node X allows us to add the form R0 between w and X, there is, due to the insertion of e, not enough space between w and X. Hence a crossing is created and a non-level planar graph is constructed as is shown in Figure 12. Consequently, a sink indicator that is found to be a sibling of a pertinent sequence and an empty sequence is never considered for edge augmentation. By applying the results of Lemmas 5.1 and 5.2 during the template matching algorithm, not all sink indicators are considered for edge insertion. Some of the indicators remain in the final P Q-tree that represents all possible permutations of vertices of V k in the level planar embeddings of G. The following lemma allows us not only to insert edges (w, t) for every w ∈ V k but also to insert an edge (v, t) for every remaining sink indicator si (v). Lemma 5.3. Let si(v) be a sink indicator of a vertex v ∈ V j , 1 < j < k. If si (v) is in the final P Q-tree T , the edge e = (v, t) can be added without destroying level planarity. Proof: Adding to every vertex w ∈ V k an edge (w, t) does not affect the level planarity of the graph. Thus consider testing the level V k+1 for level planarity. The pertinent subtree of T is equal to T and thus Lemma 5.1 applies. 2
6
Sink Indicators in Merge Operations
While the treatment of sink indicators during the application of the template matching algorithm is rather easy in principle, this does not hold for merge operations. We consider all merge operations
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
X
X
si (v)
11 00 00 11
81
11 00 00 11
w
w
v w
Figure 11: A doubly partial Q-node and its corresponding part of the form R. The new inserted edge e = (v, w) is drawn as a dotted line.
X
11111 00000 00000 11111 R0 00000 11111 v 11111 00000 00000 11111 11 00 ww
Figure 12: Merging R0 into R with the new edge e = (v, w) is not level planar.
and discuss necessary adaptions in order to treat the sink indicators correctly. If sink indicators and ignored nodes have to be manipulated correctly during the merge process, ML-values as they have been introduced for non-ignored nodes have to be introduced for ignored nodes as well. Consider a node X that becomes ignored. We make the following conventions. (i) If X is a child of a P -node Y , the corresponding ML-value for X is ML(Y ). (ii) If X is a child of a Q-node, we distinguish two cases: (a) X does not have an adjacent ignored sibling. Since X has non-ignored siblings on either side, let Z and Y be its direct non-ignored siblings. Then we leave the values ML(Z, X) and ML(X, Y ) at X, and replace according to the level planarity test the values ML(Z, X) and ML(X, Y ) by a new value ML(Z, Y ) = min{ML(Z, X), ML(X, Y )} at Z and Y . The case where X has just one non-ignored sibling is solved analogously. (b) X has adjacent ignored direct siblings. Since X has ignored siblings on either side, let ZI and YI be the direct ignored siblings and let Z and Y be its direct non-ignored siblings with Z at the side where ZI is, and Y at the side where YI is. Let ML(Z, X) and ML(X, Y ) be the ML-values between Z and X, and X and Y , respectively. Let ML(ZI , X) be the ML-value stored at ZI , and let ML(X, YI ) be the ML-value stored at YI . Then we replace at X the values ML(Z, X) by ML(ZI , X) and ML(X, Y ) by ML(X, YI ), and replace according to the level planarity test the values ML(Z, X) and
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
82
ML(X, Y ) by a new value ML(Z, Y ) = min{ML(Z, X), ML(X, Y )} at Z and Y . The cases with only one non-ignored or one ignored direct sibling are a handled analogously. This strategy ensures that non-ignored siblings Z and Y “know” the maximal height of the space between them, while the knowledge about the height of the space between the sinks and their corresponding indicators is left at the ignored nodes only. Lemma 6.1. Let X be an ignored node that is a child of a Q-node and let MLl and MLr be the ML-values that have been assigned to X by one of the rules (ii)(a) or (ii)(b) described above. Then the values MLl and MLr are valid for X. Proof: The sink indicators in frontier (X) can be interpreted as leaves corresponding to long edges. Thus the ML-values remain valid. 2 Lemma 6.2. Let X be an ignored node that is a child of a P -node Y . Then the value ML(Y ) is valid for X. Proof: Analogous to the proof of Lemma 6.1.
2
Suppose now that two reduced forms R1 and R2 and their corresponding trees T1 and T2 with LL(T1 ) ≤ LL(T2 ) have to be w-merged. As described in 3, we start with the leaf labeled w in T1 and proceed upwards in T1 until a node X 0 and its parent X are encountered such that one of the five merge conditions as described in Section 3 applies. The merge operations are discussed in an order according to the difficulties that are encountered when handling involved sink indicators. Before starting with the less problematic ones, one more convention is made. If X is a node in a P Q-tree, RX denotes the subgraph corresponding to the subtree rooted at the node X. Merge Operation E The tree T1 is reconstructed by inserting a Q-node X as new root of T1 with two children X 0 and the root of T2 . The following observation is trivial. Observation 6.3. There is no need to adapt the merge operation E in order to handle sink indicators correctly. Merge Operation A The root of T2 is attached as a child to a P -node X of T1 thus we have that ML(X) < LL(T2 ). Obviously, all ignored nodes that are children of X are allowed to be permuted in the pertinent subtree. Thus the sink indicators in their frontier are allowed to be considered for edge augmentation. However, the ignored children can only be considered if all children of X are traversed in order to find the ignored children. This implies that all empty children of X have to be traversed as well, yielding a quadratic time algorithm. Thus ignored children of X are not considered for augmentation and we can make following observation. Observation 6.4. There is no need to adapt the merge operation A in order to handle sink indicators correctly.
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
83
Merge Operation D Let X be a Q-node of T1 with ordered children X1 , X2 , . . . , Xη , η > 1. Let X 0 = Xλ , 1 < λ < η, and ML(Xλ−1 , Xλ ) < LL(T2 ) ≤ ML(Xλ , Xλ+1 ). Thus R2 has to be nested between the subgraphs RXλ−1 and RXλ and the root of T2 is attached as a child to the Q-node X between Xλ−1 and Xλ . Let I1 , I2 , . . . , Iµ , µ ≥ 0, be the sequence of ignored nodes between Xλ−1 and Xλ with Xλ−1 and I1 being direct siblings, and Xλ and Iµ being direct siblings. As illustrated in Figure 13 there may exist a ν ∈ {1, 2, . . . , µ} such that for every sink indicator si (v) ∈
µ [
φ(w)−1
frontier (Ii ) ,
v∈
i=ν
[
Vi ,
i=1
the graph has to be augmented by an edge e = (v, w). Adding these edges Sµ does not destroy level planarity. Furthermore, augmenting the graph G for every si (v) ∈ i=ν frontier (Ii ), with Sk φ(v) ≥ LL(T2 ), by an edge e0 = (v, u), u ∈ i=φ(w) V i , u 6= w destroys level planarity, since such an edge must cross either a path in R2 connecting w with a vertex v’ of R2 , φ(v 0 ) = LL(T2 ), or a path in R1 connecting w with a vertex v 00 in R1 , φ(v 00 ) = LL(T2 ).
Xλ−1 I1
Xλ−1
Iν−1 Iν
Iµ
Xλ
1111111111111 0000000000000 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 R2 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111
w
w
Figure 13: Merging the form R2 into R1 using the merge operation D forces us to augment G by the edges drawn as dotted lines. Using the following lemma we are able to find all the sink indicators that have to be considered for edge insertion when applying the merge operation D. Lemma 6.5. Let X be a child of a Q-node and let Y be a direct non-ignored sibling of X. Let I1 , I2 , . . . , Iµ , µ ≥ 0, be the sequence of ignored nodes between X and Y with X and I1 being direct siblings, and Y and Iµ being direct siblings. There exists a ν ∈ {1, 2, . . . , µ + 1} such that ML(X, Y ) = ML(Iν−1 , Iν ), with I0 = X and Iµ+1 = Y .
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
84
Proof: The lemma follows immediately from Lemma 6.1.
2
Remark 6.6. We store at every pair of direct non-ignored siblings X and Y pointers to the two ignored siblings Iν−1 and Iν with ML(Iν−1 , Iν ) = ML(X, Y ). The maintenance during the application of the template reduction algorithm and the merge operations is straightforward. We will see later how we benefit from this in the merge operations B and C. Placing the root of T2 between Iν−1 and Iν constructs a P Q-tree such that the ignored nodes This permits to augment the graph G by an Iν , Iν+1 , . . . , Iµ appear within the pertinent subtree. S edge e = (v, w) for every sink indicator si (v) ∈ µi=ν frontier (Ii ) during the reduction with respect to w. Merge Operation C Let X be a Q-node with ordered children X1 , X2 , . . . , Xη , X 0 = Xλ , 1 < λ < η, and ML(Xλ−1 , Xλ ) < LL(T2 ) and ML(Xλ , Xλ+1 ) < LL(T2 ). The node Xλ is replaced by a Q-node Y with two children, Xλ and the root of T2 . Let I1 , I2 , . . . , Iµ , µ ≥ 0, be the sequence of ignored nodes between Xλ−1 and Xλ with Xλ−1 and I1 being direct siblings, and Xλ and Iµ being direct siblings. Let J1 , J2 , . . . , Jρ , ρ ≥ 0, be the sequence of ignored nodes between Xλ and Xλ+1 with Xλ and J1 being direct siblings, and Xλ+1 and Jρ being direct siblings. As illustrated in Figure 14 there may exist a ν, 1 ≤ ν ≤ µ, such that for every sink indicator si (v) ∈
µ [
φ(w)−1
frontier (Ii ) ,
i=ν
v∈
[
Vi ,
i=1
G has to be augmented by an edge e = (v, w) if R2 is embedded between RXλ−1 and RXλ .
Xλ−1 I1
Xλ−1
Iν−1 Iν
Iµ Xλ J1
1111111111111 0000000000000 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 R2 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111
w
Jσ Jσ+1
Jρ Xλ+1
Xλ+1 w
Figure 14: Merging the form R2 into R1 using the merge operation C and embedding it between RXλ−1 and RXλ forces G to be augmented by the edges drawn as dotted lines.
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
85
As is illustrated in Figure 15, R2 can be embedded between RXλ and RXλ+1 , and there may exist a σ, 1 ≤ σ ≤ ρ, such that for every sink indicator si (v) ∈
σ [
φ(w)−1
frontier (Ji ) ,
v∈
i=1
[
Vi ,
i=1
G has to be augmented by an edge e = (v, w).
Xλ−1 I1
Iν−1 Iν
Iµ Xλ J1
Xλ−1 w
Jσ Jσ+1
Jρ Xλ+1
1111111111111 0000000000000 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 R2 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111
Xλ+1
w
Figure 15: Merging the form R2 into R1 using the merge operation C and embedding it between RXλ and RXλ+1 forces G to be augmented by the edges drawn as dotted lines. It is not possible to consider both sets of ignored nodes for edge augmentation. Consider Sµ frontier (Ii ) and for instance the example shown in Figure 16, where edges for both sets i=ν Sσ frontier (J ) have been added, yielding immediately a non-level planar graph. i i=1 However, deciding which set of sink indicators has to be considered for edge augmentation is not possible unless Xλ is a full node (see Leipert (1998)). Extending the level planarity test down the levels V φ(w)+1 to V k may embed the component R2 on either of the two sides of RXλ . Since the side is unknown during the merge operation, we have to keep the affected sink indicators in mind. Furthermore, we must devise a method that permits recognizing the correct embedding during subsequent reductions. The sequences Iν , Iν+1 , . . . , Iµ and J1 , J2 , . . . , Jσ are called the reference sequence of R2 and denoted by rseq(R2 ). We refer to Iν , Iν+1 , . . . , Iµ as the left reference sequence of R2 denoted left , J2 , . . . , Jσ as the right reference sequence denoted by rseq(R2 )right . The by rseq(R Sµ 2 ) , and to J1S σ union i=ν frontier (Ii )∪ i=1 frontier (Ji ) is called the reference set of R2 and denoted by ref (R2 ). The left and right reference set ref (R2 )left and ref (R2 )right , respectively, are defined analogously to the left and right reference sequence. In Section 7 a method using a special ignored indicator is developed for deciding which subset of ref (R2 ) has to be considered for edge augmentation. Before continuing with the algorithmic
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
Xλ−1 I1
Iν−1 Iν
Iµ
Xλ
u ˜ Xλ−1 u
w
J1
Jσ Jσ+1
1111111111111 0000000000000 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 R2 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111
86
Jρ Xλ+1
Xλ+1
w
Figure 16: Merging the form R2 into R1 using the merge operation C does not allow to consider sinks on both sides of RXλ for edge augmentation. Independently on the ˜ and chosen embedding of R2 there are always crossings between a path connecting u u and the new edges.
solution, we finish by considering the merge operation B where exactly the same problem occurs as has been encountered for the merge operation C. Merge Operation B Let X be a Q-node with ordered children X1 , X2 , . . . , Xη , and let X 0 = X1 , and ML(X1 , X2 ) < LL(T2 ). The node X1 is replaced by a Q-node Y having two children, X1 and the root of T2 . Let I1 , I2 , . . . , Iµ , µ ≥ 0, be the sequence of ignored nodes at one end of X with X1 and Iµ being direct siblings and I1 being an endmost child of X. Let J1 , J2 , . . . , Jρ , ρ ≥ 0, be the sequence of ignored nodes between X1 and X2 with X1 and J1 being direct siblings, and X2 and Jρ being direct siblings. Analogous to the merge operation C, there may exist sink indicators affected by merging R2 into R1 in both sets I1 , I2 , . . . , Iµ , µ ≥ 0, and J1 , J2 , . . . , Jρ , ρ ≥ 0. Again it is not possible to decide if the left reference set ref (R2 )left or the right reference set ref (R2 )right has to be considered for edge augmentation.
7
Contacts
In order to solve the decision problem of the merge operations B and C, we examine how R2 is fixed to either side of the vertex w ∈ V in a level planar embedding of G. For the rest of this section we consider two P Q-trees T1 and T2 , such that T2 has been w-merged into T1 using a merge operation B or C. Let X be the Q-node with children X1 , X2 , . . . , Xη , η ≥ 2, and let Xλ , λ ∈ {1, 2, . . . , η}, be its child that is replaced by a new Q-node having two children Xλ and the root of T2 . Let RXλ be the subgraph of R1 corresponding to the subtree rooted at Xλ before merging R1 and R2 . Let
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
87
RX be the subgraph corresponding to the subtree rooted at X before merging R1 and R2 . ~ X to be the set of all vertices u ∈ V such that there exists a vertex Definition 7.1. Define R v ∈ RX and a (not necessarily directed) path P connecting u and v not using the connective cut Sk Sk vertex of X. Define further D(RXλ ∪ R2 ) ⊂ i=φ(w) V i to be the set of vertices u ∈ i=φ(w) V i such that the following two conditions hold. 1. There exists a directed path P = (u1 , u2 , . . . , uξ = u), ξ > 1, with u1 ∈ RXλ ∪ R2 . Sk u1 , u ˜2 , . . . , u˜ι = u˜), ι > 1, 2. There exists a vertex u ˜ ∈ i=φ(w) V i and a directed path P˜ = (˜ u) ≥ φ(u) and the paths P and P˜ are vertex disjoint except with u ˜1 ∈ RXλ ∪ R2 , such that φ(˜ for possibly u and u ˜. The vertex set D(RXλ ∪ R2 ) is called the dependent set of RXλ ∪ R2 . Figure 17 illustrates different kinds of dependent sets D(RXλ ∪R2 ). The dependent set D(RXλ ∪ R2 ) is drawn shaded in all four cases. The vertex v in all four subfigures denotes the connective cut vertex of Xλ in Gφ(w) that permits reversing the subgraph RXλ ∪ R2 with respect to RX . For simplicity, we make the overall assumption for the rest of this section that no vertex u ∈ D(RXλ ∪ R2 ) is involved in a merge operation. This matter is discussed in the next section, handling concatenations of merge operations. However, subsequent merge operations to any other vertex not contained in D(RXλ ∪ R2 ) are allowed after w-merging R2 into R1 . Figure 17(a) illustrates the case, where v is not only a cut vertex in Gφ(w) but also a cut vertex in the graph G. Consequently, RXλ ∪ R2 ∪ D(RXλ ∪ R2 ) will be embedded within an interior face or the outer face with the option to chose its embedding unaffected from the embedding of the rest of the graph. Hence R2 may be embedded on an arbitrary side of RXλ with respect to RX . Figure 17(b) illustrates the case, where v is not a cut vertex in the graph G but there exists a vertex u ∈ D(RXλ ∪ R2 ) such that u and v form a split pair and φ(˜ u) < φ(u) if u ˜ ∈ D(RXλ ∪ R2 ) − {u} . Thus RXλ ∪ R2 ∪ D(RXλ ∪ R2 ) forms a split component and its embedding may be chosen freely. Hence R2 may be embedded on an arbitrary side of RXλ with respect to RX . Figure 17(c) illustrates a more delicate situation involving a split pair v and u1 . According to the definition of the dependent set, the vertex u2 is contained in D(RXλ ∪ R2 ) since there exists a vertex u4 with φ(u2 ) = φ(u4 ) and two directed paths P and P˜ , with (i) P connecting a vertex of RXλ ∪ R2 and u2 , (ii) P˜ connecting a vertex of RXλ ∪ R2 and u4 , and (ii) P and P˜ being disjoint. Although u2 ∈ D(RXλ ∪ R2 ), the vertex u2 is not contained in the split component of v and u1 . The vertex u3 , however, does not belong to the dependent set D(RXλ ∪ R2 ) since any directed S path connecting a vertex of RXλ ∪ R2 and a vertex in ki=φ(u3 ) V i must contain the vertex u1 . Hence, the paths are not disjoint and u3 ∈ / D(RXλ ∪ R2 ). Figure 17(c) shows a (not necessarily ˆ directed) path P connecting v and u3 via v˜, such that Pˆ and RXλ ∪ R2 ∪ D(RXλ ∪ R2 ) are disjoint. This leads to the interesting situation that u3 and therefore u2 are fixed in their embedding to the
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
88
side where v˜ is, while we are still able to flip the split component of u1 and v around, choosing an arbitrary side where to embed R2 next to RXλ with respect to RX . However, the existence of a split component does not guarantee a free choice of the embedding. In case that a (not necessarily directed) path P˜ exists, connecting the vertices v and u2 via v˜ such that the path P˜ and RXλ ∪ R2 ∪ D(RXλ ∪ R2 ) are disjoint, and the path P˜ uses only vertices in Sφ(u2 ) i i=1 V , we cannot flip the split component of v and u1 anymore. While Figure 17(a),(b),(c) describe examples of dependent sets such that an embedding of R2 can be chosen freely, Figure 17(d) gives an example of a dependent set that has to be embedded such that R2 is forced to be embedded on exactly one side of RXλ with respect to RX . Consider a vertex u1 ∈ V − (RXλ ∪ R2 ∪ D(RXλ ∪ R2 )) and a vertex u2 ∈ D(RXλ ∪ R2 ) such that there exists path Pˆ disjoint to RXλ ∪ R2 ∪ D(RXλ ∪ R2 ), connecting v and u2 via u1 , and the path Pˆ uses only Sφ(u ) vertices in i=12 V i . If there exists a vertex u3 ∈ D(RXλ ∪ R2 ), u3 6= u2 , with φ(u3 ) ≥ φ(u2 ), the path Pˆ forces R2 to be embedded on one side of RXλ with respect to RX . Figure 17 implicitly assumes that the Q-node X remains a node with at least two non-ignored children, one being the Q-node Y (the node that has been introduced when merging T (R1 ) and T (R2 )). The example of Figure 18 shows a subgraph corresponding to the subtree rooted at X, where X has become a Q-node with only one non-ignored child that is the node Y . Thus, there exists a split pair v and v˜ in G with v˜ being the connective cut vertex of RX that allows reversing the ~ X −(RX ∪R2 ∪D(RX ∪R2 )). This implies that R2 may be embedded split component containing R λ λ on either side of RXλ with respect to RX . We note that a path P = (v = u1 , u2 , . . . , uµ = u), µ ≥ 2, may exist, connecting v and a vertex u ∈ D(RXλ ∪ R2 ) such that P is disjoint to D(RXλ ∪ R2 ), Sφ(u) and the path P uses only vertices in i=1 V i . Such a path has no effect on the embedding of R2 next to RXλ with respect to RX since P must traverse the connective cut vertex v˜ of RX . Figure 18 shows the path P as a dotted line. ~ X − (RX ∪ R2 ∪ D(RX ∪ R2 )) such that for every vertex However, if there exists a vertex u ˜∈R λ λ u) holds, the embedding of R2 is fixed next to RXλ with respect ui ∈ P the inequality φ(ui ) ≤ φ(˜ to RX . Our discussion leads to the following observations. Observation 7.2. Let v be the connective cut vertex of RXλ and let v˜ be the connective cut vertex of RX if X has a parent. The subgraph R2 is not fixed to any side of RXλ with respect to RX if and only if for every vertex u in the dependent set D(RXλ ∪ R2 ) and every undirected path Sφ(u) P = (v = u1 , u2 , . . . , uµ = u), µ ≥ 2, with ui ∈ i=1 V i for all i = 1, 2, . . . , µ, one of the following conditions holds. (i) uµ−1 ∈ RXλ ∪ R2 ∪ D(RXλ ∪ R2 ). ~ X − (RX ∪ R2 ∪ D(RX ∪ R2 )) the inequality φ(v 0 ) < φ(u) holds. (ii) v˜ ∈ P and for all v 0 ∈ R λ λ (iii) v and u form a split pair in G and for all v 0 ∈ D(RXλ ∪ R2 ) − {u} the inequality φ(v 0 ) < φ(u) holds. Observation 7.3. Let v be the connective cut vertex of RXλ and let v˜ be the connective cut vertex of RX if X has a parent. The subgraph R2 is fixed to a side of RXλ with respect to RX if and only if there exists a vertex u in the dependent set D(RXλ ∪ R2 ) and an undirected path Sφ(u) P = (v = u1 , u2 , . . . , uµ = u), µ ≥ 2, with ui ∈ i=1 V i for all i = 1, 2, . . . , µ, and all of the following three conditions hold.
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
89
/ RXλ ∪ R2 ∪ D(RXλ ∪ R2 ). (i) uµ−1 ∈ (ii) (a) v˜ ∈ / P , or ~ X − (RX ∪ R2 ∪ D(RX ∪ R2 )) such that φ(v 0 ) ≥ φ(u). (b) v˜ ∈ P and there exists a v 0 ∈ R λ λ (iii) There exists a vertex v 0 ∈ D(RXλ ∪ R2 ) − {u} such that the inequality φ(v 0 ) ≥ φ(u) holds. The path P connecting the vertex v and a vertex u ∈ D(RXλ ∪ R2 ) uses only level-i vertices with i ≤ φ(u). This implies that the last edge (uµ−1 , u) on the path P must be an incoming edge of u. We use this fact to determine to which side of RXλ the form R2 is fixed with respect to RX . During the reduction of the leaves corresponding to the vertex u we analyze the incoming edges of u, determining for each edge if it is the last edge of a path that is treated in one of the Observations 7.2 and 7.3. The following two lemmas help us to perform the case distinction in a very efficient way. We note that the parent of Y (Y is the Q-node that has been inserted by the merge operation) does not need to be the node X throughout the algorithm, e.g., it may have been removed from the P Q-tree when applying a reduction using one of the templates Q2 and Q3. Lemma 7.4. The subgraph R2 has to be fixed in its embedding at one side of RXλ with respect to RX if and only if the Q-node Y is removed from the tree T during the application of the template matching algorithm using template Q2 or template Q3, and the parent of Y did not become a node with Y as the only non-ignored child. Proof: Let R2 be fixed to a side of RXλ with respect to RX . According to Observation 7.3, there exists a vertex u in the dependent set D(RXλ ∪ R2 ) and an undirected path P = (v = Sφ(u) u1 , u2 , . . . , uµ = u), µ ≥ 2, with ui ∈ i=1 V i for all i = 1, 2, . . . , µ. The last edge e = (uµ−1 , u) / RXλ ∪ R2 ∪ D(RXλ ∪ R2 ). Since u is in on P is therefore an incoming edge of u, and uµ−1 ∈ ˜ ∈ D(RXλ ∪ R2 ), it must have a second incoming edge e˜, with e˜ being incident to a vertex u Sφ(u)−1 i ˜l in T corresponding to e˜ it follows that V ∩ (R ∪ R ∪ D(R ∪ R )). Thus for the leaf X 2 X 2 λ λ i=1 ˜l ∈ frontier (Y ). Furthermore, the condition 7.3(i) guarantees that for the leaf l in T corresponding to e we have l ∈ / frontier (Y ). Let Z be the smallest common ancestor of l and ˜l in the P Q-tree. Obviously, the Q-node Y is a descendant of Z and we have Y 6= Z. ˜ be the parent of Y . If condition 7.3(ii)(a) holds, then l ∈ frontier (X), ˜ and v˜ (the Let X connective cut vertex of RX ) and v (the connective cut vertex of RXλ ) do not form a split pair in G. Thus the parent of Y did not become a node with Y as its only non-ignored child. ˜ but there exists at least If on the other hand condition 7.3(ii)(b) holds, then l ∈ / frontier (X), ~ X − (RX ∪ ˜ one empty child of X containing a leaf in its frontier corresponding to a vertex v 0 ∈ R λ R2 ∪ D(RXλ ∪ R2 )). Thus again, the parent of Y did not become a node with Y as the only non-ignored child. The node Y was a child of the Q-node X when it was introduced into the P Q-tree. Since the parent of Y did not become a node with Y as the only non-ignored child, according to Lemma 2.2 Y remains a child of a Q-node throughout the applications of the template matching algorithm. Due to the overall assumption that no vertex in D(RXλ ∪ R2 ) is involved in another merge operation, Y remains a child of a Q-node throughout every merge operation. Due to condition 7.3(iii) there exists an empty leaf in the frontier of the node Y . Thus Y is a ˜ are traversed during the reduction with respect to the vertex partial node, and Y and its parent X
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
90
˜ is a Q-node that is contained in the pertinent subtree with respect to u, either template u. Since X ˜ removing Y from the P Q-tree. Q2 or template Q3 is applied to Y and X, Now let Y be removed from the tree during the reduction with respect to some vertex u by applying template Q2 or Q3 and and let the parent of Y never become a node with Y being its only non-ignored child. Since the parent of Y always has at least two children, condition 7.3(ii)(a) or (ii)(b) must hold. Furthermore, the application of template Q2 or Q3 implies that the template matching algorithm has traversed Y and its parent, which is a Q-node as well. Hence the root of the pertinent subtree must be a proper ancestor of Y . Thus there exists a pertinent leaf l not in the subtree of Y , and Sφ(u) a path P = (v = u1 , u2 , . . . , uµ = u), µ ≥ 2, with ui ∈ i=1 V i for all i = 1, 2, . . . , µ, such that / RXλ ∪ R2 ∪ D(RXλ ∪ R2 ). Since one of the templates Q2 and Q3 has been applied in order uµ−1 ∈ to remove Y from the tree, Y itself must have been partial, and therefore must have had at least one empty leaf in its frontier. Thus condition 7.3(iii) holds. It follows that R2 is fixed on one side 2 of RXλ with respect to RX . Lemma 7.5. The subgraph R2 is not fixed to any side of RXλ with respect to RX if and only if one of the following cases occurs during the application of the template matching algorithm. (i) The Q-node Y gets ignored. (ii) The Q-node Y is a non-ignored node of the final P Q-tree. (iii) The Q-node Y has only one non-ignored child. (iv) The parent of Y has only Y as a non-ignored child. Proof: Let R2 be a subgraph not fixed to any side of RXλ . According to Observation 7.2 the cases 7.2(i), 7.2(ii), or 7.2(iii) apply. If there exists a path P and a vertex u ∈ D(RXλ ∪ R2 ) in G that satisfy condition 7.2(ii), it follows that the Q-node X was transformed into a node with only one non-ignored child and possibly some ignored children. Then the case (iv) follows immediately. If there exists a vertex u ∈ D(RXλ ∪R2 ) that satisfies 7.2(iii) then there exists a level l, φ(w) < l ≤ k, Tk (w being the vertex involved in merging RXλ and R2 ) such that D(RXλ ∪ R2 ) ∩ i=l V i = ∅ and |D(RXλ ∪ R2 ) ∩ V l−1 | = 1. Thus after completing the level planarity test for Gl−1 the node Y is a Q-node with just one non-ignored child. Now assume that 7.2(i) holds for all paths in G connecting v and a vertex u ∈ D(RXλ ∪ R2 ) and no path matches condition 7.2(ii) and 7.2(iii). It follows from 7.2(i) that 7.3(i) does not hold for any vertex u ∈ D(RXλ ∪ R2 ). According to Lemma 7.4, the Q-node Y is not removed from the tree using one of the templates Q2 and Q3, and one of the following two cases must hold. Tk 1. There exists a level l, φ(w) < l ≤ k, such that D(RXλ ∪ R2 ) ∩ i=l V i = ∅ and |D(RXλ ∪ R2 ) ∩ V l−1 | ≥ 1. Thus after completing the level planarity test for Gl−1 the node Y is a Q-node with non-ignored children. Two subcases occur (a) Every leaf in the frontier of the non-ignored children of Y is replaced by a sink indicator before testing Gl for level planarity. It follows that case (i) applies. (b) All leaves in the frontier of Y except for the leaves in the frontier of one child of Y become ignored. Thus case (iii) applies 2. The node Y is found in the final P Q-tree.
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
91
Conversely, if one of the four cases applies to the Q-node Y , by Observation 7.2 any embedding may be chosen. 2 Lemmas 7.4 and 7.5 reveal a solution for solving the problem of deciding whether R2 is fixed to one side of RXλ with respect to RX . A strategy is developed for detecting on which side of RXλ the subgraph R2 has to be embedded. One endmost child of Y clearly can be identified with the side where the root of T2 has been placed, while the other endmost child of Y can be identified with the side were Xλ is. Every reversal of the Q-node Y corresponds to changing the side were R2 has to be embedded and all we need to do is to detect the side of Y that belongs to R2 , when finally removing Y from the tree applying one of the templates Q2 or Q3. The strategy is to mark the end of Y belonging to R2 with a special ignored node. Such a special ignored node is called a contact of R2 and denoted by c(R2 ). It is placed as the endmost child of Y during the merge operation B or C next to the root of T2 . Thus the Q-node Y has now three children instead of two. See Figure 19 for an illustration. Since the contact c(R2 ) is related to a w-merge operation, the vertex w is called related vertex of c(R2 ) and denoted by ω(c(R2 )). The corresponding w-merge operation is said to be associated with c(R2 ). Before gathering some observations about contacts, it is necessary to show that the involved ignored nodes remain in the relative position of Y within the Q-node, and are therefore not moved or removed. Lemma 7.6. The ignored nodes of rseq(R2 )left and rseq(R2 )right stay siblings of Y until one of the templates Q2 or Q3 is applied to Y and its parent. Proof: The ignored nodes of rseq(R2 )left and rseq(R2 )right are children of a Q-node, and therefore remain children of a Q-node keeping their order throughout the application of the template matching algorithm, unless either rseq(R2 )left or rseq(R2 )right are found to be within a pertinent sequence. However, this can only happen if the node Y becomes pertinent, provided that the node Y does not become ignored itself. 2 A contact has some special attributes that are immediately clear and very useful for our approach. In the following observations we again assume that Y and its parent have not been an object of another merge operation B or C. Concatenation of contacts is discussed in the next section. Observation 7.7. Since the contact is an endmost child of a Q-node Y , it will remain an endmost child of the same Q-node Y , unless the node Y is eliminated applying one of the templates Q2 or Q3. Observation 7.8. If the node Y is eliminated applying the templates Q2 or Q3, the contact c(R2 ) determines the side were R2 has to be embedded next to RXλ with respect to RX . The contact is then a direct sibling to rseq(R2 )i , for some i ∈ {left , right } and ref (R2 )i has to be considered for edge augmentation. Besides placing c(R2 ) as endmost child next to the root of T2 , c(R2 ) is equipped with a set of four pointers, denoting the beginning and the end of both the left and the right reference sequence of R2 . This is necessary, since direct non-ignored siblings of Y may become ignored throughout the application of the algorithm. Let rseq(R2 )left = {Iν , Iν+1 , . . . , Iµ } be the left reference sequence and let rseq(R2 )right = {J1 , J2 , . . . , Jσ } be the right reference sequence. After performing a reduction
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
92
applying template Q2 or Q3 to the node Y , the contact is either a direct sibling of Iµ or a direct sibling of J1 . In the first case, we scan the sequence of ignored siblings starting at Iµ until the ignored node Iν is detected. In the latter case, the sequence of ignored siblings is scanned by starting at J1 until the node Jσ is detected. Figure 20 illustrates this strategy for the latter case. Storing pointers of the ignored nodes Iν , Iµ , J1 , Jσ at c(R2 ), we are able to identify the reference set ref (R2 ). The nodes Iν , Iµ , J1 , Jσ are called the reference points of the contact c(R2 ). Analogously to the definition of a reference set of R2 , ref (R2 ) is said to be the reference set of c(R2 ) and denoted by ref (c(R2 )). The section closes with a summary of the results. Lemma 7.9. Let c(R2 ) be a contact related to a vertex w and let ref (R2 )left be the left reference set of c(R2 ) with reference points Iν , Iµ and let ref (R2 )right be the right reference set of c(R2 ) with reference points J1 , Jσ . Then the following statements are true. (i) If c(R2 ) is adjacent to Iµ , then augmenting Gst by an edge (u, w) for every si (u) ∈ ref (R2 )left does not destroy level planarity. (ii) If c(R2 ) is adjacent to J1 , then augmenting Gst by an edge (u, w) for every si (u) ∈ ref (R2 )right does not destroy level planarity. Proof: The lemma immediately follows from Lemmas 7.4 and 7.6.
8
2
Concatenation of Contacts
For clarity, the previous section omitted the concatenation of merge operations applied to the vertices of the dependent set corresponding to a merge operation B or C. This section deals with the subject of concatenating merge operations. Let R1 be a reduced extended form that has been w1 -merged into a reduced extended form R by applying a merge operation B or C. Let T and T1 be the P Q-trees corresponding to R and R1 . Let X be the Q-node with children X1 , X2 , . . . , Xη , η ≥ 2, and let Xλ , λ ∈ {1, 2, . . . , η}, be the child that is replaced by a new Q-node having two children Xλ and the root of T1 . Let Ri , i = 2, 3, . . . , µ, be reduced extended forms where every Ri has to be wi -merged into R, and Ri is wi -merged into R before Ri+1 is wi+1 -merged into R, for all i = 2, 3, . . . , µ − 1. S Definition 8.1. Let D(RXλ ∪R1 ) ⊂ kν=φ(w1 ) V ν be the dependent set of RXλ ∪R1 . The dependent set of RXλ ∪ R1 ∪ R2 ∪ · · · ∪ Ri , i ∈ {2, 3, . . . , µ}, is denoted by D(RXλ ∪ R1 ∪ R2 ∪ · · · ∪ Ri ) ⊂ Sk Sk ν ν such that the ν=φ(w1 ) V , and is recursively defined to be the set of all vertices u ∈ ν=φ(w1 ) V following conditions hold. 1. wi ∈ D(RXλ ∪ R1 ∪ R2 ∪ · · · ∪ Ri−1 ). 2. There exists a directed path P = (u1 , u2 , . . . , uξ = u), ξ > 1, with u1 ∈ RXλ ∪R1 ∪R2 ∪· · ·∪Ri . S u1 , u ˜2 , . . . , u ˜ι = u˜), ι > 1, 3. There exists a vertex u ˜ ∈ kν=φ(w1 ) V ν and a directed path P˜ = (˜ u) ≥ φ(u) and the paths P and P˜ are vertex with u ˜1 ∈ RXλ ∪ R1 ∪ R2 ∪ · · · ∪ Ri , such that φ(˜ disjoint except possibly for u and u˜.
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
93
Definition 8.2. A sequence of wi -merge operations, i = 1, 2, . . . µ, of reduced extended forms Ri into a reduced extended form R is said to be a concatenation of merge operations if the following three conditions hold. (i) R1 is w1 -merged using a merge operation B or C. (ii) For all wi -merge operations we have wi ∈ D(RXλ ∪ R1 ∪ R2 ∪ · · · ∪ Ri−1 ). (iii) R1 has not been fixed to one side of RXλ with respect to RX and it is unknown if its embedding can be chosen freely. Interestingly, a concatenation of merge operations does not really affect the results of Observations 7.2 and 7.3 and the Lemmas 7.4 and 7.5. This is immediately clear for the observations that we now give for the concatenated case. Observation 8.3. Let v be the connective cut vertex of RXλ and let v˜ be the connective cut vertex of RX if X has a parent. Let Ri , i = 1, 2, . . . , µ, be a sequence of partially reduced extended forms that are wi -merged into R and where their merge operations are concatenations. The subgraph R1 is not fixed to any side of RXλ with respect to RX if and only if for every vertex u in the dependent set D(RXλ ∪ R1 ∪ R2 ∪ · · · ∪ Rµ ) and every undirected path P = (v = u1 , u2 , . . . , uξ = u), ξ ≥ 2, Sφ(u) with ui ∈ ν=1 V ν for all i = 1, 2, . . . , ξ, one of the following conditions holds. (i) uξ−1 ∈ RXλ ∪ R1 ∪ R2 ∪ · · · ∪ Rµ ∪ D(RXλ ∪ R1 ∪ R2 ∪ · · · ∪ Rµ ). ~ X − (RX ∪ R1 ∪ R2 ∪ · · · ∪ Rµ ∪ D(RX ∪ R1 ∪ R2 ∪ · · · ∪ Rµ )) the (ii) v˜ ∈ P and for all v 0 ∈ R λ λ 0 inequality φ(v ) < φ(u) holds. (iii) v and u form a split pair in G and for all v 0 ∈ D(RXλ ∪ R1 ∪ R2 ∪ · · · ∪ Rµ ) − {u} the inequality φ(v 0 ) < φ(u) holds. Observation 8.4. Let v be the connective cut vertex of RXλ and let v˜ be the connective cut vertex of RX if X has a parent. Let Ri , i = 1, 2, . . . , µ, be a sequence of partially reduced extended forms that are wi -merged into R and where their merge operations are concatenations. The subgraph R1 is fixed to a side of RXλ with respect to RX if and only if there exists a vertex u in the dependent set D(RXλ ∪ R1 ∪ R2 ∪ · · · ∪ Rµ ) and an undirected path P = (v = u1 , u2 , . . . , uξ = u), ξ ≥ 2, with Sφ(u) ui ∈ ν=1 V ν for all i = 1, 2, . . . , ξ, and all three of the following conditions hold. / RXλ ∪ R1 ∪ R2 ∪ · · · ∪ Rµ ∪ D(RXλ ∪ R1 ∪ R2 ∪ · · · ∪ Rµ ). (i) uξ−1 ∈ (ii) (a) v˜ ∈ / P , or ~ X −(RX ∪R1 ∪R2 ∪· · ·∪Rµ ∪D(RX ∪R1 ∪R2 ∪· · ·∪Rµ )) (b) v˜ ∈ P and there exists a v 0 ∈ R λ λ 0 such that φ(v ) ≥ φ(u). (iii) There exists a vertex v 0 ∈ D(RXλ ∪ R1 ∪ R2 ∪ · · · ∪ Rµ ) − {u} such that the inequality φ(v 0 ) ≥ φ(u) holds. In order to see that the results of Lemmas 7.4 and 7.5 (up to minor differences) still hold, we show that the “local structure” of the P Q-tree at the Q-node Y and its parent X either does not change or, if it changes, the embedding of R1 is fixed on one side of RXλ with respect to RX . With an “unchanged local structure” we express (informally) that throughout concatenated merge
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
94
operations the node Y (or any node that replaces Y ), and X (or any node that replaces X) stay Q-nodes with Y (or its replacing node) remaining unchanged in the position of its siblings. The following lemma formally describes how the Q-node Y is changed during subsequent concatenated merge operations. The results of the lemma then immediately lead to results similar to the ones in Lemmas 7.4 and 7.5. Lemma 8.5. Let Y be a Q-node that has been introduced by w1 -merging the P Q-tree T1 into T using a merge operation B or C, replacing a child Xλ of a Q-node X. Let Ti , i = 2, 3, . . . , µ, µ ≥ 2, be a sequence of P Q-trees that are wi -merged into T such that the wi -merge operations are concatenations. Let Y 0 be the node that occupies the position of Y in the P Q-tree after the wµ -merge operation is complete. Then Y 0 and its parent are Q-nodes. Proof: Let Ri , i = 1, 2, . . . , µ, be the forms corresponding to the P Q-trees Ti . We prove the lemma by induction. According to the definition of a concatenation, R1 has not been embedded at one side of RXλ with respect to RX and it is unknown if its embedding can be chosen freely. Lemma 7.5 therefore implies that the parent of Y did not become a node with Y as the only non-ignored child, and according to Corollary 2.2 the parent of Y must be a Q-node. Furthermore, Lemma 7.5 implies that Y must have at least two leaves in its frontier both corresponding to different vertices in G. When applying a w2 -merge operation to a vertex w2 ∈ D(RXλ ∪ R1 ) three cases are possible. (i) Only descendants of Y are affected by the merge operation. (ii) The node Y and its parent are affected by the merge operation. (iii) Proper ancestors of Y are affected by the merge operation. Consider the first case. If only proper descendants of Y are involved, neither Y nor its parent are affected. If Y and a child of Y are affected, the merge operations B, C or D are applied to the child of Y . Thus Y remains a Q-node with unchanged position in the P Q-tree. Consider the second case. Since the parent of Y is a Q-node, the only allowed merge operations are B, C, and D. The operations B and C insert a new Q-node Y 0 at the position of Y . Reducing the leaves labeled w2 after the merge operation does only affect the children of Y 0 , since Y 0 is the root of the pertinent subtree. Therefore, the Q-node Y 0 remains unchanged in its position. However, if the merge operation D is applied, the template matching algorithm performed directly after the merge operation removes Y from the tree by applying one of the templates Q2 or Q3. Hence, according to Lemma 7.4, R1 is embedded at one side of RXλ with respect to RX . Therefore, the w1 -merge operation of T1 and the w2 -merge operation of T2 are not a concatenation. If proper ancestors of Y are involved, the reduction of the P Q-tree with respect to w2 removes Y from the P Q-tree by applying one of the templates Q2 or Q3. Again, the w1 -merge operation of T1 and the w2 -merge operation of T2 are not concatenated. The lemma then follows by a simple inductive argument. 2 The following lemmas are almost identical to the Lemmas 7.4 and 7.5, taking into account that the subgraph induced by the subtree rooted at Y (or any Q-node that replaces Y due to a merge operation) may have grown by concatenated merge operations. Lemma 8.6. Let Y be the Q-node that was introduced by a w1 -merge operation B or C of a P Qtree T1 into a tree T , replacing a node Xλ that was a child of a Q-node X in T . Let Y 0 be a Q-node
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
95
occupying the position of Y , and Y 0 has been introduced during a merge operation concatenating the w1 -merge operation. The subgraph R1 corresponding to T1 has to be embedded at exactly one side of RXλ with respect to RX if and only if the Q-node Y 0 is removed from the tree T during the application of the template matching algorithm using template Q2 or template Q3, and the parent of Y did not become a node with Y as the only non-ignored child. Proof: The lemma follows from Lemma 7.4 and Lemma 8.5.
2
Lemma 8.7. Let Y be the Q-node that was introduced by a w1 -merge operation B or C of a P Qtree T1 into a tree T , replacing a node Xλ that was a child of a Q-node X in T . Let Y 0 be a Q-node occupying the position of Y , and Y 0 has been introduced during a merge operation concatenating the w1 -merge operation. The subgraph R1 corresponding to T1 is not fixed to any side of RXλ if and only if one of the following cases occurs during the application of the template matching algorithm. (i) The Q-node Y 0 gets ignored. (ii) The Q-node Y 0 is a non-ignored node of the final P Q-tree. (iii) The Q-node Y 0 has only one non-ignored child. (iv) The parent of Y 0 has only Y 0 as a non-ignored child. Proof: The lemma follows from Lemma 7.5 and Lemma 8.5.
2
Let c be a contact that is a child of the Q-node Y . As long as concatenated merge operations only affect descendants of the Q-node Y , they have no effect on c and its reference sequence. However, if Y and its parent are subject to a merge operation B or C, there exists a coherence between the existing contact c and the new contact that is introduced by the merge operation. Obviously, the merge operations A, D, and E can be performed one after another without worrying about the correct treatment of involved sink indicators. However, the merge operations B and C may “affect” each other. Consider for instance the example shown in Figure 21, presenting three forms R1 , R2 , and R3 that have been successively merged into a form R at the vertices w1 , w2 , w3 . For every form Ri , the example also gives the set of edges that have to be added as incoming edges to wi , i ∈ {1, 2, 3}, in the given embedding. On the other hand, Figure 22 gives the same example only with a different embedding showing different sets of edges that have to be added as incoming edges to wi . In the rest of this section we discuss how to handle sequences of the merge operations B and C that affect each other. We say that two contacts c1 and c2 mutually influence each other if ref (c1 ) ∩ ref (c2 ) 6= ∅. Two merge operations B or C mutually influence each other if their corresponding contacts mutually influence each other. Consider a Q-node Y that has been introduced as a child of a Q-node X applying one of the operations B or C. In case of a w-merge operation B or C, we only need to check if the node Y that has to be replaced by a new Q-node does have a contact as an endmost child. However, the contact is then separated from its reference sequence since Y is not a child of the Q-node X anymore. This seems to destroy the strategy of handling the contact and its reference sequence correctly. However, the new Q-node is obviously the root of the pertinent subtree with respect to w. Since the two merge operations are concatenated, Lemma 7.5 does not apply to Y1 . (Otherwise, simply remove the contact and either the left or right reference set.) It follows that the node Y1 must be a partial Q-node. Therefore, template Q2 or Q3 is applied to Y1 and its parent Y2 , and Y1 is removed
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
96
from the tree, and the children of Y1 become children of Y2 . This ensures that after the reduction with respect to w, c1 is again a child of a Q-node Y2 , where Y2 is a child of X occupying the former position of Y1 . We consider the position of c1 within the sequence of children of Y2 . Let c2 be the contact associated with the merge operation that introduced Y2 . Two cases may occur during the reduction with respect to w. 1. The contact c1 was at the empty end of Y1 and since Y1 was an endmost child of Y2 , c1 is now an endmost child of Y2 . 2. The contact c1 was at the full end of Y1 , and appears within the sequence of full children of Y2 . After having finished the reduction with respect to w one of the following two rules is applied to the contact c1 . Rule I If c1 is an endmost child of Y2 , c1 remains in its position as an endmost child of Y2 . Rule II If c1 is found within the sequence of pertinent nodes, c1 is placed as a new endmost child of Y2 next to c2 . The rules are easily expanded to two or more contacts. Let Yi be the i-th Q-node introduced by the i-th concatenating merge operation. Rule I’ If a sequence of contacts c1 , c2 , . . . , cξ , ξ ≤ i − 1, is endmost at Yi after the reduction is complete, the contacts c1 , c2 , . . . , cξ remain in their positions. Rule II’ If a sequence of contacts c1 , c2 , . . . , cξ , ξ ≤ i−1, is found within the sequence of pertinent nodes and c1 was the former endmost child of Yi−1 , the sequence c1 , c2 , . . . , cξ is placed next to ci that cξ and ci are directly siblings and c1 is a new endmost child of Yi . Lemma 8.8. Let Ri , i = 1, 2, . . . , µ, be a sequence of partially reduced extended forms that are wi -merged into a partially reduced extended form R of a level planar graph G such that their merge operations are concatenations. Let T , T1 , T2 , . . . , Tµ be the P Q-trees corresponding to R, R1 , R2 , . . . , Rµ . Let X, Y1 , Y2 , . . . , Yµ be Q-nodes and Xλ be a node such that (a) Xλ was a child of X in a P Q-tree T before w1 -merging T1 into T . (b) Xλ was replaced by Y1 when w1 -merging T1 into T using the merge operation B or C. (c) Yi was replaced by Yi+1 when wi+1 -merging Ti+1 into T using the merge operation B or C for all i = 1, 2, . . . , µ − 1. Let c(Ri ) be the contact that is associated with the introduction of Yi , i = 1, 2, . . . , µ. Let RXλ be the subgraph corresponding to Xλ , and assume that c(R1 ), c(R2 ), . . . , c(Ri−1 ) have been replaced by applying one of the Rules I’ or II’ when merging R1 , R2 , . . . , Ri into R, i ≥ 2. Then exactly one of the following statements holds. (i) The contacts c(R1 ) and c(Ri ) are both children at the same end of the Q-node Yi if and only if their corresponding forms have to be embedded on the same side of RXλ with respect to RX in every level planar embedding.
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
97
(ii) The contacts c(R1 ) and c(Ri ) are both children on opposite sides of the Q-node Yi if and only if their corresponding forms have to be embedded on opposite sides of RXλ with respect to RX in every level planar embedding. Proof: Since the merge operations are concatenated, Lemma 7.5 does not apply to Yi , i = 1, 2, . . . , µ − 1. It follows that Yi is a partial Q-node for every i = 1, 2, . . . , µ − 1. Thus there exist at least two leaves, one corresponding to an incoming edge of wi+1 and one corresponding to an incoming edge of a vertex u ∈ V l , u 6= w2 , φ(wi+1 ) ≤ l ≤ k. Let Yi , i ∈ {2, 3, . . . , µ − 1}, be the partial Q-node that has to be replaced by a Q-node Yi+1 in a wi+1 merge operation. Then the set {R1 , R2 , . . . , Ri } partitions into two subsets: • {R11 , R21 , . . . , Rν1 }, 1 ≤ ν ≤ i, the set of forms that are embedded on the same side as R1 and 2 , R22 , . . . , Ri2 }, the set of forms that are embedded on the opposite side of R1 . • {Rν+1
Since Yi is a partial Q-node, there exists a level planar embedding of RYi and two paths P = (u1 , u2 , . . . , uσ ) u1 ∈ R11 ∪ R21 ∪ · · · ∪ Rν1 2 uj ∈ / RXλ ∪ Rν+1 ∪ R22 ∪ · · · ∪ Ri2 − {wi } φ(uj ) < φ(wi+1 ) φ(uσ ) ≥ φ(wi+1 )
σ≥2 j = 1, 2, . . . , σ j = 1, 2, . . . , σ − 1
and P 0 = (u01 , u02 , . . . , u0ξ ) 2 ∪ R22 ∪ · · · ∪ Ri2 u01 ∈ RXλ ∪ Rν+1 1 1 uj ∈ / R1 ∪ R2 ∪ · · · ∪ Rν1 φ(u0j ) < φ(wi+1 ) φ(u0ξ ) ≥ φ(wi+1 )
ξ≥2 j = 1, 2, . . . , ξ j = 1, 2, . . . , ξ − 1
such that (a) P and P 0 are disjoint, (b) both P and P 0 are on the boundary of the outer face of the embedding of RYi , and (c) either uσ = wi+1 or u0ξ = wi+1 , but not both. See Figure 23 where we have illustrated the case i = 1. First, case (i) is proven. Let Ri+1 and R1 be embedded on the same side of RXλ . It follows that wi+1 ∈ P , otherwise Ri+1 and P would cross each other. Let Z be the child of Yi that is an ancestor of the leaf labeled wi+1 . Since the path P is on the outer face of RYi on the side where R1 is embedded, Z must be an endmost non-ignored child of Yi on the side where c(R1 ) is an endmost child. Since Yi is partial, c(R1 ) will appear within the pertinent sequence of leaves labeled wi+1 after the reduction with respect to wi+1 is complete. Therefore Rule II’ is applied and c(R1 ) and c(Ri+1 ) are both children at the same end of Yi+1 . Now let c(R1 ) and c(Ri+1 ) be children on the same side, and assume that R1 and Ri+1 have to be embedded on opposite sides of RXλ with respect to RX . It follows that wi+1 ∈ P 0 , otherwise Ri+1 and P 0 would cross each other. By construction, c(R1 ) was found within the pertinent sequence
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
98
with respect to the vertex wi+1 after Ri+1 was wi+1 -merged into R. So there exists a path P 00 on the boundary of RYi , and P 00 connects a vertex u ∈ R11 ∪ R21 ∪ · · · ∪ Rν1 and wi+1 , not using any Sk vertices u0 ∈ l=φ(wi+1 ) V l . However, P 00 must cross P , a contradiction. The case (ii) is proven analogously to case (i). 2 If two contacts c1 and c2 influence each other, and therefore ref (c1 ) ∩ ref (c2 ) 6= ∅ holds, we need to redefine their reference sets such that no conflicts appear when sink indicators for edge augmentation are considered. A situation, where we can chose for a sink indicator to which reference set it belongs has to be avoided. Again let R, R1 , R2 , X, Xλ , Y1 , Y2 , c(R1 ), and c(R2 ) be defined as in Lemma 8.8. The idea is to leave the reference set of c(R1 ) (the contact associated to the “first” merge operation) unchanged, and adapt the reference set of c(R2 ) (the contact associated to the “second” merge operation). Let I1 , I2 , . . . , Iµ , µ ≥ 0, be the sequence of ignored nodes on the left side of Xλ with Xλ and Iµ being direct siblings, and let J1 , J2 , . . . , Jρ , ρ ≥ 0, be the sequence of ignored nodes on the right side of Xλ with Xλ and J1 , being direct siblings. Let ! ! µ σ1 [ [ frontier (Ii ) ∪ frontier (Ji ) ref (c(R1 )) = i=ν1
i=1
for 1 ≤ ν1 ≤ µ + 1, 0 ≤ σ1 ≤ ρ be the reference set of c(R1 ), where we assume without loss of generality that none of the two subsets is empty. The reference points of c(R1 ) are Iν1 , Iµ , J1 , Jσ1 . Assume further that ! ! µ σ2 [ [ frontier (Ii ) ∪ frontier (Ji ) ref (c(R2 )) = i=ν2
i=1
for 1 ≤ ν2 ≤ µ + 1, 0 ≤ σ2 ≤ ρ . After performing the second merge operation including the reduction of the leaves labeled w2 , the contacts c(R1 ) and c(R2 ) occupy two relative positions at their parent Y2 . (i) c(R1 ) and c(R2 ) are endmost children on different ends of Y2 . Due to Lemma 8.8, R1 and R2 are embedded on opposite sides of RXλ with respect to RX . Thus c(R1 ) and c(R2 ) do not interfere when finally determining the sets of sink indicators that are considered for edge augmentation. We determine the reference points Iν2 , Iµ , J1 , Jσ2 and store them at c(R2 ). (ii) c(R1 ) and c(R2 ) are at the same end of Y2 with c(R1 ) being (by construction) an endmost child. Due to Lemma 8.8, R1 and R2 are embedded at the same side of RXλ . Thus c(R1 ) and c(R2 ) interfere when we finally determine the sets of sink indicators that are considered for edge augmentation. The new reference set of c(R2 ) is determined as follows. Sν1 −1 left i=ν2 frontier (Ii ) = ref (c(R2 )) ∅ right
ref (c(R2 ))
Sσ2 =
∅
i=σ1 +1
frontier (Ji )
if ν2 < ν1 otherwise if σ2 > σ1 otherwise
(1)
(2)
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
99
Then the reference set of c(R2 ) is ref (c(R2 ))
= ref (c(R2 ))right ∪ ref (c(R2 ))left .
Hence, the ignored nodes Iν2 , Iν1 −1 , Jσ1 +1 , Jσ2 are stored as reference points at c(R2 ). The application to the more general case of three or more contacts is straightforward. Remark 8.9. In order to achieve linear running time, the reference sequence of a newly introduced contact c(Ri ) and its associated form Ri is never determined by scanning the sequence of ignored siblings. Instead we proceed as follows. At every consecutive sequence of contacts, we keep a pointer at the endmost contact cα towards the innermost contact cω . The contact cω is obviously the contact that has been introduced last in this sequence of contacts. When introducing a new contact, we only need to consider the contacts on the same side as the new contact. We check the reference sequence of the innermost contact cω and determine the ML-values ML(Iνω−1 , Iνω ) and ML(Jσω , Jσω+1 ) between the reference sequence and their direct siblings. If ML(Iνω−1 , Iνω ) < LL(Ri ) or ML(Jσω , Jσω+1 ) < LL(Ri ), the left or right reference set of c(Ri ), respectively, is empty. If ML(Iνω−1 , Iνω ) ≥ LL(Ri ) or ML(Jσω , Jσω+1 ) ≥ LL(Ri ), the left or right reference sequence of c(Ri ), respectively, is determined in constant time using the pointers that we have installed as described in Remark 6.6. Consider the case were c(R1 ) and c(R2 ) are at the same end of Y2 . when removing the Q-node Y2 during the application of the template Q2 or Q3. The contact c(R1 ) is an endmost child of Y2 . Thus, after the application of the template Q2 or Q3 the contact c(R1 ) is a direct sibling of either Iµ or J1 . Therefore, the identification of sink indicators that have to be considered for edge augmentation joining the vertex w1 is a straightforward matter. After this identification is finished, the contact c(R1 ) and the set of ignored siblings that were considered for augmentation are removed from the P Q-tree, leaving the contact c(R2 ) as a direct sibling of either Iν1 −1 or Jσ1 +1 . Again, the identification of the sink indicators that have to be considered for edge augmentation joining the vertex w2 is straightforward. Lemma 8.10. Let ci , i = 1, 2, . . . , µ, µ ≥ 1, be contacts that are endmost children of a Qnode Y1 in a P Q-tree T . Let contact ci be related to vertex wi ∈ V , such that φ(wi ) ≤ φ(wi+1 ), i = 1, 2, . . . , µ − 1. In case that φ(wi ) = φ(wi+1 ) holds, let the P Q-tree Ti corresponding to ci be wi -merged into T before the tree Ti+1 corresponding to wi+1 is wi+1 -merged into T . Let ref (ci )left be the left reference set of ci with reference points Iib , Iie and ref (ci )right be the right reference set of ci with reference points Jib , Jie . For every ci , the nodes Iib and Jib denote the first ignored node in the reference sequence rseq (ci )left and rseq(ci )right , respectively, and Iie and Jie denote the last ignored node in the reference sequence rseq(ci )left and rseq(ci )right , respectively. Then the following statements are true. (i) If ci is adjacent to Iib , then augmenting Gst by an edge (u, w) for every si (u) ∈ ref (ci )left does not destroy level planarity. (ii) If ci is adjacent to Jib , then augmenting Gst by an edge (u, w) for every si (u) ∈ ref (ci )right does not destroy level planarity. Proof: By construction, the sequence of children of Y1 is partitioned into the three sets: C1 , N and C2 where
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
100
• C1 = c11 , c21 , . . . , cν1 , 0 ≤ ν ≤ µ, is the sequence of contacts on one end of Y1 with c11 being an endmost child of Y1 . • N is a sequence of ignored and non-ignored nodes. • C2 = c12 , c22 , . . . , cϕ2 , ϕ = µ − ν, is the sequence of contacts on the opposite side of C1 with c12 as an endmost child of Y1 . By construction, for Cξ , ξ = 1, 2, φ(ω(ciξ ))
≤
ξ φ(ω(ci+1 ))
i = 1, 2, . . . , |Cξ | − 1
where ω(ciξ ) denotes the vertex related to ciξ . For any i ∈ {1, 2, . . . , |Cξ | − 1} with φ(ω(ciξ )) = ξ )) the P Q-tree corresponding to ciξ has been ω(ciξ )-merged into T before the tree correφ(ω(ci+1 ξ ξ has been ω(ci+1 )-merged. sponding to ci+1 1 It follows that either c1 = c1 or c12 = c1 and c11 and c12 do no interfere, since their corresponding forms are placed on opposite sides with respect to RXλ and RX . We may assume that c11 = c1 . Due to Observation 7.8, c11 is either adjacent to I1b or to J1b . Assume without loss of generality that c11 is adjacent to I1b . It follows from Lemma 7.9 that considering ref (c1 )left for edge augmentation does not destroy level planarity. Removing c11 and ref (c1 )left from the tree, the correctness of the lemma follows by a simple inductive argument. 2 The function AUGMENT now combines all the described strategies in the level planarity test of J¨ unger et al. (1999). It is almost identical to the function LEVEL-PLANARITY-TEST, except that it does not call the function CHECK-LEVEL but a function EMBED-LEVEL. However, the function EMBED-LEVEL is almost identical to the function CHECK-LEVEL. We only need the following modifications. (i) If v is a sink in V j , 1 < j < k, replace the corresponding leaf by a sink indicator si (v) before processing Gj+1 . If this replacement constructs a node X having only sink indicators in its frontier, mark X as ignored and update the ML-values as described in Section 6. (ii) When reducing a set of leaves with respect to a vertex w in a P Q-tree, ignore all sink indicators and ignored nodes during the application of the template matching algorithm. After the reduction is complete, the pertinent subtree is removed from the tree and replaced by a single representative. During the removal of the pertinent subtree with respect to w, we check for sink indicators in the pertinent subtree. For every si (v) that is found in the pertinent subtree, we add an edge (v, w) to Gst , unless si(v) is affected by the existence of a contact c in the pertinent subtree. If the latter applies, add an edge (v, w0 ), with w0 being the vertex related to c. (iii) When w-merging a P Q-tree T 0 into a P Q-tree T , necessary adjustments as described above have to be applied to the merge operations B or C. If necessary, a contact is introduced as a third child of the new Q-node. Furthermore, if the new contact mutually influences existing ones, Rules I or II (see 8) have to be applied after reducing T with respect to w. (iv) After processing level k, an edge (v, t) is added for every vertex v ∈ V k . Furthermore we scan the final P Q-tree T for remaining sink indicators, and add for every indicator si (v) an edge (v, t) to Gst , unless si (v) is affected by the existence of a contact c in the pertinent subtree. If the latter applies we add an edge (v, w0 ), with w0 being the vertex related to c.
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
101
Theorem 8.11. The algorithm LEVEL-PLANAR-EMBED computes a level planar embedding of a level planar graph G = (V, E, φ) in O(n). Proof: From Lemmas 5.1, 5.2, 5.3 and 8.10 it follows that augmenting Gst to a hierarchy using the function AUGMENT does not destroy level planarity. Consequently, the augmentation of Gst to a single source, single sink graph does not destroy level planarity either. The vertices s and t are on the outer face of a level planar embedding of Gst . By the discussion of Section 4 we can compute a topological sorting of Gst that induces an st-numbering and applying the planar embedding algorithm of Chiba et al. (1985) to Gst a level planar embedding of G can be constructed. Since the number of edges added to G to construct Gst is bounded by n, the level planar embedding is computed in O(n) time. It remains to show that augmenting Gst to a hierarchy can be done in O(n) time. The function AUGMENT performs as the function LEVEL-PLANARITY-TEST, with certain modifications. It is sufficient to show that the amount of extra work performed by these modifications consumes O(n) time. Clearly, the maintenance of the ignored nodes during all template reductions, and all merge operations A, D, and E is bounded by the number of ignored nodes in the P Q-trees. The number of ignored nodes is O(n), thus it remains to show that the number of operations needed to perform merge operations B and C is as well bounded by the number of ignored nodes. As described in Remark 8.9 the installation of a contact and the identification of its corresponding reference sequence is bounded by a constant number of operations. Clearly, the number of operations for deinstalling all contacts and their reference sequences is bounded by the number of ignored nodes. Hence, the amount of time needed to handle ignored nodes during the application of the merge operations is in O(n). 2
9
Remarks
Once a level graph has been level planar embedded, we want to visualize it by producing a level planar drawing. This is very simple for proper graphs. Assign the vertices of every level integer x-coordinates according to the permutation that has been computed by CONSTRUCT-LEVELEMBED, and draw the edges as straight line segments. This produces a level planar drawing and after applying some readjustments such a drawing can be aesthetically pleasing. For level graphs that are not necessarily proper, this approach is not applicable. It would be necessary to expand the level graph in the horizontal direction for drawing the edges as straight line segments. If many long edges exist in the graph, the area that is needed will be rather large, and the drawings are not aesthetically pleasing. However, there is a nice and quick solution to this problem that uses some extra information that is computed by our level planar embedding algorithm. Instead of drawing the graph G, we draw the st-graph Gst , and remove afterwards all edges and the vertices s and t that are not contained in G. Drawing st-graphs has been extensively studied recently (see, e.g, Kant (1993), Luccio, Mazzone, and Wong (1987), Rosenstiehl and Tarjan (1986), Tamassia and Tollis (1986), and Tamassia and Tollis (1989)). Suitable approaches for drawing the st-graph Gst have been presented by Di Battista and Tamassia (1988) and Di Battista, Tamassia, and Tollis (1992). These algorithms construct a planar upward polyline drawing of a planar st-graph according to a topological numbering of the vertices. The vertices of the st-graph are assigned to grid coordinates and the edges are
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
102
drawn as polygonal chains. If we assign a topological numbering to the vertices according to their leveling, the algorithm presented by Di Battista and Tamassia (1988) produces in O(n) time a level planar polyline grid drawing of Gst such that the number of edge bends is at most 6n − 12 and every edge has at most two bends. This approach can be improved to produce in O(n) time a level planar polyline grid drawing of Gst such that the drawing of Gst has O(n2 ) area, the number of edge bends is at most (10n − 31)/3, and every edge has at most two bends. Thus once we have augmented G to the st-graph Gst , we can immediately produce a level planar drawing of G in O(n) time.
References Booth, K. and Lueker, G. (1976). Testing for the consecutive ones property, interval graphs, and graph planarity using PQ-tree algorithms. Journal of Computer and System Sciences, 13, 335–379. Chiba, N., Nishizeki, T., Abe, S., and Ozawa, T. (1985). A linear algorithm for embedding planar graphs using PQ-trees. Journal of Computer and System Sciences, 30, 54–76. Di Battista, G. and Tamassia, R. (1988). Algorithms for plane representations of acyclic digraphs. Theoretical Computer Science, 61, 175–198. Di Battista, G., Tamassia, R., and Tollis, I. G. (1992). Constrained visibility representations of graphs. Information Processing Letters, 41, 1–7. Even, S. and Tarjan, R. E. (1976). Computing an st-numbering. Theoretical Computer Science, 2, 339–344. Fulkerson, D. R. and Gross, O. A. (1965). Incidence matrices and interval graphs. Pacific J. Mathematics, 15, 835–855. Heath, L. S. and Pemmaraju, S. V. (1995). Recognizing leveled-planar dags in linear time. In F. J. Brandenburg, editor, Proc. Graph Drawing ’95 , volume 1027 of Lecture Notes in Computer Science, pages 300–311. Springer Verlag. Heath, L. S. and Pemmaraju, S. V. (1996). Stack and queue layouts of directed acyclic graphs: Part II. Technical report, Department of Computer Science, Virginia Polytechnic Institute & State University. J¨ unger, M., Leipert, S., and Mutzel, P. (1998). Level planarity testing in linear time. In S. Whitesides, editor, Graph Drawing ’98 , volume 1547 of Lecture Notes in Computer Science, pages 224–237. Springer Verlag. J¨ unger, M., Leipert, S., and Mutzel, P. (1999). Level planarity testing in linear time (full version). Technical report, Institut f¨ ur Informatik, Universit¨at zu K¨ oln. Kant, G. (1993). A more compact visibillity representation. In J. van Leeuwen, editor, Proc. 19th International Workshop on Graph-Theoretical Concepts in Computer Science , Lecture Notes in Computer Science. Springer Verlag.
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
103
Leipert, S. (1998). Level Planarity Testing and Embedding in Linear Time. Ph.D. thesis, Universit¨ at zu K¨ oln. Luccio, F., Mazzone, S., and Wong, C. (1987). A note on visibility graphs. Discrete Mathematics, 64, 209–219. Rosenstiehl, P. and Tarjan, R. E. (1986). Rectilinear planar layouts and bipolar orientations of planar graphs. Discrete and Computational Geometry, 1, 343–353. Tamassia, R. and Tollis, I. G. (1986). A unified approach to visibillity representations of planar graphs. Discrete and Computational Geometry, 1, 321–341. Tamassia, R. and Tollis, I. G. (1989). Tessellation representations of planar graphs. In Proc. 27th Allerton Conf. Communication Control Computing , pages 48–57.
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
10
104
Glossary
c(R) is the contact of a form R. The contact is an ignored node that is placed as an endmost child of a Q-nodes Y next to the root of the P Q-tree T (R) where Y was introduced by a merge operation B or C. D(RXλ ∪ R2 ) is the dependent set of RXλ ∪ R2 where RXλ is the subgraph of a form R1 and corresponds to the subtree rooted at Xλ before merging the forms R1 and RS 2 using a merge operation B or C. The dependent set D(RXλ ∪ R2 ) is the set of vertices u ∈ ki=φ(w) V i such that there exists a directed path P = (u1 , u2 , . . . , uξ = u), ξ > 1, with u1 ∈ RXλ ∪ R2 , and Sk u1 , u ˜2 , . . . , u ˜ι = u ˜), ι > 1, there exists a vertex u ˜ ∈ i=φ(w) V i and a directed path P˜ = (˜ ˜ u) ≥ φ(u) and the paths P and P are vertex disjoint except with u ˜1 ∈ RXλ ∪ R2 , such that φ(˜ for possibly u and u ˜. D(RXλ ∪ R1 ∪ R2 ∪ · · · ∪ Ri ) is the dependent set of RXλ ∪ R1 ∪ R2 ∪ · · · ∪ Ri and is recursively Sk defined to be the set of all vertices u ∈ ν=φ(w1 ) V ν such that (i) Ri is wi -merged into R and wi ∈ D(RXλ ∪ R1 ∪ R2 ∪ · · · ∪ Ri−1 ), (ii) there exists a directed path P = (u1 , u2 , . . . , uξ = u), S ξ > 1, with u1 ∈ RXλ ∪ R1 ∪ R2 ∪ · · · ∪ Ri , and (iii) there exists a vertex u˜ ∈ kν=φ(w1 ) V ν and a directed path P˜ = (˜ u1 , u ˜2 , . . . , u ˜ι = u ˜), ι > 1, with u ˜1 ∈ RXλ ∪ R1 ∪ R2 ∪ · · · ∪ Ri , such that φ(˜ u) ≥ φ(u) and the paths P and P˜ are vertex disjoint except possibly for u and u˜. Fij denotes a component of Gj , where i = 1, 2, . . . , mj . G = (V, E, φ) is called a level graph and is a directed acyclic graph with a mapping φ : V → {1, 2, . . . , k}, k ≥ 1, that partitions the vertex set V as V = V 1 ∪ V 2 ∪ · · · ∪ V k , V j = φ−1 (j), V i ∩ V j = ∅ for i 6= j, such that φ(v) ≥ φ(u) + 1 for each edge (u, v) ∈ E. Gj denotes the subgraph of G induced by V 1 ∪ V 2 ∪ · · · ∪ V j . Hij is the graph arising from Fij by introducing for each edge e = (u, v), where u is a vertex in Fij and v ∈ V l , l ≥ j + 1, a virtual vertex with label v and a virtual edge that connects u and this virtual vertex. LL(Fij ) is the low indexed level of Fij , the smallest d such that Fij contains a vertex in V d . ML(S) For any subset S of the set of vertices in V j+1 ∪ V j+2 ∪ · · · ∪ V k that belongs to a form Hij or Rij , ML(S) is the greatest d ≤ j such that V d , V d+1 , . . . , V j induces a subgraph in which all nodes of S occur in the same connected component. The level ML(S) is said to be the meet level of S. mj denotes the number of components of Gj . φ is a mapping φ : V → {1, 2, . . . , k}, k ≥ 1, of a directed acyclic graph G = (V, E) that partitions the vertex set V as V = V 1 ∪ V 2 ∪ · · · ∪ V k , V j = φ−1 (j), V i ∩ V j = ∅ for i 6= j, such that φ(v) ≥ φ(u) + 1 for each edge (u, v) ∈ E. RX is the subgraph corresponding to the subtree rooted at a node X of a P Q-tree.
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
105
~ X is the set of all vertices u ∈ V such that there exists a vertex v ∈ RX and a (not necessarily R directed) path P connecting u and v not using the connective cut vertex of X. Rij is the reduced extended form that is created from an extended form Hij by identifying all virtual vertices with the same label to a single vertex. If Rij has been subject to a merge operation, it is a partially reduced extended form. Rij ∪v Rlj is the graph arising from the identification of two virtual vertices vi and vl (labeled v) of two reduced extended forms Rij and Rlj . rseq(R) is the reference sequence of a form R. It is the sequence of ignored nodes Iν , Iν+1 , . . . , Iµ left of a node Xλ and J1 , J2 , . . . , Jσ right of a node Xλ , where Xλ is subject to a merge operation B or C. The reference sequence describes the two sets of sink indicators of which exactly one set has to be considered for edge augmentation in combination with the merge operation and is associated with the ”smaller” form R that has been merged into the larger form. rseq(R)right denotes the right sequence of ignored nodes of rseq(R). rseq(R)left denotes the left sequence of ignored nodes of rseq(R). ref (R) is the reference set of a form R. It is the union of the frontiers of all elements of the reference sequence rseq(R). ref (R)left is the left reference set of a form R. ref (R)right is the right reference set of a form R. ref (c(R2 )) is the reference set of a contact c(R2 ). si (v) is the sink indicator of a sink v. The sink indicator is a leaf for keeping the position of the sink v in a P Q-tree. Siv is the set of virtual vertices of Hij or Rij that are labeled v ∈ V j+1 . vi is the vertex with label v of Rij , i.e., the vertex that arose from identifying all virtual vertices of Siv . ω(c(R)) is the related vertex w of a contact c(R) where the contact c(R) was introduced by a w-merge operation. Concatenation of merge operations is a sequence of wi -merge operations, i = 1, 2, . . . µ, of reduced extended forms Ri into a reduced extended form R such that (i) R1 is w1 -merged using a merge operation B or C, (ii) for all wi -merge operations we have wi ∈ D(RXλ ∪ R1 ∪ R2 ∪ · · · ∪ Ri−1 ), and (iii) R1 has not been fixed to one side of RXλ with respect to RX and it is unknown if its embedding can be chosen freely. Connective cut vertex Let X be a Q-node in T corresponding to a subgraph B of Gj , 1 ≤ j ≤ k. The children of X each correspond to a cut vertex on the border of the outer face of B. If X is not the root, then there exists an extra cut vertex on the border of the outer face of B that separates the subgraph G0 induced by the subtree rooted at X from Gj − G0 . This cut vertex is called the connective cut vertex of B.
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
106
Contact of a form R is an ignored node that is placed as the endmost child of a Q-node Y next to the root of the P Q-tree T corresponding to R where Y was introduced by a merge operation B or C. S Dependent set of RXλ ∪ R2 is the set D(RXλ ∪ R2 ) of vertices u ∈ ki=φ(w) V i such that there exists a directed path P = (u1 , u2 , . . . , uξ = u), ξ > 1, with u1 ∈ RXλ ∪ R2 , and there S u1 , u ˜2 , . . . , u ˜ι = u˜), ι > 1, with exists a vertex u ˜ ∈ ki=φ(w) V i and a directed path P˜ = (˜ ˜ u) ≥ φ(u) and the paths P and P are vertex disjoint except for u˜1 ∈ RXλ ∪ R2 , such that φ(˜ possibly u and u ˜. Dependent set of RXλ ∪R1 ∪R2 ∪· · ·∪Ri is denoted by D(RXλ ∪R1 ∪R2 ∪· · ·∪Ri ) and is recursively Sk defined to be the set of all vertices u ∈ ν=φ(w1 ) V ν such that (i)Ri is wi -merged into R and wi ∈ D(RXλ ∪ R1 ∪ R2 ∪ · · · ∪ Ri−1 ), (ii) there exists a directed path P = (u1 , u2 , . . . , uξ = u), Sk ξ > 1, with u1 ∈ RXλ ∪ R1 ∪ R2 ∪ · · · ∪ Ri , and (iii) there exists a vertex u˜ ∈ ν=φ(w1 ) V ν and a directed path P˜ = (˜ u1 , u ˜2 , . . . , u ˜ι = u ˜), ι > 1, with u ˜1 ∈ RXλ ∪ R1 ∪ R2 ∪ · · · ∪ Ri , such that φ(˜ u) ≥ φ(u) and the paths P and P˜ are vertex disjoint except possibly for u and u˜. Extended form Hij of Fij is the graph arising from Fij by introducing for each edge e = (u, v), where u is a vertex in Fij and v ∈ V l , l ≥ j + 1, a virtual vertex with label v and a virtual edge that connects u and this virtual vertex. Ignored node is a node of a P Q-tree such that its frontier contains only sink indicators. Level graph is a directed acyclic graph G = (V, E, φ) with a mapping φ : V → {1, 2, . . . , k}, k ≥ 1, that partitions the vertex set V as V = V 1 ∪ V 2 ∪ · · · ∪ V k , V j = φ−1 (j), V i ∩ V j = ∅ for i 6= j, such that φ(v) ≥ φ(u) + 1 for each edge (u, v) ∈ E. Merged reduced form is the graph arising from the identification of two virtual vertices vi and vl (labeled v) of two reduced extended forms. Mutual influence of two contacts c1 and c2 appears if ref (c1 ) ∩ ref (c2 ) 6= ∅. Mutual influence of two merge operations B or C is at hand if the corresponding contacts mutually influence each other. Partially reduced extended form is an improper merged reduced form possibly having several virtual vertices with the same label. This form is the result of algorithmic design for achieving linear running time. Primary A reduced extended form Rij that is v-unconnected for all v ∈ V j+1 is called primary. Reduced extended form Rij is the graph that is created from an extended form Hij by identifying all virtual vertices with the same label to a single vertex. Reference points of the contact c(R2 ) are the nodes Iν , Iµ , J1 , Jσ of a reference sequence of the associated merge operation.
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
107
Reference sequence is the sequence of ignored nodes Iν , Iν+1 , . . . , Iµ left of a node Xλ and J1 , J2 , . . . , Jσ right of a node Xλ , where Xλ is subject to a merge operation B or C. The reference sequence describes the two sets of sink indicators of which exactly one set has to be considered for edge augmentation in combination with the merge operation and is associated with the ”smaller” form that has been merged into the larger form. Reference sequence, left is the sequence of ignored nodes Iν , Iν+1 , . . . , Iµ left of a node Xλ where Xλ is subject to a merge operation B or C. Reference sequence, right is the sequence of ignored nodes J1 , J2 , . . . , Jσ right of a node Xλ , where Xλ is subject to a merge operation B or C. Sσ Sµ Reference set is the union i=ν frontier (Ii ) ∪ i=1 frontier (Ji ) of a reference sequence Iν , Iν+1 , . . . , Iµ and J1 , J2 , . . . , Jσ . Related vertex ω(c(R)) of a contact c(R) is the vertex w related to the w-merge operation that introduced contact c(R). Secondary A reduced extended form Rij that is v-connected for at least one v ∈ V j+1 is called secondary. Sink indicator is a leaf denoted by si (v) for keeping the position of a sink v in a P Q-tree. Virtual edge is an edge of a form Hij connecting a vertex of the component Fij that corresponds to Hij and a vertex on a level l ≥ j + 1. Virtual vertex is a vertex of a form Hij on a level l ≥ j + 1. v-connected A form Rij is called v-connected , if any reduced extended form has been v-merged into Rij , v-merged If Rij and Rlj are merged at a vertex v and LL(Rij ) ≤ LL(Rlj ) we say Rlj is v-merged into Rij . The form that is created by v-merging Rlj into Rij and identifying all virtual vertices with the same label w 6= v is again a reduced extended form and denoted by Rij (thus renaming Rij ∪v Rlj with the name of the “higher” form). v-unconnected A form Rij is called v-unconnected if no reduced extended form has been v-merged into Rij .
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
R1 v R2
R1
RXλ
v
1111111111 0000000000 w 0000000000 1111111111 0000000000 1111111111 0000000000 1111111111 0000000000 1111111111 0000000000 1111111111 0000000000 1111111111 0000000000 1111111111
R2
RXλ
1111111111 0000000000 w 0000000000 1111111111 0000000000 1111111111 0000000000 1111111111 0000000000 1111111111 u
(a) Cut vertex v allows a free embedding of RXλ ∪ R2 ∪ D(RXλ ∪ R2 ).
(b) Split pair u, v allows a free embedding of RXλ ∪ R2 ∪ D(RXλ ∪ R2 ).
R1 v R2
v˜
RXλ
1111111111 0000000000 0000000000 1111111111 w 0000000000 1111111111 0000000000 1111111111 0000000000 1111111111 0000000000 1111111111 0000000000 1111111111 u1 000000000 111111111 0000000000 1111111111 000000000 111111111 0000000000 1111111111 000000000 111111111 0000000000 1111111111 000000000 111111111 0000000000 1111111111 000000000u2 u4 111111111
R1
Pˆ Pˆ
u3 (c) Split pair u, v allows a free embedding of R2 .
v
u1 R2
RXλ
111111111111111111111111111 000000000000000000000000000 w 000000000000000000000000000 111111111111111111111111111 u2 000000000000000000000000000 111111111111111111111111111 000000000000000000000000000 111111111111111111111111111 000000000000000000000000000 111111111111111111111111111 (d) Fixed embedding of RXλ ∪ R2 ∪ D(RXλ ∪ R2 ).
Figure 17: The figure illustrates different dependent sets D(RXλ ∪R2 ). The dependent sets are drawn shaded and path Pˆ is drawn grey.
108
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
v˜
RX
P
v R2
RXλ
111111111111111111111111111 000000000000000000000000000 w 000000000000000000000000000 111111111111111111111111111 000000000000000000000000000 111111111111111111111111111 000000000000000000000000000 111111111111111111111111111 000000000000000000000000000 111111111111111111111111111
u
Figure 18: A graph corresponding to the situation where X became a Q-node with one non-ignored child. The embedding of RXλ ∪ R2 ∪ D(RXλ ∪ R2 ) with respect to RX may be chosen freely.
109
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
110
T1
Xλ Xλ−1 I1
Iν−1 Iν
Iµ
111 000 000 111
J1
Jσ Jσ+1
Jρ Xλ+1
w
T2 1111 0000 0000 1111 0000 1111 0000 1111 0000 1111 01 w
(a) ML(Xλ−1 , Xλ ) < LL(T2 ) and ML(Xλ , Xλ+1 ) < LL(T2 ).
T1
Y
I1
Iν−1 Iν
Iµ
Xλ
111 000 T2 111 000 0000 c(R2 ) 111 000 1111 0000 1111 0000 1111 w 1111 0000 1010
J1
Jσ Jσ+1
w
(b) Contact c(R2 ) is added as a child to Y next to the root of T2 .
Figure 19: Adding a contact during the merge operation C.
Jρ
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
111
T1
Y
I1
Iν−1 Iν
Iµ
J1
Jσ Jσ+1
Jρ
c(R2 )
(a) The node Y with the contact c(R2 ) before the application of a template Q2 or Q3.
T1
I1
Iν−1 Iν
Iµ
c(R2 )
J1
Jσ Jσ+1
Jρ
(b) The contact c(R2 ) is adjacent to the ignored node J1 . We chose ref (R2 )right for augmentation.
Figure 20: The identification of the reference set that has to be chosen for augmentation. The dotted lines denote the pointers of c(R2 ) to its reference points.
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
v 1111111 0000000 0000000 1111111 0000000 1111111 R1 0000000 1111111 0000000 1111111 w1
R3
112
1111111111111 0000000000000 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 R2 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 0000000000000 1111111111111 w2
w3
Edges added to w1 forced by R1 Edges added to w2 forced by R2 Edges added to w3 forced by R3 Figure 21: A concatenation of merge operations. First possible embedding of the forms R1 , R2 , and R3 next to RXλ with respect to RX .
11111111111111111 00000000000000000 00000000000000000 11111111111111111 00000000000000000 11111111111111111 00000000000000000 11111111111111111 00000000000000000 11111111111111111 00000000000000000 11111111111111111 00000000000000000 11111111111111111 00000000000000000 11111111111111111 00000000000000000 11111111111111111 00000000000000000 11111111111111111 00000000000000000 v 11111111111111111 00000000000000000 11111111111111111 00000000000000000 11111111111111111 00000000000000000 11111111111111111 00000000000000000 11111111111111111 00000000000000000 11111111111111111 00000000000000000 11111111111111111 00000000000000000 11111111111111111 R2 00000000000000000 11111111111111111 00000000000000000 11111111111111111 00000000000000000 11111111111111111 00000000000000000 11111111111111111 00000000000000000 11111111111111111 w2
1111111 0000000 0000000 1111111 0000000 1111111 R1 0000000 1111111 0000000 1111111
R3
w1
w3
Edges added to w1 forced by R1 Edges added to w2 forced by R2 Edges added to w3 forced by R3 Figure 22: A concatenation of merge operations. Second possible embedding for the forms R1 , R2 , and R3 next to RXλ with respect to RX .
M. J¨ unger, S. Leipert, Level Planar Embedding, JGAA, 6(1) 67–113 (2002)
u1
v 1111111 0000000 0000000 1111111 0000000 1111111 R1 0000000 1111111 0000000 RX 1111111
λ
u01
w1
P0
P uµ
u0ν
Figure 23: Illustration of the proof of Lemma 8.8.
113
Journal of Graph Algorithms and Applications http://www.cs.brown.edu/publications/jgaa/ vol. 6, no. 1, pp. 115–129 (2002)
Embedding Vertices at Points: Few Bends suffice for Planar Graphs Michael Kaufmann
Roland Wiese
Wilhelm-Schickard-Institut f¨ur Informatik Universit¨at T¨ ubingen Sand 13, 72026 T¨ ubingen, Germany
[email protected] [email protected] Abstract The existing literature gives efficient algorithms for mapping trees or less restrictively outerplanar graphs on a given set of points in a plane, so that the edges are drawn planar and as straight lines. We relax the latter requirement and allow very few bends on each edge while considering general plane graphs. Our results show two algorithms for mapping four-connected plane graphs with at most one bend per edge and for mapping general plane graphs with at most two bends per edge. Furthermore we give a point set, where for arbitrary plane graphs it is NP-complete to decide whether there is an mapping such that each edge has at most one bend.
Communicated by H. de Fraysseix and and J. Kratochv´ıl: submitted February 2000; revised May 2001.
M. Kaufmann and R. Wiese, Few Bends, JGAA, 6(1) 115–129 (2002)
1
116
Introduction
The problem of mapping the vertices of a graph to points in the plane has been considered in the past under various objectives depending on the specific applications. This ranges from the band width minimization problem [17, 8] where the points are at unit distance on a line and the objective is to minimize the distance of the points between adjacent vertices to embedding problem of a guest graph onto a host graph [14] under some objectives like dilation, congestion, load, etc. Here we consider a more geometric version of the problem: Originally, the problem was how to map a given tree T of n vertices at a given set of points S in the plane such that the edges can be drawn straightline and without any crossings. Variants of this problem have been explored, either with or without keeping the position of one specific node fixed [16, 12, 2]. Generalizing the graph class, but still using the required straightline planar drawing, Gritzmann et al. [11] gave an elegant divide and conquer scheme to partition the point set and the set of vertices simultaneously. They showed that using this mapping outerplanar graphs can be drawn without any bends. In the consequent papers [3] and [1], efficient implementations have been developed. The latest result in [1] is an O(n · log3 n) time algorithm to find a straightline drawing for such a graph. Astonishingly enough, the case for more general planar graphs has not been considered systematically. It is at exactly this point that we start. Another similar scenario has been recently considered by Pach and Wenger [15]. They assume that the mapping of the vertices to the points is already fixed. The authors prove that O(n) bends per edge are sufficient and that we can not expect to significantly improve the worst case bound for the maximum number of bends per edge. We consider just the first scenario where the mapping of the vertices to the points is not yet fixed. On the other hand, we preserve the given planar embedding of the graph. In the next section, a simple scheme is presented, that provides drawings with at most one bend per edge for a large class of graphs. Next we generalize the technique so that it will work for any planar graph and produces drawings with at most two bends per edge. In section 4, we give a class of graphs and a set of points, where we can prove that there is at least one edge with two bends. Finally, we extend the techniques
M. Kaufmann and R. Wiese, Few Bends, JGAA, 6(1) 115–129 (2002)
117
developed so far to a simple proof to the expected NP-completeness result, namely to decide whether a drawing can be found where each edge has at most one bend. Throughout this paper, we deal with triangulated embedded (plane) graphs, only in the last section do we discuss a more general case. Of course, we always require the drawings to be planar, even if it is not explicitly stated.
2
A basic technique
In this section, we present the basic technique for the mapping and consider the following restriction on the graph. Let G = (V, E) be any plane graph with a hamiltonian cycle C, such that C has at least one edge, say e, on the outer face of G. We call such a property ’external hamiltonicity’ and a corresponding cycle ’external hamiltonian’. We assume the vertices of V to be ordered from v1 to vn as being prescribed by the hamiltonian cycle C. The vertex with the smallest index is chosen such that the edge e is incident to vn and v1 . Let S be any set of points p1 , p2 , ..., pn with pi = (xi , yi ). Assume the plane is rotated in such a way to make the x-coordinates of the points pairwise different. Furthermore assume that the points are ordered with increasing x-coordinates. Now we map the hamiltonian cycle C = (v1 , v2 , . . . , vn , v1 ) to the points p1 , ..., pn , so that the edge e = (vn , v1 ), is assigned in such a way that vn = pn and v1 = p1 . All edges on C with the exception of e can be drawn as a straight line so that they extend monotonically in x-direction. The edge e is drawn from the rightmost point pn to the leftmost point p1 with one bend b located at a place existing very high above all the other points. The idea is to choose the segments of e such that their slopes are the same and they are cone-shaped, c.f. figure 1. The slopes of e is determined by the maximal slope of the straightline edges on the hamiltonian path C − e. This also determines the place where the bend of e is located. More precisely, the slope for a possible straightline segment is computed by σ 0 = maxi |yi+1 − yi |/(xi+1 − xi ). To ensure that the segments of e do not interfere with other segments or points, we have to increase the value σ 0 slightly. In fact, we assign the value σ = 2 · σ 0 as the slope of a line through
M. Kaufmann and R. Wiese, Few Bends, JGAA, 6(1) 115–129 (2002)
118
p1 and −σ should be the slope of another line through pn . The intersection of the two lines gives the position of bend b. The remaining edges are drawn each with exactly one bend such that all the left segments of the edges have the same slope σ and the right segments will have the slope −σ. They will run in parallel. This is more because of aesthetic reasons and to simplify the arguments about avoiding some possible crossings. The edges inside of C are drawn above the polygonal chain C − e, and the edges outside are drawn below. The following case checking proves the planarity of the drawing: Edges inside and outside of C do not cross since they are separated by the polygonal path C − e. We explain the case of two edges e1 and e2 inside of C in more detail. Let e1 = (vi , vl ) and e2 = (vj , vk ). Clearly i ≤ j < k ≤ l holds because of planarity. Now, since the left segments run in parallel and the right segments as well and the four end points occur in that order on the x-monotone polygonal line C − e, there are no crossing segments. The same holds for the edges outside. The slopes for the segments of the edges not in C have been chosen large enough such that edges in C cannot interfere with edges not in C. Note that by this technique, some of the segments adjacent to the same vertex might overlap (cf. the second segments of (p2 , p8 ) and (p3, p8) in Fig. 1). We devise a perturbation scheme that resolves those overlappings: Let be the minimum distance between any two non-overlapping parallel segments, let L be the maximum length of a segment and maxdeg the maximum degree. For each vertex v, we sort the pairwise overlapping adjacent segments according to their length in decreasing order. For each segment s being the i-th overlapping segment adjacent to v, we rotate s by i · L·maxdeg downwards. The new intersection points for the segments give new positions for the bends. This way we ensure that the previously overlapping segments are spread out, and new intersections are avoided since the rotation angles are kept small enough. Theorem 2.1 Let S be an arbitrary set of n points and G be any plane graph with an external hamiltonian cycle and n vertices. Then G can be drawn planar with a mapping of the vertices to the points such that each edge has at most one bend.
M. Kaufmann and R. Wiese, Few Bends, JGAA, 6(1) 115–129 (2002)
6
119
7
4
5
8
9
p7 3 1
p4 p2 2
p5
p1
p8
p9
p6 p3
Figure 1: The basic construction Remarks on the area. Note that the area may be much larger than the area R occupied by the point set. More precisely, let us assume that the minimal enclosing rectangle R is a square of width W and δ is the minimal distance in x-direction between any two points. Clearly, the absolute value of the slope σ of the segments of edge (vn , v1 ) is at most 2 · W/δ. Hence the resulting height is at most 2 · W · W/δ while the width remains the same. This means that if we assume integer-coordinates (δ = 1), we achieve an area of O(W 3) for the drawing. Note that if we would allow 2 bends per edge, we could easily draw the edges in an orthogonal way and keep the area proportional to the area of the convex hull of the point set. In this case, the perturbation scheme does not work anymore and we might have to enlarge the size of the vertices and assign offsets to the adjacent segments. The details are left to the reader.
M. Kaufmann and R. Wiese, Few Bends, JGAA, 6(1) 115–129 (2002)
120
δ
Figure 2: Wasting and saving some area by spending another bend per edge.
3
The general case
In order to apply the technique above we need to find an external hamiltonian cycle, namely a hamiltonian cycle including an edge on the outer face. Testing all possible edges e = (v, w) on the outer face, we could request a hamiltonian path, which is a well-known NP-complete problem even on planar triangulated graphs [6]. On the other hand, we know of a linear-time algorithm to find external hamiltonian cycles by Chiba and Nishizeki [5], if the graph is four-connected. Since the graphs we consider are triangulated, the problematic cases appear if there are separating triangles, namely cycles of length 3 which do not circumscribe single faces. Only such graphs may not contain external hamiltonian cycles. First of all, we give a reduction to the four-connected case which will finally lead to drawings with at most two bends per edge. Then, in the following section we present a small plane graph with only 12 vertices without any external hamiltonian cycle and a point set, and we prove that any planar drawing of this graph on this point set must have at least one edge with 2 bends. This indicates that our simple technique is reasonably good and it will not normally be beaten by other algorithms with respect to the maximal number of bends per edge. Assume G is a plane triangulated graph which is not four-connected. Let e = (v, w) be an edge of any particular separating triangle which clearly
M. Kaufmann and R. Wiese, Few Bends, JGAA, 6(1) 115–129 (2002)
121
exists. Edge e lies adjacent to two triangular faces (v, w, s) and (v, w, t). We destroy those triangles by inserting a dummy vertex z on e, deleting e and connecting z by four new edges to the vertices v, w, s and t. Note that by each single operation, the number of separating triangles decreases and no such triangles are created anew. The dummy vertices z do not appear in any separating triangle. We perform this operation until all separating triangles are destroyed. The separating triangles can be efficiently found by the algorithm of Chiba and Nishizeki [4]. Then the new graph G0 is fourconnected and triangulated. We now apply the basic technique described in the previous section to G0 . The only modification is the handling of the dummy vertices z. Figure 3 gives an example. 1
3
4
5
7 2
1
2 3
4
5
6
7 z1
8
9
10 z2 11 12
1
2 3
4
5
6
7 z1
8
9
10 z2 11 12
6
z1
8 9 10
11 z2
12
Figure 3: An example for the construction of graphs without external hamiltonian cycle. Vertices z1 and z2 are dummies. They arise when destroying the separating triangles. The figures to the right indicate the solutions with three and two bends respectively. Let C 0 be the external hamiltonian cycle as found by the algorithm of Chiba and Nishizeki. Clearly, C 0 visits z, and immediately before and afterwards, it visits two vertices a, b ∈ {v, w, s, t}. We place a new dummy point pz exactly between the points assigned to a and b. Then the graph can be drawn as described above. Finally, we remove the edges (s, z) and (t, z) and join the (at most) two segments of (v, z) and
M. Kaufmann and R. Wiese, Few Bends, JGAA, 6(1) 115–129 (2002)
122
(z, w). This immediately gives a drawing with at most 3 bends per edge, since there is at most one dummy vertex on each edge. Lemma 3.1 Given an arbitrary plane graph with n vertices and a set of n points in the plane. In time O(n log n), we can find a mapping of the vertices to the points, so that the edges can be drawn planar and with at most 3 bends each. Markus Eiglsperger suggested a way of saving one bend (out of three) by drawing some of the segments of the edges vertically. In the third part of Figure 3, we indicate the idea. Lemma 3.2 Given a solution with at most three bends for each edge constructed by the algorithms above, we can modify the drawing so that it remains planar and the maximal number of bends is two. The used area might grow exponentially. Proof: Let P be the designated hamiltonian path along the points p1 , . . . pn such that the edges (pi , pi+1 ) are drawn as a straight line. P induces a partition of the drawing plane into an upper and a lower part. Note that for each edge e with two or three bends there is a dummy vertex de placed on an edge (pi , pi+1 ) where the edge e crosses path P . Following the construction above, it is clear that each edge crosses P once at most, hence the two segments of e incident to the dummy vertex de may be able to be drawn vertically. We discuss now the implications of such operations: We consider just the section in the upper part of the drawing, the lower part is handled analogously. Let e be the edge under consideration with segments s1 and s2 where s2 ends at dummy vertex de . Let α1 and α2 be the angles indicating the slopes of the segments as shown in figure 4. Stretching s1 such that α1 remains the same, the angle α2 increases to 90 and the segment s2 becomes vertical. We will call it s02 now. Planarity is eventually violated if there are some segments s with angle β crossing the cone between s2 and s02 . We can correct this easily by rotating the segment s such that β also increases. This process is iterated if necessary. Obviously it ends after at most m steps since we only proceed from left to right and never backtrack. The proper nesting of the edges (halfedges) in the upper o
M. Kaufmann and R. Wiese, Few Bends, JGAA, 6(1) 115–129 (2002)
s
s02
s2
β
123
s1 α1
α2
de
Figure 4: The configuration before and after rotating segment s2 in vertical position. part of the drawing ensures that for each edge only m rotations are necessary, implying a quadratic running time. Combined with a corresponding process for the lower part we end when the segments incident to any dummy vertices are vertical and the corresponding bend is saved. In the second part of the proof we sketch a situation where the area grows exponentially. The next figure shows two nested edges with corresponding dummy vertices on different sides (left and right). We assume that the slopes are at 45o to start with and the points and bends lie on integer coordinates. When we perform the modifications described above, so that the segments incident to the dummy vertices become vertical, the drawing grows by more than a factor of two. Now assume that we have n/2 of such pairs nested, as indicated in the next figure. Consider the i-th pair from the inside. The drawing of Gi−1 includes an axis-parallel rectangle Ri determined by the length of the vertical segments of the edges from the i − 1-th pair. Next, we see that the two edges from pair i have to circle around this rectangle using only two bends and one vertical segment in the middle. It follows quite easily that the lengths of these segments must be quite large compared to the height of the rectangle Ri−1 and that a new rectangle Ri of height at least twice as large as the height of Ri−1 results. Hence, we can conclude that the height of the drawing grows
M. Kaufmann and R. Wiese, Few Bends, JGAA, 6(1) 115–129 (2002)
124
exponentially, at the very least.
el Gi−1 er i-th pair
Figure 5: The recursive definition of the graph with exponential height. We conclude with a note regarding the runtime. Clearly the first part of the construction works in linear time, since we can use the linear time algorithm of Chiba/Nishizeki [4] to determine the separating triangles. Then the saving of the third bends by rotating some of the segments might cause a quadratic number of steps. Theorem 3.3 Any plane graph can be mapped on any given point set in the plane and can be drawn with at most three bends per edge in linear time and with at most two bends per edge in quadratic time.
4
The lower bound
Next, we show that this bound is optimal in the worst case. Consider the following triangulated graph discussed in the example from figure 3. Although there is a hamiltonian path in G, there is no external hamiltonian path. We try to map G on a set of 12 points with the same y-coordinate Y . This point set has the property that each edge with only one bend must lie completely above or completely below the Y -line. Any edge segment that crosses the Y -line must belong to an at-least-two bend edge. Let x1 , . . . , x12 be the x-coordinates of the points in increasing order. Since the outer face of G is a triangle with vertices a, b, c it is clear that in any one bend drawing {x1 , x12 } ⊂ {xa , xb , xc } (With xa , we mean the xcoordinate vertex a is mapped to). We examine the case where x1 = xc , x12 =
M. Kaufmann and R. Wiese, Few Bends, JGAA, 6(1) 115–129 (2002)
125
a
g
e f h d
b
c
Figure 6: The candidate for the lower bound proof.
c
d
b
h
g
f
e
a
Figure 7: Edge (b, f ) needs two bends in this drawing. xa . Both of the other cases are similar or symmetric. Next we want to draw the outer face. For that we map b to xb , (x1 < xb < x12 ) and draw the outer face edges such that (a, c) bends above the Y -line and (a, b), (b, c) bend below. Next we draw the edges of the triangles b, d, a and b, c, d. W.l.o.g., we map vertex d to xd , (xa < xd < xb ) and draw (a, d), (d, c) with a bend above the Y -line. We draw the edge (d, b) with a bend above the Y -line and show that one edge within triangle {b, d, a} cannot be drawn with only one bend (since {b, c, d} and {b, d, a} are symmetric, we could show the same for {b, c, d} if we would draw edge (d, b) with no bend or a bend below the Y -line). Now we want to draw the edges from d to e, f and h. Since we do not
M. Kaufmann and R. Wiese, Few Bends, JGAA, 6(1) 115–129 (2002)
126
want to change the embedding and edge (d, b) bends above the Y -line, these edges must also bend above the Y -line and the x-coordinates of their end points must obey the order xb < xh < xf < xe < xc . Next we draw the edges from a to e, f and g. Since (d, e) bends above the Y -line the edges (a, f ) and (a, g) must bend below the Y -line. The order of the coordinates is nearly fixed by now: xd < xb < xg , xh < xf < xe < xa . Now we are at a point where we cannot draw edge (b, f ) without letting it cross the Y -line, since (d, h) and (a, g) have their bends in opposite directions. See Figure 7. Theorem 4.1 There is a plane triangulated graph with only 12 vertices such that for every placement of the vertices on a straight line at least one edge must bend at least twice in the resulting drawing.
5
The NP-completeness result
In this section we prove Theorem 5.1 Given any plane graph G with n vertices and n points on a line. The mapping problem of the vertices at the points so that the edges are drawn planar and with at most one bend each is NP-complete. Proof: To show that the 1-bend drawability problem is NP-complete, we reduce it to the hamiltonian cycle problem for plane graphs. First, note that the external-hamiltonian-cycle problem for plane graphs is NP-complete since it can be used to solve the hamiltonian-cycle problem for plane graphs by an iteration over all faces of the embedding. We call a plane graph G = (V, E) (external) hamiltonian-extensible if some edges E 0 can be inserted without destroying the previous planar embedding enabling G0 = (V, E ∪ E 0 ) to become (external) hamiltonian. The problem as to whether a given planar graph G can be made (external) hamiltonian by inserting at most k ≥ 0 edges is clearly NP-complete since its variant with k = 0 is equivalent to the (external) hamiltonian-cycle problem for planar graphs. Let G = (V, E) be a given plane graph. The following argument shows that solutions for the problem to make G (external) hamiltonian-extensible
M. Kaufmann and R. Wiese, Few Bends, JGAA, 6(1) 115–129 (2002)
127
can be converted in polynomial time into a 1-bend drawing for G with a set of points on a straight line and vice versa. If G is external-hamiltonian extensible, we take the corresponding external hamiltonian cycle C and apply our basic technique from section 2 to achieve 1-bend drawings. On the other hand, if G has a mapping M : V → P on the points of the horizontal line L such that a 1-bend drawing D(G) exists, there is clearly no edge which crosses line L. Otherwise, it would bend twice. Let w.l.o.g. M be the mapping such that M(vi ) = pi for i = 1, . . . , n. Hence we can easily extend the embedding of G by edges between any vertex vi and vi+1 for i = 1, . . . , i−1 if necessary. such that this extension completes a hamiltonian path. The last (external) edge between vn and v1 completing the hamiltonian cycle can also be inserted if it does not already exist. This proves the NP-hardness of the drawing problem. From the ‘equivalence’ of the problem to make G (external) hamiltonian and the 1-bend drawability problem for G with a set of points on a straight line we derive that the latter problem is in NP since like the hamiltoneancycle problem, the extensibility problem is in NP.
6
Discussion
One might argue that we are cheating regarding the lower bound example since all points with the same y-coordinate contradict the commonly used assumption of a general position of the points. On the other hand, the scenario seems quite realistic. If the objects (vertices) are required to be arranged in linear order horizontally or vertically, we get exactly the given set of points which we have already proved to be hard. Open problems: 1. Improve the area bounds, especially for the general case. 2. Extend the lower bound proof and the NP-completeness result to a set of points in general position. 3. Note that the complexity of the no-bend variant is still open, although NP-completeness is also conjectured [1].
M. Kaufmann and R. Wiese, Few Bends, JGAA, 6(1) 115–129 (2002)
128
References [1] Bose, P., On Embedding an Outer-Planar Graph in a Point Set, in: G. DiBattista (ed.), Proc. 5th Intern. Symposium on Graph Drawing (GD’97), LNCS 1353, Springer 1998, pp. 25-36. [2] Bose, P., M. McAllister, and J. Snoeyink. Optimal algorithms to embed trees in a point set. Journal of Graph Algorithms and Applications 1998. [3] Castaneda, N. and J. Urrutia., Straight line embeddings of planar graphs on point sets. Proc. 8th Canadian conf. on Comp. Geom., pp. 312-318, 1996. [4] Chiba, N., and T. Nishizeki, Arboricity and subgraph listing algorithms, SIAM J. Comput. 14 (1985), pp. 210–223. [5] Chiba, N., and T. Nishizeki, The hamiltonian cycle problem is linear-time solvable for 4-connected planar graphs, J. Algorithms 10 (1989), pp. 189-211. [6] Chvatal, V., The traveling salesman problem, J. Wiley and Sons, 1985, pp. 426. [7] Di Battista, G., Eades, P., Tamassia R. and I.G. Tollis, Algorithms for Automatic Graph Drawing: An Annotated Bibliography, Brown Univ., Tech. Rep., 1993. [8] Feige, U., Approximation the bandwidth via volume respecting embeddings. Proc. 30th Annual ACM Symp. on Theory of Computing, 1998, pp. 90-99. [9] Garey, M.R., D.S. Johnson, The Rectilinear Steiner Tree Problem is NPcomplete, SIAM J. Appl. Math. 32 (1977), pp. 826-834. [10] Garey, M.R., D.S. Johnson and L. Stockmeyer, Some simplified NP-complete graph problems, Theoret. Comp. Science 1 (1976), pp. 237–267. [11] Gritzmann, P., Mohar, B., Pach, J. and Pollack, R. Embedding a planar triangulation with vertices at specified points. in: American Mathematical Monthly 98 (1991), pp. 165-166. (Solution to problem E3341). [12] Ikebe Y., M. Perles, A. Tamura and S. Tokunaga, The rooted tree embedding problem into points in the plane, Discr. and Comp. Geometry 11 (1994), pp. 51–63. [13] Lengauer, Th., Combinatorial Algorithms for Integrated Circuit Layout, Wiley, 1990.
M. Kaufmann and R. Wiese, Few Bends, JGAA, 6(1) 115–129 (2002) [14] Leighton, F.T., Parallel Algorithms and Architectures: Hypercubes, Morgan Kaufmann, 1992.
129
Arrays-Trees-
[15] Pach J. and R. Wenger, Embedding Planar Graphs at Fixed Vertex Locations, in: Sue Whitesides (ed.), Proc. 6th Intern. Symposium on Graph Drawing (GD’98), LNCS 1547, Springer 1999, pp. 263-274. [16] Pach J. and J. T¨ or¨ ocsik, Layout of rooted trees, in: W.T. Trotter (ed.), Planar Graphs, vol. 9 of DIMACS Series, pages 131-137, 1993. [17] Papadimitriou, Ch., The NP-completeness of the bandwidth minimization problem, Computing, 16(3), 1976, pp. 263–270.
Journal of Graph Algorithms and Applications http://www.cs.brown.edu/publications/jgaa/ vol. 6, no. 2, pp. 131–147 (2002)
Art of Graph Drawing and Art Jaroslav Neˇsetˇril Department of Applied Mathematics and Institute for Theoretical Computer sciences (ITI) Charles University Malostransk´en´ am. 25, 11800 Praha, Czech Republic
[email protected]
Communicated by H. de Fraysseix and and J. Kratochv´ıl: submitted October 2001; revised November 2001.
The Institute for Theoretical Computer sciences (ITI) is supported by Grant LN00A56 from the Czech Ministry of Education.
J. Neˇsetˇril, Art of Graph Drawing and Art , JGAA, 6(2) 131–147 (2002)
1
132
Introduction
Art and Science .... These seems to be key words of many contemporary writings. And scientists certainly are only happy to stress aesthetic qualities of their activity and artists like to justify their endeavor by science and technology. But these connections are very often superficial and often lead only to impatience how superficially without a deeper understanding and insight these connections are treated [7]. Here we want to illustrate some conceptual, or rather spiritual and methodological similarities of doing mathematics and art. We stress the word ‘doing’. ‘Doing’ in the true sense of informed and complex pursuit of actual questions and problems of contemporary art and science. (By ”Science” we mean here Mathematics in general, but also Computer Science and. of course, Graph Drawing; this is a volume devoted to the Drawing of Graphs.) Although both these areas are manifold and extremely diverse, we believe that they share some common qualities and profound similarities. These similarities are best traced by considering together the development and the methods of modern mathematics and modern art. Rather than considering the final products (works of art or theorems) we wish to stress similarities in the modus operandi of artists and mathematicians. We wish to stress that some of these similarities can be traced to all levels and moments of the production of both art and mathematics. And we are convinced that these similarities stem mainly from the idealistic character of both pursuits. But one has to search deep and one has to try to avoid superficial similarities and differences. We would like to rephrase the words Kandinsky used when comparing art and music [18]: In our opinion the similarities of art and mathematics are evident but they lie very deep. In fact, in the realm of true activity guided by inspiration and inspiring awareness there seem to be common features in most human activities. We put this forward as a creative thesis [29] and we return to this at the end of this article. But this article is for Graph Drawing and also there is more here than meets the eye. The prime problem of Graph Drawing is to visualize properly and as accurately as possible the information which is given to us in a confusing, sometimes pictorial and sometimes mathematical, or “technical”, way. This intended visualization should help us to understand, should attract and should explain. It is interesting to note that on such abstract gnoseological level these are the same aspects and problems which are facing an artist when he/she is trying to convey his/her message. Visualization, representation, the reality and its model are the code words. Clearly this is complemented by further aspects which make the whole picture more complicated and stresses the differences of these areas but still the abstract core is similar if not the same. (At this place it is only proper to stress the following: one has to be careful with analogies and parallels. We try to stress only those points which one can see and prove beyond doubts. Otherwise we can easily slip to the level of an essay and unjustified speculations.) This text is based on the article Art of Drawing [28] which in turn is based on an invited talk delivered by the author at GD’99. That lecture was conceived as
J. Neˇsetˇril, Art of Graph Drawing and Art , JGAA, 6(2) 131–147 (2002)
133
a multimedia show with slides, transparencies and CD projection (which operated fluently thanks to Hubert de Fraysseix). These three parts of the lecture, projected on three different screens, were called Samples, Stories and Souveniers. Since then some progress has been made and this lecture has been given in another context. Most notably in March 2001 in the Institute for Art History of the Academy of Sciences of the Czech Republic (thanks to an invitation of Mahulena Neˇslehov´ a) and at E.H.E.S.S., Paris, (thanks to an invitation of Pierre Rosenstiehl). Also on the scientific level a progress (a bit surprisingly) has been made. Recently this author devised an invariant, Combinatorial Entropy, which could serve as a measure of an aesthetic quality of a scheme and this, after several discussions with Michel Mend`es France, was thoroughly tested together with Jan Adamec on a large number of examples from both Art and Graph Drawing. A research article appeared in [2] and led to an article (of a more philosophical contents) in [30]. This text then complements both of these texts and it contains some new complementary material. I thank to the editors H. de Fraysseix and J. Kratochv´ıl for suggestion to include this paper in their volume and for several constructive remarks.
2
Three easy problems
We begin our story by recalling a situation which happens often at IQ (or similar) tests: The person being tested is asked to perform a routine task, task which may be a bit time consuming and which basically tests whether he or she understands a certain notion (i.e., understands under certain mental-time stress). Such a question may read: 1. Draw a curve! 2. Divide a square in two rectangles and two squares! 3. Divide a rectangle into two triangles and two pentagons! Of course the authors (of such tests, if they exist at all) are seeking an easy answer. But sometimes in their own naivete they perhaps do not know that a dog is hidden under carpet. The expected answer to Question 1. is of course some ”easy” picture of a curve. And as the authors of these tests believe, the easier answer mirrors a deeper understanding. But the complicated history of curves and their theory tells us something else. It is hard to tell what a curve is. It is hard to postulate it once for all by means of a self-contained definition (not involving pictures and hand waving) which would nevertheless cover all the variety of shapes of all possible curves. As often happens - a thing which is intuitively clear becomes less clear the more we think about it: A curve may have no derivative (e.g. a sharp peak) at any of its points (Bolzano and Weierstrass), a curve may have an infinite length and yet it may enclose a finite area (Koch and others), a curve may fill the whole plane (Peano and others). Even the notion like the length of a curve is a complicated phenomenon and this question was in fact one of the initial questions which
J. Neˇsetˇril, Art of Graph Drawing and Art , JGAA, 6(2) 131–147 (2002)
134
started the Theory of Fractals [20] and led to the notion of the fractal dimension. If we generalize Euclidean plane and space to n-dimension we always have n an integer (as it depicts the number of coordinates). However measuring curves in a fractal way we arrive at dimensions which are not necessarily integers. So some curves may have, say, dimension 4/3. The concept of fractal dimension goes back to the beginning of this century (Hausdorff and Besicovitch). Much later it recently played key role in theory which became truly part of popular science. With all its beautiful and easily generated pictures (and perhaps, because of this, so often quoted misleadingly in an art-historical context; see e.g. [19]). The fractal theory got mathematics seemingly as close to visual mathematics and even art as possible. As a result of this, the results were popularized, misunderstood and even misused at both ends of the spectrum. On one side these mathematically involved theories with all its interesting visual output are too tempting to the scientific audience and as a result of this they substitute modern art for many. On the other side, the interesting ‘mystical’ vocabulary is too tempting to art historians and critics alike. There is much evidence that this is done freely, too freely, like a new poetic enchanting word machine. (There is a newly emerging new candidate for this: the complexity theory). But the fractal theory is a natural counterpart of our theory and of our definition of Combinatorial Entropy below. Returning to our main theme: so just to define a curve is a highly non-trivial matter and thus an answer to question 1. could be certainly less self-confident. An informed individual would have the right to ask ‘A curve in which sense?’ Admittedly we cannot use this strategy at questions 2. and 3. Here the questions call for a solution (displaying that one knows the meaning of the concepts). And the answer to 3. comes without any effort at the very moment when one gives up (try a flat rectangle and indicate that you give up by crossing it twice!). But both these questions involve the construction of a special pavement or tiling and that is in general both an important and complicated question. A question which can be traced from prehistoric times, through mysticism of the Middle Ages until today. And in its combinatorial refinement this area took several surprising twists. We cannot resist mentioning here the spectacular configuration (non-periodic tiling of the plane using just two building blocks!) due to Penrose which had spectacular influence in as remote areas as algebra, crystallography, molecular chemistry and other areas which had nothing to do with the original intentions. Now, here is one of the pearls of the tiling theory: In 1903 the German mathematician Max Dehn asked a simple, seemingly innocent question: Can one divide a square into a finite number of squares of different sizes? Unlike in the usual picture (a possible answer to the Question 2) where we divide a square into 4 squares all of which are of the same size. Such a partition of the square is called perfect square. Does a perfect square exist? Does a perfect square exist at all? Yes or no? This is one of the beautiful aspects of mathematics, yes or no, there is no other way around. Modern mathematics developed techniques for asking and answering imprecise questions, for relative answers (subject to
J. Neˇsetˇril, Art of Graph Drawing and Art , JGAA, 6(2) 131–147 (2002)
135
various models), for answering and (lying) with certain probability. Yet the categorical yes/no question is still one of the main (and proud) characteristics of the field. The Dehn’s problem appeared to be not so easily solvable and after few decades it was solved independently by A. Sprague(1940) and a group of Cambridge undergraduates: A. Brooks, C. Smith, A. H. Stone and W. Tutte (1940), all of whom later became well known researchers. The affirmative answer was not obtained by an elaborate (and primitive) search, but by a search involving the rudiment of a theory. A series of ingenious reductions and reformulations (involving areas such as flows and electrical networks) made the initial problem accessible. Without this the problem would be too difficult to handle. It is interesting to note that the smallest perfect square is uniquely determined. It presents a division of a square into 21 different squares. One cannot partition a square in less than 21 different squares and there is only one such partition into 21 squares (up to natural transformation such as rotations and flipping). This unique design was sought for several decades and Duijvestijn solution finally came in 1978 (partly with the help of a computer). The uniqueness of this configuration of 21 squares is quite astonishing! It is the conviction of this author that the concentration of hard work and ideas makes from this square tiling a similarly unique object as the sensitivity, experience and (yes) hard work of Mondrian. So perhaps these special qualities justify its inclusion here. Actually, Charles Payan (Grenoble) produced an artistic object based on the Duijvestijn pattern and his object shares similarities with some of the Mondrian’s painting, see [30].
3
Openings
The formal similarities between art and various aspects of mathematics (mostly geometry) are both classical and contemporary. The mysticism of the golden ratio, of the pentagon, of the regular polyhedra and of pythagorean numbers draws fascination of many and this is applied with a lot of effort to the analysis of anything from the principles of life to pyramids and Gothic cathedrals. And this is of course more true for complicated mathematical questions of perspective and vision in general. Particularly the Renaissance connection is usually quoted as the prime time of relevance of mathematics and art. There can be no doubts that mathematics at that time did some good service to art. (If only to help to upgrade artists from mere craftsmen to free artists in the same category as thinkers.) Maybe at this time of confusion and (what some call) art crisis, art intuitively seeks again a helping hand or solid base or whatever name you want to use for outwardly directed trends in recent art. But this is not so simple and traps are waiting on this road. All this will succeed only in the case when the mutual relationship (of mathematics and art) is freed from arbitrariness, superficial analogies and passing comments. Mathematics was always a source (yes, a generator; mathematics is also a logical machine) of complex (for outsiders, mystical) patterns. This is even more
J. Neˇsetˇril, Art of Graph Drawing and Art , JGAA, 6(2) 131–147 (2002)
136
true today than ever. With our understanding of randomness, of deterministic chaos and aided by graphical devices attached to computers, this ‘artistic potential’ of mathematics is growing. It is our conviction that this pattern generation displays mostly formal and superficial similarities to art. This is the case with fractals (mentioned above) and computer graphics in general, with patterns in chip design which resemble both minimalistic works and complex patterns of microbiology and underwater life. These tricks found one of their culminating forms in wonderful commercials and video clips. Complexity of these forms surpasses any expectation and the variety and combination of tools (and energy, and money) is simply amazing. Consider an example from another corner: the work of M.C. Escher displays a dizzying technique and explicitly touches and even anticipates some mathematical problems of tilings (tilings with special symmetries; similar to those we described above). But however intriguing all this may be, we feel that this has no bearing on the mainstream of art, better on the main problems and challenges which art and artists have been solving and are facing and solving today. And in a sense all these forms are based on combinatorially refined byproducts of mathematics and computer science as well.
4
Archaeology of Aesthetic
Consider the following two problems: I. When was the last time that you taught somebody (possibly your own child) how nice this world is and what marvels and beauties it contains? II. When was the last time that men and women were solving the problems how to make a painting, a drawing or a photograph which would depict accurately (and/or romantically, and/or critically, and/or harmoniously) the surrounding world? The answers to these questions seem to be very different. An answer to the first is reflecting (everyday) experience of parents and educators and on the abstract (theoretical) level it was treated in numerous books by various theories. These theories seem to be in (general) agreement with the concrete and mainstream educational praxis. The second question seems to be more complex (and it is also a more abstract problem). Somehow it seems (to many) that this is an old fashioned problem which is the subject of early modernism if not renaissance. Yet we believe that with computers this question gains a new momentum. In this paper we address this problem. Despite the implicit word computer in the title in this paper, we do not address the question of visualization, of picture processing of visual information in the sense of Computer Graphics. The information for us is already processed and typically is of a very simple type such as a drawing (however, not necessarily a technical drawing, it may be also a drawing of an artist). What we would like to decide is how to formalize the fact that a picture (drawing) is harmonious. We mean harmonious in the sense of being aesthetically pleasing. We prefer the word harmonious to aesthetical (which is probably more in common usage)
J. Neˇsetˇril, Art of Graph Drawing and Art , JGAA, 6(2) 131–147 (2002)
137
as an aesthetic feeling is probably highly individual and we cannot have an ambition to define it (or even approach it). The long tradition of art history is convincingly telling us this. We propose an approach which should capture some features of what makes a picture (drawing) harmonious by means of the notion of Combinatorial Entropy. This approach is based on the analysis of curves ([25]) which in turn goes back to Steinhaus and Poincar´e. The hereditary approach which we introduce below may be viewed as an approach dual to Piaget’s analysis of intelligence, see e.g. [33] and compare [30]. Combinatorial Entropy is an invariant with respect to scaling and rotations, and it is a very robust parameter. This is an important feature as a perception of harmony (and of aesthetic pleasure) is a robust feeling. Moreover Combinatorial Entropy can be computed for a large class of drawing and pictures. It is routine to apply it to scanned information and no analytic description is needed. Perhaps this parameter could aid in the hierarchical approach to graph visualization in selecting a particular model which suits the best a given specific context. And as it can be scanned routinely it can be applied to vast data of molecular biology, digital libraries and even museum collections (particularly graphics and drawings) as an easily available descriptor. After these introductory lines let us begin by describing our initial situation in greater detail.
5
On Invariants for Graph Drawing
What makes the following pictures similar and what makes them different? (The substance and the context are important artistic aspects. However we are interested here only in formal similarities of these pictures; one picture is a musical score - a sketch by Jan´ aˇcek [35], the other picture is one of the Moduli - a sketch by Naˇceradsk´ y and the author [31].)
J. Neˇsetˇril, Art of Graph Drawing and Art , JGAA, 6(2) 131–147 (2002)
138
And, very simply, can we distinguish or order in some systematic way the following three figures (graph drawings using a program due to [9])?
The modern version of these questions is not how to teach a gifted and collaborating child what is nice and beautiful. Instead we need to teach an individual which is not collaborating at all and who takes every our information deadly seriously and exploits it to the last bit - a computer. People usually do not react this way (and if so, then only in comedies like [13] or [14]; the fact that these great novels have a military setting is then not an accident). In order to “teach” a computer (and even without ambition for teaching, just dealing with it) we need a precision. And precision in the other words calls for some concrete measures of our phenomena, in the other words for invariants. The purpose of this note is to suggest such an invariant and to document some experiments which we performed. Consequently, the traditional principal problem of aesthetics (and art history) - to explain and to predict artistic and aesthetically pleasing - took recently an unexpected twist. We do not explain and deal with individual instances, we have to classify a vast amount of data and we have to design procedures with likely harmonious output. This problem in its manifold variety is interesting already when our objects are well defined compositions composed from simple building blocks such as lines, squares, sticks,.... This in fact is a familiar exercise and training ground of schools of design and architecture and (traditional) art academies. This illustrates difficulty and variety of solutions even of simple situations. This should be not surprising if we realize how many simple lines needed, say Rembrandt or Picasso, to produce full images (for example drawings; 50 lines or even less!). For our “simple composition from simple building blocks” we would like to create an invariant which would help us to categorize and order these compositions. It is difficult to say even on this simple level what it is an invariant, but we can certainly state which properties such an invariant should have: i. invariant should be an (easy) computable aspect of the structure; ii. invariant should be consistent (or invariant, meaning it should not change)
J. Neˇsetˇril, Art of Graph Drawing and Art , JGAA, 6(2) 131–147 (2002)
139
under chosen modification of structure; iii. invariant should be useful in that it can be used to catalogue, to order (which structure is “better”), to classify, to distinguish. We propose here an invariant - called hereditary combinatorial entropy - to measure an aesthetic quality of a visual data (drawing, scheme, painting, note score, molecular data output and others). This invariant is presented in the next section.
6
Hereditary Combinatorial Entropy of a Drawing
Before defining the invariant we want to specify the rules under which the invariant should remain unchanged. Such rules were specified several times and are folklore in the visualization of scientific results. For example the book [5] lists (in section “Aesthetics”) the following 11 graphic properties (called aesthetics) which are commonly adopted: Crossings, Area, Total Edge Length, Maximal Edge Length, Uniform Edge Length, Total Bends, Maximum Bends, Uniform Bends, Angular Resolution, Aspect Ration and Symmetry. The names of these criteria are self-explanatory and together they form a very good paradigm for drawing of graphs. However most of them are specific for drawings of graphs (or similar structures) and they do not apply generally (for example to artistic drawings or sketches). Yet we believe that the aesthetic quality of visual algorithms should be tested on aesthetically charged objects. This is one of the underlying ideas of our approach. There is another drawback of the above paradigm. In all of these criteria (with exception of angular resolution, where we want to maximize, and symmetry which is a structural property) we are aiming for a minimization (for example we want to minimize the total length of our drawing). That of course means that we have to optimize these criteria (as they are sometimes mutually pointed against each other) and we have to add to our paradigm preferences among them. However as optimization problems these criteria are computationally hard (see [5]). Our approach is different and we believe it could add a new aspect to visualization and analysis of visual data. Let us first specify objects which are relevant to our method: A drawing D is a finite set of curves in Euclidean plane. (As our drawings are man made we assume that the set is finite.) A curve is a continuous image of unit interval in plane (we mean a “nice” image; this is not place for technicalities). A painting can be any image, including photographs. It typically consists of differently colored areas. An engraving is a very special kind of object, since it can be included in the previous two classes. However seeing it as a drawing gives a lot more information.
J. Neˇsetˇril, Art of Graph Drawing and Art , JGAA, 6(2) 131–147 (2002)
140
For an infinite line L and a drawing D denote by i(L, D) the number of intersections of the line L and the drawing D. We define the Combinatorial Entropy Hc (D) of a drawing D as the expected value of i(L, D) where expectation relates to the random selection of line L. Combinatorial Entropy is also called Fractional Length from reasons to be mentioned later, see [1, 2]. By virtue of this definition we note the following: i. The combinatorial entropy Hc (D) is easily evaluated by a random generation of lines; ii. Hc (D) is invariant under transposition and rotation; iii. Hc (D) is invariant under scaling (i.e. “blowing up”). The role of randomness in the art has been discussed e.g. in [25], [26]. These facts make it possible to evaluate (or very accurately to estimate) combinatorial entropy of many drawing schemata, drawings of artists (we systematically tested some of the early works of Picasso [32] and Kandinsky [18] as well some drawings from [31]). We also used the analytical description of tertiary structure of some of the proteins (provided by P. Panˇcoˇska, compare [17]). The software developed in [1] uses standard tools of digital image processing, see [3], [34] and allows to handle a very broad spectrum of examples. Most difficulties are with paintings, because they must be transformed into drawings in order to count number of intersections (several filters are applied on the picture to find its contours, the resulting picture is drawing as we defined it before). Let us state some specific examples: the above Jan´aˇcek score had combinatorial entropy 18.55 which is quite similar to the combinatorial entropy 17.87 of the above drawing of Naˇceradsk´ y and Neˇsetˇril taken from [31]. The three graph drawings depicted above have combinatorial entropy (from left to right) 5.70, 5.37, 6.96.
J. Neˇsetˇril, Art of Graph Drawing and Art , JGAA, 6(2) 131–147 (2002)
141
The method is flexible enough to handle complex drawings and pictures. For example classical prints from J. Verne novels when considered as a dense network of individual lines (no blurring). For example the following picture (due to Roux) [38] which serves as the front illustration of [22] has combinatorial entropy 136.6. As expected (both by the intuition and a few trials) the n × n grid has approximate combinatorial entropy n. (As lattices are given analytically we can perform this experiment for very large n). Many more examples are contained in [1, 2]. What do these numbers mean? What is a significance of the combinatorial entropy of a drawing? The definition of the combinatorial entropy is motivated
J. Neˇsetˇril, Art of Graph Drawing and Art , JGAA, 6(2) 131–147 (2002)
142
by the research done by prof. Michel Mendes France in a series of papers devoted to the analysis of curves, [25]. He defines the temperature T (D) of a curve D by the following formula T (D) = (log
E(i(L, D)) −1 ) E(i(L, D)) − 1
where expectation relates to the random selection of the line L. He related this parameter to entropy, dimension and other parameters which he defined in an analogy to fractal theory, statistical physics and geometric probability and integral geometry. These definitions rest on classical theorems due to Steinhaus [37] (which in turn goes to Poincar´e). One can show that the logHc (D) is a good approximation of the entropy of a curve. Thus the name Combinatorial Entropy for our invariant. By viewing a drawing as a set of curves and thinking of Eulerian trail [22](in each component of the drawing) as a new curve of double length (as we traverse every segment of a drawing twice) we can define the the temperature by the same formula for a more general class of pictures (drawings). For large number of intersections (of a drawing D with a line L) the temperature T (D) is approximately equal to the average value of i(D, L) − 1 = Hc (D) − 1 while the entropy H(D) (in the classical sense) is approximated by the logarithm of the combinatorial entropy Hc (D). It follows (and this is Steinhaus’ theorem) that the combinatorial entropy Hc (D) of a drawing D is approximated by the ratio 2`(D)/c(D) where `(D) denotes the total length of the drawing D and c(D) denotes the length of circumference of the (convex closure) of D. (This suggests the alternative name fractional length, see [30] for details.) Based on these interpretations Hc (D) measures the information content and the amount of work which the artist (explicitly) put into his drawing. On the other hand, by comparing various drawings of the same object (or theme) the lower Hc (D) indicates the elegance and simplicity of the output. However as such the combinatorial entropy captures only the global properties of the drawing (expressed by the total length of the drawing and the circumference). Still, via the average number of intersections it captures, implicitly, many properties of the drawing. In [30] we also proposed a technique (based on the algebraic structure cogroup ) to generate harmonious objects. In our setting this can be formulated as follows: Hereditary Combinatorial Entropy Thesis A harmonious (or aesthetically pleasing) drawing or design has combinatorial entropy in each of its (meaningful) parts proportional to the global combinatorial entropy. Here a meaningful part is a part which reflects the properties of D. For the following (author) drawing (of our institute in Prague)
J. Neˇsetˇril, Art of Graph Drawing and Art , JGAA, 6(2) 131–147 (2002)
143
we found the following distribution of combinatorial entropies (this is based on the regular partition of the square into smaller squares; the combinatorial entropy of the drawing restricted to a particular subsquare is listed in the middle of the subsquare):
J. Neˇsetˇril, Art of Graph Drawing and Art , JGAA, 6(2) 131–147 (2002)
7
144
Constructible World
The spiritual contents of art is growing. More and more an artistic object is an act, quoting Damisch, a move of the mind. A painter thinks and he/she does so through and in his/her painting, just in the same way as a mathematician thinks and he/she does so through his/her results: definitions, theorems, proofs. We do not have here in mind only conceptual art and the like, we think of art generally. And this is not a revolution. Only the dust of time, misinterpretations of history and the pride of contemporaries covered all the bold moves (how fitting a word in this context) of old masters. Let us summarize: Our intention in this short paper has been to draw some parallels between art and mathematics mainly from the creative point of view. We have tried to stress some similarities. [28, 29, 30] contains some more and perhaps more complete material. The interested reader probably knows many other examples of such similarities from his/her experience. Is the existence of such similarities just a coincidence? We do not know. Let us end this note in a highly speculative way: In mathematics there is a principle called ‘Church thesis’ which in essence claims that every (intuitive) algorithmic procedure takes a particular form, a form expressed by (any) universal computing machine. Maybe something like Church’s thesis holds in general for human activities. Let us try to formulate this thesis as follows:
J. Neˇsetˇril, Art of Graph Drawing and Art , JGAA, 6(2) 131–147 (2002)
145
Creative Thesis( [29]) All sufficiently deep human activities, all sufficiently deep understandings, have profound similarities. This is exhibited in the way the work (knowledge) is organized, in the way it is revealed and in the way it interacts with other activities. Admittedly this is too vague. But this one has to expect at such a level of generality. Perhaps one should interpret the thesis positively. How often are stressed only the conflicting features of artistic and scientific communities, say, along the lines of feelings and sensibilities as opposed to mind and brain activities. We feel that these views are often superficial and isolationist, and sometimes simply an overreaction. On the other hand there is a numerous supporting evidence and two such examples were considered in [29]: sketches or sketching and minimalistic trends. By the same token it is difficult to find a counterexample to the thesis. Mathematics, in particular, is a rich generator of complex patterns and as such it is often used (above we mentioned some examples). So it will be difficult to break the mathematical trap -everything goes, everything is possible. There is no doubt that the new means of technology and guided by math- and computerdevices will lead to new art form. But it is a conviction of this author that to break the trap of uniformity and unbelievable combinatorial variety of technology will require some profound and probably not yet discovered ideas. And this is probably the realm of scientists and artists, maybe for the first time since the Renaissance. We do not know yet. But we have to try...
J. Neˇsetˇril, Art of Graph Drawing and Art , JGAA, 6(2) 131–147 (2002)
146
References [1] J. Adamec. Kreslen´ı graf˚ u. Diploma thesis, Charles University, Prague (2001). [2] J. Adamec, and J. Neˇsetˇril. An Aesthetic Invariant for Graph Drawing. In: Proceedings of Graph Drawing 2001, LNCS, Springer Verlag 2001. [3] G. A. Baxes. Digital Image Processing. Principles and Applications, Wiley, 1994. [4] G. D. Birkhoff. Aesthetic Measure. Harvard University Press, Cambridge, Mass. 1933. [5] G. Di Battista, P. Eades, R. Tamassia, and I. G. Tollis. Graph Drawing. Algorithms for the Visualization of Graphs. Prentice Hall 1999. [6] T. J. Clark. Modernism–a farewell to an idea. Yale Univ. Press, 2000. [7] H. Damisch. The Origins of Perspective. MIT Press 1994, original French edition Flamarion 1987. [8] H. Damisch. Le travail de l’art: vers une topologie de la couleur? In: [31]. [9] H. de Fraysseix. Graph Drawing SW (personal communication). [10] T. de Duve. Kant after Duchamp. MIT Press 1998. [11] R. J. Gardner. Geometric Tomography. Notices AMS, 42, 4 (1995), 422– 429. [12] B. Gr¨ unbaum, and I. Steward. Tilings and patterns. W.H. Freeman, 1986. ˇ [13] J. Haˇsek. Osudy dobr´eho voj´ aka Svejka. 1920 (in English: The Good Soldier Schweik ). [14] J. Heller. Catch–22. 1961. [15] D. Hilbert. Grundlagen der Geometrie. Teubner 1934 [16] A. Edelman, and E. Kostlan. How many zeros of a random polynomial are real? Bull. Amer. Math. Soc. 32, 1 (1995), 1–37. [17] V. Janota, J. Neˇsetˇril, and P. Panˇcoˇska. Spectra Graphs and Proteins. Towards Understanding of Protein Folding. In: Contemporary Trends in Discrete Mathematics, AMS, DIMACS Series 49, 1999, pp. 237–255. [18] W. Kandinsky. Point and Line to Plane. Dover Publications 1979. [19] S. Kol´ıbal. Retrospektiva. N´ arodn´ı Galerie, Praha 1997 [20] B. Mandelbrot. Les Objects Fractals Flammarion 1975, 1984, 1989, 1995.
J. Neˇsetˇril, Art of Graph Drawing and Art , JGAA, 6(2) 131–147 (2002)
147
[21] J. Mandelbrojt, and P. Mounoud. On the Relevance of Piaget’s Theory to the Visual Arts. Leonardo 4 (1971), 155–158. [22] J. Matouˇsek, and J. Neˇsetˇril. Invitation to Discrete Mathematics. Oxford Univ. Press 1998. [23] K. Mehlhorn, and S. Naher. LEDA–A platform for combinatorial and geometric computing. Cambridge Univ. Press, 1999. [24] M. Mend`es France, and A. H´enaut. Art, Therefore Entropy. Leonardo, 27, 3 (1994), 219–221. [25] M. Mend`es France. The Planck Constant of a Curve. In: Fractal Geometry and Analysis (J. B´elair, S. Dubuc, eds.) Kluwer Acad. Publ. 1991, pp. 325– 366. [26] M. Mend`es France, and J. Neˇsetˇril. Fragments of a Dialogue. KAM Series 95–303, Charles University Prague (a Czech translation in Atelier 1997). [27] A. I. Miller. Insight of genius. Springer Verlag, 1966. [28] J. Neˇsetˇril. The Art of Drawing. In: Graph Drawing (ed. J. Kratochv´ıl), Springer Verlag,1999 [29] J. Neˇsetˇril. Mathematics and Art. From The Logical Point of View, 2, 2/93 (1994), 50–72. [30] J. Neˇsetˇril. Aesthetic for Computers or How to Measure a Harmony. To appear in Visual Mind (ed. M. Emmer), MIT Press. [31] J. Naˇceradsk´ y, and J. Neˇsetˇril. Antropogeometrie I, II (Czech and English). Rabas Gallery, Rakovn´ık, 1998 (ISBN 80-85868-25-3). [32] P. Picasso. Picasso–Der Zeichner 1893–1929. Diogenes, 1982. [33] J. Piaget. Logique et connaissance scientifique, Gallimard. Paris, 1967. [34] W. K. Pratt. Digital Image Processing. Wiley, 1978. ˇ edroˇ [35] M. Stˇ n. Leoˇs Jan´ aˇcek and Music of 20. Century. Nauma, Brno, 1998 (in Czech). [36] L. A. Santal´ o. Integral geometry and geometric probability. Addison Wesley 1976. [37] H. Steinhaus. Length, shape and area. Colloq. Math. 3 (1954), 1–13. [38] J. Verne. Sans Dessus Dessous. J. Het zel (Paris), 1889. [39] H. Weyl. Invariants. Duke Math. J. 5 (1939).
Journal of Graph Algorithms and Applications http://www.cs.brown.edu/publications/jgaa/ vol. 6, no. 1, pp. 149–153 (2002)
Realization of Posets Patrice Ossona de Mendez CNRS UMR 8557 E.H.E.S.S. 54 Bd Raspail, 75006 Paris, France http://www.ehess.fr/centres/cams/person/pom/index.html
[email protected] Abstract. We prove a very general representation theorem for posets and, as a corollary, deduce that any abstract simplicial complex has a geometric realization in the Euclidean space of dimension dim P (∆) − 1, where dim P (∆) is the Dushnik-Miller dimension of the face order of ∆.
Communicated by H. de Fraysseix and and J. Kratochv´ıl: submitted May 2000; revised July 2001.
P. Ossona de Mendez, Realization of Posets, JGAA, 6(1) 149–153 (2002)
1
150
Introduction
Schnyder proved in [3] that a graph is planar if and only if its incidence poset (that is: the poset where x < y iff x is a vertex, y is an edge and y is incident to x) has dimension at most 3. That an incidence poset has dimension at most 3 implies that the corresponding graph is planar has been extended to abstract simplicial complexes in [2]: if the face order of an abstract simplicial complex ∆ is bounded by d + 1, then ∆ has a geometric realization in Rd . We prove here a more general result on poset representation which implies this last result straightforwardly. We shall first recall some basic definitions from poset theory: A partially ordered set (or poset) P is a pair (X, P ) where X is a set and P a reflexive, antisymmetric, and transitive binary relation on X. A poset is P = (X, P ) is finite if its ground set X is finite. We shall write x ≤ y in P or x ≤P y if (x, y) ∈ P . Two elements x, y ∈ X such that x ≤ y in P or y ≤ x in P are said to be comparable;otherwise, they are said to be incomparable. If P and Q are partial orders on the same set X, Q is said to be an extension of P if x ≤ y in P implies x ≤ y in Q, for all x, y ∈ X. If Q is a linear order (that is: a partial order in which every pair of elements are comparable) then it is a linear extension of P . The dimension dim P of P = (X, P ) is the least positive integer t for which there T exists Tt a family R = (<1 , <2 , . . . ,
2
The Poset Representation Theorem
Definition 2.1 Let P = (X, P ) be a finite poset, n an integer and f : X 7→ Rn a mapping from X to the n-dimensional space Rn . Then f is said to have the separation property for P if, for any A, B ⊆ X, there exists a hyperplane of Rn which separates the points of f (Inf(A) \ Inf(B)) and the ones of f (Inf(B) \ Inf(A)), where Inf(Z) = {x ∈ X, ∀z ∈ Z, x ≤P z} for any Z ⊆ X. Theorem 2.1 Let P = (X, P ) be a finite poset and let d = dim P be its dimension. Then, there exists a function f : X 7→ Rd−1 , which satisfies the separation property for P. Proof: Let R = {<1 , . . . ,
P. Ossona de Mendez, Realization of Posets, JGAA, 6(1) 149–153 (2002)
151
functions from X to ]1; +∞[, each Fi being fast increasing with respect to
On one hand, for any z ∈ Inf(B)\Inf(A), there exists a ∈ A and 1 ≤ i0 ≤ d, with z >i0 a. Then, we get Fi0 (z) > d.Fi0 (a). As min(B,
i0 min(A, d. On the other hand, for any z ∈ Inf(A), we have Fi (z) ≤ Fi (a) for every i ∈ [d] and every a ∈ A. Thus, LA,B (F (z)) ≤ d. Altogether, for any A, B ⊆ X such that none is included in the other, the hyperplane HA,B with equation LA,B (π) − LB,A (π) = 0 separates the points from F (Inf(B) \ Inf(A)) (for which LA,B (F (z)) > d ≥ LB,A (F (z))) and those from F (Inf(A)\ Inf(B)) (for which LA,B (F (z)) ≤ d < LB,A (F (z))). Notice that the origin O belongs to all the so-constructed hyperplanes. P Now, consider a hyperplane H0 with equation 1≤i≤d πi = 1, which separates the origin O and the set of the images of X by F . To each element z of X, we associate the point f (z) of H0 which is the intersection of H0 with the line (O, F (z)). Now, for any A, B ⊆ X (such that none is included in the other), as HA,B includes O, the hyperplane HA,B ∩H0 of H0 separates the points from F (Inf(B)\ Inf(A)) and those from F (Inf(A) \ Inf (B). As H0 ' Rd−1 and as the separation property would be obviously true if A ⊆ B or conversely, the theorem follows. 2 The preceding theorem is sharp, as proved here using the standard example Sn of poset of dimension n (introduced in [1]): Theorem 2.2 For any n ≥ 3, there exists no function f : [n] 7→ Rn−2 which satisfies the separation property for the standard example Sn of poset of dimension n, which is the height two poset on {a1 , . . . , an , b1 , . . . , bn }, with minima {a1 , . . . , an }, maxima {b1 , . . . , bn } and such that ∀i, j, (ai < bj ) ⇐⇒ (i 6= j). Proof: Assume there exists a function f : {a1 , . . . , an , b1 , . . . , bn } 7→ Rn−2 having the separation property for Sn . According to Radon’s lemma, for any family of n point in Rn−2 , there exists a bipartition V, W of them, such that the convex hulls of V and W intersects and thus such that V and W cannot be separated by an hyperplane of Rn−2 . Let A = {bi , f (ai ) 6∈ V } and B = {bi , f (ai ) 6∈ W }. Then, V ⊆ f (Inf(A)) and W ⊆ f (Inf(B)). Hence, the separation property fails for A, B. 2
P. Ossona de Mendez, Realization of Posets, JGAA, 6(1) 149–153 (2002)
152
From Theorem 2.1, one derives a sufficient condition for a graph to be planar, which is that its incidence poset shall be of dimension at most 3 and this condition is actually also a necessary condition: Theorem 2.3 (Schnyder [3]) The incidence poset Incid(G) of a graph G has dimension at most 3 if and only if G is planar, that is: if and only if there exists a mapping f from V (G) ∪ E(G) to R2 having the separation property for Incid(G). 2
3
Applications
Corollary 3.1 Let U be a finite set, and F a family of subsets of U such that: ∀x, y ∈ U, ∃X ∈ F,
x ∈ X and y 6∈ X.
(1)
Let d be the Dushnik-Miller dimension of the inclusion order ⊂F on F . Then, there exists a function f : U 7→ Rd−1 such that (denoting f (A) the set {f (z), z ∈ A}, for A ⊆ U ): ∀X ∈ F, ∀X 6= Y ∈ F,
Conv(f (X)) ∩ f (U ) = f (X),
(2)
Conv(f (X \ Y )) ∩ Conv(f (Y \ X)) = ∅.
(3)
Proof: Equation (3) is a direct consequence of Theorem 2.1. For (2), consider successively all the elements z 6∈ X: According to (1), the intersection of all the sets in F including z does not intersect X. Hence, setting A = {X} and B = {Y ∈ F, z ∈ Y }, it follows from Theorem 2.1 that z does not belong to Conv(f (X)). 2 An abstract simplicial complex ∆ is a family of finite sets such that any subset of a set in ∆ belongs to ∆: ∀X ∈ ∆, ∀Y ⊂ X, Y ∈ ∆. The face order of ∆ is the partial ordering of the elements of ∆ by ⊆. S A geometric realization of ∆ is an injective mapping f of the ground set |∆| = X∈∆ X to some Euclidean space Rd , such that, for any two elements (or faces) X, Y of ∆, the convex hulls of the images of X and Y have the convex hull of the image of X ∩ Y as their intersection: Conv(f (X)) ∩ Conv(f (Y )) = Conv(f (X ∩ Y )). It is a folklore lemma that a mapping from |∆| to Rd is a geometric realization of ∆ if and only if disjoints faces of ∆ are mapped to point sets with disjoint convex hulls. It is well known that an abstract simplicial complex has a geometric realization in Rd when d > 2(maxX∈∆ |X|− 1) and that, obviously, it has no geometric realization in Rd if d < maxX∈∆ |X| − 1. Theorem 3.2 (Ossona de Mendez [2]) Let ∆ be an abstract simplicial complex, and let d be the dimension of the face order of ∆. Then, ∆ has a geometric realization in Rd−1 . Proof: Consider the mapping from the ground set |∆| of ∆ to Rd−1 , whose existence is ensured by Corollary 3.1. Then, for any disjoint faces F, F 0 of ∆, we get Conv(f (F ))∩Conv(f (F 0 )) = ∅, that is: f induces a geometric realization 2 of ∆ in Rd−1 .
P. Ossona de Mendez, Realization of Posets, JGAA, 6(1) 149–153 (2002)
153
References [1] B. Dushnik and E.W. Miller, Partially ordered sets, Amer. J. Math. 63 (1941), 600–610. [2] P. Ossona de Mendez, Geometric realization of simplicial complexes, Graph Drawing (J. Kratochvil, ed.), Lecture Notes in Computer Science, vol. 1731, Springer, 1999, pp. 323–332. [3] W. Schnyder, Planar graphs and poset dimension, Order 5 (1989), 323–343. [4] W.T. Trotter, Combinatorics and partially ordered sets: Dimension theory, John Hopkins series in the mathematical sciences, Johns Hopkins University Press, London, 1992.
Journal of Graph Algorithms and Applications http://www.cs.brown.edu/publications/jgaa/ vol. 6, no. 2, pp. 157–173 (2002)
Traversing Directed Eulerian Mazes S. Bhatt Akamai Technologies 500 Tech Square, Cambridge MA 02139 [email protected]
S. Even Computer Sci. Dept., Technion – Israel Inst. of Tech. Haifa, Israel [email protected]
D. Greenberg Center for Computing Science Bowie, MD [email protected]
R. Tayar Computer Sci. Dept., Technion – Israel Inst. of Tech. Haifa, Israel [email protected] Abstract The paper describes two algorithms for threading unknown, finite directed Eulerian mazes. Each of these algorithms is performed by a traveling robot whose control is a finite-state automaton. It is assumed that each vertex has a circular list of its outgoing edges. The items of this list are called exits. Each of the algorithms puts in one of the exits of each vertex a scan pebble. These pebbles can be used by a simple robot as traffic signals, which allow it to traverse an Eulerian cycle of the maze. For a directed graph (maze) G(V, E), the simple algorithm performs O(|V | · |E|) edge traversals, while the advanced algorithm traverses every edge three times. Let dout (v) be the out-degree of vertex v. The algorithms use, at each vertex v, a local memory of size O(log dout (v)). Communicated by S. Khuller: submitted January 2002; revised June 2002
Work by S. Even supported by the Fund for the Promotion of Research at the Technion.
S. Bhatt et al., Traversing Eulerian Mazes, JGAA, 6(2) 157–173 (2002)
1
158
Introduction and Model
The question of how best to traverse an unknown maze, given only local knowledge, has been long studied. [8, 3, 5, 7, 6, 1, 4, 2]. Without the ability to store some knowledge about the maze the searcher can easily become trapped in cycles. In this paper we consider the case of directed Eulerian mazes/graphs, and show that a finite state automaton, with access to some local memory stored in the vertices, can find an Eulerian cycle. During the search for this cycle, each edge is traversed three times. It is assumed that each vertex has a circular list of its outgoing edges. The items of this list are called exits. The challenge is to use only as simple a “robot,” R, as possible. R has a finite automaton control and a few external actions. The external actions affect the external state which consists of the following: • The vertex in which R is at, and more specifically, the exit at which R is at. • For every vertex v, the location of some small constant number of pebbles at exits of v, and the value of a constant number of flags’ bits at v. Let dout (v) be the out-degree of v. The external actions allow R to access O(log dout (v)) bits of information, stored at v. Note that R’s memory may not be sufficient to store all these bits at any one time, since no bound on dout (v) is assumed. The robot R can perform two essential movement actions: • R can traverse an edge from its beginning, which is an exit of the vertex it is at, to its end, to enter another (the same, in case of a self-loop) vertex. • R can move from the exit it is at to the next/previous exit in the cyclic order of the exits of the vertex it is at. Also, R can perform two pebbling actions: • R can observe if a pebble of a specified type is located at the exit R is at. • R can put/remove any pebble at/from the exit it is at. Finally, R can perform two flagging actions: • R can observe whether a certain flag is turned on at the vertex R is at. • R can turn on/off a certain flag at the vertex R is at. For simplicity we will often use compound actions such as traverse the edge with the scan pebble which are straightforward finite automata functions of the basic actions. The problem considered in this paper can now be restated as follows: Design a robot R so that when it is placed at any vertex of any directed Eulerian finite
S. Bhatt et al., Traversing Eulerian Mazes, JGAA, 6(2) 157–173 (2002)
159
graph, with any cyclic ordering of the exits of each vertex, R will eventually halt, leaving a scan pebble at one exit of each vertex. These scan pebbles serve as traffic signals for a simple scanning robot. Using these pebbles, and moving them as it goes along, this robot will traverse an Eulerian cycle, will halt, and when it does, the scan pebbles will be exactly where they have been when the simple robot started this traversal.
2
History of Maze Traversal
In 1967, Michael Rabin [8] considered the problem of threading undirected connected graphs by means of a finite automaton which has some fixed number of pebbles it can leave at vertices and which it can move from one vertex to another. Note that by threading we mean visiting every vertex, at least once. He proved that no such automaton can thread all finite undirected graphs. It follows that no finite automaton can thread all finite, connected graphs, unless some unbounded information can be stored in the vertices. In view of this impossibility result, it is no wonder that the classical (19-th century) algorithms for threading undirected mazes, such as that of Tr´emaux’s and Tarry’s (see, for example Even’s book [5], Chapter 3) store data in the vertices. More about threading undirected mazes can be found in the book of Hemmerling [7]. However, these algorithms are not easy to implement on directed graphs due to the fact that backtracking along edges is no longer allowed. Notice that every connected undirected graph can be transformed to a directed Eulerian graph by replacing every edge u—v with two directed edges u −→ v and v −→ u. Thus, the impossibility result for threading undirected graphs implies the impossibility of threading for directed Eulerian graphs. This, in turn, proves the impossibility of finding an Euler cycle in Eulerian directed graphs. Therefore, in order to thread all finite directed Eulerian graphs, it is natural to allow our robot, R, to store and use some information in the vertices. Even, Litman and Winkler [6] presented an algorithm of time complexity O(|V |2 ) to thread directed networks. However, their algorithm assumes a different computational model — each vertex is a finite automaton and the directed edges are communication links. Afek and Gafni [1] present a fairly complicated solution which uses essentially Depth-First Search (like Tr´emaux’s algorithm), and includes a method to effectively backtrack on directed edges. Their method uses O(|V | · |E| + |V |2 · log |V |) edge traversals, and requires that vertices are labeled with distinct names. We shall later say more about the comparison of our results with those of Afek and Gafni. Deng and Papadimitriou [4] also use a more powerful model than we do. Their purpose is to explore the graph; i.e. to discover its structure. They assume that vertices have distinct identities and that the robot is a general purpose computer (Turing equivalent). They describe a recursive algorithm which finds an Eulerian cycle in a directed Eulerian graph. This algorithm traverses each edge twice. They build on this algorithm to attack the problem
S. Bhatt et al., Traversing Eulerian Mazes, JGAA, 6(2) 157–173 (2002)
160
of exploring general strongly connected directed graphs. (See, also, Albers and Henzinger [2].)
3
Overview of the Robot Algorithms
Let G(V, E) be a finite Eulerian directed graph. Namely, G’s underlying undirected graph is connected, and for every vertex v ∈ V , din (v) = dout (v), i.e., its indegree is equal to its outdegree. Euler’s Theorem implies that G has a directed cycle in which every edge of G appears exactly once. Since din (v) = dout (v) we shall simply use d(v) to denote dout (v).
3.1
The Simple Algorithm
Without any pebbles the robot, R, might be doomed to pick the same exit every time it visited a vertex. In this algorithm, R uses a scan pebble to “remember” which is the next exit to be taken. At each vertex, R moves to the exit with the pebble, call it Ep , places the pebble at the next exit, returns to Ep , and traverses that edge. As we will show below, the repetition of this simple “move pebble forward before traverse” alone will eventually establishes an Eulerian tour, i.e., after wandering for a while, R will traverse an Eulerian cycle, and repeat it, indefinitely, unless some mechanism causes it to halt. Afek and Gafni [1] used a similar idea in their Traversal-1 algorithm. We use a different halting mechanism (employing a two bits flag at each vertex and using a single bit of internal state of R,) and take advantage of the fact that our graphs are assumed to be Eulerian, while they assumed only strong connectivity. We will show that this Simple algorithm makes O(|V | · |E|) edge traversals before it halts, using our halting rule. Afek and Gafni [1] show that their scanning method is existentially optimal, that is, that there exists a family of (non-Eulerian) directed graphs which require Ω(|V | · |E|) edge traversals. However, as is shown in the Appendix, there are dense (Eulerian) graphs for which any Depth-First Search approach, including that of Afek and Gafni, takes Ω(|V | · |E|) = Ω(|V |3 ) edge traversals, while our variant takes O(|V |2 ).
3.2
The Advanced Algorithm
To prepare for our second robot algorithm we first describe an algorithm which does not meet our traveling robot model. We first prove the validity of this algorithm and later show that we can return to our model and preserve the validity. The algorithm consists of two phases. The first phase, called preparatory, is nondeterministic. It concludes by placing a scan pebble at one exit of each vertex, thus, in fact, having found an Eulerian tour. The second phase, called stroll, can then execute the simple traveling robot algorithm to trace an Eulerian
S. Bhatt et al., Traversing Eulerian Mazes, JGAA, 6(2) 157–173 (2002)
161
cycle. When it halts the pebbles are back where the preparatory phase had placed them. Finally, our Advanced Algorithm replaces the nondeterministic preparatory phase with a traveling robot sub-algorithm. The new preparatory phase requires two more pebbles per vertex and two additional 3-value variables in each vertex. Including both its phases, the Advanced Algorithm traverses each edge 3 times.
3.3
The Recursive Algorithm
It is worth noting that the Recursive Algorithm of Deng and Papadimitriou can also be performed by a traveling finite robot. However, the required memory in each vertex v is Θ(d(v) · log d(v)). If the robot is “input aware”, (i.e. when a vertex is entered the output edge is a constant 1-1 function of the input edge,) then the Recursive algorithm need scan every edge only twice. Without input awareness, each edge is scanned exactly 3 times. This was shown by Tayar [9]. Finally, we note that while each of the three algorithms (Simple, Advanced and Recursive) produces an Eulerian cycle, they may produce different cycles (e.g. when applied to the maze shown in Figure 1.)
4
The Simple Algorithm
4.1
The Algorithm
The traversal of the graph is to be performed by a finite-state robot R. The algorithm which governs the behavior of R consists of two mechanisms: The scanning mechanism, which determines the order in which the edges are traversed, and the halting mechanism. 4.1.1
The Scanning Mechanism
In each vertex v there is a scan pebble, initially placed at some arbitrary exit. Each time the robot enters a vertex it finds the scan pebble, moves it forward one position, and exits through the edge where the scan pebble has been. Clearly, the scanning continues indefinitely, unless the halting mechanism stops it. 4.1.2
The Halting Mechanism
For the purpose of deciding when R stops scanning, vertices and exits are marked as follows: • Each vertex has a root flag r. Initially r = 0 at all vertices. The first action by the robot is to mark its initial vertex flag r = 1. Thereafter, no vertex has its r flag changed. • Each vertex also has a status flag, s, which is initially marked NEW. On first visiting a vertex the robot changes s to SEEN. Eventually, the
S. Bhatt et al., Traversing Eulerian Mazes, JGAA, 6(2) 157–173 (2002)
162
robot will change each s flag to DONE and thereafter leave it unchanged. Also, on the first visit the robot finds the exit in which the scan pebble is located and puts the start pebble at the same exit. The start pebble is not moved anymore. It helps determine if all exists have been used to leave the vertex. In addition, the robot carries a state bit F . This bit may be U P or DOW N . The initial value of F is DOW N . The meaning of F = U P is that on the present ”phase”, to be defined shortly, all vertices, it has encountered so far, have had all their outgoing edges traversed, at least once. The actions of the robot under the Simple Algorithm are given in Table 1. Lines 3, 5, 7 and 20 perform the scanning mechanism. Lines 1-2, 4, 8-16 and 18-19 perform the halting mechanism. Line 17 defines the end of a phase. The phases are only defined to simplify the proof. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
r←1 s ← SEEN goto exit with scan pebble put start edge pebble at exit move scan pebble to next exit and leave vertex through current exit while TRUE goto exit with scan pebble if s = N EW then do put start edge pebble at exit s ← SEEN if r = 0 then do if s 6= DON E then do F ← DOW N if start edge pebble at next exit then s ← DON E if r = 1 and exit has the start edge pebble then do (end of phase) if F = U P then HALT F ← UP move scan pebble to next exit and leave vertex through current exit
Table 1: The Simple Algorithm
4.2
Validity
The vertex where r = 1 is called the root ρ. Theorem 1 The robot R will halt at the root, ρ, after having traversed all edges of G. This will happen within O(|V | · |E|) edge traversals. In its last |E| edge traversals R makes an Eulerian tour.
S. Bhatt et al., Traversing Eulerian Mazes, JGAA, 6(2) 157–173 (2002)
163
Note that upon termination the scan pebbles are not necessarily back in their initial condition. In fact, their position is exactly what has been “learned”. If now the traversal is restarted, with F = U P , R will perform an Eulerian tour and stop, and the scan pebbles will again be in the “learned” position. Proof: Note the definition of a phase, as in Table 1, Line 17. First, let us examine the route of R during the first phase. Clearly, every edge incident with ρ has been traversed exactly once. Furthermore, every edge on the route of the first phase is traversed once only. This is easily proved by induction on the order in which the edges are traversed: When a vertex v 6= r is entered by an edge (traversed for the first time) the number of used incoming edges is one greater than the number of used outgoing edges. Thus, the exit in which the pebble is placed leads to an edge which has not yet been traversed. Note that if during the first phase every incident edge of v 6= ρ has been traversed then v’s s flag is DON E. Other vertices are still flagged N EW or SEEN . However, for every vertex the number of untraversed incoming edges is equal to the number of untraversed outgoing edges. Now consider the second phase. As long as for every vertex v 6= ρ, encountered by R, s = DON E, the route of the second phase is identical to that of the first phase. This follows from the fact that, at the end of the first phase, for ρ and every DON E vertex, the scan pebble is back at the start exit. If not all edges of G have been traversed in the first phase, there must be vertices on the first route for which some of their outgoing edges have not been traversed and such vertices are still flagged SEEN . This follows from the fact that G is strongly connected. If SEEN vertices exist, let v be the first SEEN vertex encountered in the second phase. A new tour starts at v, using only edges untraversed in the first phase, and ending in v. Now v is flagged DON E and its scan pebble is at the start exit. The route of the first phase is resumed. Since every vertex which is still flagged SEEN and which is on the route of the first phase is similarly treated, at the end of the second phase all vertices encountered on the first route are now flagged DON E. Every traversed edge has been traversed exactly once in the second phase, which is the second time for those traversed on the first route. For every phase i > 1, the algorithm maintains the following properties: • While R is traveling through ρ and DON E vertices, it retraces the route of the (i − 1)0 st phase. • If R encounters a SEEN vertex, u, it suspends the retracing of the tour of the (i − 1)0 st phase. A new tour starts at u and ends there. u is now DON E. The tour of the (i − 1)0 st phase is resumed (using the start exit). Thus, every edge it traversed at most once during a phase. • If for every vertex v 6= ρ, which R encounters, v is DON E, then R returns to ρ with F = U P , and halts. During each phase, other than the last and possibly the first, at least one SEEN vertex becomes DON E. Thus, there are at most |V | + 1 phases. Hence, the number of edge traversals is O(|V | · |E|). 2
S. Bhatt et al., Traversing Eulerian Mazes, JGAA, 6(2) 157–173 (2002)
5
164
The Generic Algorithm
In order to explain our more efficient algorithm for finding an Eulerian directed cycle in G(V, E), in terms of the number of edge traversals, we describe first a Generic Algorithm. This is a nondeterministic algorithm which deviates from our computational model; i.e. it is not limited to actions performed by a traveling finite automaton. Later on we show how to remove the nondeterminism and run the algorithm by means of a finite automaton which threads the directed graph.
5.1
Definitions
• An edge is new if it has not been traversed yet. It is old otherwise. • A vertex is new if all its outgoing edges are new. It is old otherwise. • An exploration from vertex v is a directed path which starts in v and continues via a new directed edge, as long as there is one. It is assumed that, in each vertex, exits are chosen according to the specified circular order. For convenience, we shall assume that the exits of a vertex v are labeled v.1, v.2, . . . , v.d, where v.1 is the start exit, as we used it in Section 4, d is dout (v) and the exits are numbered according to the specified circular order. Also, we shall use a scan pebble, one per vertex, to be placed at one of the exists.
5.2
The Preparatory Algorithm
Consider Preparatory, as stated in Table 2. choose a vertex ρ run an exploration from ρ while there are old vertices which have new exits do choose such a vertex u run an exploration from u for every vertex v do if only one exploration passed through v then put v’s pebble at the first exit of this exploration else put the pebble at the first exit of the second exploration which passed through v Table 2: Preparatory Note that the first exploration ends at ρ, the vertex at which it started. This observation, like the proof of Euler’s theorem, follows from the fact that
S. Bhatt et al., Traversing Eulerian Mazes, JGAA, 6(2) 157–173 (2002)
165
whenever any vertex u, other than ρ, is entered, the number of old incoming edges is greater (by 1) than the number of old outgoing edges, and since din (u) = dout (u), there is at least one new outgoing edge. When the first exploration ends, for every vertex the number of new incoming and outgoing edges is the same, and this invariant holds every time an exploration ends. For every vertex, Preparatory places a pebble at one of its exits. The position of these pebbles is the information learned by running Preparatory.
5.3
The Scan Algorithm
The benefit of the Preparatory Algorithm becomes evident when it is followed by the Scan Algorithm. The Scan Algorithm is similar to the actions taken by R in the last phase of the Simple Algorithm. The pebble is used just as the scan pebble has been used there. However, the locations of the pebbles, when Scan begins, may be different from those of the scan pebbles, when the last phase of Simple starts. Scan halts when exit ρ.1 is about to be used again. The route R takes during Scan is an Eulerian tour. 1 2
c
r 1
3 2 1
1
b
a 2
Figure 1: Example for running Generic The interaction of Preparatory with Scan may seem a bit magical so we demonstrate their action on the example shown in Figure 1. For each vertex, the exits are numbered, and for convenience, all vertices are given names. Assuming ρ = r, the first exploration yields the cycle C1 : r.1, a.1, c.1. Assume the second exploration starts at a; it yields a cycle C2 : a.2, b.1, c.2. Assume the third cycle is C3 : b.2, c.3. Since only one exploration cycle includes r, a pebble is placed on r.1. The other vertices are in more than one exploration so the pebbles are placed at the first edge used by the second exploration, that is, a.2, b.2 and c.2. This completes the operation of Preparatory. Now, during a Scan, the following Eulerian cycle is traversed: r1, a2, b2, c2, a1, c3, b1, c1. Note that the edges of a Preparatory cycle may not be scanned consecutively, and they may even appear in an order different from the order in which they have been traversed in the exploration. Nonetheless, as we show below, Scan will always traverse an Eulerian path.
S. Bhatt et al., Traversing Eulerian Mazes, JGAA, 6(2) 157–173 (2002)
166
Lemma 1 In the directed path indicated by Scan, no edge is traversed more than once. Proof: The only exploration which passes through ρ is the first one, and therefore Preparatory places the pebble at exit ρ.1. Scan halts when R is at ρ and the pebble is back at exit ρ.1 when ρ is entered. Thus, every edge out of ρ has been traversed exactly once. e Assume there are edges which R traverses more than once, and let u −→ v be the first such edge on the route of R. By the argument above, u 6= ρ. Since the pebble is moved in a round robin fashion, the number of times R has left u, at the time it traverses e for the second time, is d(u) + 1. R has not started in u and is not at u now. Thus, u must have an incoming edge which R has traversed more than once before traversing e the second time. This contradicts the choice of e. 2 The following simple observation is used in the proofs of the next three lemmas: The exits of every vertex v are used by Preparatory in consecutive order. Exits v.1, v.2, . . . , v.l1 are used in the first exploration which passes through v. Next, v.(l1 + 1), v.(l1 + 2), . . . , v.l2 are used in the second exploration which passes through v, etc. Lemma 2 Let u be a vertex and Ci , i ≥ 1, is the cycle of the first exploration to pass through u. If during Scan, R traverses all edges of Ci which exit from u, then R has traversed all outgoing edges of u. Proof: If all outgoing edges of u belong to one exploration then the claim is trivial. Otherwise, Preparatory places the pebble at the first exit of the second exploration which passes through u. Thus, R has traversed all other outgoing 2 edges of u before it traverses the edges of Ci . Lemma 3 During Scan, R traverses all edges of G. Proof: Consider the cycles traced during Preparatory, and let Ci be the cycle traced in the i-th exploration. Assume there are edges of G which are not traversed by R during Scan, and let Ck be the first cycle to contain such an edge. Let s be the vertex in which the k-th exploration has started (and ended). First, consider the claim that all outgoing edges of s are traversed by R. If k = 1 then the claim follows from the halting condition of Scan. If k > 1 then there are earlier cycles which pass through s, and all outgoing edges of these cycles have been traversed by R. By Lemma 2, all outgoing edges of s have been traversed. This proves the first claim. Now, let us call all edges of Ck , which have been traversed by R, black, and the remaining edges of Ck — red. The edges of other cycles remain colorless. Next, consider the (second) claim that there is a vertex on Ck for which the number of black outgoing edges is greater than the number of black incoming edges. Note that this holds if and only if there is a vertex on Ck for which the number of black outgoing edges is less than the number of black incoming edges.
S. Bhatt et al., Traversing Eulerian Mazes, JGAA, 6(2) 157–173 (2002)
167
Clearly, in every vertex the exits to black edges are consecutive, and the red ones succeed the black. Now, let us trace the edges of Ck in the order they have been chosen in Preparatory. According to the first claim, all outgoing edges of s have been traversed by R, and therefore are all black, and thus, the first edge of Ck is e black. Consider the first red edge u −→ v while we trace Ck . Since we have entered u via a black edge, and all our previous entries into u have been via black edges, the number of black incoming edges is an upper bound on the number of times we visited u. All previous exits from u were through black edges, and e is red. Thus, the number of black outgoing edges is less than the number of black incoming edges. This proves the second claim. Assume v is a vertex on Ck which has more black outgoing edges than black incoming edges. If Ck is the first cycle which passes through v then the number of times that R has visited v is equal to the number of black outgoing edges, plus the number of colorless outgoing edges; these belong to later cycles, and they have all been traversed by R. This follows from the fact that the pebble has been put, by Preparatory, at the first such exit, and all these exits have been used, by R, before the exits of Ck , while at least one black edge exists. Note that the number of entries by R, when it leaves through the last black outgoing edge, is equal to the number of departures. Also note that the number of colorless incoming edges is equal to the number of colorless outgoing edges and that no edge is traversed more than once (Lemma 1). It follows that the number of black incoming edges must be greater than or equal to the number of black outgoing edges. A contradiction. If Ck is not the first cycle which passes through v, then the choice of Ck and Lemma 2 imply that all outgoing edges have been traversed by R, and therefore all incoming edges of u have been traversed as well. Therefore the number of black incoming edges is equal to the number of black outgoing outgoing edges. A contradiction. It follows that every edge is traversed by R. 2 Theorem 2 The robot R, moving according to algorithm Scan, traverses an Eulerian cycle. Proof: By Lemma 1 no edge is traversed more than once, and by Lemma 3, every edge is traversed. 2 Note that after Scan halts, the pebbles are back where Preparatory had put them.
6
The Advanced Algorithm
In this section we describe an algorithm in which the operation of Preparatory is performed by a traveling robot R, whose control is a finite automaton. This new algorithm will ensure that a pebble is placed on edges in a manner consistent
S. Bhatt et al., Traversing Eulerian Mazes, JGAA, 6(2) 157–173 (2002)
168
with Preparatory. In total four pebbles are used (equivalently, the amount of memory required in each vertex v is 4 log d(v)+O(1)), and each edge is traversed 3 times. Each vertex has four pebbles, named start-edge, explore, retrace and scan. It is assumed that all four pebbles are initially placed at the same exit. The start-edge pebble will never move. Thus, in what follows, only the movements of the other three pebbles will be discussed. In addition to the root flag, which marks the initial vertex ρ (whose placement will not be discussed any further), there are two more flags stored in each vertex v: • The flag visited indicates the number of cycles (explorations) which have passed through v; its value is 0, 1, or 2. Initially visited = 0. If its value is 2 then there are at least two cycles which have passed through v. • The flag seen indicates if v has previously been passed in the current cycle (exploration). Initially, seen = 0, and when R reaches v for the first time during the current exploration, it changes the flag seen to 1. Once all edges of an exploration are found, R retraces the cycle and assigns all seen flags on the cycle to be 0 again. Thus, the seen flag of a vertex v is changed to 1, and back to 0, as many times as there are cycles which pass through it. The main procedure, which governs the actions of R, is create-euleriancycle; see Table 3. It employs two subroutines, explore (Table 4) and retrace (Table 5). Also, we use the macro: • exit(X-pebble): R exits the vertex it is at via the exit in which the X-pebble is located now, but first it moves the X-pebble to the next exit, in a round-robin fashion.
6.1
The Explore Subroutine
Subroutine explore is activated in order to perform an exploration. If seen = 0 then the current vertex is visited during this exploration for the first time. If in addition, visited = 1 then the running exploration is not the first to pass through the current vertex, and the scan-pebble is moved to the exit where the explore-pebble is at; which is the first exit of the second exploration to pass through the vertex. If visited < 2 then it is incremented. Now seen is set to 1. R leaves the current vertex through the exit indicated by the explore-pebble, not before moving it to the next exit, in a round robin fashion. If seen = 1 then inquire whether all outgoing edges of the current vertex have been explored; this is done by checking if the explore-pebble is back where the start-pebble is at. If so, R is back at the vertex where the exploration has started and the subroutine is terminated. Otherwise, there are still unexplored outgoing edges and the exploration continues.
S. Bhatt et al., Traversing Eulerian Mazes, JGAA, 6(2) 157–173 (2002)
1 2 3 4 5 6 7 8
call explore call retrace repeat exit(scan-pebble) if explore-pebble not at start-edge then do call explore call retrace until R is at ρ and scan-pebble is at start-edge
Table 3: Procedure create-eulerian-cycle
while TRUE if seen = 0 then do if visited = 1 then put scan-pebble at explore-pebble’s exit if visited < 2 then visited ← visited + 1 seen ← 1 exit(explore-pebble) elsif explore-pebble at start-edge pebble then EXIT explore subroutine else exit(explore-pebble) Table 4: Subroutine explore while seen = 1 or retrace-pebble not at start-edge do seen ← 0 exit(retrace-pebble) Table 5: Subroutine retrace
169
S. Bhatt et al., Traversing Eulerian Mazes, JGAA, 6(2) 157–173 (2002)
6.2
170
The Retrace subroutine
Subroutine retrace is activated after an exploration cycle is found. Its purpose is to reset all seen flags of the vertices of the newly found cycle to 0. This is done as follows. If seen = 0 and the retrace-pebble is at the start-edge, then all edges of the new cycle have been retraced and retrace halts. The halting condition can occur only at the vertex where the exploration has started and all exits of that cycle have been retraced. In every encountered vertex seen is set to 0, whatever its value has been.
6.3
The Create-Eulerian-Cycle Procedure
We shall refer to lines 3,4 and 8 of Table 3 as the Scan behavior. Procedure create-eulerian-cycle uses explore and retrace to perform a deterministic version of Preparatory. R starts an exploration from ρ, first performing explore and then retrace. Now it is back at ρ, while all three pebbles are at the start-edge. R behaves now as Scan, advancing the scanpebble only, but this behavior is stopped when R hits a vertex v which has new outgoing edges; this is detected by the fact that the exit where the explorepebble is at is not at the start-edge. When this happens, R suspends the Scan behavior. It performs an exploration from v, again by first running explore and then retrace. While doing that, the scan-pebble of every vertex encountered on this cycle is moved from its start-edge to the first exit of the new exploration if the present exploration is the second to pass through that vertex. When retrace terminates, R resumes the Scan behavior. It is easy to see that create-eulerian-cycle causes R to place the scanpebbles in accord with Preparatory, and when R uses the exits where the scanpebbles are at, it traverses every edge once. When create-eulerian-cycle terminates, the scan-pebbles are back where Preparatory could have placed them. Thus, at that time, one can use Scan behavior to traverse an Eulerian cycle.
S. Bhatt et al., Traversing Eulerian Mazes, JGAA, 6(2) 157–173 (2002)
171
References [1] Y. Afek and E. Gafni, Distributed Algorithms for Unidirectional Networks, SIAM J. Comput., Vol. 23, No. 6, 1994, pp. 1152-1178. [2] S. Albers and M.R. Henzinger, Exploring Unknown Environments, SIAM J. Comput., Vol. 29, No. 4, 2000, pp. 1164-1188. [3] M. Blum and W.J. Sakoda, On the Capability of Finite Automata in 2 and 3 Dimensional Space. In Proceeding of the Eighteenth Annual Symposium on Foundations of Computer Science, 1977. pp. 147-161. [4] X. Deng and C.H. Papadimitriou, Exploring an Unknown Graph, J. of Graph Th., Vol. 32, No. 3, 1999, pp. 265-297. [5] S. Even, Graph Algorithms, Computer Science press, 1979. [6] S. Even, A. Litman and P. Winkler, Computing with Snakes in Directed Networks of Automata. J. of Algorithms, Vol. 24, 1997, pp. 158-170. [7] A. Hemmerling, Labyrinth Problems; Labyrinth-Searching Abilities of Automata, Teubner-Texte zur Mathematik, Band 114, 1989. [8] M.O. Rabin, Maze Threading Automata. An unpublished lecture presented at MIT and UC Berkeley, 1967. [9] R. Tayar, Scanning Directed Eulerian Mazes by a Finite-State Robot, Master thesis, Computer Science Department, Technion — Israel Inst. of Tech., Haifa, Israel. Sep. 2000, 31 pages.
S. Bhatt et al., Traversing Eulerian Mazes, JGAA, 6(2) 157–173 (2002)
172
Appendix: The Simple Algorithm — Lower bounds and a comparison with depth first techniques Let us show that, in a certain sense, the upper bound on edge traversals, i.e. O(|V | · |E|), is tight for the Simple Algorithm. And yet, there are some cases in which the Simple Algorithm performs significantly better than any depth-first search algorithm. We present two examples of graphs, one sparse and one dense, for which the Simple Algorithm reaches its upper bound for edge traversals. As our sparse example, we consider a simple chain, as shown in Figure 2. The start exit of every vertex is labeled 1. 1
2
1
1
2
2
1
2
3
1
n-1
1
n
Figure 2: A simple chain Let us denote by fs (n) the number of edge traversals until every edge is traversed, when the initial vertex is vertex No. 1. The last edge to be discovered is the edge from vertex n to vertex n − 1. Clearly, fs (2) = 2 and fs (n + 1) = fs (n) + 2n − 1. Thus, fs (n) = n2 − 2n + 2. It follows that in this case, the bound of O(|V | · |E|) is tight. As our dense graph example, consider the following directed graph Gp (V, E), where p is an odd prime. V = {0, 1, . . . , 2p − 1}, The set of directed edges consists of two types: • body 4 For every two vertices, i, j < p, let δ(i, j) = j − i mod(p); i.e. 0 ≤ δ(i, j) < p. If δ(i, j) < p2 then there is an edge i −→ j, and the exit at i is labeled δ(i, j). • tail – There is an edge 0 −→ p labeled
p+1 2 .
– For every p ≤ i < 2p − 1 there is an edge i −→ i + 1, labeled 2. – For every p < i ≤ 2p − 1 there is an edge i −→ i − 1, labeled 1. – There is an edge p −→ 0 labeled 1.
S. Bhatt et al., Traversing Eulerian Mazes, JGAA, 6(2) 157–173 (2002) 2
2
2
173
2
3 5
6 1
1
8 1
9 1
1
0
1
1
2 2
4
7
1 2
2
1
1
2 3
2 1
Figure 3: G5 The case of G5 is shown in Figure 3. Note that according to the Simple Algorithm, starting in vertex 0, R scans edges of the body; i.e. the edges between vertices whose name is less all p(p−1) 2 than p, before it takes the edge to p. In fact, every time R returns to vertex 0, via the edge from p, it repeats the scan of all edges of the body. This will occur p times. Thus the tour, until the last edge (from 2p − 1 to 2p − 2) is discovered, is of length p(p − 1) + p2 − 2p + 2. p· 2 Again, this is of the order |V | · |E|. We now present two examples in which the Simple Algorithm is superior to any DFS algorithm. The first example is a directed cycle, with a self-loop in every vertex, where exit No. 2 leads to its self-loop. R visits all vertices in the first phase and thus, performs an Eulerian tour on the second phase. The edge traversal complexity is O(|V |). However, if we execute any DFS based algorithm on the same graph, R has to make Ω(|V |2 ) edge traversals. The second example is the case of a complete directed graph of n vertices; namely for every two vertices a and b there is an edge a −→ b. In the first phase all vertices are visited, since the root has an edge to every other vertex. Therefore, all edges not traversed in the first phase are traversed in the second, and the third phase is the last phase. Thus, the total number of edge traversals is O(|V |2 ). However, if one applies a DFS based algorithm, it takes Ω(|V |3 ) steps. (The DFS tree is a directed path of length |V | − 1, and each time a backedge is traversed, the tree must be traversed again, at least up to the parent of the start vertex of the back-edge.).
Journal of Graph Algorithms and Applications http://jgaa.info/ vol. 6, no. 3, pp. 177–178 (2002)
Special Issue on Selected Papers from the 8th International Symposium on Graph Drawing, GD’00 Guest Editor’s Foreword Michael Kaufmann Wilhelm-Schickard-Institut f¨ ur Informatik Universit¨at T¨ ubingen 72076 T¨ ubingen, Germany http://www-pr.informatik.uni-tuebingen.de [email protected]
M. Kaufmann, Foreword , JGAA, 6(3) 177–178 (2002)
178
It is becoming a nice tradition and add-on to the Symposium on Graph Drawing to invite a selection of papers to be included in a special issue of Journal of Graph Algorithms and Applications. After a more theory-oriented special issue for GD’99, I decided to emphasize application-oriented papers. A highlight of GD’00 was the simultaneous submission of three independent papers about spring embedder methods for large graphs. Two of them are included here: a detailed report by Harel and Koren, describing the basis of their multiscale method, and an article by Gajer and Kobourov about the system and the experiments that they conduct to show the effectiveness of their algorithm. Two other papers on related topics in this issue are those by Bridgeman and Tamassia and by Purchase, who derive quality measures and the evaluation of quality measures for different types of drawings. This topic is related to information visualization. Further, two papers on drawing algorithms for specific applications are included in this issue. The first paper, by Tollis et al., deals with the drawing of state chart diagrams using floorplanning methods from VLSI, while the second paper, by Carmignani et al., describes HERMES, a tool for the visualization of web structures. Their method is based on extension of bend-minimization algorithms for orthogonal drawings. Finally, Friedrich presents a nice methodology that describes how one can avoid occlusion and more general confusion when morphing structures from one drawing into another (animation). This special issue indicates in a way the diversity of the graph drawing field: the emphasis here lies on practicability and applicability, and less on algorithmics. Only the first two papers contain new algorithms, the other papers contain either extensions of existing methods or no algorithmics at all.
July, 2002
Michael Kaufmann
Journal of Graph Algorithms and Applications http://jgaa.info/ vol. 6, no. 3, pp. 179–202 (2002)
A Fast Multi-Scale Method for Drawing Large Graphs David Harel
Yehuda Koren
Dept. of Computer Science and Applied Mathematics The Weizmann Institute of Science, Rehovot, Israel http://www.wisdom.weizmann.ac.il/ [email protected] [email protected] Abstract We present a multi-scale layout algorithm for the aesthetic drawing of undirected graphs with straight-line edges. The algorithm is extremely fast, and is capable of drawing graphs that are substantially larger than those we have encountered in prior work. For example, the paper contains a drawing of a graph with over 15,000 vertices. Also we achieve “nice” drawings of 1000 vertex graphs in about 1 second. The proposed algorithm embodies a new multi-scale scheme for drawing graphs, which was motivated by the earlier multi-scale algorithm of Hadany and Harel [HH99]. In principle, it could significantly improve the speed of essentially any force-directed method (regardless of that method’s ability of drawing weighted graphs or the continuity of its cost-function).
Communicated by Michael Kaufmann: submitted February 2001; revised December 2001 and June 2002.
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)180
1
Introduction
A graph G(V, E) is an abstract structure that is used to model a relation E over a set V of entities. Graph drawing is a conventional tool for the visualization of relational information, and its usefulness depends on its readability, that is, the capability of conveying the meaning of the diagram quickly and clearly. In recent years, many algorithms for drawing graphs automatically were proposed (the state of the art is surveyed comprehensively in [Di+ 99, KW01]). We concentrate on the problem of drawing an undirected graph with straightline edges. In this case the problem reduces to that of positioning the vertices by determining a mapping L : V −→ R2 . A popular generic approach to this problem is the force-directed technique, which introduces a heuristic cost function (an energy) of the mapping L, which (hopefully) achieves its minimum when the layout is nice. Variants of this approach differ in the definition of the energy, and in the optimization method that finds its minimum. Some known algorithms are those of [Ea84, KK89, DH89, FR91]. Major advantages of forcedirected methods are their relatively simple implementation and their flexibility (heuristic improvements are easily added), but there are some problems with them too. One severe problem is the difficulty of minimizing the energy function when dealing with large graphs. The above methods focus on graphs of up to 100 vertices. For larger graphs the convergence to a minimum, if possible at all, is very slow. We propose a new method for drawing graphs that could in principle improve the speed of every force-directed method. We build our algorithm around the Kamada-Kawai method, and the resulting algorithm, which is extremely fast, is capable of drawing graphs that are substantially larger than those we have encountered in prior work (although subsequent developments are reviewed in Section 6). The algorithm, which was motivated by the earlier multi-scale algorithm of Hadany and Harel [HH99], works by producing a sequence of improved approximations of the final layout. Each approximation allows vertices to deviate from their final place by an extent limited by a decreasing constant r. As a result, the layout can be computed using increasingly coarse representations of the graph, where closely drawn vertices are collapsed into a single vertex. Each layout in the sequence is generated very rapidly, by performing a local beautification on the previously generated layout.
2
Force-Directed Graph Drawing
The force-directed approach is apparently the prevalent attitude for drawing general graphs. Algorithms based on this approach consist of two components. The first is the force (or energy) model that quantifies the quality of a drawing. The second is an optimization algorithm for computing a drawing that is locally optimal with respect to this model. The resulting final layout brings the system to equilibrium, where the total force on each vertex is zero, or equivalently, the potential energy is locally minimal with respect to the vertex positions. Regard-
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)181 ing the drawing standard, force-directed methods draw the edges as straight-line segments, so the whole issue reduces to the problem of positioning the vertices. In this section we outline some notable work on force-directed graph drawing.
2.1
The Spring Embedder Method
The spring embedder method is the earliest viable algorithm for drawing general graphs. It was proposed by Eades [Ea84], and was later refined by Fruchterman and Reingold [FR91]. This method likens a graph to a mechanical collection of electrical charged rings (the vertices) and connecting springs (the edges). Every two vertices reject each other by a repulsive force and adjacent vertices (connected by an edge) are pulled together by an attractive force. The method seeks equilibrium of these conflicting constraints. Spring based methods are very successful with small-sized graphs of up to around 50 vertices. Regarding the optimization algorithm, we describe the method of [FR91]. A predetermined number of sweeps is performed. In each sweep every vertex is moved in the direction of the total force exerted on it. The extent of the movement is determined by a global cooling schedule that restricts the distance a vertex can move as a decreasing function of the sweep number. Frick et al. [Fr+ 94] have suggested several improvements on this scheme, the most notable of which is a local cooling schedule, resulting in a different extent of movement for each vertex according to its temperature. They show graphs of size 256. More recently, Tunkelang [Tu99] suggested several other refinements to the optimization method. One is to approximate the effect of many distant repulsive forces as being exerted by a single vertex using a quad-tree, in the spirit of the Barnes-Hut method [BH86]. Another improvement is the use of the ConjugateGradient method for decreasing the energy. Tunkelang dealt with 1000-vertex graphs, drawn in 5-10 minutes.
2.2
Kamada and Kawai’s Method
Kamada and Kawai [KK89] modelled a graph as a system of springs that act in accordance with Hooke’s Law: Every two vertices are connected by a spring, whose rest length is proportional to the graph-theoretic distance between its two endpoints, and its stiffness is inversely proportional to the square of its rest length. The optimization procedure tries to minimize the total energy of the system, that is: X 1 (l(u, v) − Lduv )2 E= d2uv v,u∈V
where l(u, v) is the length of the spring between u and v, L is the length of a single edge, and duv is the graph-theoretic distance between u and v. Kamada and Kawai’s method treats all the aesthetic criteria that the springembedder method addresses, and produces drawings with a similar quality. An advantage of this method is that it can be applied straightforwardly to drawing edge-weighted graphs, assuming that edge lengths have to reflect their weights.
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)182
2.3
Hadany and Harel’s Multi-Scale Algorithm
The multi-scale approach proposed by Hadany and Harel [HH99] is an improvement of the force-directed technique, which facilitates the drawing of larger graphs. The main idea of this method is to consider a series of abstractions of the graph called coarse graphs, in which the combinatorial structure is significantly simplified, but important topological features are well preserved. The energy minimization is divided between these coarse graphs, in such a way that globally related properties are optimized on coarser graphs, while locally related properties are optimized on finer graphs. As a result, the energy minimization process considers only small neighborhoods at once, yielding a quick running time. The scheme of the algorithm is a recursive repetition of: 1. Perform fine-scale relocations of vertices that yield a locally organized configuration. 2. Perform coarse-scale relocations (through local relocations in the coarse representations) correcting global disorders not found in stage (1). 3. Perform fine-scale relocations that correct local disorders introduced by stage (2). All actual local relocations are carried out in [HH99] by minimizing the energy defined in [KK89] using simple gradient-descent. The coarsening step is done in a pre-processing stage by contracting edges that minimize a convex combination of three objectives (in a greedy fashion): • The cluster number : The number of original vertices forming the new vertex. • The degree number : The degree of the vertices forming the new vertex in the current abstraction of the graph. • The homotopic number : The number of vertices (in the coarse graph) that are adjacent to both the vertices forming the edge. The algorithm produces good results on large graphs containing hundreds of vertices, in a reasonable time. In this paper we continue the multi-scale approach of Hadany and Harel [HH99], and introduce a simpler and much faster algorithm which produces better drawings.
3
Multi-Scale Graph Drawing
The intuition of [HH99] for beauty in graph layout is that the graph should be nice on all scales. In other words the drawing should be nice at both the micro level and the macro level. Relying only on this intuition, we will formalize the notion of scale relevant to the graph drawing problem. The crucial observation
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)183 is that global aesthetics refer to phenomena that are related to large areas of the picture, disregarding its micro structure, which has only a minor impact on the global issue of beauty. On the other hand, local aesthetics refer to phenomena that are limited to small areas of the drawing. Following this line of thinking, we will construct a coarse scale of a drawing by shrinking nodes that are drawn close to each other, into a single node, obtaining a new drawing that eliminates many local details but preserves the global structure of the original drawing. An alternative view of our notion of coarsening is as an approximation of a nice layout. This approximation allows vertices to deviate from their final position by an amount limited to some constant r. As a consequence, we can unify all the vertices whose final location lies within a circle of radius r, and thus obtain the coarse scale representation. Our presentation of the drawing scheme is preceded by some definitions: Definition 3.1 A layout of a graph G(V, E) is a mapping of the vertices to the Euclidean space: LG : V −→ R2 . We often omit the subscript G . For simplicity, we assume that there is a single optimal layout with respect to fixed set of aesthetic criteria accepted in force-directed algorithms. We term this layout nice. The nice layout of G is denoted by L∗G , or simply L∗ . Definition 3.2 L is a locally nice layout of G(V, E) with respect to r, if the intersection of L(V ) with every circle of radius r induces a nice layout of the appropriate subgraph of G. Definition 3.3 L is a globally nice layout of G(V, E) with respect to r if max{|L(v) − L∗ (v)|} < r v∈V
Definition 3.4 A locality preserving k-clustering (a k-lpc for short) of G(V, E) with respect to r is the weighted graph G({V1 , V2 , . . . , Vk }, E 0 , w), where: V = V1 ∪ V2 · · · ∪ Vk ,
∀i 6= j : Vi ∩ Vj = ∅
0
E = { (Vi , Vj ) | ∃(vi , vj ) ∈ E ∧ vi ∈ Vi ∧ vj ∈ Vj } X 1 dvu , ∀(Vi ,Vj )∈E 0 w(Vi , Vj ) = |Vi ||Vj | v∈Vi ,u∈Vj
(dvu is the shortest distance between u and v in G) and for every i: max {|L∗ (v) − L∗ (u)|} < r
v,u∈Vi
i.e., all the vertices in one cluster are drawn relatively close in the nice layout. We sometimes call the vertices of a k-lpc clusters.
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)184 At first glance, this definition seems to be of a little practical value, as it refers to the unknown nice layout L∗ . We will discuss this important point in the next section. Definition 3.5 A multi-scale representation of a graph G(V, E) is a sequence of graphs Gk1 , Gk2 , . . . , Gkl , where k1 < k2 < · · · < kl = |V |, and for all 1 6 i 6 l : Gki is a locality preserving ki -clustering of G(V, E) with respect to ri , where r1 > r2 > · · · > rl = 0. Remark: We naturally assume that in a nice layout of an edge-weighted graph, the lengths of the edges have to reflect their weights. Our method relies on the ease of drawing graphs with a small number of vertices and on the following two assumptions, which formalize what we think to be amenability to multi-scale aesthetics — independence between global and local aesthetics. Assumption 3.1 Let Gr be k-lpc of a graph G with respect to r, and let rˆ > r. L is a globally nice layout of Gr with respect to rˆ if and only if L is a globally nice layout of G with respect to rˆ. (In G, we take L(v) = L(Vi ) for each v ∈ Vi ). Corollary: If L is a nice layout of a k-lpc of a graph G with respect to r then L is a globally nice layout of G with respect to r. The intuition of Assumption 3.1 is that global aesthetics is independent of the micro structure of the graph, so the differences between the layouts of Gr and of G are bounded with r. Assumption 3.2 If L is both a locally and a globally nice layout of a graph G with respect to r, then it is a nice layout of G. Now we present the multi-scale drawing scheme, which draws a graph by producing a sequence of improved approximations of the final layout.
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)185 The Multi-Scale Drawing Scheme 1. Place the vertices of G randomly in the drawing area. 2. Choose an adequate decreasing sequence of radiuses ∞ = r0 > r1 > r2 > · · · > rl = 0. 3. for i=1 to l do 3.1 Choose an appropriate value of ki , and construct Gki , a ki -lpc of G w.r.t. ri . 3.2 Place each vertex of Gki at the (weighted) location of the vertices of G that constitute it. 3.3 Locally beautify local neighborhoods of Gki . 3.4 Place each vertex of G at the location of its cluster (i.e., the vertex in Gki ). 4. end The viability of the scheme stems from the following observations: 1. In the first iteration, after step 3.3, we should have a nice layout of Gk1 . To guarantee this, the value of r1 has to be large enough so that the resulting Gk1 will be small and can be easily drawn nicely. 2. Step 3.3 should yield a locally nice layout of Gki w.r.t. ri−1 . To guarantee this, we have to choose large enough neighborhood. 3. At the beginning of iteration i, we have a globally nice layout of Gki w.r.t. ri−1 . Hence, by Assumption 3.2, after step 3.4 we have a nice layout of Gki . This layout is a globally nice layout of Gki+1 w.r.t. ri , by Assumption 3.1. We remark that the choice of the multi-scale representation can be based upon either the decreasing sequence r1 , . . . , rl = 0 (as described above) or the increasing sequence k1 , . . . , kl = |V | (as we have done in our implementation). In Definition 3.4 we added weights to the edges of the k-lpc in order to retain the size proportions of G, which is necessary for making Assumption 3.1 valid. However, in practice, we conjecture that our scheme works well even without weighting the edges of the k-lpc, when using some variants of the springembedder method (e.g., those of [Ea84] and [FR91]) as the local beatification method. The reason for this is that such methods benefit significantly from the better initialization, which, while not capturing the final size of the graph, often solves many large scale conflicts correctly.
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)186
4
The New Algorithm
In order to implement a multi-scale graph drawing algorithm based on the scheme of Section 3, we have to further elaborate on two points: (1) how to find the multi-scale representation of a graph (line 3.1 of the scheme), and (2) how to devise a locally nice layout (line 3.3 of the scheme).
4.1
Finding a Multi-Scale Representation
In order to construct a multi-scale representation of a graph G based on Definition 3.5, we must find a k-lpc of G, in it vertices that are drawn close in the nice layout should be grouped together. The important question is: How can we know which vertices will be close in the final picture, if we still do not know what the final picture looks like? 1 Luckily we do have a heuristic that can help decide which vertices will be drawn closely. Moreover, this key decision can be made very rapidly, and is a major reason for the fast running time of our algorithm. The heuristic is based on the observation that a nice layout of the graph should convey visually the relational information that the graph represents, so vertices that are closely related in the graph (i.e., the graph theoretic distance is small) should be drawn close together. This heuristic is very conservative, and all the force directed drawing algorithms use it heavily. Employing this heuristic, we can approximate a k-lpc of G by using an algorithm for the well known k-clustering problem. In this problem we wish to partition V into k clusters so that the longest graph-theoretic distance between two vertices in the same cluster is minimized. In reality, we would like to identify every vertex in the cluster with a single vertex that approximates the barycenter of the cluster. Hence we use a solution to the closely related k-center problem, where we want to choose k vertices of V , such that the longest distance from V to these k centers is minimized. These fundamental problems arise in many areas and have been widely investigated in several papers (see e.g., [Go85] and [HS86]). Unfortunately, both problems are NP-hard, and it has been shown in [Go85] and [HS86] that unless P=NP there does not exist a (2−)-approximation algorithm for any fixed > 0.2 Nevertheless, there are various fast and simple 2-approximation algorithms for these problems. We will approximate a k-lpc as the solution to the k-center problem, adopting a 2-approximation method mentioned in [Ho96]: 1 What
is needed is only a sufficient (even if not necessary) condition that vertices are close. δ-approximation algorithm delivers an approximate solution guaranteed to be within a constant factor δ of the optimal solution. 2A
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)187 K-Centers (G(V, E) ,k)
% Goal: Find a set S ⊆ V of size k, such that maxv∈V mins∈S {dsv } is minimized.
S ← {v} for some arbitrary v ∈ V for i = 2 to k do 1. Find the vertex u farthest away from S (i.e., such that mins∈S {dus } > mins∈S {dws }, ∀w ∈ V ) 2. S ← S ∪ {u} return S
Complexity: Line 1 can be carried out in time Θ(|E|) by BFS. In our case, it can be done faster, since, as we shall see, we already have the all-pairs shortest path length (APSP) at our hands (it is needed for the local beautification). Utilizing this fact and memorizing the current distance of every vertex from S, we can implement line 1 in time Θ(|V |), yielding a total time complexity of Θ(k|V |) (without the APSP computation).
4.2
Local Beautification
We have chosen to use a variant of the Kamada and Kawai method [KK89] as our local drawing method. We found it to be very appropriate, because it relates every pair of vertices, so, when constructing a new coarse representation of the graph, we do not have to define which pairs of vertices are connected by an edge. Notice that this property of the Kamada and Kawai method has a price: it forces us to waste Θ(|V |2 ) memory, even when the graph is sparse. Another advantage of the Kamada and Kawai method is that it can deal directly with weighted graphs, which is convenient in our case since the multi-scale representation of a graph contains weighted graphs. The Energy Function: We consider the graph G(V, E), where each vertex v is mapped by the layout L into a point in the plane L(v) with coordinates (xv , yv ). The distance duv is defined as the length of the shortest path in G between u and v. We define the k-neighborhood of v to be: N k (v) = {u ∈ V | 0 6 duv < k}. In order to find a layout with aesthetically pleasing k-neighborhoods, we use an energy function that relates the graph theoretic distance between vertices in the graph to the Euclidean distance between them in the drawing, and is defined as follows: X X kuv (kL(u) − L(v)k − lduv )2 Ek = v∈V u∈N k (v)
where l is the length of a single edge, kL(u)−L(v)k is the Euclidean distance 1 between L(u) and L(v), and kuv is a weighting constant that can be either duv 1 or d2 . uv The energy represents the normalized mean squared error between the Euclidean distance of vertices in the picture and the graph-theoretic distance. Only pairs in the same k-neighborhood are considered.
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)188 Local Minimization of the Energy: Our purpose is to find a layout that brings the energy Ek to a local minimum. The necessary condition of a local minimum is as follows: ∂Ek ∂Ek = = 0, ∂xv ∂yv
∀v ∈ V
To achieve this condition we iteratively choose the vertex that has the largest value of ∆kv , which is defined as: s ∂Ek 2 ∂Ek 2 k ) +( ) ∆v = ( ∂xv ∂yv and move this vertex, v, by the amount of δvk = (δvk (x), δvk (y)). The computation of δvk is carried out by viewing Ek as a function of only L(v) = (xv , yv ), and the use of a two-dimensional Newton-Raphson method. As a result, the unknowns δvk (x) and δvk (y) are found by solving the following pair of linear equations: ∂ 2 Ek k ∂Ek ∂ 2 Ek k δ (x) + δv (y) = − v 2 ∂xv ∂xv ∂yv ∂xv ∂ 2 Ek k ∂Ek ∂ 2 Ek k δ (x) + δ (y) = − ∂yv ∂xv v ∂yv2 v ∂yv The interested reader can find further details in [KK89]. Algorithms for Locally Nice Layout The following algorithm, which is based on [LSD] and as mentioned in [Br+ 95], is a modification of [KK89]. The algorithm computes a nice layout of every k-neighborhood of a graph: LocalLayout(dV ×V , L, k, Iterations) % Goal: Find a locally nice layout L by beautifying k-neighborhoods % dV ×V : all-pairs shortest path length % L: initialized layout % k: radius of neighborhoods
for i = 1 to Iterations · |V | do 1. Choose the vertex v with the maximal ∆kv 2. Compute δvk by solving the above mentioned equations 3. L(v) ← L(v) + (δvk (x), δvk (y)) end A typical value of the parameter Iterations is 4. Complexity: An efficient implementation of line 1 is by storing the first derivatives of Ek in a binary heap, sorted by the values of ∆kv . (After the
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)189 movement of each vertex v, the first derivatives of vertices in N k (v) are updated.) Hence, the computation time of line 1 is Θ(log |V |). The computation time of δvk (line 2) is Θ(|N k (v)|), which is a constant for a bounded degree graph. These computations are carried out Iterations · |V | times, so the overall time complexity for a bounded degree graph is Θ(|V | log |V |). This algorithm differs from the one of Kamada and Kawai [KK89] in its single loop structure, and in the use of a predefined number of iterations, instead of basing termination on the value of ∆kv . This results in much faster termination when dealing with large graphs. We recommend this as an improvement (in a stand-alone sense) of the Kamada and Kawai method. We have tested it and have found it far superior for larger graphs. The recommended value of Iterations when running this algorithm as a stand alone (not as a part of the multi-scale algorithm) is 10, at least. Performance can be improved by executing most of the iterations (the first ones) without choosing the vertex with the largest value of ∆kv , but iterating through all the vertices in some order.
4.3
The Multi-Scale Drawing Algorithm
We now describe the full algorithm: LayoutG(V, E) % Goal: Find L, a nice layout of G % Constants: % Rad[= 7] — determines radius of local neighborhoods % Iterations[= 4] — determines number of iterations in local beautification % Ratio[= 3] — ratio between number of vertices in two consecutive levels % M inSize[= 10] — size of the coarsest graph
Compute the all-pairs shortest path length: dV ×V Set up a random layout L k ← M inSize while k 6 |V | do centers ← K-Centers(G(V, E) ,k) radius = maxv∈centers minu∈centers {dvu } · Rad LocalLayout (dcenters×centers , L(centers),radius,Iterations) for every v ∈ V do L(v) ← L(center(v)) + rand k ← k · Ratio return L Comments: Inside the for-loop, the call center(v) returns the center that is closest to v. We add a small random noise (0, 0) < rand < (1, 1), because our local beautification algorithm performs badly when the vertices are initialized to the same point. One might try to improve the global aesthetics by iteratively repeating the body of the while-loop (for each fixed k) a number of times that | decreases with k (e.g., |V |k| times).
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)190 Complexity: The overall asymptotical complexity is determined by the computation of the all-pairs shortest path length (APSP) (line 1), which we implemented by initiating a BFS from every vertex. It thus takes time Θ(|V ||E|). Experimental running times are given in Table 1. The space complexity is Θ(|V |2 ), since we have to memorize the all-pairs shortest path length matrix.
5
Examples
This section contains examples of the results of our algorithm. The implementation is in C++, and runs on a Pentium III 1GHz PC. Table 1 gives the actual running times of the algorithm on the graphs given here. We should mention that our implementation is far from being efficient, and an optimized version will probably do better. For all the executions, we have used the default parameters: Iterations = 4, Ratio = 3, M inSize = 10. Regarding, Rad, its default value – 7 was sufficient for achieving reasonable results for all the graphs, except the full binary tree. However, we have found for several graphs, that we can get “smoother” results when increasing Rad. Hence, for these graphs we give also results with Rad > 7, as indicated in the table. As can be seen in the table, almost all the running time is dedicated for computing the all-pairs shortest path length (APSP), and for performing local beautification. The layouts shown in Figures 1–3 demonstrate applying our algorithm to regular graphs. We were particularly happy with the graphs in Figures 4 and 5, since the “correct” (grid or torus) appearance is retained despite the partiality of information available to the algorithms. Drawing the full binary trees in Figure 6 was harder. Force-directed methods behave better on bi-connected graphs, since there are forces that work in many ways and directions. They perform quite badly on trees. Our method succeeded in finding a nice layout of the trees only when it considered the entire graph as one in its “local” beautification stages. The problem is that the local beautification scheme is based only on neighborhoods in the graph-theoretic sense, but in deep kinds of trees, leaves should show up close to each other even if they are far apart in the graph-theoretic sense. We mention that even in laying out full binary trees our method has two advantages when compared to Kamada and Kawai’s method [KK89]. First, its running time is still faster; about 5sec for a 1023-vertex tree, compared with 15sec of Kamada-Kawai’s method (implemented efficiently, as discussed in Section 4.2), on account of the relatively few beautification iterations. Second, the resulting picture (Figure 6(a)) is almost planar and has no global distortions, in contrast to Kamada-Kawai’s method, which will be trapped in many local minima, and will always result in many edge crossings (see Figure 6(c)). Figure 7, which is a grid with some of the horizontal edges removed, illustrates a similar problem. In Figure 7(a), we set things up so that the local beautification procedure considered larger than regular neighborhoods, as this is the only way to take into account together the vertices of two consecutive “lines” to make the resulting picture planar. On the other hand, since in Figure
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)191
Graph Name
|V|
|E|
Rad
1(b)
1024 3025 6400 10000 6400
1984 5940 12640 19800 12642
2(a)
1024
2048
2(b)
6400
12800
3
9843
19683
4(b)
6400
5(b)
9480
7 7 7 7 7 20 7 15 7 15 7 15 7
APSP time 0.3 1.45 12.11 38.27 12.11 12.11 0.3 0.3 12.13 12.13 39.36 39.36 12.58
Beautification time 0.7 4.11 15.153 35.11 15.34 34.81 0.81 1.94 15.6 27.06 29.39 38.59 13.75
Overall time 1.08 5.87 29.39 76.22 29.16 49.22 1.16 2.28 29.57 41.27 71.45 80.83 28.11
1600
2133
7
0.42
1.41
2.02
6
1023
1022
7
3025
5156
3elt
8
4720
13722
Crack 4elt
10 9
10240 15606
30380 45878
16 18 7 35 7 20 7 7 20
0.13 0.13 1.41 1.41 6.13 6.13 49.61 129.98 129.98
3.59 4.72 3.85 20.31 10.28 31.75 22.05 143.67 236.33
3.73 4.88 5.56 22.04 17.73 39.71 73.34 285.45 383.06
Grid 32 × 32 Grid 55 × 55 Grid 80 × 80 Grid 100 × 100 Folded Grid 80 × 80 Torus 64 × 16 Torus 160 × 40 Sierpinski depth 8 Random Sparse Grid Random Sparse Torus Full Binary Tree Partial Grid
Figure
1(a)
Table 1: Running time (in seconds; non-optimized) of the various components of the algorithm
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)192
(a)
(b)
Figure 1: (a) 55x55 (3025-vertex) square grid; (b) 80x80 (6400-vertex) square grid with each two opposite corners connected
7(b) the local beautification procedure considered neighborhoods that were too small, we get the overlapping. In Figures 8 and 9 we present “real-life” graphs taken from Francois Pellegrini’s Scotch graph collection, at: http://www.labri.u-bordeaux.fr/Equipe/ PARADIS/Member/pelegrin/graph/. In Figure 10 we present the beautiful Crack graph taken from the collection of Jordi Petit, at: http://www.lsi.upc.es/ ~jpetit/MinLA/Experiments/.
6
Related Work
The multi-scale approach to graph drawing was first proposed in [HH99], as described in Section 2. The major technical improvement of our approach over [HH99] is a more intuitive and easier to implement coarsening step, which is the source of its much better running time. Our method eliminates the entire costly pre-processing step of [HH99] (with the exception of the computation of dV ×V , which is part of the local beautification process). Practically all the coarsening overhead in our algorithm is carried out in a negligible fraction of the overall execution time. Another advantage of our algorithm over that of [HH99] is its simpler schematic structure. Ours starts by beautifying the coarsest-scale representation and proceeds by improving the finer-scale representations until reaching the original graph. The Hadany-Harel method starts with the original graph, continues until it reaches the coarsest level, and then proceeds back to the original graph.
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)193
(a)
(b)
Figure 2: Toruses: (a) 64x16 (1024-vertex) (b) 160x40 (6400-vertex)
Figure 3: A depth 8 Sierpinski (9843 vertices)
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)194
(a)
(b)
Figure 4: (a) 40x40 (1600-vertex) grid with 13 of the edges omitted at random; (b) 80x80 (6400-vertex) grid with 14 of the edges omitted at random
(a) Figure 5: 80x20 (1600-vertex) torus with
(b) 1 5
and
1 3
of the edges omitted at random
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)195
(a)
(b)
(c) Figure 6: Full binary trees: (a,b) 1023-vertices, depth 9; In (a) beautification considered the whole graph at once, while in (b) neighborhoods of radius 16 were considered at once; (c) is the result of the Kamada-Kawai algorithm. Notice that unlike our algorithm, Kamada-Kawai results with bad “global” edge crossings (i.e., near the root).
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)196
(a)
(b)
Figure 7: 55x55 (3025-vertex) partial grid: (a) beautification considered larger than normal neighborhoods, of radius 35 (b) beautification considered usual neighborhoods of radius 7
Figure 8: The graph 3elt from the Scotch collection; |V | = 4720, |E| = 13722
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)197
Figure 9: The graph 4elt from the Scotch collection; |V | = 15606, |E| = 45878
Figure 10: The graph Crack; |V | = 10240, |E| = 30380
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)198 Eliminating this alone results in a 50% improvement in beautification time, by making only half of the local beautification steps. In addition, the beautification process of [HH99] does not directly change the layout, but performs a relative change of the layout, since every vertex is located anew relative to its previous location. This imposes a strong inter-dependency between all the multi-scale representations of the graph. As a result, one has to introduce weights on the edges in order to make it possible to link the layouts of the different scales. In contrast, our scheme makes a direct change to the graph’s layout at each level of the beautification process. As a consequence, the dependencies between the various representations are weaker, and we can use a multi-scale representation with unweighted edges, which while not capturing the final size of the graph often solves many large scale conflicts correctly. As a result of this, we can potentially utilize other force-directed methods as our local beautification procedure, a fact that might possibly yield several additional benefits. Following the appearance of our technical report [HK99], two other multiscale (or “multi-level”) methods were presented at the Graph Drawing 2000 conference together with ours, claiming to have certain advantages over ours. We now describe what seem to be their most important characteristics. The method of Gajer et al. [G+ 00] introduces several changes to our algorithm. The most notable one is that the graph theoretic distances between vertices are not stored in a |V | × |V | table, but are computed dynamically, when needed. This improves the storage requirements of our algorithm, making it suitable for dealing with larger graphs. Other attributes of [G+ 00] are: drawing in higher dimensions and optimizing the energy using gradient-descent, where extent of movement is limited by a local temperature (like [Fr+ 94]). [G+ 00] reports on drawings of 16,000-vertex graphs in around 40 seconds. The method of Walshaw [Wa00] is a multi-level extension of Fruchterman’s and Reingold’s spring embedder algorithm [FR91]. An advantage of working with the forces of [FR91] (compared to the energy of Kamada and Kawai) is that the method of [FR91] does not require the computation (and storage) of the all-pairs shortest path length. As a result, Walshaw [Wa00] can deal with huge graphs of 100,000 vertices in 10–20 minutes, which is very impressive. Another method for drawing large graphs is that of Quigley and Eades [QE00]. Their method is an improvement of the spring embedder algorithm. Unlike the multi-scale approach, they consider the whole graph at once. However, in order to accelerate computation, the nodes are clustered in a quad-tree structure, which reflects actual spatial proximity. The repulsive forces between a vertex and a cluster of distant vertices are approximated as a single force, what significantly lessens the number of forces in the system. There seem to be some connection with the work of Tunkelang [Tu99] mentioned in Section 2 above. We have not conducted tests to compare the running time of the multi-scale approach with that of [QE00]. However, the multi-scale approach optimizes several different energies on several levels, thus apparently capturing the various scales of beauty. Moreover, the multi-scale method may be faster and more robust, since it is not sensitive to the initial placement that is derived
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)199 from coarser scales. Recently, we have developed two new methods [K+ 01, HK02] for drawing huge graphs. They can draw 105 -vertex graphs in few seconds and 106 -vertex graphs in less than a minute, and thus appear to be significantly faster than previously known methods. The method in [K+ 01] draws a graph by quickly calculating eigenvectors of the Laplacian matrix associated with it, using a special algebraic multigrid technique, which is a rather accurate variant of the multi-scale paradigm. The method in [HK02] is somewhat more novel and has two phases: first embed the graph in a very high dimension (say, 50) and then project it onto the 2-D plane using Principal Components Analysis. The high-dimensional embedding is done very rapidly using a simple algorithm that utilizes the freedom given by the many dimensions. This method possesses a useful inherent capability to exhibit the graph in various dimensions, and an effective means for interactive exploration of large graphs.
7
Conclusions and Future Work
We have presented a new multi-scale approach for drawing graphs nicely, and have suggested a useful formulation for the desired properties of the coarse graphs. Our algorithm is able to deal extremely well and extremely fast with certain classes of large graphs. The algorithm was designed for speed and simplicity and does not require explicit representations of coarse graphs. A more powerful and general implementations of the multi-scale drawing scheme would overcome some limitations of our algorithm. We can improve the time and space complexity of our algorithm, by discarding the all-pairs shortest path length computation. This would enable the algorithm to deal with larger graphs. Another improvement lies in the construction of the coarse scale representation, for which we used a simple heuristic. For many graphs this heuristic is fine, but for some graphs it may not be enough. For example consider graphs with a tiny diameter, like the graph of Figure 11, whose diameter is 2. Our heuristic will totally fail on such a graph, since the distances between each pair of vertices are roughly the same, and it is thus unable to differentiate different clusters. Our algorithm uses the heuristic of Kamada and Kawai [KK89], which does not punish edge-crossings explicitly. It may be interesting to see how the explicit consideration of crossings, as is done, e.g., in [DH89], will be reflected in the results of a multi-scale method such as ours. This could be of particular importance in drawing less regular-looking (that is, more random-looking) graphs.
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)200
Result of Fruchterman-Reingold
Result of our method
Figure 11: Bad example: a graph with a degenerate diameter
Acknowledgements We would like to thank the referees for their helpful comments.
References [BH86] J. Barnes and P. Hut, “A hierarchical O(N log N ) Force-Calculation Algorithm”, Nature, 324 (1986), 446–449. [Br+ 95] F.J. Brandenburg, M. Himsolt and C. Rohrer, “An Experimental Comparison of Force-Directed and Randomized Graph Drawing Algorithms”, Proceedings of Graph Drawing ’95, Lecture Notes in Computer Science, Vol. 1027, pp. 76–87, Springer Verlag, 1995. [Di+ 99] G. Di Battista, P. Eades, R. Tamassia and I.G. Tollis, Algorithms for the Visualization of Graphs, Prentice-Hall, 1999. [DH89] R. Davidson and D. Harel, “Drawing Graphs Nicely Using Simulated Annealing”, ACM Trans. on Graphics 15 (1996), 301–331. (Preliminary version: Technical Report, The Weizmann Institute of Science, 1989.) [Ea84] P. Eades, “A Heuristic for Graph Drawing”,Congressus Numerantium 42 (1984), 149–160. [Fr+ 94] A. Frick, A. Ludwig and H. Mehldau, “A Fast Adaptive Layout Algorithm for Undirected Graphs”, Proceedings of Graph Drawing 1994, Lecture Notes in Computer Science, Vol. 894, pp. 389–403, Springer Verlag, 1995.
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)201 [FR91] T.M.G. Fruchterman and E. Reingold, “Graph Drawing by ForceDirected Placement”, Software-Practice and Experience 21 (1991), 1129–1164. [G+ 00] P. Gajer, M. T. Goodrich, and S. G. Kobourov, “A Multi-dimensional Approach to Force-Directed Layouts of Large Graphs”, Proceedings of Graph Drawing 2000, Lecture Notes in Computer Science, Vol. 1984, pp. 211–221, Springer Verlag, 2000. [Go85] T. Gonzalez, “Clustering to Minimize the Maximum Inter-Cluster Distance”, Theoretical Computer Science 38 (1985), 293–306. [HH99] R. Hadany and D. Harel, “A Multi-Scale Method for Drawing Graphs Nicely”, Discrete Applied Mathematics, 113 3-21 (2001). (Also, Proc. 25th Inter. Workshop on Graph-Theoretic Concepts in Computer Science (WG ’99), Lecture Notes in Computer Science, Vol. 1665, pp. 262–277, Springer Verlag, 1999.) [HK99] D. Harel and Y. Koren, “A Fast Multi-Scale Method for Drawing Large Graphs”, Technical Report MCS99-21, Faculty of Mathematics and Computer Science, The Weizmann Institute of Science, 1999. [HK02] D. Harel and Y. Koren, “A Multi-dimensional Approach to ForceDirected Layouts of Large Graphs”, to appear in Proceedings of Graph Drawing 2002, Lecture Notes in Computer Science, Springer Verlag. [Ho96] D. S. Hochbaum (ed.), Approximation Algorithms for NP-Hard Problems, PWS Publishing Company, 1996. [HS86] D. S. Hochbaum and D.B. Shmoys, “A Unified Approach to Approximation Algorithms for Bottleneck Problems”, J. Assoc. Comput. Mach. 33 (1986), 533–550. [KK89] T. Kamada and S. Kawai, “An Algorithm for Drawing General Undirected Graphs”, Information Processing Letters 31 (1989), 7–15. [KW01] M. Kaufmann and D. Wagner (Eds.), Drawing Graphs Methods and Models, Lecture Notes in Computer Science, Vol. 2025, Springer Verlag, 2001. [K+ 01] Y. Koren, L. Carmel and D. Harel “ACE: A Fast Multiscale Eigenvectors Computation for Drawing Huge Graphs”, Technical Report MCS01-17, The Weizmann Institute of Science, 2001. Available at: www.wisdom.weizmann.ac.il/reports.html. To appear in Proceedings of IEEE Symposium on Information Visualization (InfoVis 2002). [LSD]
The LSD library, available from the Graphlet website http://www.fmi.uni-passau.de/Graphlet/download.html
at
Harel and Koren, Fast Drawing of Large Graphs, JGAA, 6(3) 179–202 (2002)202 [QE00] A. Quigley and P. Eades, “FADE: Fraph Drawing, Clustering, and Visual Abstraction”, Proceedings of Graph Drawing 2000, Lecture Notes in Computer Science, Vol. 1984, pp. 183–196, Springer Verlag, 2000. [Tu99] D. Tunkelang, A Numerical Optimization Approach to General Graph Drawing, Ph.D. Thesis, Carnegie Mellon University, 1999. [Wa00] C. Walshaw, “A Multilevel Algorithm for Force-Directed Graph Drawing”, Proceedings of Graph Drawing 2000, Lecture Notes in Computer Science, Vol. 1984, pp. 171–182, Springer Verlag, 2000.
Journal of Graph Algorithms and Applications http://www.cs.brown.edu/publications/jgaa/ vol. 6, no. 3, pp. 203-224 (2002)
GRIP: Graph Drawing with Intelligent Placement Pawel Gajer Department of Computer Science Johns Hopkins University Baltimore, MD http://www.math.jhu.edu/~pgajer/
Stephen G. Kobourov Department of Computer Science University of Arizona Tucson, AZ http://www.cs.arizona.edu/people/kobourov/ Abstract This paper describes a system for Graph dRawing with Intelligent Placement, GRIP. The system is designed for drawing large graphs and uses a novel multi-dimensional force-directed method together with fast energy function minimization. The algorithm underlying the system employs a simple recursive coarsening scheme. Rather than being placed at random, vertices are placed intelligently, several at a time, at locations close to their final positions. The running time and space complexity of the system are near linear. The implementation is in C using OpenGL for 3D viewing. The GRIP system allows for drawing graphs with tens of thousands of vertices in under one minute on a mid-range PC. To the best of the authors’ knowledge, GRIP surpasses the fastest previous algorithms. However, speed is not achieved at the expense of quality as the resulting drawings are quite aesthetically pleasing.
Communicated by Michael Kaufmann: submitted March 2001; revised February 2002 and June 2002.
This research partially supported by NSF under Grant CCR–9625289. A preliminary version of this paper appeared in the Proceedings of the 8th Symposium on Graph Drawing (GD 2000).
Gajer and Kobourov, GRIP, JGAA, 6(3) 203-224 (2002)
1
204
Introduction
Let G be a graph G = (V, E), where V is a set of vertices and E a set of edges, where |V | = n and |E| = m. We would like to display G in two or three dimensions so as to show clearly the underlying relationships. This problem is generally known as the graph drawing problem. In a graph drawing we typically use points to represent the vertices and straight-line segments to represent the edges. The quality of the drawings produced by such algorithms is measured by a set of aesthetic criteria such as: • minimizing the number of edge crossings • displaying graph symmetries • distributing the vertices evenly • uniform edge length. A large class of graph drawing algorithms (including ours) is based on the force-directed placement technique. The spring embedder of Eades [8] is one of the earliest examples and uses a physical model from Newtonian mechanics. In this model vertices are physical objects (steel rings) and edges are springs connecting them. An initial random placement of the vertices is repeatedly refined until a configuration with low energy has been obtained. The functions modeling the forces in these computations are typically simplified in order to speed up the computation. In Eades’ spring embedder, there are two types of forces: attractive and repulsive. Attractive forces exist between vertices connected by edges and are defined by the log of the distance between them, c1 log
distR2 (u, v) , c2
where c1 and c2 are constants and distR2 (u, v) is the distance between vertices u and v in the drawing. Similarly, repulsive forces exist between all pairs of vertices and are defined by the distance between the vertices, c3 , 2 distR2 (u, v) where c3 is a constant. Kamada and Kawai [15, 16] use a similar approach but specify explicitly the function for the total energy of the graph: X cuv (distR2 (u, v) − distG (u, v))2 , 1≤u
where cuv is a constant associated with the spring between vertices u and v, and distG (u, v) is the length of the shortest path between u and v in G. This algorithm also begins with a random placement of all the vertices. The energy
Gajer and Kobourov, GRIP, JGAA, 6(3) 203-224 (2002)
205
is minimized by applying a Newton-Raphson method for moving one vertex at a time. Fruchterman and Reingold [10] present a modification of the spring embedder which yields a faster algorithm. In their method the attractive forces are defined by dist2R2 (u, v) , k p where k is the optimum distance between two vertices, defined as k = ( area n ). The repulsive forces are defined as k2 . distR2 (u, v) Davidson and Harel [7] introduce techniques from simulated annealing to the graph drawing process while adding more terms to the energy function to control the distance between vertices and edges. Frick et al. [9] present further improvements. Recently, Bruß and Frick [3] and Cruz and Twarog [6] describe several extensions of the drawing algorithms from 2D to 3D. Most of the above algorithms concentrate on drawing small graphs, typically with 10-50 vertices and produce nice drawing in reasonable time. However, these techniques fail when directly applied to larger graphs. Direct application of these techniques to larger graphs (e.g. graphs with tens of thousands of vertices) fail due to the local nature of the optimization methods used, and the space and time complexity of these techniques. One of the first algorithms to tackle graphs with thousands of vertices is that of Hadany and Harel [12] which uses a multi-scale technique to produce a sequence of approximations to the final layout. The main idea in this approach is to create a hierarchy of graphs, in which each consecutive layer is a coarser version of the previous one. The hierarchy of graphs is created by taking into account the cluster number, the degree number, and the homotopic number. Several new algorithms for drawing large graphs were presented at the 8th Symposium on Graph Drawing. Harel and Koren [13] present a multi-scale scheme that computes a simpler graph hierarchy. Walshaw [20] describes a similar multilevel algorithm. The n-body simulation method of Quigley and Eades [19] uses the Barnes-Hut [1] hierarchical space decomposition method. A method similar to our intelligent placement is described in the context of incremental drawing by Cohen in [4]. In the remainder of this paper we focus on the GRIP system which is based on a multi-dimensional force-directed technique.
2
The GRIP System
The GRIP system is based on the algorithm of Gajer, Goodrich, and Kobourov [11]. GRIP follows a number of force-directed drawing tools [3, 7, 9, 10, 13, 15] but employs several novel ideas first introduced in [11]: intelligent placement of vertices, drawing in higher dimensions, a fast energy minimization function, and a
Gajer and Kobourov, GRIP, JGAA, 6(3) 203-224 (2002)
206
G = (V,E)
FILTRATION V 0, V 1 , . . . , V k
i=k
PLACEMENT
REFINEMENT
of V i
of V i i=i-1 i=0 display G
Figure 1: An overview of the algorithm. Given a graph G, the algorithm proceeds in three stages. In the first stage we create a maximal independent set (MIS) filtration. In the second and third stages we use the filtration sets Vk , Vk−1 , . . . , V0 to repeatedly add more vertices and refine the drawing.
simple vertex filtration. Carefully put together, these techniques allow GRIP to draw graphs with tens of thousands of vertices in under one minute. While [11] contains the main methodology this paper focuses on the actual system, implementation, examples and experiments. An overview of the system and its three main stages is given in Fig. 1 and the main algorithm is summarized in Fig. 2. Starting with a graph G = (V, E), we first create a maximal independent set (MIS) or a random filtration V : V = V0 ⊃ V1 ⊃ . . . ⊃ Vk ⊃ ∅ of the set V of vertices of G, so that k = O(log n), and |Vk | = 3. A filtration V of V is called a maximal independent set filtration if V1 is a maximal independent set of G, and each Vi is a maximal subset of Vi−1 so that the graph distance between any pair of its elements is at least 2i−1 + 1. Recall that the graph distance between a pair of vertices is defined as the length of the shortest path between them in the original graph G. Note that the length of a maximal independent set filtration is log δ(G), where δ(G) is the diameter of the graph. Since δ(G) = O(n), the depth of the filtration is also O(log n). Similarly, the expected depth of the random filtration is O(log n). We ensure that the last set has exactly three elements by modifying the last one or two sets in the filtration. Once we have obtained the desired vertex filtration, we proceed to the initial placement and refinement stages. First, we generate an initial embedding of Vk . The vertices of Vk are placed in Rn using their graph distances. More precisely, since |Vk | = 3, we find a triangle with sides equal to the graph distances between the three vertices and place the vertices at the endpoints the triangle. Then, we add the vertices of Vk−1 that are not in Vk , placing them initially at the positions determined by their graph distances to a subset of the elements of Vk . The positions of the vertices in Vk−1 are modified using a force-directed layout method. This process of adding new vertices and refining their positions is repeated for Vk−2 , . . . , V1 , V0 . The refined positions of the elements of V0 constitute the final layout of the vertices of G. Note that we draw only the
Gajer and Kobourov, GRIP, JGAA, 6(3) 203-224 (2002)
207
Main Algorithm create a filtration V : V0 ⊃ V1 ⊃ . . . ⊃ Vk ⊃ ∅ for i = k to 0 do for each v ∈ Vi − Vi+1 do find vertex neighborhood Ni (v), Ni−1 (v), . . . , N0 (v) find initial position pos[v] of v repeat rounds times for each v ∈ Vi do compute local temperature heat[v] − → disp[v] ← heat[v] · FNi (v) for each v ∈ Vi do pos[v] ← pos[v] + disp[v] add all edges e ∈ E Figure 2: After creating the vertex filtration and setting up the scheduling function the algorithm processes each filtration set, starting with the smallest one. Here pos[v] is a point in Rn corresponding to vertex v and rounds is a small constant. In the refinement stage heat[v] is scaling factor for the displacement vector disp[v], which in turn is computed over a restriction Ni (v) of the vertices of G.
vertices of G up to this point. Only when all the vertices have been placed and their positions refined do we draw the edges of G as straight line segments connecting their endpoints.
3
Building MIS Filtrations
A straightforward algorithm for finding a maximal independent set filtration of a graph G is to compute the distances between all the pairs of vertices of G and then use this information to produce a maximal independent set filtration. A problem with the all-pairs shortest path algorithm is its running time of is Ω(nm) and storage complexity of Ω(n2 ), e.g., see [5]. When dealing with graphs with tens of thousand of vertices, both the running time and the space complexity of the all-pairs shortest path algorithms pose serious problems. Our solution is based on the observation that to construct a maximal independent set filtration we do not need the distances between all the pairs of vertices. Indeed, we only need the distances between the vertices in the filtration sets. Moreover, the information that has been used to construct Vi is not needed to construct Vi+1 . Therefore, we have adopted the following “create then destroy” strategy for construction of MIS filtrations. Suppose we have already constructed set Vi . The next set in the filtration, Vi+1 is going to contain a proper subset of the vertices in Vi . More precisely, to create Vi+1 , we build for each vertex of Vi a breadth-first search (BFS) tree up to depth 2i , but store in it only elements of Vi . We need to keep track of these vertices as they should
Gajer and Kobourov, GRIP, JGAA, 6(3) 203-224 (2002)
208
not be copied to Vi+1 . Note that this is all we need to build Vi+1 . In the process of creating Vi+1 we may need to build many BFS trees, but we destroy them immediately once they have been used, so that by the time we enter the next phase (of building Vi+2 ), all memory has been freed. Note that as i decreases, the number of vertices for which we have to perform a BFS calculation increases, but at the same time the depth to which we have to build these BFS trees decreases as well. The storage required for this strategy is X |bfs2i (v, Vi )|, max i
v∈Vi
where |bfs2i (v, Vi )| is the number of elements of Vi that belong to the BFS tree of v of depth 2i . The time complexity for this strategy in the case of bounded degree graph G is X k X |bfs2i (v)| , Θ i=0 v∈Vi
where |bfs2i (v)| is the number of vertices in the BFS tree of depth 2i for vertex v. Clearly, if we build a complete BFS tree for each vertex of G, then the running time and space complexity of this procedure, even in the bounded degree case, would be O(n2 ). For the above MIS filtration construction procedure however, our tests indicate that the running time is near linear as we only construct partial BFS trees and destroy them right away. In all of our experiments, the time spent creating the MIS filtration was less than 3% of the total running time, see Fig 11 and Fig 12. We store a MIS filtration of a graph of n vertices in an array misFiltration of size n so that the first |Vk | entries in the misFiltration array are the elements of Vk . The first |Vk−1 | entries in the array are the elements of Vk−1 . Similarly, the first |Vi | entries in the array are the elements of Vi . To keep track of where one set ends and another one begins we store the indices indicating the borders of different level sets of the filtration in a separate array misBorder of size log δ(G), see Fig. 3. Thus the space complexity for storing a MIS filtration is n + log δ(G). The same method can be applied to any filtration. In GRIP we have also implemented a random filtration. The random filtration is similar to MIS filtrations and k-centers filtrations of Harel and Koren [13], except that the vertices are filtered out at random. We assign each vertex in Vi a 1/2 probability of propagation to Vi+1 , for i = 0, 1, . . . , k − 1. Random filtrations take O(n) time to create, as opposed to the O(n2 ) time required by MIS and k-centers filtrations. Random filtrations have expected depth O(log n) as opposed to O(log δ(G)) for MIS filtrations. While for most graphs we tested the random filtration produces drawings similar to those created using MIS filtrations, for sparse graphs the performance deteriorates.
Gajer and Kobourov, GRIP, JGAA, 6(3) 203-224 (2002)
1
1
209
12
11
1 2
11
3
3 4
10 5
9
5
9
5
9 8
V2
misFiltration
1
5
misBorder
9
3
3
7
6
11
6
7
7
V1
V0
2
4
6
8
10
12
12
G is a cycle on 12 vertices and the filtrations sets are V0 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}, V1 = {1, 3, 5, 7, 9, 11}, and V2 = {1, 5, 9}. Note how the filtration is stored in the misFiltration array and how the misBorder array is used to identify the borders of the filtration sets. The first entry, 3, in the misBorder array identifies the first three elements of the misFiltration array as V2 . The second entry, 6, identifies the first 6 elements of the misFiltration array as V1 and the third entry, 12, identifies the first 12 elements of the array as V0 .
Figure 3:
4
Initial Placement and Refinement
The second and third phases of the algorithm are the placement and refinement stages, respectively. In the ith placement stage, the vertices of set Vi are intelligently placed in Rn . In the ith refinement stage, a local force-directed method is used to obtain better positions for the vertices of Vi . After the placement and refinement stages for Vi have been completed, the process is repeated for Vi−1 , Vi−2 , all the way to V1 . Recall that there are exactly three vertices in Vk . We compute their pairwise graph distances and place them at the endpoints of a triangle with sides of lengths equal to these distances. Consider the general placement case. Suppose the refinement and placement stages for Vi have been completed and we want to begin the placement phase for Vi−1 . All the vertices in Vi are also in Vi−1 , since Vi−1 ⊃ Vi as defined by the construction of the filtration. Thus we are only concerned with the placement of the vertices in Vi−1 that are not in Vi . The idea behind the intelligent placement is that every vertex t is placed “close” to its optimal position as determined by the graph distances from t to several already placed vertices. The intuition is that if we can place the vertices close to their optimal positions from the very beginning, then the refinement stages
Gajer and Kobourov, GRIP, JGAA, 6(3) 203-224 (2002)
210
Figure 4: Drawing of the vertices in the filtration sets. Here V : V0 ⊃ V1 ⊃ V2 ⊃ V3 ⊃ V4 . The sizes of the sets are 231, 60, 21, 6, 3, respectively. The process begins with a placement for V4 , followed by V3 , etc. Note that edges are drawn only when all the vertices are placed.
need only a few iterations of a local force-directed method to reach a minimal energy state. After experimenting with several initial placement strategies we decided to use two simple strategies in GRIP. The first strategy, “simple barycenter” begins by setting pos[t], the initial position for a new vertex t, to the barycenter (pos[u]+pos[v]+pos[w])/3 of u, v, and w, the three vertices closest to t that are already placed. This is followed by a force-directed modification of the position vector of t with the energy function E calculated only at the three points u, v, w. This makes the procedure very fast, and in our tests it produced good results, see Fig. 4. The second strategy “three closest neighbors” uses the positions of the three closest already placed neighbors to determine the location of new vertex t. We begin by finding t’s three closest neighbors u, v, w ∈ Vi . Since u, v and w have already been placed we can obtain a suitable place for t by solving the following system of equations for u, v, w, and t 2 2 2 (x − xu ) + (y − yu ) = distG (u, t) 2 2 2 (x − xv ) + (y − yv ) = distG (v, t) (x − xw )2 + (y − yw )2 = distG (w, t)2 , where pos[u] = (xu , yu ), pos[v] = (xv , yv ), pos[w] = (xw , yw ), pos[t] = (x, y). Since this system of equations is over-determined and may not have any solutions, we solve the following three pairs of equations instead ( distR2 (u, t) = distG (u, t) distR2 (v, t) = distG (v, t) ( distR2 (v, t) = distG (v, t) distR2 (w, t) = distG (w, t) ( distR2 (u, t) = distG (u, t) distR2 (w, t) = distG (w, t). Solving these three systems of quadratic equations, we obtain up to six different + + solutions. We choose the three closest to each other, call them t+ 1 , t2 , t3 , and + + + place t are their barycenter: pos[t] = (t1 + t2 + t3 )/3.
Gajer and Kobourov, GRIP, JGAA, 6(3) 203-224 (2002)
211
Refinement of Vi repeat rounds(i) times for each v ∈ Vi do if i > 0 then − → disp[v] ← F KK (v) else − → disp[v] ← F FR (v) heat [v] ← updateLocalTemp(v) disp[v] disp[v] ← heat[v] · kdisp[v]k for each v ∈ Vi do pos[v] ← pos[v] + disp[v] Figure 5: Pseudocode of the refinement phase of the algorithm. While the refinement is calculated using a force-directed method, it is important to note that the forces are calculated locally, see Fig. 5. For each level of the filtration Vi , we perform rounds(i) updates of the vertex positions, where rounds(i) is a scheduling function which can be specified at the beginning of the execution. Typically, 5 ≤ rounds(i) ≤ 30. At all levels of the filtration except the last one, the displacement vector disp[v] of v is set to a local Kamada-Kawai force vector, X distRn (u, v) − → − 1 (pos[u] − pos[v]). F KK (v) = distG (u, v) · edgeLength2 u∈Ni (v)
In the last level of the filtration, V0 = V all the vertices have been placed. In order to speed up computation, we set the displacement vector for the last level to a local Fruchterman-Reingold force vector, X
− → F FR (v) =
u∈Adj(v)
+
X u∈Ni (v)
s
distRn (u, v)2 (pos[u] − pos[v]) + edgeLength2
edgeLength2 (pos[v] − pos[u]), distRn (u, v)2
Here, distRn (u, v) is the Euclidean distance between pos[u] and pos[v], and distG (u, v) is the graph distance between u and v. In the above equations, edgeLength is the unit edge length, Adj(v) is the set of vertices adjacent to v, and s is a small scaling factor which is set to 0.05 in our program. Note that for a vertex v ∈ G the force calculation is performed over a restriction Ni (v) of the vertices of G. Each vertex neighborhood Ni (v) contains a constant number of vertices closest to v which belong to Vi . Thus only a constant number of vertices which are near vertex v are used to refine v’s position. This is why we call this type of force calculation local.
Gajer and Kobourov, GRIP, JGAA, 6(3) 203-224 (2002)
212
updateLocalTemp(v) if kdisp[v]k = 6 0 and koldDisp[v]k = 6 0 then cos[v] =
disp[v] ∗ oldDisp[v] kdisp[v]k ∗ koldDisp[v]k
r = 0.15, s = 3 if oldCos[v] ∗ cos[v] > 0 then heat[v] = heat[v] + (cos[v] ∗ r ∗ s) else heat[v] = heat[v] + (cos[v] ∗ r) oldCos[v] = cos[v] Figure 6: Pseudocode of the local temperature calculation. The local temperature heat[v] of v is a scaling factor of the displacement vector for vertex v, similar to that of Fruchterman and Reingold [10] and Frick et al [9]. The algorithm for determining the local temperature is in Fig. 6. To speed up the calculation, we maintain two auxiliary arrays oldDisp and oldCos, where oldDisp[v] is the previous displacement vector for v, and oldCos[v] is the previous value of the cosine of the angle between oldDisp[v] and disp[v]. When a displacement vector of v is calculated for the first time, heat[v] is set to a default value edgeLength/6. The local temperature helps speed up convergence by distinguishing between oscillating vertices and vertices that continue moving in one directions. There are three cases for determining the local temperature : 1. if either oldDisp[v] or disp[v] is a zero vector, then the value of heat[v] does not change; 2. if v is oscillating around some stationary point we add to it a factor (cos[v]∗ r ∗ s); 3. in all other cases we add a factor of (cos[v] ∗ r).
5
Implementation
The GRIP system was originally written in C++ and then re-done in C with OpenGL, with a Tcl/Tk interface, see Fig. 7. GRIP is available for download at http:\\www.cs.arizona.edu/~kobourov/GRIP. The system can read in files and generates several typical classes of graphs parametrized by their number of vertices, e.g. paths, cycles, square meshes, triangular meshes, and complete graphs. GRIP also contains generators for complete n-ary trees, random graphs with parametrized density, and knotted triangular and rectangular meshes. Different types of tori, as well as cylinders and Moebius bends can be generated with parametrized thickness and length. Finally, Sierpinski graphs in 2 and 3
Gajer and Kobourov, GRIP, JGAA, 6(3) 203-224 (2002)
213
Figure 7: The GRIP system: On the top left we have the control window, which lets us chose the type of graph, the graph parameters, dimension of the drawing, parameters of the algorithm, and display settings. Graphs can be read from a file, or one of the several built-in generators can be used. Currently we support generators for trees, paths, cycles, cylinders, tori, degree 4 meshes, degree 6 meshes, and Sierpinski graphs. Parameters of the algorithm include attractive/repulsive force ratio and initial and final number of rounds, among others. The display settings control the interactive display, speed, and color. Within the OpenGL window the graph can be dragged, rotated, and zoomed.
Figure 8: GRIP can read files in the gml format. This allows for displaying properties such as direction of edges, self-loops and colors specified for vertices and edges.
Gajer and Kobourov, GRIP, JGAA, 6(3) 203-224 (2002)
214
dimensions (Sierpinski triangles and Sierpinski pyramids, respectively) are also available. In addition to the set of graphs that GRIP can generate, other graphs can be read from a file in gml format [14]. This allows the display of options such as directed edges, different color vertices and edges, self-loops, etc., see Fig. 8. GRIP can draw graphs directly in 2D or 3D or projected down from higher dimensions. Drawings produced in higher dimensions and projected down to 2D or 3D usually produce better results. At this time, the projections are done at random. We are working on incorporating projections based on spectral analysis similar to [2]. Figures 9-10 show how the MIS filtration method compares to the random filtration method. In both the final drawing for each level of the filtration is captured. Note that all but the last drawings show only vertices as the induced graphs are never computed. For a given filtration level Vi , the vertices in Vi \ Vi−1 are shown as bigger dots, while those that came down from the previous level (Vi−1 ) are shown as small dots. While random filtrations take a small fraction of the time required to create MIS filtrations in general they induce more refinement levels. Most drawings produced with random filtrations and MIS filtrations are similar, see Fig. 9. Random filtrations perform worse for sparse graphs as the variation in the distances between vertices in the same level becomes greater, see Fig. 10. Running times for the MIS creation and for the entire drawing process as shown in Fig 11 and Fig. 12. Most of the drawings in the following examples took less than 1 second. The Sierpinski pyramid of order 8 (with 32,770 vertices, 196,608 edges) was the most time consuming: it took 58 seconds on a 500MHz Pentium III machine. The parameters discussed in this paper can be changed via GRIP’s interface, thus allowing for experimentation with different scheduling functions, scaling parameters, filtrations, etc. There are controls for the drawing dimension and the drawing speed. The drawings produced by default are three dimensional, interactive, and use color and shading to aid three dimensional perception. For faster results, the interactive display can be turned off so that only the final drawing is shown. The size and colors of the vertices and edges can also be modified.
6
Examples
In the next few pages we provide several examples of graphs produced by GRIP. None of the drawings have been additionally modified. We focus mostly on larger graphs but also provide several “classical” smaller graphs to illustrate the versatility of the system. Fig. 13 shows drawings of a dodecahedron, C60 (bucky ball), and a 3D cube mesh. Fig. 14 shows 3D drawings of a 4D cube, 5D cube, and 6D cube. Fig. 15 shows binary, 3-ary, and 4-ary trees. Fig. 16 shows several cycles. Fig. 17 shows three “real-world” graphs from the Stanford GraphBase [17]. Fig. 18 shows regular degree 4 meshes of up to 10,000 vertices.
Gajer and Kobourov, GRIP, JGAA, 6(3) 203-224 (2002)
215
Figure 9: Mesh on 225 vertices using MIS filtration (1st column) and random filtration (2nd and 3rd columns).
Gajer and Kobourov, GRIP, JGAA, 6(3) 203-224 (2002)
216
Figure 10: Cycle on 20 vertices using MIS filtration (1st column) and random filtration (2nd and 3rd columns).
Fig. 19 shows drawings of the same meshes with their endpoints attached (knotted meshes). Fig. 20 shows several cylinders and Fig. 21 shows tori. Fig. 22 shows regular degree 6 meshes and Fig. 23 shows the same meshes with their endpoints attached (knotted meshes). The Sierpinski triangle (pyramid) is a classic fractal [18]. Several 2D, 3D, and 4D drawings are shown on Fig. 24 and Fig. 25. Whereas traditionally the image is defined with fixed vertices and edges, we make ours a fractal graph with no specific embedding. The Sierpinski pyramid graph is created by a recursive procedure, parametrized on the order of the recursion. As in the 2D case, at each iteration, every pyramid is divided into five congruent smaller pyramids with the central pyramid removed. In a Sierpinski pyramid of order k k the number of vertices is |Vk | = 42 + 2 and the number of edges is |E| = 6(|V | − 4) + 12 = 3 × 4k . Fig. 24(c) shows a Sierpinski pyramid of order 7 with 8,194 vertices and 49,152 edges. Fig. 25 shows a Sierpinski pyramid of order 8 with 32,770 vertices and 196,608 edges. Given the parameter k we generate
Gajer and Kobourov, GRIP, JGAA, 6(3) 203-224 (2002)
217
6 Cycle Degree 4 Mesh Degree 6 Mesh
Running time in seconds
5
4
3
2
1
0 0
5000
10000
15000
20000 25000 Number of vertices
30000
35000
40000
45000
Figure 11: The chart contains the running times for construction of a MIS filtration for cycles, meshes of degree 4, and meshes of degree 6. As can be expected, the depth of the filtration is the largest for the sparsest graphs, in this case, the cycles.
Cycle Degree 4 Mesh Degree 6 Mesh
60
Running time in seconds
50
40
30
20
10
0 0
2000
4000
6000
8000 10000 Number of vertices
12000
14000
16000
18000
Figure 12: The chart contains the total running time for the three classes of graphs from Fig 11. Note that the construction of the MIS filtration takes less than 3% of the total running time.
Gajer and Kobourov, GRIP, JGAA, 6(3) 203-224 (2002)
218
the adjacency matrix of a graph which corresponds to the Sierpinski pyramid of order k. The drawings have been taken directly from the output of GRIP, without any modifications.
7
Conclusion and Future Work
In the process of writing this program several interesting questions arose. Some we answered in this paper, others we address in [11] but quite a few still remain: • How should the type of the graph affect the number of rounds? • What can we do about dense graphs and graphs with small diameter? (The MIS filtration is very shallow for such graphs.) • What filtrations (other than MIS) could produce good results? • Can the MIS filtration be created in provable subquadratic time, in the number of vertices and edges of the graph? (Currently, we have a modified MIS filtration, with similar properties which can be built in linear time. However, we are not aware of a subquadratic algorithm for the creation of a standard MIS filtration, as defined in the paper.)
8
Acknowledgements
We would like to thank Michael Goodrich, Christian Duncan, and Alon Efrat for helpful discussions. The conversion from C++ to C is due to Roman Yusufov who also wrote the user manual.
Figure 13: Small graphs: (a) dodecahedron (20 vertices); (b) C60 – bucky ball (60 vertices); (c) 3D cube mesh (216 vertices).
Gajer and Kobourov, GRIP, JGAA, 6(3) 203-224 (2002)
219
Figure 14: Cubes in 3D: (a) a 4D cube (16 vertices); (b) 5D cube (32 vertices); (c) 6D cube (64 vertices).
Figure 15: Trees: (a) a complete binary tree of depth 9 (511 vertices); (b) complete 3-ary tree of depth 7 (1093 vertices); (c) complete 4-ary tree of depth 6 (1365 vertices).
Figure 16: Cycles of 100, 200, and 400 vertices.
Gajer and Kobourov, GRIP, JGAA, 6(3) 203-224 (2002)
220
Figure 17: Graph from “real-world data”, as given by Knuth [17]: (a) miles2, (128 vertices, 368 edges); (b) miles3 (128 vertices, 518 edges) (c) miles4 (256 vertices, 312 edges
Figure 18: Rectangular (degree 4) meshes of 1600, 2500, and 10000 vertices.
Figure 19: Knotted rectangular (degree 4) meshes of 1600, 2500, and 10000 vertices.
Figure 20: Cylinders of 1000, 4000, and 10000 vertices.
Gajer and Kobourov, GRIP, JGAA, 6(3) 203-224 (2002)
221
Figure 21: Tori of various length and thickness: 1000, 2500, and 10000 drawn in four dimensions and projected down to three dimensions.
Figure 22: Triangular (degree 6) meshes of 496, 1035, and 2016 vertices.
Figure 23: Knotted triangular (degree 6) meshes of 496, 1035, and 2016 vertices.
Figure 24: Sierpinski graphs in 2D and 3D (a) 2D Sierpinski of order 7 (1,095 vertices); (b) 3D Sierpinski of order 6 (2,050 vertices); (c) 3D Sierpinski of order 7 (8,194 vertices). The last drawing took 15 seconds on a 500Mhz Pentium III machine.
Gajer and Kobourov, GRIP, JGAA, 6(3) 203-224 (2002)
222
Figure 25: 4D Sierpinski graph of order 8 on 32,770 vertices and 196,608 edges. The drawing took 58 seconds on a 500Mhz Pentium III machine.
Gajer and Kobourov, GRIP, JGAA, 6(3) 203-224 (2002)
223
References [1] J. Barnes and P. Hut. A hierarchical O(N log N) force calculation algorithm. Nature, 324:446–449, Dec. 1986. Institute for Advanced Study, Princeton, New Jersey. [2] Brandes and Cornelsen. Visual ranking of link structures. In WADS: 7th Workshop on Algorithms and Data Structures, volume 2125 of Lecture Notes in Computer Science, pages 222–232, 2001. [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 Computer Science, pages 99–110. Springer-Verlag, 1996. [4] J. D. Cohen. Drawing graphs to convey proximity: An incremental arrangement method. ACM Transactions on Computer-Human Interaction, 4(3):197– 229, Sept. 1997. [5] T. H. Cormen, C. E. Leiserson, and R. L. Rivest. Introduction to Algorithms. MIT Press, Cambridge, MA, 1990. [6] 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 Computer Science, pages 162–165, 1996. [7] R. Davidson and D. Harel. Drawing graphics nicely using simulated annealing. ACM Trans. Graph., 15(4):301–331, 1996. [8] P. Eades. A heuristic for graph drawing. Congressus Numerantium, 42:149–160, 1984. [9] A. Frick, A. Ludwig, and H. Mehldau. A fast adaptive layout algorithm for undirected graphs. In R. Tamassia and I. G. Tollis, editors, Graph Drawing (Proc. GD ’94), LNCS 894, pages 388–403, 1995. [10] T. Fruchterman and E. Reingold. Graph drawing by force-directed placement. Softw. – Pract. Exp., 21(11):1129–1164, 1991. [11] P. Gajer, M. T. Goodrich, and S. G. Kobourov. A multi-dimensional approach to force-directed layouts. In Proceedings of the 8th Symposium on Graph Drawing (GD 2000), pages 211–221, 2000. [12] R. Hadany and D. Harel. A multi-scale algorithm for drawing graphs nicely. In Proc. 25th International Workshop on Graph Teoretic Concepts in Computer Science (WG’99), 1999. [13] D. Harel and Y. Koren. A fast multi-scale method for drawing large graphs. In Proceedings of the 8th Symposium on Graph Drawing (GD 2000), pages 183–196, 2000. [14] M. Himsolt. Gml: A portable graph file format. Technical report, Universit¨ at Passau, 1994. [15] T. Kamada and S. Kawai. Automatic display of network structures for human understanding. Technical Report 88-007, Department of Information Science, University of Tokyo, 1988. [16] T. Kamada and S. Kawai. An algorithm for drawing general undirected graphs. Inform. Process. Lett., 31:7–15, 1989.
Gajer and Kobourov, GRIP, JGAA, 6(3) 203-224 (2002)
224
[17] D. E. Knuth. The Stanford GraphBase: A Platform for Combinatorial Computing. ACM Press, New York, NY 10036, USA, 1993. [18] B. B. Mandelbrot. The Fractal Geometry of Nature. W.H. Freeman and Co., New York, rev 1983. [19] A. Quigley and P. Eades. FADE: graph drawing, clustering, and visual abstraction. In Proceedings of the 8th Symposium on Graph Drawing (GD 2000), pages 197–210, 2000. [20] C. Walshaw. A multilevel algorithm for force-directed graph drawing. In Proceedings of the 8th Symposium on Graph Drawing (GD 2000), pages 171–182, 2000.
Journal of Graph Algorithms and Applications http://www.cs.brown.edu/publications/jgaa/ vol. 6, no. 3, pp. 225-254 (2002)
A User Study in Similarity Measures for Graph Drawing Stina Bridgeman Department of Computer Science Colgate University Hamilton, NY 13346 http://cs.colgate.edu/faculty/stina/ [email protected]
Roberto Tamassia Center for Geometric Computing Department of Computer Science Brown University Providence, RI 02912–1910 http://www.cs.brown.edu/~rt/ [email protected] Abstract The need for a similarity measure for comparing two drawings of graphs arises in problems such as interactive graph drawing and the indexing or browsing of large sets of graphs. Many applications have been based on intuitive ideas of what makes two drawings look similar — for example, the idea that vertex positions should not change much. In this paper, we formally define several of these intuitive ideas of similarity and present the results of a user study designed to evaluate how well these measures reflect human perception of similarity.
Communicated by Michael Kaufmann: submitted February 2001;revised January 2002 and June 2002.
Research supported in part by the National Science Foundation under grants CCR– 9732327, CCR–0098068 and CDA–9703080, and by the U.S. Army Research Office under grant DAAH04-96-1-0013. Work completed while the first author was at Brown University.
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 226
1
Introduction
The question of how similar two drawings of graphs are arises in a number of situations. One application is interactive graph drawing, where the graph being visualized changes over time and it is important to preserve the user’s “mental map” [12] of the original drawing as much as possible so the user does not need to spend a lot of time relearning the drawing after each update. Having to relearn the drawing can be a significant burden if the graph is updated frequently. Animation can be used to provide a smooth transition between the drawings and can help compensate for greater changes in the drawing, but it is still important to maintain some degree of similarity between the drawings to help the user orient herself to the new drawing. Related to interactive graph drawing is layout adjustment, where an existing drawing is modified so as to improve an aesthetic quality without destroying the user’s mental map. Another application is in indexing or browsing large sets of graphs. An example of a graph browser is contained the SMILE graph multidrawing system of Biedl et. al. [1]. The SMILE system tries to find a good drawing by producing many drawings of the graph and letting the user choose among them, rather than trying to code the properties of a good drawing into the algorithm. The graph browser arranges the drawings so that similar ones are near each other, to help the user navigate the system’s responses. Related to this is the idea of using similarities between drawings as a basis for indexing and retrieval. Such a system has applications in character and handwriting recognition, where a written character is transformed into a graph and compared to a database of characters to find the closest match. Let M be a similarity measure defined so that M ’s value is always nonnegative and is 0 when the drawings are identical. In order to be useful, M should satisfy three properties: Rotation: Given drawings D and D0 , M (D, Dθ0 ) should have the minimum value for the angle a user would report as giving the best match, where Dθ0 is D0 rotated by an angle of θ with respect to its original orientation. Ordering: Given drawings D, D0 , and D00 , M (D, D0 ) < M (D, D00 ) if and only if a user would say that D0 is more like D than D00 is like D. Magnitude: Given drawings D, D0 , and D00 , M (D, D0 ) = 1c M (D, D00 ) if and only if a user would say that D0 is c times more like D than D00 is like D. This paper describes a user study performed in order to evaluate several potential similarity measures with respect to rotation and ordering, and to test a possible method for obtaining data to be used for evaluating measures with respect to magnitude. Data cannot be collected directly for the magnitude part as it can be for rotation and ordering because it is very difficult to assign numerical similarity values to pairs of drawings; Wickelgren [18] observes that it is more difficult to assign numerical values than to judge ordering. As a result, other data must be gathered — for example, response times on a particular task —
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 227 with the hope that the data is sufficiently related to the actual similarity values to be useful. This can be partially tested by using the data (e.g., response times) to order the drawings, and determining whether the results are consistent with user responses on the ordering part. This study improves on our previous work [3] in several ways: • More Experimental Data: A larger pool of users (103 in total) was used for determining the “correct” behavior for the measure. • Refined Ordering Part: Users made only pairwise judgments between drawings rather than being asked to order a larger set. • Addressing of Magnitude Criterion: The previous experiment did not address magnitude at all. • More Realistic Drawing Alignment: The previous drawing alignment method allowed one drawing to be scaled arbitrarily small with respect to the other; the new method keeps the same scale factor for both drawings. • Refinement of Measures: For those measures computed with pairs of points, pairs involving points from the same vertex are skipped. • New Measures: Several new measures have been included. We describe the experimental setup in Section 2, the measures evaluated in Section 3, the results in Sections 4 and 5, and conclusions and directions for future work in Section 6.
2
Experimental Setup
This study focuses on similarity measures for orthogonal drawings of nearly the same graph. “Nearly the same graph” means that only a small number of vertex and edge insertions and deletions are needed to transform one graph into the other. In this study, the graphs differ by one vertex and two or four edges. The focus on orthogonal drawings is motivated by the availability of an orthogonal drawing algorithm capable of producing many drawings of the same graph, and by the amount of work done on interactive orthogonal drawing algorithms. (See, for example, Biedl and Kaufmann [2], F¨ oßmeier [8], Papakostas, Six, and Tollis [14], and Papakostas and Tollis [15].) Producing multiple drawings of the same graph is important because it can be very difficult to judge if one pair of drawings is more similar than another if the graphs in each pair are different.
2.1
Graphs
The graphs used in the study were generated from a base set of 20 graphs with 30 vertices each, taken from an 11,582-graph test suite. [7] Each of 20 base graphs was first drawn using Giotto [17]. Each of the Giotto-produced base drawings was modified by adding a degree 2 and a degree 4 vertex, for a total of 40 modified
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 228 drawings. Each modified drawing is identical to its base drawing except for the new vertex and its adjacent edges, which were placed in a manner intended to mimic how a user might draw them in an editor. Because InteractiveGiotto (used in the next step) preserves edge crossings and bends, routing the edges realistically avoids introducing a large number of extra crossings. Finally, a large number of new drawings were produced for each modified drawing using InteractiveGiotto [4], and four drawings were chosen from this set. The four drawings chosen range from very similar to the base drawing to very different.
2.2
Definition
The experiment consisted of three parts, to address the three evaluation criteria. In all cases, the user was asked to respond as quickly as possible without sacrificing accuracy. To promote prompt responses, each trial timed out after 30 seconds if the user did not respond. Rotation Part The rotation part directly addresses the rotation criterion. The user is presented with a screen as shown in Figure 1. The one drawing D on the left is the base drawing; the eight drawings D1 , . . . , D8 on the right are eight different orientations of the same new (InteractiveGiotto-produced) drawing derived from D. The eight orientations consist of rotations by the four multiples of π/2, with and without an initial flip around the x-axis. For orthogonal drawings, only multiples of π/2 are meaningful since it is clear that rotation by any other angle is not the correct choice. The vertices are not labelled in any of the drawings to emphasize the layout of the graph over the specifics of vertex names. The user’s task is to choose which of D1 , . . . , D8 looks most like the base drawing. A “can’t decide” button is provided for cases in which the drawings are too different and the user cannot make a choice. The user’s choice and the time it took to answer are recorded. Ordering Part The ordering part directly addresses the ordering criterion. In this part, the user is presented with a screen as shown in Figure 2. The one drawing D on the left is the base drawing; the two drawings D1 and D2 on the right are two different (InteractiveGiotto-produced) new drawings of the same modified drawing derived from D. The user’s task is to choose which of D1 and D2 looks most like the base drawing. A “can’t decide” button is provided for cases in which the drawings are too different and the user cannot make a choice. The user’s choice and the time it took to answer are recorded. Difference Part The difference part addresses the magnitude criterion by gathering response times on a task, with the assumption that a greater degree of similarity between the drawings will help the user complete the task more quickly. The screen presented to the user is shown in Figure 3. The drawing
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 229 D on the left is the base drawing; the drawing D1 on the right is one of the InteractiveGiotto-produced new drawings derived from D. The user’s task is to identify the vertex present in the right drawing that is not in the left drawing. The vertices are labelled with random two-letter names — corresponding vertices in drawings in a single trial have the same name, but the names are different for separate trials using the same base drawing to prevent the user from simply learning the answer. Displaying the vertex names makes the task less difficult, and mimics the scenario where the user is working with a dynamically updated graph where the vertex labels are important. The user’s choice and the time it took to answer are recorded.
2.3
Methodology
The three parts were assigned to students as part of a homework assignment in a second-semester CS course at Brown University. A total of 103 students completed the problem. Before being assigned the problem, the students had eight lectures on graphs and graph algorithms, including one on graph drawing. They had also been assigned a programming project involving graphs, so they had some familiarity with the subject. The homework problem made use of an online system which presented the displays shown in Figures 1, 2, and 3. A writeup was presented with the problem explaining how to use the system, and the directions were summarized each time the system was run. Each of the three parts was split into four runs, so the students would not have to stay focused for too long without a break. The graphs used were divided into 10 batches: the first batch (the practice batch) contained two modified drawings along with their associated new drawings, and each of the other nine batches contained three modified drawings and the associated new drawings. All of the students were assigned the practice batch for the first run of each part, and were randomly assigned three of the other batches for later runs so that each batch was completed by 1/3 of the students. A given student worked with the same batches for all three of the parts. Within each run of the system, the individual trials were presented in a random order and the order of the right-hand drawings in the rotation and ordering parts was chosen randomly. On average, students spent 6.9 minutes total on all four runs the rotation task (out of 22 minutes allowed), 8.3 minutes on the ordering task (out of 33), and 12.9 minutes on the difference task (out of 22). After the students completed all of parts, they answered a short questionnaire about their experiences. The questions asked were as follows: 1. (Ordering and Rotation) What do you think makes two drawings of nearly the same graph look similar? Are there factors that influenced your decisions? Did you find yourself looking for certain elements of the drawing in order to make your choice?
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 230
Figure 1: The rotation part.
Figure 2: The ordering part.
Figure 3: The difference part.
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 231 2. (Difference) What factors helped you locate the extra vertex more quickly? Did you compare the overall look of the two drawings in order to aid your search, or did you just scan the second drawing? 3. (All Parts) As you consider your answers, think about what this means for a graph drawing algorithm that seeks to preserve the look of the drawing. What types of things would it have to take into account?
3
Measures Evaluated
All of the measures evaluated in this study are described below. Most are the same as or similar to those described in [3]; the primary difference is that all of the measures have been scaled so that 0 means the drawings are identical and 1 is the maximum difference. The upper bound is frequently based on the worst-case scenario for point positioning and may not be achievable by an actual drawing algorithm. (For example, the upper bound may only be achieved when all of the vertices are placed on top of each other, an impossible situation with most drawing algorithms.)
3.1
Preliminaries
Corresponding Objects Most of the measures make use of the fact that the graph in the drawings being compared is the same. (If the graphs are not the same, those parts that are different are ignored and only the common subgraphs used.) This means that each vertex and edge of G has a representation in each of the drawings, and it is meaningful to talk about the corresponding vertex or edge in one drawing given a vertex or edge in the other drawing. Point Set Selection All measures except for the shape measures are defined in terms of point sets derived from the edges and vertices of the graph rather than the edges and vertices themselves. Like vertices and edges, each point in one drawing has a corresponding point in the other drawing. Points can be selected in a variety of ways; inspired by North [13], one point set contains the four corners of each vertex. Inspired by feedback from the study (section 5.2), a second “borders-only” point set was also considered. This is a subset of the “full” point set which contains only those points outside an ellipse centered within the drawing’s bounding box and with radii 90% of the width and height of the bounding box, or whose corresponding point in the other drawing meets this criterion. A change from the previous experiment [3] is that the computation of the nearest neighbor measures skips pairs of points derived from the same vertex. This can have a great effect because a point’s nearest neighbor will often be another corner of the same vertex, which does not convey much information about how that vertex relates to other vertices in the drawing. In this study, a point’s nearest neighbor is the nearest point from a different vertex. This is not
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 232 explicitly written in the definitions below for clarity of notation, but it should be assumed. Drawing Alignment For the measures involving the comparison of coordinates between drawings, the value of the measure is very dependent on how well the drawings are aligned. Consider two identical drawings, but let the x-coordinate of each point in the second drawing be one bigger than the xcoordinate of the corresponding point in the first drawing. The average distance moved by each point will be reported as 1, even though the drawings actually are the same. Aligning the drawings before comparing the coordinates removes this effect. In the previous experiment [3], alignment was done by simultaneously adjusting the scale and translation of one drawing with respect to the other so as to minimize the distance squared between corresponding points. This had the effect of potentially reducing one drawing to a very small area if the drawings did not match well. This has been replaced by a new alignment method which separates the determination of the scale and translation factors into two steps. First, the scale factor is set to ensure that the two drawings are drawn to the same scale. Since the drawings are orthogonal drawings, there is a natural underlying grid which can be used to adjust the scale. Once scaled, the translation factor is chosen so as to minimize the distance squared between corresponding points. The new alignment method is intended to better match how a person might try to match up the drawings — it does not seem likely that someone would mentally shrink or enlarge one drawing drastically with respect to the other, but rather would work with the current scale and try to adjust the translation. Suitability for Ordering vs. Rotation and Ordering Some of the measures do not depend on the relative rotation of one drawing with respect to the other. This means that they fail the rotation test, however, they are included because there may be situations in which the measure is not being used to determine the proper rotation for the drawings. Furthermore, a successful ordering-only measure could be combined with one which is successful at rotation but less so at ordering to obtain a measure which is good at both. Measures suitable for ordering only are marked [order only] below. Notation In the following, P and P 0 will always refer to the point sets for drawings D and D0 , respectively, and p0 ∈ P 0 will be the corresponding point for p ∈ P (and vice versa). Let d(p, q) be the Euclidean distance between points p and q.
3.2
Degree of Match
The following measures measure a degree of matching between the point sets by looking at the maximum mismatch between points in one set and points in
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 233 another. The motivation for these measures is straightforward — if point sets are being used to represent the drawings, then classical measures of point set similarity can be used to compare the drawings. Undirected Hausdorff Distance The undirected Hausdorff distance is a standard metric for determining the quality of the match between two point sets. It does not take into account the fact that the point sets may be labelled. haus(P, P 0 ) =
1 max { max min d(p, q 0 ) , max min d(p0 , q) } p∈P q0 ∈P 0 p0 ∈P 0 q∈P UB
UB is the maximum distance between a corner of the bounding box of P and a corner of the bounding box of P 0 . Maximum Distance The maximum distance is an adaptation of the undirected Hausdorff distance for labelled point sets, and is defined as the maximum distance between two corresponding points: maxdist(P, P 0 ) =
1 max d(p, p0 ) UB p∈P
UB is the maximum distance between a corner of the bounding box of P and a corner of the bounding box of P 0 .
3.3
Position
These measures are motivated by the idea that the location of the points on the page is important, and points should not move too move far between drawings. Average Distance tween drawings.
Average distance is the average distance points move be-
dist(P, P 0 ) =
1 X d(p, p0 ) |P | p∈P
Nearest Neighbor Between Nearest neighbor between is based on the assumption that a point’s original location should be closer to its new position than any other point’s new position. nnb(P, P 0 ) =
1 X weight(nearer(p)) UB p∈P
where
nearer(p) = {q | d(p, q 0 ) < d(p, p0 ) , q ∈ P , q 6= p}
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 234 Unweighted In the unweighted version, the score for p counts only whether or not there are points in P 0 between p and p0 . 0 if |S| = 0 weight(S) = 1 otherwise UB = |P | Weighted In the weighted version, the number of points in P 0 between p and p0 is taken into account. weight(S) UB
3.4
= |S| = |P | (|P | − 1)
Relative Position
These measures are based on the idea that the relative position of points should remain the same. There are two components to relative position — the distance between the points, and the orientation. All of the measures except for average relative distance are concerned with changes in orientation. Orthogonal Ordering Orthogonal ordering measures the change in orientation between pairs of points. Imagine compass roses centered on p and p0 , with north oriented towards the top of the page. Let θq and θq0 be the directions associated with q and q 0 , respectively. (Z 0 ) Z θq θq X 1 min weight(θ) dθ, weight(θ) dθ order(P, P 0 ) = W θq θq 0 p,q∈P
Constant-Weighted In the constant-weighted version, all changes of direction are weighted equally. weight(θ) W
= =
1 π
Linear-Weighted In the linear-weighted version, changes in the north, south, east, west relationships between points are weighted more heavily than changes in direction which do not affect this relationship. The weight function grows linearly with the distance between θ and north, south, east, or west. ( (θ mod π/2) if (θ mod π/2) < π/4 π/4 weight(θ) = π/2−(θ mod π/2) otherwise π/4 W = π/2
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 235 Ranking The ranking measure considers the relative horizontal and vertical position of the point. This is a component of the similarity measure used in the SMILE graph multidrawing system. [1] Let right(p) and above(p) be the number of points to the right of and above p, respectively. rank(P, P 0 ) =
1 X min{ | right(p)−right(p0 ) |+| above(p)−above(p0 ) | , UB } UB p∈P
where UB = 1.5 (|P | − 1) Of note here is that the upper bound is taken as 1.5 (|P |−1) instead of 2 (|P |−1), the actual maximum value occurring when a point moves from one corner of the drawing to the opposite corner. The motivation for this is simply that it scales the measure more satisfactorily. Average Relative Distance [order only] The average relative distance is the average change in distance between pairs of points. rdist(P, P 0 ) =
X 1 | d(p, q) − d(p0 , q 0 ) | |P | (|P | − 1) p,q∈P
λ-Matrix [order only] The λ-matrix model is used by Lyons, Meijer, and Rappaport [10] to evaluate cluster-busting algorithms. It is based on the concept of order type used by Goodman and Pollack [9], where two sets of points P and P 0 have the same order type if, for every triple of points (p,q,r), they are oriented counterclockwise if and only if (p0 ,q 0 ,r0 ) are also oriented counterclockwise. Let λ(p, q) be the number of points in P to the left of the directed line from p to q. 1 X | λ(p, q) − λ(p0 , q 0 ) | lambda(P, P 0 ) = UB p,q∈P
where the upper bound for a set of size n is: (n − 1)2 UB = n 2
3.5
Neighborhood
These measures are guided by the philosophy that each point’s neighborhood should be the same in both drawings. The measures do not explicitly take into account the point’s absolute position, and considers its position relative to other points only in the sense of keeping nearby points together.
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 236 Nearest Neighbor Within [order only] For nearest neighbor within, a point’s neighborhood is its nearest neighbor. Let nn(p) be the nearest neighbor of p in the p’s point set and nn(p)0 be the corresponding point in P 0 to nn(p). Ideally, nn(p)0 should be p0 ’s nearest neighbor. nnw(P, P 0 ) =
1 X weight(nearer(p)) UB p∈P
where nearer(p) = { q | d(p0 , q 0 ) < d(p0 , nn(p)0 ) , q ∈ P , q 6= p , q 6= nn(p) } Unweighted The unweighted version considers only whether or not nn(p)0 is p0 ’s nearest neighbor. 0 if |S| = 0 weight(S) = 1 otherwise UB = |P | Weighted The weighted version takes into account the number of points in P 0 closer to p0 than nn(p)0 . weight(S) UB
= |S| = |P | (|P | − 1)
-Clustering [order only] -clustering defines the neighborhood for each point to be its -cluster, the set of points within a distance , defined as the maximum distance between a point and its nearest neighbor. The -cluster for each point is guaranteed to contain at least one other point. The measure considers the ratio of the number of points in p’s -cluster in both drawings to the number of points in the -cluster in at least one of the drawings; ideally, this ratio would be 1 because the same points would be in both clusters. eclus = 1 −
|SI | |SU |
where SI SU clus(p, P, )
= max min d(p, q) p∈P q∈P,q6=p
= { (p, q) | p ∈ P , q ∈ clus(p, P, ) and q 0 ∈ clus(p0 , P 0 , 0 ) } = { (p, q) | p ∈ P , q ∈ clus(p, P, ) or q 0 ∈ clus(p0 , P 0 , 0 ) } = { q | d(p, q) ≤ , q ∈ P , q 6= p }
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 237 Separation-Based Clustering [order only] In the separation-based clustering measure, points are grouped so that each point in a cluster is within some distance δ of another point in the cluster and at least distance δ from any point not in the cluster. The intuition is that the eye naturally groups things based on the surrounding whitespace. Formally, for every point p in cluster C such that |C| > 1, there is a point q 6= p ∈ C such that d(p, q) < δ, and d(p, r) > δ for all points r 6∈ C. If C is a single point, only the second condition holds. Let clus(p) be the cluster to which point p belongs. |SI | sclus = 1 − |SU | where SI SU
3.6
= { (p, q) | p, q ∈ P , clus(p) = clus(q) and clus(p0 ) = clus(q 0 ) } = { (p, q) | p, q ∈ P , clus(p) = clus(q) or clus(p0 ) = clus(q 0 ) }
Edges
Shape The shape measure treats the edges of the graph as sequences of north, south, east, and west segments and compares these sequences using the edit distance. 1 X edits(e,e’) shape = UB e∈E
Regular The edit distance is not normalized for the length of the sequence, and the upper bound is as follows: X | length(e) − length(e0 ) | + min{ length(e) , length(e0 ) } UB = e∈E
Normalized The edit distance is normalized for the length of the sequence using the algorithm of Marzal and Vidal [11], and the upper bound is as follows: UB = |E|
4
Results: Rotation and Ordering
Figures 4(a) and 4(b) show the results for the rotation and ordering tasks, respectively. The measures are grouped according to the categorization of section 3. These results are explained and discussed in the following sections.
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 238
1 position
degree of match
0.9
edges
relative position
0.8 0.7
correctness
0.96
0.96
0.96
0.96
0.96
0.96
0.96
0.91
0.6 0.5
0.93
0.93
0.94
0.95
0.94
0.94
0.88 0.78
0.4
0.86
0.82 0.50
0.3
0.82
0.81
0.76
0.82 0.76
0.63 0.43
0.2
0.53
0.1 0
Hausdorff maximum unweighted weighted nearest neighbor distance distance between
mode
all
similar
average distance
linear- normalized constantweighted weighted shape orthogonal ordering
ranking
contradictory
features
(a) Rotation task.
1 0.9
degree of match
position 0.99
neighborhood
relative position
0.99
1.00
1.00
1.00
0.96
1.00
0.97
1.00
0.92 0.88
0.91
0.8
0.85
0.86
correctness
0.7 0.6
edges
0.99
0.88
0.84
0.83
0.89
0.91
0.92
0.93
0.93
0.91
0.92
0.91
0.93
0.89 0.88
0.85
0.5 0.4 0.3 0.2 0.1 0
mode Haus. max dist. dist. all
sep.- norm. unw. weighted ave. const.- linear- ranking λ-mat. relative unw. weighted orthogonal dist. neighbor neighbor -clus. based shape dist. ordering cluster within between
similar/features
similar/contradictory
features/features
features/contradictory
contradictory/contradictory
(b) Ordering task.
Figure 4: Average measure correctness for the rotation and ordering tasks. Numbers by columns show average relative correctness for that group; for (b), relative correctness is shown only for the “similar” and “not” trial groups.
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 239
4.1
Correctness
The success or failure of the candidate similarity measures is determined by how well they match observed user responses. A measure’s “correctness” is the fraction of the time the measure correctly predicted user responses on the tasks. For the rotation task, let an individual trial Trot be described by the tuple (D, D1 , . . . , D8 ), where D is the base drawing and the Di are the eight orientations the user must choose between. There are only two drawings that the user must choose between for the ordering task, so an ordering trial Torder can be described by the tuple (D, D1 , D2 ). Let TM be the measure’s choice for a rotation or ordering trial T : Dk if M (D, Dk ) < M (D, Di ) ∀i 6= k tie if ∃ j, k such that M (D, Dj ) = M (D, Dk ) ≤ M (D, Di ) TM = ∀i 6= j, k (j 6= k) Also, let Tk denote user k’s response for trial T : Dk if the user chose drawing Dk Tk = tie if the user clicked the “can’t decide” button Note that Tk is only defined if user k was presented with trial T — each trial was completed by about one-third of the users. Define the correctness of the measure M with respect to user k for T as C(M, T, k): 1 if TM = Tk or if Tk = tie C(M, T, k) = 0 otherwise C(M, T, k) is undefined if Tk is undefined. Any TM is considered to be correct for those trials where the user’s response is “can’t decide” because it is assumed that if the user has no preference as to the correct response, she will be happy with any of the choices. Let K be the set of users k for which Tk is defined for a particular trial T . Then the correctness CM,T of measure M for a trial T is X C(M, T, k) CM,T =
k∈K
|K|
The solid shaded areas behind the columns in Figures 4(a) and 4(b) show the average correctness for each measure over all rotation and all ordering trials, respectively. Only the results for the full point set (for point-based measures) are shown in Figures 4(a) and 4(b); the results for the borders-only point sets are discussed in section 4.4. Also, only results for the normalized shape measure are included because there is little difference in the performance of the two shape measures (p = .95). Unless otherwise specified, the performance of different measures over a set of trials is compared using Student’s t-test to determine the probability that the measures have the same average correctness for those trials.
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 240 Observations For the rotation task, the average correctness over all trials for even the best measures is disappointingly low — below 50%! — meaning that even the best of the tested measures will tend to rotate drawings incorrectly much of the time. For both rotation and ordering, a striking result is that no one measure stands out as being significantly better than the others. There is little difference between the angle-sensitive relative position measures (constant- and linear-weighted orthogonal ordering, ranking, λ-matrix) and the nearest neighbor within measures; distance, weighted nearest neighbor between, and shape also have similar good performance on the rotation task. On the other hand, several measures stand out as being noticeably worse than the others. Hausdorff distance, the clustering neighborhood measures (-clustering and separationbased clustering), unweighted nearest neighbor between, and to a lesser degree maximum distance have the poorest performance over all trials. Figures 5 and 6 summarize the significant similarities and differences in measure performance.
4.2
Correctness By Drawing Category
Some trials were easier than others — one might expect that in the rotation task it might be easier to choose the “correct” rotation when the new drawing is very similar to the old, and that in the ordering task it might be easier to pick the most similar drawing of two when one is very similar to the base. As a result, the measures under consideration may perform better or worse in these circumstances. To evaluate this, the new drawings were separated into categories: similar for drawings very close to the corresponding base, features for drawings somewhat different from the base but with noticeable recognizable features to help identification, contradictory for drawings with recognizable features but where those features contradicted each other (for example, when one feature was rotated with respect to another), and different for drawings that are very different from the base. The trials were also grouped according to the type of drawing(s) involved: rotation trials were considered to be “similar”, “features”, or “contradictory” according to the category of the new drawing used in the trial, and ordering trials were considered to be “similar” or “not” depending on whether or not one of the new drawings in the trial was classified as “similar”. Since only two drawings were classified as “different”, the results from trials involving these drawings were included only in the “all trials” results and not in the results from any other subgroup of trials. The multiple columns for each measure in Figures 4(a) and 4(b) show the average correctness for each category of trials. Figure 4(b) breaks down the trials beyond the two “similar” and “not” groupings, but the discussion is only in terms of the two groups. There were no ordering trials in which both drawings were similar, so that combination is not shown. The categorization used is based on human judgment and the assumption that features play a key role in similarity. The latter assumption is supported
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 241 edges
relative position
degree of match
position
angle−sensitive relative position
normalized shape
average distance weighted nearest neighbor between
ranking orthogonal ordering
maximum distance
unweighted nearest neighbor between
Hausdorff distance
Figure 5: Similarities and differences in measure performance for the rotation task. The vertical position of the measure name indicates its average correctness over all trials, with the lowest at the bottom. Gray-shaded areas group related measures. Measures with similar performance are grouped by ovals; arrows indicate differences between measures or groups of measures. The line style indicates the significance level: solid for p = .01/p = .99, dashed for p = .05/p = .95. by the feedback portion of the study (section 5.2). It is intended that the ordering “similar”, “features”, and “contradictory” represent groups of new drawings that are increasingly different from the base drawing to which they are compared. This goal seems to have been met: in the ordering task, users picked the drawing from the most similar group in 80% of the trials involving drawings from different groups, and the most common user response was the drawing from the most similar group in 90% of the trials. Also, using Student’s t-test to compare the distances between base and new drawings in each group shows that, for all of the similarity measures under consideration except Hausdorff distance, the means of the groups are significantly different and follow the expected pattern (p = .01). Since most of the measures being tested seem to capture at least some of the users’ ideas of similarity, this lends support to the categorization.
unweighted nearest neighbor between
Hausdorff distance
epsilon−clustering
clustering neighborhood maximum distance normalized shape
relative distance
distance−sensitive relative position
separation−based clustering
weighted nearest neighbor between
unweighted nearest neighbor within
non−clustering neighborhood
weighted nearest neighbor within orthogonal ordering lambda matrix
ranking
relative position edges
angle−sensitive relative position
degree of match
neighborhood
position
average distance
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 242
Figure 6: Similarities and differences in measure performance for the ordering task. Observations Within measures, the expected drop in performance between “similar” and “features” trials and between “features” and “contradictory” trials for rotation, and between “similar” and “not” trials for ordering is significant for nearly every measure (p = .01). The only exceptions are for Hausdorff distance in the rotation task (differences are not significant, and average correctness is
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 243 higher for “contradictory” than for “features”) and -clustering for the ordering task (drop in performance is significant only at p = .05).
4.3
Mode Correctness
The “correct” answer for any given trial is based on a user’s opinion, and because approximately 34 students gave responses for each set of drawings, there was the potential for getting different “correct” user responses for the same set of drawings. Since each measure always chooses the same response for the same set of drawings, the best correctness score a measure could receive is if it always makes the choice that was most common among the users. Let f (T, r) be the frequency with which the users completing trial T picked response r from the choices Di . Also define the most common response Tmode as the response for which f (T, r) is maximized, and the correctness of the most common response for trial T and user k as 1 if Tmode = Tk or Tk = tie C(mode, T, k) = 0 otherwise Then the “best possible score” for a measure for trial T is: X C(mode, T, k) Cbest,T =
k∈K
|K|
where K is the set of users completing trial T . The “mode” columns of Figures 4(a) and 4(b) show the average value of Cbest over the various groups of trials. The relative correctness for a given measure and trial is the ratio of the measure’s correctness to the mode correctness for that trial. The numbers listed by the measure columns in Figure 4(a) give the average relative correctness for each group of trials for which the average correctness is given; the numbers shown in Figure 4(b) give the average relative correctness for the “similar” and “not” trial groups. Observations The first observation is that, as one might expect, the average mode correctness drops for the less similar trials. The differences in average mode correctness between “similar”, “features”, and “contradictory” trials in the rotation task and between “similar” and “not” trials in the ordering task are significant (p = .01). The drop in correctness between the more similar and more different trials is due to an increase in user disagreement over the correct answer for each trial. Table 1 summarizes the degree to which users preferred some drawings to others for different groups of trials. The mode correctness is also affected by the number of users choosing “can’t decide” for each trial — a large number of “can’t decide” answers will raise the value of the mode correctness. For rotation, the percentage of “can’t decide” answers grew from 1.1% for “similar” drawings to 3.9% for “features” drawings
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 244 rotation preference no preference
all trials 92% -
similar 100% -
ordering preference no preference
all trials 70% 1.9%
similar 94% -
features 94% -
contradictory 83% not 61% 2.6%
Table 1: Percentage of trials for which users preferred one or more choices over the others, and for which there was no preference. Preference was determined using the χ2 test to compare the distribution of frequencies for each possible choice in a trial with a uniform distribution (the expectation if there was no preference among the choices in the trial). “Preference” indicates a significant difference between the distribution of user responses and the uniform distribution (p = .05); “no preference” indicates no difference between the distribution of user responses and the uniform distribution (p = .95). and 6.7% for “contradictory” drawings. For ordering, the percentage grew from 2.7% for trials involving “similar” drawings to 6.1% for trials not involving “similar” drawings. The increase in “can’t decide” answers partially offsets the drop in mode correctness due to increased user disagreement, but did not cancel out the effect. A second observation concerns the relative correctness. While the average correctness is low for all measures, the relative correctness results are better. For both rotation and ordering, the average correctness is at least 90% of the average mode correctness for most measures. (Exceptions are Hausdorff distance, unweighted nearest neighbor between, and the clustering neighborhood measures (-clustering and separation-based clustering).) This indicates that low correctness values for these measures, especially in the rotation task, are primarily due to disagreements between users about the correct answer rather than major failings on the part of the measures. An interesting note is that the average relative correctness of most measures drops with the more difficult trials — the lower performance for these trials is not due only to increased user disagreement about the correct answer. Table 2 lists the measures for which the drop is significant. The drop in relative correctness, combined with the presence of some user preference for many of even the most different trials, suggests that there are more subtle similarities that users are picking up on that the measures do not capture. The good relative performance for “similar” trials is the result of the drawings in those trials being similar in many ways — including those ways captured by the measures — while the poorer relative performance for more different trials is the result of the measures’ missing something that the users are seeing.
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 245 ordering rotation maximum distance maximum distance unweighted nearest neighbor between weighted nearest neighbor between average distance ranking constant-weighted orthogonal ordering normalized shape linear-weighted orthogonal ordering ranking λ-matrix relative distance unweighted nearest neighbor within weighted nearest neighbor within Table 2: Measures for which the average relative correctness is significantly lower between “similar” or “features” trials and “contradictory” trials (rotation) or between “similar” and “not” trials (ordering); p = .05.
4.4
Border vs. Full Point Sets
Based on user feedback (see section 5.2), a second point set using only those points near the borders of the drawing was tested for point-based measures. There was no significant difference in performance between the two point sets for any measure (p = .95), and so results for the borders-only point set are not included in Figures 4(a) and 4(b).
4.5
Per-User Correctness
The low correctness for even the mode (65% for the most similar drawings) in the rotation task indicates that not all users agree on what the “correct” answer is for a given trial. This suggests that users have different ideas about what factors make drawings look more similar, or different ideas about the relative importance of different aspects of similarity. Let Tk be the set of trials for which Tk is defined, i.e., the set of trials user k completed. Then the correctness of measure M for user k is X C(M, T, k) CM,k =
T ∈Tk
|Tk |
Figure 7 shows CM,k for each measure/user combination in the rotation task. Observations The most striking observations from Figure 7 are that the measures that do badly overall (Hausdorff distance and unweighted nearest neighbor between) perform badly for every user, and the measures that perform well overall tend to all perform well or all perform badly for an individual user. The results are similar, but less dramatic, for the ordering task.
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 246
normalized shape ranking orthogonal linear-weighted ordering constant-weighted average distance nearest neighbor weighted between unweighted
99
38
81
36
97
90
40
87
72
82
59
58
27
54
70
63
22
37
66
89
29
101
6
92
74
7
46
30
61
42
98
26
78
48
maximum distance Hausdorff distance
users
Figure 7: Average correctness per user for the rotation task. Colors indicate the average correctness, from light gray (1) to black (0). Each measure label (except normalized shape) spans two rows, where the top row shows the borders-only point set and the bottom row the full point set. rotation borders-only better full better no difference
all trials 5.8% 2.0% 23%
similar 100%
ordering borders-only better full better no difference
all trials 6.9% 8.8% 1.0%
similar 4.9% 8.8% 40%
features 54%
contradictory 7.1% 39% not 6.9% 9.8% 2.9%
Table 3: Percentage of users which are significantly better predicted by one of the point sets used (p = .05), and the percentage for which there is no difference (p = .95). Of interest, though, is that there is a small group of users who are significantly better- or worse-predicted by the borders-only point set than the full point set. The CM,k values for a user k for selected measures were compared for the full and borders-only point set using Student’s t-test. The measures used were for the better measures: all of the point-based measures except Hausdorff distance, unweighted nearest neighbor between, and the clustering neighborhood measures (-clustering and separation-based clustering). Table 3 summarizes the results. The cases for which the borders-only point set performs better meshes well with the feedback from the study (section 5.2), though many more users commented on the importance of the borders than had a significant improvement for that point set. One possibility for this is that the change in the border may be representative of the change in the drawing as a whole, so that full point set performs well for users even if they are focusing primarily on the borders of the drawing. For the rotation task, another possibility is that many of the measures
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 247 are already more sensitive to changes in the border regions than in the centers of the drawings because rotation moves points near the borders farther than those near the center. This means that the full point set versions will tend to perform similarly to the border-only sets for rotation. Another interesting note is that a larger number of users were betterpredicted by the border point set for more different trials than for the similar trials. This suggests that the borders become important when the obvious similarities disappear — when the drawings are similar, users can easily select their responses based on the overall look of the drawing, but when the drawings become more different, they begin focusing on the borders to look for distinguishing characteristics. Focusing on cases where the borders-only point set outperforms the full point set ignores those instances where the reverse is true. In fact, more users are predicted better by the full point set than by the borders-only point set for the ordering task — a pattern which is not seen in the results from the rotation task. This may be the result of users looking for different things in each task — the overall look may be more important in the ordering task, while users gravitate towards the borders when looking for hints as to the proper orientation in the rotation task. The border-sensitivity of many measures under rotation may also explain this difference — if both full and border-only point sets are sensitive to the same things, they will tend to perform in the same way and thus the full point set will not perform better.
4.6
Other Rotation Angles
The rotation task focused on differences of π/2 in the rotation angle — a very large difference, though it is the only meaningful difference for orthogonal drawings since a user can easily tell that a rotation by some other angle is not the best match. Ideally, there would be no change in a measure’s correctness if additional rotation angles are considered, since the user’s “correct” answer would not change. Figure 8 shows the average correctness over all trials for three sets of orientations: the π/2 multiples (with and without an initial flip around the x-axis) discussed so far (labelled “π/2”), the π/2 multiples augmented by the four additional multiples of π/4 (labelled “π/4”), and the π/2 multiples augmented by the four additional rotations π/36, π/2 + π/36, π + π/36, and 3π/2 + π/36 (labelled “π/36 offsets”). (The shape measure is not included in the figure because it is defined only in terms of orthogonal drawings.) The π/4 set adds several additional orientations, though the angle between successive rotations is still relatively large; the π/36 offsets add rotation angles which are very close to angles a user would consider. The additional rotations were not presented to the users, as it was assumed that no one would pick one of them. Observations Clearly the ideal outcome did not happen — over all trials, there is a drop in the average correctness with the addition of the extra orienta-
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 248 1 position
degree of match
0.9
relative position
0.8
correctness
0.7 0.6 0.5 0.4 0.3 0.2 0.1 0
mode
Hausdorff distance
average maximum unweighted weighted distance nearest neighbor between distance π/2
π/4
π/36 offsets
ranking
linearconstantweighted weighted orthogonal ordering
Figure 8: Measure correctness for rotation with other sets of orientations. tions and the drop is greater for the π/36 offsets group than for the π/4 group. Table 4 summarizes the significant results. If the correctness criterion is relaxed so that measures are only expected to choose a rotation near the correct one, the drop in performance is eliminated. The expanded definition of “correct” is as follows: Cnear (M, T, k) = 1 if Tk is “tie” or if the rotation angle of TM is within ±π/4 of the rotation angle of Tk for “π/4” and within ±π/36 for “π/36 offsets.” The improvement in the results indicates that when the wrong rotation is chosen, it tends to be near the right one. This suggests that while the measures would likely perform less satisfactorily when asked to pick the correct rotation in non-orthogonal applications, they would still perform reasonably well if the goal is only to obtain approximately the right orientation.
5 5.1
Other Results Difference Task
The goal in the difference part was to be able to use the user’s response times as an indicator of similarity, the idea being that a user can locate the new vertex faster if the drawings are more similar. As a test of the validity of this, the times on the difference part were used to order the pairs of drawings used in the ordering task. The results were very unsatisfactory, achieving only 45% correctness on average (compare to Figure 4(b), where even the worst of the
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 249 π/2 vs. π/4 Hausdorff distance maximum distance nearest neighbor between unweighted weighted average distance orthogonal ordering constant-weighted linear-weighted ranking
all trials
π/2 vs. π/36 offsets Hausdorff distance maximum distance nearest neighbor between unweighted weighted average distance orthogonal ordering constant-weighted linear-weighted ranking
all trials >> >>
similar
>> >> >>
> >
similar
>> > >
>> >> >>
features
contradictory
>>
>>
= == ==
>> >>
== == ==
> > >
>>
features > >>
contradictory
>> >> >>
> >> >>
>> >> >>
> > >>
>>
Table 4: Comparing the average performance for each group of trials for different sets of orientations. “>” and “>>” indicate a drop in performance with additional drawings; “=” and “==” indicate that the performance did not change. The number of symbols indicates the significance level: “>” and “=” for p = .05/p = .95, “>>” and “==” for p = .01/p = .99. measures under consideration reached 62% correctness). As a result, the times on the difference task are not a good indicator of similarity and are not suitable for evaluating measures with respect to the magnitude criterion.
5.2
User Feedback
The students’ responses to the final questionnaire yielded several interesting notes. As might be expected, the responses as to what makes two drawings look similar in the rotation and ordering parts included a sizable percentage (35%) who said preserving the position, size, number of large vertices was important and another large percentage (44%) who said they looked for distinctive clusters and patterns of vertices, such as chains, zigzags, and degree 1 vertices. More surprising was that 44% of the students said that borders and corners of the drawing are more important than the interior when looking for similarity. This is supported by research in cognitive science indicating that people often treat
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 250 filled and outline shapes as equivalent, focusing primarily on the external contour (Wickelgren [18]). A number of these students mentioned the importance of “twiddly bits around the edges” — distinctive clusters and arrangements of vertices, made more obvious by being on the border. Related comments were also that the orientation and aspect ratio of the bounding box should remain the same, and that the outline of the drawing should not change. Another sizable group (34%) commented that the “general shape” of the drawing is important. For the question about the difference part, several users expressed frustration at the difficulty of the task. The usefulness of the “big picture” view — looking at the overall shape of the drawing — was contested, with nearly equal numbers reporting that the overall look was useful in the task, and that it was confusing and misleading. About 16% of the users mentioned limited use of the overall look, using it on a region-by-region basis to quickly eliminate blocks that remained the same and falling back on simply scanning the drawing or matching corresponding vertices and tracing edges when the regions were too different. Another 24% reported using vertex-by-vertex matching from the beginning. A similar-sized group (20%) figured out shortcuts, such as that the edges added along with the new vertex frequently caused one of the neighboring vertices to have a degree larger than 4 and thus be drawn with a larger box, so they scanned for the neighbors of the large boxes to find the new vertex. Overall, just over a quarter of the users (28%) reported searching for vertices with extra edges rather than searching for new vertex directly. For the final question, about what a graph drawing algorithm should take into account if the look of the drawing should be preserved, the most common answers echoed those from the rotation/ordering question: maintaining vertex size and shape, the relative positions of vertices, the outline of the drawing, and clusters.
6
Conclusions and Future Work
Table 5 summarizes the best and worst of the measures evaluated. As groups, the angle-sensitive relative position measures (orthogonal ordering, ranking, and λ-matrix) and the non-clustering neighborhood measures (weighted and unweighted nearest neighbor within) performed significantly better than the degree-of-match measures (Hausdorff distance and maximum distance) and the clustering neighborhood measures (-clustering and separationbased clustering). As a result, the orthogonal ordering, ranking, λ-matrix, and nearest neighbor within measures are given the highest ranking. Two of the three position measures (weighted nearest neighbor between and average distance) also perform significantly better than the degree-of-match and clustering neighborhood measures, and so are also ranked well. They are given the second-level ranking because there was a slightly greater dropoff in their performance when additional rotation angles were introduced, suggesting that they might not perform quite as well for non-orthogonal drawings. Shape and relative distance are also given an above-average ranking be-
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 251 best measures angle-sensitive relative position non-clustering neighborhood position
n edges distance-sensitive relative position
ranking orthogonal ordering (constant- and linear-weighted) λ-matrix nearest neighbor within (weighted and unweighted) average distance weighted nearest neighbor between shape relative distance
middle-of-the-road n measures degree of match maximum distance worst measures clustering neighborhood n position n degree of match
-clustering separation-based clustering unweighted nearest neighbor between Hausdorff distance
Table 5: Overall ranking of the measures evaluated. Measures are listed in groups from best to worst; groups are separated by horizontal lines. There is little difference between measures in a single group. cause of their performance on the ordering task — while not significantly worse than the top-ranked measures, they were also not significantly better than the bottom-ranked measures. It should be noted that shape was among the best measures for the rotation task. Maximum distance received a middle-of-the-road ranking because of its middle-of-the-road performance in both tasks — while it performed as well the several top-ranked measures for the “similar” rotation trials, its average correctness was between the top- and bottom-ranked measures for both rotation and ordering. Also, when the degree-of-match measures were considered as a group, their performance was significantly worse than the top-ranked groups. The clustering neighborhood measures and the unweighted nearest neighbor between measure all performed significantly worse than the top-ranked groups of measures, and so are given a low ranking. Hausdorff distance is given the bottom ranking because it performs significantly worse than most other measures in most groups of trials. Several other conclusions can be drawn from this study: • The difference in relative correctness between the more similar and more different trials for both rotation and ordering task suggests that there are
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 252 more subtle notions of similarity which are being missed by the measures tested, and which, if incorporated, would improve their performance. • The per-user analysis suggests that while it is meaningful to talk about “good” measures and “bad” measures in overall terms, to get the maximum performance it may be necessary to tailor the specific similarity measure used to a particular user. • The difficulty of the difference part suggests that the amount of difference between the drawings that is considered reasonable varies greatly with the task — when the user simply needs to recognize the graph as familiar, the perimeter of the drawing and the position and shape of few key features are the most important. On the other hand, when trying to find a specific small change, the drawings need to look very much alike or else the user needs some other cues (change in color, more distinctive vertex names, etc.) in order to highlight the change. The students’ responses on the questionnaire suggest several possible directions for future investigation. • The number of students who mentioned focusing on drawing borders was surprising, and additional study is needed to further investigate the importance of borders. • Large vertices are identified as being especially important, which could lead to a scheme in which changes in the position and size of large vertices are weighted more heavily than other vertices. • Another major focus was clusters of vertices — both the presence of clusters in general, and the presence of specific shapes such as chains and zigzags. The relatively poor showing of the clustering measures indicates that they are not making use of clusters in the right way. The fact that the students reported looking for specific shapes suggests an approach related to the drawing algorithms of Dengler, Friedell, and Marks [6] and Ryall, Marks, and Shieber [16]. These algorithms try to produce drawings which employ effective perceptual organization by identifying Visual Organization Features (VOFs) used by human graphic designers. VOFs include horizontal and vertical alignment of vertices, particular shapes such as “T” shapes, and symmetrically placed groups of vertices. VOFs can also be used not to guide the creation of drawings from scratch, but to identify features in an existing drawing that may be important because they adhere to a particular design principle. This is related to the work of Dengler and Cowan [5] on semantic attributes that humans attach to drawings based on the layout — for example, symmetrically placed nodes are interpreted as having common properties. A similarity measure could then measure how well those structures are preserved, and an interactive graph drawing algorithm could focus on preserving the structures.
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 253
References [1] T. Biedl, J. Marks, K. Ryall, and S. Whitesides. Graph multidrawing: Finding nice drawings without defining nice. In S. Whitesides, editor, Graph Drawing (Proc. GD ’98), volume 1547 of Lecture Notes Comput. Sci., pages 347–355. Springer-Verlag, 1998. [2] T. C. Biedl and M. Kaufmann. Area-efficient static and incremental graph drawings. In R. Burkard and G. Woeginger, editors, Algorithms (Proc. ESA ’97), volume 1284 of Lecture Notes Comput. Sci., pages 37–52. Springer-Verlag, 1997. [3] S. Bridgeman and R. Tamassia. Difference metrics for interactive orthogonal graph drawing algorithms. Journal of Graph Algorithms and Applications, 4(3):47–74, 2000. [4] S. S. Bridgeman, J. Fanto, A. Garg, R. Tamassia, and L. Vismara. InteractiveGiotto: An algorithm for interactive orthogonal graph drawing. In G. Di Battista, editor, Graph Drawing (Proc. GD ’97), volume 1353 of Lecture Notes Comput. Sci., pages 303–308. Springer-Verlag, 1997. [5] E. Dengler and W. Cowan. Human perception of laid-out graphs. In S. H. Whitesides, editor, Graph Drawing (Proc. GD ’98), volume 1547 of Lecture Notes Comput. Sci., pages 441–443. Springer-Verlag, 1998. [6] E. Dengler, M. Friedell, and J. Marks. Constraint-driven diagram layout. In Proc. IEEE Sympos. on Visual Languages, pages 330–335, 1993. [7] G. Di Battista, A. Garg, G. Liotta, R. Tamassia, E. Tassinari, and F. Vargiu. An experimental comparison of four graph drawing algorithms. Comput. Geom. Theory Appl., 7:303–325, 1997. [8] U. F¨ oßmeier. Interactive orthogonal graph drawing: Algorithms and bounds. In G. Di Battista, editor, Graph Drawing (Proc. GD ’97), volume 1353 of Lecture Notes Comput. Sci., pages 111–123. Springer-Verlag, 1997. [9] J. E. Goodman and R. Pollack. Multidimensional sorting. SIAM J. Comput., 12(3):484–507, Aug. 1983. [10] K. A. Lyons, H. Meijer, and D. Rappaport. Algorithms for cluster busting in anchored graph drawing. J. Graph Algorithms Appl., 2(1):1–24, 1998. [11] A. Marzal and E. Vidal. Computation of normalized edit distance and applications. IEEE Transactions on Pattern Analysis and Machine Intelligence, 15(9):926–932, Sept. 1993. [12] K. Misue, P. Eades, W. Lai, and K. Sugiyama. Layout adjustment and the mental map. J. Visual Lang. Comput., 6(2):183–210, 1995.
Bridgeman and Tamassia, Similarity Measures, JGAA, 6(3) 225-254 (2002) 254 [13] S. North. Incremental layout in DynaDAG. In Graph Drawing (Proc. GD ’95), volume 1027 of Lecture Notes Comput. Sci., pages 409–418. SpringerVerlag, 1996. [14] A. Papakostas, J. M. Six, and I. G. Tollis. Experimental and theoretical results in interactive graph drawing. In S. North, editor, Graph Drawing (Proc. GD ’96), volume 1190 of Lecture Notes Comput. Sci., pages 371–386. Springer-Verlag, 1997. [15] A. Papakostas and I. G. Tollis. Interactive orthogonal graph drawing. IEEE Trans. Comput., C-47(11):1297–1309, 1998. [16] K. Ryall, J. Marks, and S. Shieber. An interactive system for drawing graphs. In S. North, editor, Graph Drawing (Proc. GD ’96), volume 1190 of Lecture Notes Comput. Sci., pages 387–393. Springer-Verlag, 1997. [17] R. Tamassia, G. Di Battista, and C. Batini. Automatic graph drawing and readability of diagrams. IEEE Trans. Syst. Man Cybern., SMC-18(1):61– 79, 1988. [18] W. A. Wickelgren. Cognitive Psychology. Prentice-Hall, Inc., Englewood Cliffs, NJ, 1979.
Journal of Graph Algorithms and Applications http://www.cs.brown.edu/publications/jgaa/ vol. 6, no. 3, pp. 255–279 (2002)
Graph Layout Aesthetics in UML Diagrams: User Preferences Helen C. Purchase
Jo-Anne Allder
David Carrington
School of Information Technology and Electrical Engineering The University of Queensland Brisbane 4072, Australia {hcp,joanne,davec}@itee.uq.edu.au Abstract The merit of automatic graph layout algorithms is typically judged by their computational efficiency and the extent to which they conform to aesthetic criteria (for example, minimising the number of crossings, maximising orthogonality). Experiments investigating the worth of such algorithms from the point of view of human usability can take different forms, depending on whether the graph has meaning in the real world, the nature of the usability measurement, and the effect being investigated (algorithms or aesthetics). Previous studies have investigated performance on abstract graphs with respect to both aesthetics and algorithms, finding support for reducing the number of crossings and bends, and increasing the display of symmetry. This paper reports on preference experiments assessing the effect of individual aesthetics in the application domain of UML diagrams. Subjects’ preferences for one diagram over another were collected as quantitative data. Their stated reasons for their choice were collected as qualitative data. Analysis of this data enabled us to produce a priority listing of aesthetics for this domain. These UML preference results reveal a difference in aesthetic priority from those of previous domain-independent experiments.
Communicated by Michael Kaufmann: submitted April 2001; revised December 2001 and June 2002.
H.C. Purchase et al., Layout Aesthetics in UML, JGAA, 6(3) 255–279 (2002)256
1
Introduction
The success of automatic graph layout algorithms which display relational data in a graphical form is typically measured by their computational efficiency and the extent to which they conform to aesthetic criteria (for example, minimising the number of crossings, maximising