1 Introduction

Linear graph layouts, in particular book embeddings [1, 12] (also known as stack layouts) and queue layouts [9, 10], form a classic research topic in graph drawing with many applications beyond graph visualization as surveyed by Dujmović and Wood [6]. A k-page linear layout \(\varGamma =(\prec , \mathcal P)\) of a graph \(G=(V, E)\) consists of an order \(\prec \) on the vertex set V and a partition of E into k subsets \(\mathcal P = \{P_1, \dots , P_k\}\) called pages. Visually, we may represent \(\varGamma \) by mapping all vertices of V in the order \(\prec \) onto a line \(\ell \). Each page can be represented by mapping all edges to semi-circles connecting their endpoints in a halfplane bounded by \(\ell \). If a page P is a stack page, then no two edges in P may cross, or at least the number of crossings should be minimized. More precisely, two edges uv, wx in P cross (assuming \(u \prec v\), \(w \prec x\), and \(u \prec w\)) if and only if their vertices are ordered as \(u \prec w \prec v \prec x\). Conversely, if a page P is a queue page, then no two edges in P may be nested, or at least the number of nestings should be minimized. Here, an edge wx is nested by an edge uv if and only if their vertices are ordered as \(u \prec w \prec x \prec v\) (under the same assumptions as above).

Stack and queue layouts have mostly been studied for planar graphs with a focus on investigating the stack number (also called book thickness) and the queue number of graphs, which correspond to the minimum integer k, for which a graph admits a k-stack or k-queue layout. It is known that recognizing graphs with queue number 1 or with stack number 2 is -complete [1, 10]. Further, it is known that every planar graph admits a 4-stack layout [16], but it is open whether the stack number of planar graphs is actually 3. Due to their practical relevance, book drawings, i.e., stack layouts in which crossings are allowed, have also been investigated from a practical point of view. Klawitter et al. [11] surveyed the literature and performed an experimental study on several state-of-the-art book drawing algorithms aiming to minimize the number of crossings in layouts on a fixed number of stack pages. Conversely, for queue layouts it was a longstanding open question whether planar graphs have bounded queue number [9]; this was recently answered positively by Dujmović et al. [5].

Mixed layouts, which combine \(s \ge 1\) stack pages and \(q \ge 1\) queue pages, are studied less. For an s-stack q-queue layout \(\varGamma = (\prec , \mathcal P)\), the set of pages \(\mathcal P\) is itself partitioned into the stack pages \(\mathcal S = \{S_1, \dots , S_s\}\) and the queue pages \(\mathcal Q = \{Q_1, \dots , Q_q\}\). Heath and Rosenberg [10] conjectured that every planar graph admits a 1-stack 1-queue layout, but this has been disproved recently by Pupyrev [13], who conjectured that instead every bipartite planar graph has a 1-stack 1-queue layout. Pupyrev further provides a SAT-based online tool for testing the existence of an s-stack q-queue layoutFootnote 1.

Contributions. We first show two -completeness results in Sect. 2. The first one shows that testing the existence of a 2-stack 1-queue layout is -complete, and the other proves that an -complete mixed layout recognition problem with fixed vertex order remains -complete under addition of stack or queue pages. Next, we focus our attention on 1-stack 1-queue layouts and propose, to the best of our knowledge, the first heuristic targeted at minimizing conflicts in 1-stack 1-queue layouts, see Sect. 3. In a computational experiment in Sect. 4 we show that our heuristic achieves fewer conflicts compared to previous heuristics for stack layouts with a straightforward adaptation to mixed layouts.

Due to space constraints, proofs of statements marked with \(\star \), as well as some additional plots are available only in the full version of this paper [4].

2 Complexity

In this section we give new complexity results regarding mixed linear layouts. For Theorem 1 we first make some useful observations, see the full paper [4] for details. Let \( K_8 \) be the complete graph on eight vertices and \(\varGamma = (\prec ,\{S_1,S_2\},\{Q\}) \) a 2-stack 1-queue layout of a \(K_8\). Using exhaustive searchFootnote 2 we verified that in such a 2-stack 1-queue layout the three longest edges are in \( S_1 \cup S_2 \) and the edges between the first and third, and the sixth and eighth vertex in \( \prec \) are in Q. Finally, for two \( K_8 \)’s only the last and first vertex from each \( K_8 \) can interleave.

