Journal of Graph Algorithms and Applications http://jgaa.info/ vol. 16, no. 3, pp. 651–673 (2012) DOI: 10.7155/jgaa.00263 Inapproximability of Orthogonal Compaction Michael J. Bannister David Eppstein Joseph A. Simons Computer Science Department, University of California, Irvine Abstract We show that several problems of compacting orthogonal graph drawings to use the minimum number of rows, area, length of longest edge or total edge length cannot be approximated better than within a polynomial factor of optimal in polynomial time unless P = NP. We also provide a fixed-parameter-tractable algorithm for testing whether a drawing can be compacted to a small number of rows. Submitted: November 2011 Reviewed: February 2012 Article type: Regular paper Revised: Accepted: Final: February 2012 February 2012 March 2012 Published: September 2012 Communicated by: M. van Kreveld and B. Speckmann This work was supported in part by NSF grant 0830403 and by the Office of Naval Research under grant N00014-08-1-1015. A previous version of this paper appeared in the International Symposium on Graph Drawing 2011. E-mail addresses: mbannist@uci.edu (Michael J. Bannister) eppstein@uci.edu (David Eppstein) jsimons@uci.edu (Joseph A. Simons) 652 1 Bannister, Eppstein, Simons Compaction for Graph Drawings Introduction Orthogonal graph drawing is a widely used graph drawing style for low-degree graphs, in which each vertex is represented as a point or a rectangle in an integer grid, and each edge is represented as a polyline composed out of axis-parallel line segments [5]. When used for nonplanar graphs (Figure 1), orthogonal drawing has several desirable properties including polynomial area, high angular resolution, and right-angled edge crossings; the last property, in particular, has been shown to aid in legibility of graph drawings [9]. Typical orthogonal graph drawing systems employ a multiphase approach [1, 5] in which the input graph is planarized by replacing its crossings with vertices, a topological embedding of the graph (specifying the ordering of the edges around each vertex, but not the vertex and edge locations) is found, a flow algorithm is used to orient the edges in a way that minimizes the number of bends [16], and vertex coordinates are assigned. If vertices of degree greater than four exist, they may be expanded to rectangles as another phase of this process [1]. Finally, the drawing is improved by compaction, a step in which the vertices and bends of the graph are moved to new locations in order to reduce the area of the drawing while preserving its edge orientations and other features. Some positive algorithmic results are known for the final compaction step for planar drawings; for instance, Bridgeman et al. [3] showed that planar orthogonal drawings in which the shapes of the faces in the drawing are restricted (so-called turn-regular drawings) may be compacted into optimal area in polynomial time. In the case of variable size vertices, e.g. due to labels, Eiglsperger et al. [6] have found heuristic based compaction algorithms that work well in practice. Also, Klau et al. have shown that the compaction step can be done via integer linear programming [12]. An experimental analysis of planar compaction methods was done by Klau et al. [11] However, when drawing nonplanar graphs, it may not be necessary or desirable for the compaction phase to preserve a fixed planarization of the graph. If one is compacting one dimension of a drawing at a time, then for planar compaction it is only possible to map the rows of the drawing monotonically to a smaller set of rows, while for nonplanar graphs it may also be useful to permute the rows with respect to each other. This greater freedom to choose how to Figure 1: Examples of non-planar orthogonal drawings. JGAA, 16(3) 651–673 (2012) 653 compact the drawing may lead to much greater savings in drawing area, but it also leads to greater difficulty in finding a good compaction. As Patrignani [15] showed, even for arbitrary planar orthogonal graph drawings, compacting the drawing in a way that minimizes its area, total edge length, or maximum edge length is NP-hard. Although these results do not directly extend to the nonplanar case, NP-hardness in that case also follows from results of Eades et al. on rectilinear (bendless) drawing [4], and Maňuch et al. where certain restricted cases of rectilinear drawing are considered [13]. But since compaction is performed primarily for aesthetic reasons (a smaller area drawing allows the drawing to be viewed at a larger scale, making its features more legible), exact optimization may not be important if a layout with small area can be achieved. Thus, we are led to the problem of how closely it is possible to approximate the minimum area layout. The problem of approximate compaction for nonplanar orthogonal drawings was explicitly listed as open by Eiglsperger et al. [5], and there appears to have been little progress on it since then. In this paper we show that nonplanar compaction is hard even to approximate. There exists a real number c > 0 such that, unless P = NP, no polynomial time algorithm can find a compaction of a drawing with n features that is within a factor of nc of optimal. The main idea is to find approximation-preserving reductions from graph coloring, a problem known to be hard to approximate. We also give a fixed-parameter tractable algorithm for finding compactions that use very small numbers of grid rows, for drawings in which such a compaction is possible. 1.1 Variations of the compaction problem In the compaction problems we study, the task is to move vertices and bends while preserving the axis-parallel orientation (although not necessarily the direction) of each edge, to minimize the number of rows, area, longest edge, or total edge length of the drawing. Our results apply either to orthogonal drawings (drawings in which edges may be polylines with bends, possible for any graph of maximum degree four) or rectilinear drawings (bendless drawings, only possible for some graphs) [4, 7]; the distinction between bends and vertices is unimportant for our results. We distinguish between three variants of the compaction problem, depending on what vertex motions are allowed. In row-by-row compaction (Figure 2), the compacted layout maps each row of the input layout to a row of the output; all vertices that belong to the same row must move in tandem. In vertex-by-vertex vertical compaction (Figure 3), each vertex or bend may move independently, but only its y-coordinate may change; it must retain its horizontal position. In vertex-by-vertex free compaction, vertices or bends may move arbitrarily in both coordinate directions. In all three of these problems, edges or edge segments must stay vertical or horizontal according to their orientation in the original layout. The compaction is not allowed to cause any new intersection between a vertex and a feature it was not already incident with, nor is it allowed to cause any two edges or edge segments to overlap for nonzero length; however, it 654 Bannister, Eppstein, Simons Compaction for Graph Drawings may introduce new crossings that were not previously present. Therefore, the compacted drawing remains a valid representation of the graph; however, the introduction of crossings may reduce the aesthetics and readability of the graph, especially in cases where the initial input drawing is planar. Figure 2: Example of row-by-row compaction. Figure 3: Example of vertex-by-vertex compaction. 1.2 New results We show the following results. • In the row-by-row compaction problem, it is difficult to compact even a drawing of a path graph (or a drawing of the two-vertex graph with many bends). If the drawing has n vertices or bends, then for every > 0 there is no polynomial time algorithm that can find a compacted drawing whose number of rows, maximum edge length, total edge length, or area is within O(n1/2− ) of optimal, unless P = NP. Moreover, even finding drawings with a fixed number of rows is hard; it is NP-complete to determine whether there exists a compaction with only three rows. • In vertex-by-vertex vertical compaction, for every > 0, there is no polynomial time algorithm that can find a compacted drawing of graphs of maximum degree three such that the number of rows, maximum edge length, total edge length, or area of the drawing is within O(n1/3− ) of optimal, unless P = NP. The same result also applies in the vertex-byvertex free compaction problem. JGAA, 16(3) 651–673 (2012) 655 • For the vertex-by-vertex or vertex-by-vertex free compaction problem of three-dimensional orthogonal drawings, for every > 0, it is not possible to approximate the minimum number of layers in any one dimension, maximum edge length, total edge length, or volume to within O(n1/2− ) of optimal in polynomial time, unless P = NP, nor is it possible in polynomial time to determine whether a three-layer drawing exists. • In vertex-by-vertex vertical compaction, there is an algorithm for testing whether an orthogonal graph drawing can be compacted into k rows, whose running time is O(k!n). Thus, the problem is fixed-parameter tractable. • In vertex-by-vertex free vertical compaction, there is a simple linear time algorithm for finding an optimal row compaction of a path. • We provide a counterexample showing that an approximation algorithm described in the conference version of this paper was incorrect. 2 Preliminaries 2.1 Orthogonal Drawing We define an orthogonal drawing of a graph to be a drawing in which each vertex is represented as a point in the Euclidean plane (although most of our results apply as well to drawings in which the vertices are rectangles), and each edge is represented as a polyline (a polygonal chain of line segments), with each line segment parallel to one of the coordinate axes. (See, for example, Figure 1.) If each edge is itself a line segment, the drawing is rectilinear ; otherwise, the segments of a polyline meet at bends. Each vertex or bend must only intersect the edges that it belongs to, and no two vertices or bends may coincide. Edges may cross each other, but only at right angles, at points that are neither vertices nor bends. It is natural, in orthogonal graph drawing, to restrict the coordinates of the vertices and bends to be integers. In this case, the width of a two-dimensional drawing is the maximum difference between the x-coordinates of any two of its vertices or bends, the height is the maximum difference between y-coordinates of any two vertices or bends, and the area is the product of the width and height. A compaction of a drawing D is another drawing D0 of the same graph, in which the vertices and bends of D0 correspond one-for-one with the vertices and bends of D, and in which corresponding segments of the two drawings are parallel to each other. Typically, D0 will have smaller height, width, or area than D. We distinguish between three types of compaction: • In row-by-row compaction, the x-coordinate of each vertex or bend remains unchanged, and two vertices or bends that have the same y-coordinate in D must continue to have the same y-coordinate in D0 (Figure 2). 656 Bannister, Eppstein, Simons Compaction for Graph Drawings • In vertex-by-vertex vertical compaction, the x-coordinate of each vertex or bend remains unchanged, but the y-coordinates may vary independently of each other subject to the condition that the result remains a valid drawing with edge segments parallel to the original drawing (Figure 3). • In vertex-by-vertex free vertical compaction, the x- and y- coordinates of each vertex or bend are free to vary independently of other vertices or bends. As can be seen in Figure 2, we allow compaction to introduce new edge crossings and to reverse the directions of edge segments. These concepts generalize straightforwardly to three dimensions. 2.2 Graph Coloring and Inapproximability In the graph coloring problem, we are given as input a graph and seek to color the vertices of the graph with as few colors as possible, in such a way that the endpoints of each edge are assigned different colors. Our results on the difficulty of compaction are based on known inapproximability results for graph coloring, one of the triumphs of the theory of probabilistically checkable proofs [8,10,17]. Theorem 1 (Zuckerman [17]) Let > 0 be any fixed constant. Then, unless P = NP, there is no polynomial time algorithm that can compute the minimal number of colors χ(G) in an optimal coloring of a given n-vertex graph within a factor of n1− . Our proofs use approximation-preserving reductions from coloring to compaction. Given a graph G to be colored, we will construct a different graph G0 and a drawing D of G0 such that the number of rows, maximum edge length, or total edge length in a compaction D0 of D necessarily correspond to the number of colors in a coloring of G. With a reduction of this type, the approximation ratio for compacting D cannot be better than the approximation ratio for coloring G. However, D will in general have many more vertices and bends than the number of vertices in G; the size of D will be at least proportional to the number of edges in G, which is quadratic in its number of vertices. Therefore, although the approximation ratio will remain unchanged as a number by our reduction it will be expressed as a different function of the input size. 2.3 Notation We write nG , nD , or (where unambiguous) n for the number of vertices in a graph G or drawing D and mG , mD , or m for its number of edges. Additionally, bD stands for the number of bends in drawing D. When we consider compaction problems with the objectives of minimizing the number of rows, maximum edge length, and total edge length in a drawing D we will use λ(D), µ(D), and τ (D) to denote respectively the number of rows, maximum edge length, and total edge length in an optimal compaction. χ(G) represents the chromatic number of graph G. JGAA, 16(3) 651–673 (2012) 2 1 657 1 2 3 3 5 4 5 4 6 6 Figure 4: Path constructed from a graph G with the walk 1, 5, 3, 2, 5, 4, 3, 5, 6. 3 Hardness of Row-By-Row Compaction As a warm-up, we start with a simplified path compaction problem in which every pair of objects on the same row of the drawing must move in tandem. Our proof constructs a drawing of a path graph such that the valid row assignments for our drawing are the same as the valid colorings of a given graph G. Lemma 1 Given a graph G we can construct in polynomial time a rectilinear drawing D of a path graph with O(mG ) vertices, such that λ(D) = χ(G). Proof: Find a Chinese postman walk for G of length less than 2mG ; that is, a walk that starts at an arbitrary vertex and visits each edge at least once, allowing vertices to be visited multiple times. Such a walk may be found, for instance, by doubling each edge of G and constructing an Euler tour of the doubled graph. Let ui vi be the ith edge in the walk, where vi = ui+1 , and let k ≤ 2mG be the number of edges in the walk. Additionally, choose arbitrary distinct integer labels for the vertices of G with `(v) being the label for the vertex v. To construct the drawing D, for i from 0 to k, place vertices in the plane at the points (i, `(ui )) and (i + 1, `(ui )), connected by a unit-length horizontal edge. Additionally, for i from 0 to k − 1 draw a vertical edge from (i + 1, `(ui )) to (i + 1, `(vi )). See Figure 4 for an example of such a construction. Two rows in the drawing conflict if and only if the corresponding vertices in G are adjacent. For every coloring of G, we may compact D by using one row for the vertices of each color, and conversely for every row-by-row compaction of D we may color G by using one color class for each row of the compaction (Figure 5). Therefore, λ(D) = χ(G). Also, nD = 2k + 2 = O(mG ). The same drawing D can equivalently be viewed as an orthogonal drawing of the two-vertex graph K2 with O(mG ) bends. In the restricted model of compaction used in this section, horizontal compaction is disallowed, so optimizing the area of a compaction of D is the same as optimizing the number of rows. Theorem 2 Let > 0 be any positive fixed constant, and suppose that P 6= NP. Then there does not exist a polynomial time algorithm that approximates the number of layers or the area in an optimal row-by-row compaction of a given orthogonal or rectilinear drawing D to within a factor of (nD + bD )1/2− . 658 Bannister, Eppstein, Simons Compaction for Graph Drawings 2 3 1 5 4 6 Figure 5: The rows of a compacted drawing D correspond to the colors in a coloring of G. Proof: Suppose for a contradiction that algorithm A can solve the row-by-row 1/2− compaction problem to within a factor ρ ≤ nD of optimal. Let A0 be an algorithm for coloring an input graph G by performing the following steps: 1. Use Lemma 1 to construct a path drawing D from the given graph G. 2. Use algorithm A to compact D. 3. Color G using one color for each row of the compacted drawing. Then the approximation ratio of algorithm A0 for coloring is the same number ρ as the approximation ratio of algorithm A for compaction, whether measured by area or by number of rows. However, 1/2− ρ ≤ nD 1/2− = O(mG ) = O(n1−2 ), G an approximation ratio that contradicts Theorem 1. The same reduction, together with the NP-completeness of graph 3-colorability, shows that it is NP-complete to determine whether a given drawing D has a row-by-row compaction that uses at most three rows. Theorem 3 The problem of determining if an orthogonal graph has a row-byrow compaction into at most three rows is NP-complete. For the compaction problems with respect to longest edge, and total edge length we will modify the construction in Lemma 1 by the addition of a frame that will be used to measure χ(G) with τ (D) and µ(D). The frame is illustrated in Figure 6. Lemma 2 Given a graph G we can construct in polynomial time a rectilinear drawing D of a path graph with O(mG + φ) vertices, such that µ(D) = χ(G) + 1 and φχ(G) ≤ τ (D) ≤ O(mG + φ)χ(G). Proof: Given a graph G we construct D by first performing the construction of Lemma 1, and then adding the vertices and edges as illustrated in Figure 6. JGAA, 16(3) 651–673 (2012) 659 φ 1 2 3 4 5 6 Figure 6: We add a frame above and below the path construction of Figure 4 (shaded gray). The longest edge runs along the right side of the drawing from the top frame to the bottom frame and will have length exactly χ + 1. We claim that vertices created by Lemma 1 must stay between the two gray regions in a row-by-row compaction. The leftmost vertex cannot be placed above the upper gray region without causing an illegal edge overlap, and if one vertex is placed above the upper gray region then all vertices must be placed above the upper gray region to avoid illegal edge overlaps. Hence none of the original vertices can be placed above the upper gray region (unless the entire drawing is flipped). Similar reasoning shows that none of the original vertices may be placed below the lower gray region. By construction the φ edges to the right of the drawing are the longest edges in the drawing, even after a row-by-row compaction. The length of one of these edges is always 2 more than the length of the gap between the gray regions, which is χ(G) − 1 by Lemma 1. Hence the length of the edges in an optimal compaction is µ(D) = χ(G) + 1. For the total edge length we note that there are at most 2mG + φ columns, and each of these columns has at most 2χ(G) in length. The horizontal segments make at most O(mG + φ) total length. So altogether we have that τ (D) is at most O(mG + φ)χ(G). Considering only the vertical edges on the right we see that φχ(G) ≤ τ (D), which gives the desired bounds. Theorem 4 Let > 0 be any positive fixed constant, and suppose that P 6= NP. Then there does not exist a polynomial time algorithm that approximates the longest edge length or the total edge length in an optimal row-by-row compaction of a given orthogonal or rectilinear drawing D to within a factor of (nD + bD )1/2− . 660 Bannister, Eppstein, Simons Compaction for Graph Drawings Proof: The proof of the longest edge case is the same as the proof of Theorem 2 for the number of rows where Lemma 2 is used in place of Lemma 1. More work is needed for the total length case. Suppose for a contradiction that an algorithm A could solve the row-by-row compaction problem with re1/2− spect to total edge length to within a factor of nD of optimal. Let A0 be an approximation algorithm for χ(G) that compacts the drawing produced by Lemma 2 with φ = n2G , and returns τ 0 (D)/n2G where τ 0 is the total edge length of the approximate compaction. From Lemma 2 we know that n2G χ(G) ≤ τ (D) ≤ O(n2G )χ(G), 1/2− and τ (D) ≤ τ 0 (D) ≤ nD τ (D) by assumption. Thus, 1/2− χ(G) ≤ τ 0 (D)/n2G ≤ nD 1/2− /n2G τ (D) ≤ O(n2G )/n2G nD χ(G) ≤ O(n1−2 )χ(G) G contradicting Theorem 1. 4 Hardness of Vertex-By-Vertex Compaction Our hardness result for vertex-by-vertex vertical compaction follows roughly the same outline as Theorem 2: translate graph vertices into drawing features such that two features can be compacted onto the same row if and only if the corresponding graph vertices can be assigned the same color. However, if we translated adjacencies in the graph to be colored into direct overlaps between pairs of features, as we did for row-by-row compaction of path graphs, this translation would only let us represent interval graphs, which are easily colored [14]. Instead we use an edge gadget depicted in Figure 7 to represent an edge between two vertices of the input graph. This gadget has six vertices and six line segments; the two vertices A and B of the gadget may be placed on two line segments representing vertices of the input graph. This connection forces the two line segments containing A and B to be placed on different rows of any compacted drawing, even if these two line segments have no vertical overlap with each other: one of the two line segments must be above the central rectangle of the gadget, and the other must be below the central rectangle, although either of these two orientations is possible. B A Figure 7: The basic version of an edge gadget (left), connecting two horizontal segments representing vertices (right). JGAA, 16(3) 651–673 (2012) 661 The use of these edge gadgets leads to a second difficulty in our reduction: the number of rows in the compacted drawing will depend both on the features coming from input graph vertices and the rows needed by the edge gadgets themselves. In order to make the first of these two terms dominate the total, we represent an input graph vertex by a vertex bundle of θ parallel line segments, for some integer θ > 0. The edge gadgets may be modified to enforce that all segments in one bundle be in different rows from all segments of a second bundle, as shown in Figure 8, while only using a constant number of rows for the gadget itself. Figure 9 shows the complete reduction, for a graph G with five vertices and six edges, and for θ = 1. Each vertex of G is represented as a horizontal black line segment (or bundle of segments, for θ > 1), and each edge of G is represented by an edge gadget. The vertices of G are numbered arbitrarily from 1 to nG , and these numbers are used to assign vertical positions to the corresponding bundles of segments in the drawing. The edge gadgets are given x-coordinates that allow them to attach to the two vertex bundles they should be attached to, and y-coordinates that place them between these two vertex bundles. Lemma 3 Given a graph G and a parameter θ we can construct in polynomial time an orthogonal drawing D such that the vertices of D have maximum degree 3, nD = O(θnG + mG ), and θχ(G) ≤ λ(D) ≤ θχ(G) + O(n2G ). Proof: The construction of D is as described above. Since each edge gadget has a constant number of vertices together they contribute O(mG ) to nD , and each vertex bundle has O(θ) vertices together they contribute O(θnG ) to nD . Hence nD = O(θnG + mG ). The bound on the degree is clear from the construction. If G has a coloring with χ colors, it is possible to assign the vertex bundles of D to χ sets of θ rows each, according to those colors, with an additional O(nG ) rows between any two such sets to allow room for the edge gadgets Figure 8: The full edge gadget for θ = 5. 662 Bannister, Eppstein, Simons Compaction for Graph Drawings 5 4 1 3 2 5 3 2 1 4 Figure 9: Example of the complete reduction for θ = 1. 1 3 2 5 4 3 2 4 5 1 Figure 10: Example coloring based on the compaction of the drawing in Figure 9. to be placed without interference with each other; see Figure 10. Therefore, λ(D) ≤ θχ(G) + O(n2G ). If D0 is a compacted drawing of D, acyclically orient the edges of G from the vertex whose bundle is below the edge gadget to the vertex whose bundle is above the edge gadget, and assign each vertex v in G a color indexed by the length of the longest path from a source to v in this acyclic orientation. Then the number of colors needed equals the number of vertices in the longest path, and the number of rows in D0 needed just for the vertices in this path is θ times the number of vertices of G in the path. Therefore, θχ(G) ≤ λ(D). Theorem 5 If P 6= NP, then no polynomial time algorithm approximates the number of rows or the area in an optimal vertex-by-vertex vertical compaction 1/3− of a given orthogonal graph drawing to within a factor of nD . Proof: If an algorithm could achieve this approximation ratio for compaction, we could get an O(n1−3 ) ratio for coloring by applying Lemma 3 with θ = n2G , G compacting the resulting drawing, and using the coloring derived from the compaction in the proof of Lemma 3, contradicting Theorem 1. JGAA, 16(3) 651–673 (2012) 663 Lemma 4 Given a graph G and parameters θ and φ we can construct in polynomial time an orthogonal drawing D such that the vertices of D have maximum degree 3, nD = O(θnG + mG + φ), with the bounds θχ(G) ≤ µ(D) ≤ θχ(G) + O(n2G ) when θ > 6n2G on the longest edge, and the bounds τ (D) = Θ(n4G )χ(G) when θ, φ = Θ(n2G ) on the total edge length. Proof: We add two rows of vertices one above and one below the drawing produced by Lemma 3 (illustrated in Figure 9) by placing vertices above and below the left most column of vertices in each vertex bundle. We also place φ additional vertices on the top and the bottom to the right of the original drawing. The vertices are then connected as illustrated by Figure 11. First, we consider the bounds on the longest edge. For these bounds we let φ = 1 and θ > 6n2 . The width of the original drawing (from Lemma 3) is 2nG for the vertex bundle and 4mG for connecting the edge gadgets to the vertex bundles; see the right side of Figure 8. So the width of the original drawing is bounded above by 6n2G . When adding the additional frame (the green vertices with purple edge in Figure 11), all added horizontal edges have length at most 2nG , more precisely twice the degree of the vertex being represented by the bundle. Now, by construction the vertical edge on far right is the longest vertical edge in the drawing, and has length at least θχ(G)+O(mG ) > 6n2G by Lemma 3, making it the longest edge in the drawing even after compaction. So we have that µ(D) = λ(D) − 1 for the constructed drawing, i.e., minimizing the longest edge in the new drawing is equivalent minimizing the number of rows in the original drawing. The bounds for longest edge now follow from the bounds in Lemma 3. For the bounds on total edge length, we let θ, φ = Θ(n2G ). Each vertex bundle contributes O(θnG ) for a total of O(θn2G ). The height of each edge gadget is O(θχ(G)) from the vertex bundle plus O(mG ) from the other edge gadgets. The horizontal contribution from each edge gadgets is O(n2G ), as the width of the drawing is at most 6n2G . Altogether each edge gadget contributes O(θχ(G)+n2G ) for a total of O(n2G θχ(G) + n4G ). The added frame contributes O(n2G + φ) in horizontal edge length, and φθχ(G) in vertical edge length. Since φ = Θ(n2G ) the vertical lines holding the the drawing in the frame do not contribute to the asymptotic complexity. Summing up the total edge length, τ (D) = O(θn2G ) + O(n2G θχ(G) + n4G ) + φθχ(G) = Θ(n4G )χ(G), we get the desired bounds. Theorem 6 If P 6= NP, then no polynomial time algorithm approximates the length of the longest edge or total edge length in an optimal vertex-by-vertex vertical compaction of a given orthogonal graph drawing to within a factor of 1/3− nD . 664 Bannister, Eppstein, Simons Compaction for Graph Drawings φ Figure 11: Long-edges-frame added to the drawing in Figure 9 Proof: If an algorithm could achieve this approximation ratio for compaction, we could get an O(n1−3 ) ratio for coloring by applying Lemma 4 with θ = 7n2 and φ = 1 and compacting with respect to longest edge, or by applying Lemma 4 with θ = φ = n2 and compacting with respect to total edge length. 5 Hardness of Vertex-By-Vertex Free Compaction In the reduction from the previous section, allowing the vertices to move horizontally as well as vertically does not make any difference in how much vertical compaction is possible. However, if we want to prove inapproximability for minimal-area compaction, we also need to worry about horizontal compaction. By making the width uncompactable we may make the vertical compaction factor the same as the area compaction factor. Lemma 5 From a drawing D a drawing D0 can be constructed by adding at most O(nD ) vertices, such that λ(D0 ) = λ(D) + 1 and D0 is uncompactable in the horizontal direction. If D has maximum degree three, then so does D0 . Proof: Place a line of vertices on a new row below D; for each set of vertices with a given x-coordinate in D, add a vertex on the new row at the same xcoordinate. Connect the added vertices with horizontal edges, and add a vertical edge to connect these vertices to D at the point of D that is rightmost on its bottom row, as shown in Figure 12. This added layer conflicts with all existing horizontal layers, and forces D0 to be uncompactable in the horizontal direction. Theorem 7 Unless P = NP, it is impossible to find vertex-by-vertex free compactions with respect to number of rows, area, longest edge length or total edge JGAA, 16(3) 651–673 (2012) 665 Figure 12: Adding a row of vertices to D prevents horizontal compaction. 1/3− length within a factor of nD of optimal in polynomial time. Proof: For the case of compaction with respect to area we apply Lemma 5 to reduce compaction with respect to area to compaction with respect to the number of rows. Since we only added a linear number of vertices the approximation ratios are the same. The rest of the theorem follows from the results on vertex-by-vertex vertical compaction. 6 Hardness of Three-Dimensional Compaction Our hardness result for three-dimensional vertical compaction (along the z-axis) follows from the construction of a drawing whose valid two-dimensional layer assignments are the same as the valid colorings of a graph G. We assign to each vertex in G a horizontal layer parallel to the xy-plane containing an L-shaped pair of line segments, such that when projected vertically onto the xy-plane every two of these L-shaped gadgets cross each other. For each edge in G we place a vertical edge in the drawing connecting the L-shaped gadgets that correspond to the endpoints of the edge. Figure 13 shows an example. Lemma 6 Given a graph G we can construct in polynomial time a 3D orthogonal drawing D with maximum degree three such that nD = 3nG +2mG = O(n2G ), and such that the number of layers in an optimal y-compaction is χ(G). Proof: Our construction uses three vertices in D to form the L-shaped gadget for each vertex in G, and two more vertices for the vertical edge corresponding to each edge in G, so nD = 3nG + 2mG = O(n2G ). By construction the only conflicting features in a vertical (along the z-axis) compaction come from the vertical edges, forcing χ(G) to be the number of layers in an optimal compaction of D. Theorem 8 If P 6= NP, then there does not exist a polynomial time algorithm that approximates the number of layers in an optimal vertex-by-vertex or vertexby-vertex free vertical compaction of a given three dimensional orthogonal draw1/2− ing to within a factor of nD . 666 Bannister, Eppstein, Simons Compaction for Graph Drawings Proof: In this case nD = O(n2G ), and the number of layers in an optimal compaction is equal to χ(G). The proof follows same lines as the proofs in Section 3 on row-by-row-compaction. As we did in previous sections we will reduce compaction with respect to volume, longest edge, and total edge length to compaction with respect to layering via a frame. In this case we will place a mesh layer above and below the drawing, keeping the original drawing between the two layers. Lemma 7 Given a graph G with more than 4 vertices we can construct in polynomial time a 3D orthogonal drawing D with maximum degree three with nD = O(n2G ), and such that µv (D) = χ(G) + 1 and n2G χ(G) ≤ τ (D) ≤ O(n2G )χ(G) where µv (D) is the length of the longest vertical edge in an optimal vertical compaction. 4 3 2 2 3 1 1 4 Figure 13: Reduction from coloring to three-dimensional compaction where y is the vertical direction. 2n Figure 14: Left: View of the 3D-drawing in Figure 13 from above. Vertical edges meet at lighter shaded vertices. Right: Top/bottom frame. JGAA, 16(3) 651–673 (2012) 667 Proof: From the drawing produced by Lemma 6 we add O(n2G ) edges, and consequently O(n2G ) vertices, in 2nG parallel paths above and below the drawing as illustrated in Figure 14, where the frame on the right side of the drawing is placed directly over and below the 3D drawing to the left. The diagonal nodes are connected to the ends of the L-gadgets from the top and the bottom to keep them between the two frames. The sub-diagonal green vertices are connected with edges between the upper and lower frame. This construction is illustrated in Figure 15. By construction the longest vertical edges are the edges connecting the top and bottom frames; their length is one unit more than the number of layers between the top and the bottom frame. Hence µv (D) = χ(G) + 1 by Lemma 6. The number of edges connecting the two layers is given by 1 + 2 + 3 + · · · + (2nG − 2) = O(n2G ) and is greater than n2G for n > 4. The total edge length used by the L-gadgets is at most 2n2G , and χ(G)mG for the connecting segments. The top and bottom frames add O(n2G ) length to the drawing, and the connecting edges add O(n2G )χ(G). So we have that n2G χ(G) ≤ τ (D) ≤ O(n2G )χ(G). Figure 15: 3D frame construction 668 Bannister, Eppstein, Simons Compaction for Graph Drawings Theorem 9 If P 6= NP, then there does not exist a polynomial time algorithm that approximates the volume, longest vertical edge, or total edge length in an optimal layer compaction of a given three dimensional orthogonal drawing to 1/2− within a factor of nD . Proof: Having the bounds in Lemma 7 the proof follows as before. We can also achieve a similar result for longest edge, without having to limit our result to the longest vertical edge, by replacing each L-shaped vertex gadget by an L-bundle, similar to our vertex bundle in the two dimensional case. This is needed to prevent the longest edge from being a nG length leg of the L-gadget. We omit the details. 7 Coloring Counterexample In the conference version of this paper we included an approximation algorithm for compaction which was later discovered to be flawed. In this algorithm we defined a incompatibility graph, where the vertices of the incompatibility graph represent sets of features in the drawing that must move in tandem. Two vertices of the incompatibility graph are connected by an edge when the drawing features they represent cannot be compacted to the same row of the drawing, i.e., when they contain parts of the drawing that are directly above one another. A coloring of the incompatibility graph was then used to to compact the drawing, using a row for each color. The problem is that although compacting a drawing does produce a coloring of its incompatibility graph, the converse does not hold. In Figure 16 we see a drawing whose incompatibility graph is 2-colorable (in fact it is a path), but which is completely uncompactable. Figure 16: An uncompactable graph with a 2-colorable incompatibility graph. JGAA, 16(3) 651–673 (2012) 8 669 Fixed-Parameter Tractability of Vertex-By-Vertex Vertical Compaction Lemma 8 Given an orthogonal drawing D we can compact D into k rows in O(k!(nD + bD )) time, if such a compaction is possible. Proof: We construct local assignments of the features into k rows via a leftto-right plane sweep. The input drawing may be assumed to be given with coordinates on an n × n grid, so its features can be sorted in linear time using bucket sorting. While sweeping the plane we maintain the set of input features that intersect the sweep line along with a record of valid assignments of these features into the k rows of our output drawing. When a feature first intersects the sweep line we try to place it into the collection of valid assignments. If there are ` features intersecting the sweep line prior to the insertion, we have at most `! k` valid assignments to consider. In each of these valid assignments there are k − ` free rows. Altogether at most k! configurations will be considered for each feature insertion. When the sweep line moves past a feature its row is freed for future use. If at any point we cannot find any valid assignment for a new feature, we conclude that a compaction into k rows is not possible. On the other hand if the last feature can be placed into a valid assignment, then a compaction into k layers is possible. To recover the global assignment of horizontal features into rows, we may backtrack through the sets of local assignments as is standard for a dynamic programming algorithm of this type. Theorem 10 An optimal vertex-by-vertex vertical compaction of an orthogonal drawing D can be found in O(λ!(nD + bD )) time where λ = λ(D). Proof: Apply Lemma 8 for k = 1, 2, 3, . . . until finding a value of k for which a valid layering exists. 9 Vertex-By-Vertex Free Compaction for Paths In contrast with row-by-row compaction (Section 3), we have a polynomial time algorithm for vertex-by-vertex free compaction of a path. In fact, in the following theorem, we give a simple, linear time algorithm to achieve an optimal compaction. In this section by a vertical subpath we mean a maximal subpath containing only vertical edges, similarly for a horizontal subpath Theorem 11 An optimal vertex-by-vertex free row compaction for an orthogonal path can by found in O(nD + bD ) time. Such a compaction will be into k rows where k is the number of vertices on the longest vertical path. 670 Bannister, Eppstein, Simons Compaction for Graph Drawings Figure 17: Compacting a path into k = 5 rows. Here the colors on vertices are simply meant to help clarify the correspondence between the two paths. Proof: First we replace the bends in the path with special “bend vertices” that will be changed back to bends after the compaction. Now, the number of rows required by a compacted drawing must be at least the number of vertices in the longest vertical subpath, since each of these vertices must be placed in its own row to achieve an unambiguous drawing. We will show that we can compact the drawing into exactly this number of rows, and therefore optimally compact the drawing. To perform a vertex-by-vertex free compaction of an orthogonal path we perform the following steps, which are illustrated in Figure 17. 1. Compute the number k of vertices is the longest vertical subpath by walking the path. 2. Order the horizontal subpaths in walk order. Alternate placing horizontal paths, in path order, in rows 1 and k overlapping in their endpoints. 3. Connect the overlapping horizontal paths with vertical lines, and place the appropriate number of vertices on the edge to construct the vertical path between the overlapping horizontal paths. The end result is an optimally vertex-by-vertex free compacted path with respect to the number of rows. In this algorithm moving vertices horizontally was essential, so such a compaction is not possible in vertex-by-vertex vertical compaction. In contrast to our result, Brandes et al. showed that the problem of orthogonal order preserving drawing is NP-hard for a path [2]. We leave as an interesting open problem the complexity of vertex-by-vertex vertical compaction for a path. JGAA, 16(3) 651–673 (2012) 10 671 Conclusions Our investigations have determined lower bounds for several different approximation and fixed-parameter versions of the compaction problem. Currently we have no upper bounds on the √ approximation ratio for these compaction problems. With our techniques O( n) is a natural upper bound, as our reductions produce drawings with at least one vertex for each edge in the original graph, approximately squaring the number of vertices in the problem. Can algorithms be constructed to match this expected upper bound? Can the lower bounds of Ω(n1/3− ) be improved to Ω(n1/2− ) or higher? We leave these questions open for future research. 672 Bannister, Eppstein, Simons Compaction for Graph Drawings References [1] T. C. Biedl, B. P. Madden, and I. G. Tollis. The three-phase method: a unified approach to orthogonal graph drawing. Int. J. Comput. Geom. Appl. 10(6):553–580, 2000, doi:10.1142/S0218195900000310. [2] U. Brandes and B. Pampel. On the hardness of orthogonal-order preserving graph drawing. Graph Drawing, pp. 266–277. Springer Berlin / Heidelberg, Lecture Notes in Computer Science 5417, 2009, doi:10.1007/978-3-642-00219-9 25. [3] S. S. Bridgeman, G. Di Battista, W. Didimo, G. Liotta, R. Tamassia, and L. Vismara. Turn-regularity and optimal area drawings of orthogonal representations. Computational Geometry: Theory and Applications 16(1):53–93, 2000, doi:10.1016/S0925-7721(99)00054-1. [4] P. Eades, S.-H. Hong, and S.-H. Poon. On rectilinear drawing of graphs. Graph Drawing, pp. 232–243. Springer Berlin / Heidelberg, Lecture Notes in Computer Science 5849, 2010, doi:10.1007/978-3-642-11805-0 23. [5] M. Eiglsperger, S. Fekete, and G. Klau. Orthogonal graph drawing. Drawing Graphs, pp. 121–171. Springer Berlin / Heidelberg, Lecture Notes in Computer Science 2025, 2001, doi:10.1007/3-540-44969-8 6. [6] M. Eiglsperger and M. Kaufmann. Fast compaction for orthogonal drawings with vertices of prescribed size. Graph Drawing, pp. 67–71. Springer Berlin / Heidelberg, Lecture Notes in Computer Science 2265, 2002, doi:10.1007/3-540-45848-4 11. [7] D. Eppstein. The topology of bendless three-dimensional orthogonal graph drawing. Graph Drawing, pp. 78–89. Springer Berlin / Heidelberg, Lecture Notes in Computer Science 5417, 2009, doi:10.1007/978-3-642-00219-9 9. [8] U. Feige and J. Kilian. Zero knowledge and the chromatic number. J. Comput. System Sci. 57(2):187–199, 1998, doi:10.1006/jcss.1998.1587. Complexity 96—The Eleventh Annual IEEE Conference on Computational Complexity (Philadelphia, PA). [9] W. Huang, S.-H. Hong, and P. Eades. Effects of crossing angles. IEEE Pacific Visualization Symposium (PacificVIS ’08), pp. 41–46, 2008, doi:10.1109/PACIFICVIS.2008.4475457. [10] S. Khot. Improved inapproximability results for MaxClique, chromatic number and approximate graph coloring. 42nd IEEE Symposium on Foundations of Computer Science (Las Vegas, NV, 2001), pp. 600–609. IEEE Computer Soc., Los Alamitos, CA, 2001, doi:10.1109/SFCS.2001.959936. JGAA, 16(3) 651–673 (2012) 673 [11] G. Klau, K. Klein, and P. Mutzel. An experimental comparison of orthogonal compaction algorithms. Graph Drawing, pp. 109–112. Springer Berlin / Heidelberg, Lecture Notes in Computer Science 1984, 2001, doi:10.1007/3-540-44541-2 5. [12] G. Klau and P. Mutzel. Optimal compaction of orthogonal grid drawings (extended abstract). Integer Programming and Combinatorial Optimization, pp. 304–319. Springer Berlin / Heidelberg, Lecture Notes in Computer Science 1610, 1999, doi:10.1007/3-540-48777-8 23. [13] J. Maňuch, M. Patterson, S.-H. Poon, and C. Thachuk. Complexity of Finding Non-Planar Rectilinear Drawings of Graphs. Graph Drawing, pp. 305–316. Springer Berlin / Heidelberg, Lecture Notes in Computer Science 6502, 2011, doi:10.1007/978-3-642-18469-7 28. [14] S. Olariu. An optimal greedy heuristic to color interval graphs. Inf. Process. Lett. 37:21–25, January 1991, doi:10.1016/0020-0190(91)90245-D. [15] M. Patrignani. On the complexity of orthogonal compaction. Computational Geometry 19(1):47–67, 2001, doi:10.1016/S0925-7721(01)00010-4. [16] R. Tamassia. On embedding a graph in the grid with the minimum number of bends. SIAM J. Comput. 16(3):421–444, 1987, doi:10.1137/0216030. [17] D. Zuckerman. Linear degree extractors and the inapproximability of max clique and chromatic number. Theory of Computing 3(1):103–128, 2007, doi:10.4086/toc.2007.v003a006.