Let \( G_1 = (V_1, E_1) \) and \( G_2 = (V_2, E_2) \) be two distinct \(K_8\)’s. A double-\( K_8 \) G is formed, by identifying two so-called shared vertices u, v of \( G_1 \) and \( G_2 \) with each other and adding one more edge wz between so-called outer vertices \( w \in V_1 \), \( z \in V_2 \) such that neither w nor z is one of the shared vertices, see Fig. 1(a). For any 2-stack, 1-queue layout \(\varGamma = (\prec ,\{S_1,S_2\},\{Q\}) \) of a double-\( K_8 \) we verified with exhaustive search that the shared vertices have to be the two middle vertices in \( \prec \) and that the outer vertices are always the first and last vertices in the ordering of such a layout.

Lemma 1

(\(\star \)). Let \( G = (V, E) \) be a double-\( K_8 \) with outer vertices w, z and two additional vertices \( a, b \in V \) with an edge \( ab \in E \). In every 2-stack 1-queue layout \( \varGamma = (\prec ,\{S_1, S_2\},\{Q\}) \) of G, with \( w \prec a \prec z \) and \( b \prec w \) or \( z \prec b \), it holds that \( ab \in Q \) and a is between the first or last three vertices in the double-\( K_8 \).

Fig. 1.
figure 1

(a) A 2-stack 1-queue layout of a double-\( K_8 \). Only the left \( K_8 \) is drawn fully, dashed edges are in the queue page. (b) Sketch of the gadget for Theorem 1.

Corollary 1

(\(\star \)). Let \( G_1 = (V_1,E_1) \) and \( G_2 = (V_2,E_2) \) be two double-\( K_8 \)’s. In a 2-stack 1-queue layout \(\varGamma \) of \( G_1 \cup G_2 \) with linear order \( \prec \), either \( u \prec v \) or \( v \prec u \) for all \( u \in V_1 \), \( v \in V_2 \).

Let \( G = (V, E) \) be a graph consisting of two double-\( K_8 \)’s \( G_1 = (V_1, E_1) \) and \( G_2 = (V_2, E_2) \). Let \( w_1 \in V_1 \) and \( w_2 \in V_2 \) be two outer vertices. Further, let \( x_1, x_2 \in V_1 \) and \( y_1, y_2 \in V_2 \) be four vertices such that \( x_1, x_2 \) are in the same \( K_8 \) as \( w_1 \), \( w_2 \) respectively for \( y_1, y_2 \), and none of them is a shared vertex. Finally, add a vertex u to V and the edges \( x_1y_1 \), \( x_2y_2 \), \( w_1u \), and \( w_2u \) to E, see Fig. 1(b).

Lemma 2

(\(\star \)). Let \( G = (V,E) \) be the graph constructed as above. Then in any 2-stack 1-queue layout \( \varGamma = (\prec ,\{S_1, S_2\},\{Q\}) \) of G we find, w.l.o.g., \( w_1 \prec u \prec w_2 \) and \( w_1u, w_2u \in S_1 \cup S_2 \).

Theorem 1

Let \( G = (V,E) \) be a simple undirected graph. It is -complete to decide if G admits a 2-stack 1-queue layout.

Proof

The problem is clearly in . We show the result by a reduction from the problem of deciding the existence of a 2-stack layout, which is -complete and equivalent to decide whether a graph is subhamiltonian [1, 2]. Let \( G' = (V',E') \) be a graph constructed as in Lemma 2. Identify the special vertex u in \( V' \) with any vertex in G and add the rest of G to \( G' \). Clearly, if G has a 2-stack layout, we can construct a 2-stack 1-queue layout of \( G' \) as sketched in Fig. 1(b). Conversely, let \(\varGamma = (\prec ,\{S_1,S_2\},\{Q\}) \) be a 2-stack 1-queue layout of \( G' \). As for u in Lemma 2, we find that \( w_1 \prec v \prec w_2 \) for every neighbor \( v \in V \) of u. By induction we find for all \( v' \in V \) that \( w_1 \prec v' \prec w_2 \). Hence all edges in G are nested by \( x_1y_1 \) and \( x_2y_2 \), which are both in Q. It follows that G has a 2-stack layout.    \(\square \)

Our second complexity result shows that adding stack or queue pages to the specification of an already -complete mixed linear layout problem with given vertex order \(\prec \) remains -complete. Note that for \( s = 4 \) and \( q = 0 \) the problem of deciding if the edges can be assigned to the pages even when the vertex order is fixed is known to be -complete [15].

Theorem 2

(\(\star \)). Let \( G = (V,E) \) be a simple undirected graph and \(\prec \) a fixed order of V. If it is -complete to decide if G admits an s-stack q-queue layout respecting \(\prec \), then it is also -complete to decide if G admits (i) an s-stack \( (q + 1) \)-queue layout or (ii) an \( (s +1) \)-stack q-queue layout respecting \(\prec \), respectively.

3 Heuristic Algorithm

Most heuristics for minimizing crossings in book drawings work in two steps [11]. First compute a vertex order and then a page assignment. We propose a new page assignment heuristic, specifically tailored to mixed linear layouts. To the best of our knowledge, this is the first heuristic for minimizing crossings and nestings in mixed linear layouts. It uses stack and queue data structures for keeping track of conflicts and estimating possible future conflicts. The design allows us to consider the assigned and unassigned edges at the same time while efficiently processing them to run in \(O(m^2)\) time for a graph with m edges.

In the following, we describe how the algorithm works for a 1-stack 1-queue layout. We note that it is straight forward to adapt our approach to s-stack, q-queue layouts for arbitrary s and q. A stack (queue) can be used to validate that a given page has no crossings (nestings) by visiting the vertices in their linear order and inserting (removing) each edge when the left (right) end-vertex is visited, respectively [9]. We can use a similar strategy for our heuristic. Here it is allowed to remove edges even if they are not on top of the stack or in front of the queue, but of course this might produce conflicts. Let S be a stack and Q a queue. We additionally keep two counters for each edge e, the so called crossing counter c(e) and the nesting counter n(e). The vertices are processed from left to right in a given vertex order. For the current vertex u we insert all edges \( e = uv \) into S and Q. If there are multiple edges uv, we add them according to their length to S and Q. For S we sort them from long to short, for Q from short to long. Once the second vertex v of an edge \(e=uv\) is visited, we remove e from S and Q, and decide to which page we assign it. Let \( s_e \) be the number of edges on top of e in S and \( q_e \) the number of edges in front of e in Q. Then we assign e to the stack page if \( c(e) + 0.5s_e \le n(e) + 0.5q_e \) and update \( c(e') \) for each edge \( e' \) on top of e in S. Otherwise we assign e to the queue page and update \(n(e')\) for each edge \(e'\) in front of e in Q. Intuitively we estimate for each edge e how many conflicts this edge produces for edges \( e' \) to be processed later. The advantage of this estimation is that we potentially assign the edge to a page that adds more conflicts now, but might create fewer conflicts in the future.

4 Experiments

We denote our algorithm as stack-queue heuristic and compare it with the two page assignment heuristics eLen [3] and ceilFloor [14] that are commonly used with book drawings [11] (For the source code and benchmark instances see footnote 2). Both can be adapted to mixed layouts, while other book drawing heuristics try to explicitly partition the edges into planar sets, which is obviously not suitable for queue pages in mixed layouts. Both process the edges by decreasing length and greedily assign each edge to the page where it causes fewer conflicts at the time of insertion. In case of ties, a stack page is preferred over a queue page. The difference is that eLen computes the length based on the linear vertex order and ceilFloor based on the corresponding cyclic vertex order as follows. Given a vertex order \( 1 \prec 2 \prec \ldots \prec n \), eLen considers the edge (1, n) first and the edges \( (i, i + 1) \) last. In ceilFloor the length of an edge uv is defined as \( min(|u - v|, n - |u - v|) \). All three heuristics run in \(O(m^2)\).

The goal of our experiment is to explore the performance differences in terms of the number of conflicts per edge of the adapted book drawing algorithms compared to our new heuristic. We thus measure the resulting number of conflicts per edge for all three algorithms, as well as record for each instance the algorithm with the fewest number of conflicts. We first tested the algorithms on the complete graphs with up to 50 vertices. Furthermore, we generated 500 random graphs for each number of vertices in \(\{25, 50, \dots , 400\}\) from different sparse graph classes, see Fig. 2, since it is known that both, stack and queue page, can contain at most \(2n-3\) conflict-free edges [1, 10]. All experiments ran on a Linux cluster (Ubuntu 16.04.6 LTS), where each node has two Intel Xeon E5540 (2.53 GHz Quad Core) processors and 24 GB RAM. The running time of one run of each algorithm was relatively low, taking less than one second on average and at most 2.5 s for the denser random graphs with 400 vertices.

For the complete graphs stack-queue was the best page assignment heuristic producing about 2/3 of the conflicts of eLen and ceilFloor. For other graphs, the vertex order has a strong effect on the results. In our experiments we first compared three state-of-the-art vertex order heuristics (breadth-first search (rbfs [14]), depth-first search (AVSDF [8]) and connectivity (conGreedy [11])) before applying the page assignment heuristics. It turned out that for all of them the same vertex order heuristic performed best on the same graph class, so that all experiments could be run without bias on exactly the same input order.

Benchmark Graphs. We first generated random (not necessarily planar) graphs of n vertices and either \(m=3n\) or \(m=6n\) edges. The graphs were created by drawing uniformly at random the required number of edges, discarding disconnected graphs. The best vertex order heuristic was conGreedy.

Since 1-stack 1-queue layouts are especially interesting for planar and planar bipartite graphs [13], we generated random planar and maximal planar bipartite graphs. The planar graphs are generated as Delaunay triangulations of n random points in the plane. Since every planar bipartite graph has a 2-stack embedding [7], we randomly generated a vertex order of alternating vertices from both vertex sets to ensure that a Hamiltonian path exists. We then randomly selected two vertices of the two sets and added the edge to the graph if it was possible to do so without a crossing. We repeated the process of randomly selecting the vertices until the maximum number of \( 2n - 4 \) edges had been reached. The vertex order for the Delaunay triangulations was computed by rbfs and for maximal planar bipartite graphs by AVSDF. As it turned out that stack-queue did not perform as well as ceilFloor and eLen on the Delaunay triangulations, which is in contrast to the random and planar bipartite graphs, we wondered whether the presence of many triangles might be the reason. Hence, we considered two graph classes with many triangles and the same maximal edge densities as planar and planar bipartite graphs, respectively, namely planar 3- and 2-trees. For 2-trees the best vertex order was computed by AVSDF and for 3-trees by conGreedy.

Fig. 2.
figure 2

How many times each algorithm obtained the fewest conflicts in percent.

Results. Aggregated results of our experiments are shown in Fig. 2. Additional plots are provided in the full version [4]. For random graphs stack-queue performs best among the three heuristics for almost all instances, even though the difference to ceilFloor in conflicts per edge is small. For Delaunay triangulations, stack-queue performs best for small graphs (\( n \le 25 \)), but for the larger instances ceilFloor computes better solutions for the majority of instances. In terms of conflicts per edge, however, all three algorithms are quite close together. In the case of planar bipartite graphs, stack-queue is the best algorithm for up to 300 vertices. Afterwards ceilFloor performs slightly better, but in both cases, again, the difference in the number of conflicts is small. For 2-trees, the results are more or less evenly split among all three algorithms. Yet, for 3-trees, stack-queue computes the best solutions for 70–80% of the instances with up to 100 vertices. The differences in the number of conflicts per edge is also more noticeable. For larger instances ceilFloor catches up with stack-queue.

Discussion. The results of our experiments showed that the proposed stack-queue heuristic beats or competes with previously existing and suitably adapted page assignment heuristics for book drawings on most of the tested benchmark graph classes with the exception of Delaunay triangulations, where ceilFloor performed best. Since the running time of all three algorithms is \(O(m^2)\) this does make stack-queue a suitable method for computing 1-stack 1-queue layouts.

5 Conclusion

We believe it is possible to adapt our technique from Theorem 1 for \( s > 2 \) and \( q = 1 \). The biggest obstacle is to find such rigid structures as the double-\( K_8 \). In the algorithmic direction it could be interesting to investigate specialized heuristics for finding vertex orders in the queue- and mixed layout case. Whether every planar bipartite graph admits a 1-stack 1-queue layout remains open.