1 Introduction

Motivated by the need of visually exploring non-planar graphs, hybrid planarity is one of the emerging topics in graph drawing (see, e.g., [1,2,3, 9]). A hybrid planar drawing of a non-planar graph suitably represents in restricted geometric regions those dense subgraphs for which a classical node-link representation paradigm would not be visually effective. These regions are connected by edges that do not cross each other. Different representation paradigms for the dense subgraphs give rise to different types of hybrid planar drawings.

Angelini et al. [1] consider hybrid planar drawings where dense portions of the graph are represented as intersection graphs of sets of rectangles and study the complexity of testing whether a non-planar graph admits such a representation. In the context of social network analysis, Henry et al. [9] introduce NodeTrix representations, where the dense subgraphs are represented as adjacency matrices. Batagelj et al. [2] study the question of minimizing the size of the matrices in a NodeTrix representation of a graph while guaranteeing the planarity of the edges that connect different matrices. While Batagelj et al. can choose the subgraphs to be represented as matrices, Da Lozzo et al. [3] consider the problem of testing whether a flat clustered graph (i.e. a graph with clusters and no sub-clusters) admits a NodeTrix planar representation. In the paper of Da Lozzo et al. each cluster must be represented by a different adjacency matrix and the inter-cluster edges are represented as non-intersecting simple Jordan arcs. They prove that NodeTrix planarity testing for flat clustered graphs is NP-hard even in the constrained case where for each matrix it is specified which inter-cluster edges must be incident on the top, or on the left, or on the bottom, or on the right side.

Motivated by these hardness results, in this paper we study whether NodeTrix planarity testing can be efficiently solved when the size of the clusters is not “too big”. More precisely, we consider flat clustered graphs whose clusters have size bounded by a fixed parameter k and we want to understand whether the NodeTrix planarity testing problem is fixed parameter tractable, i.e. it can be solved in time f(k)T(n), where T(n) is a polynomial in n and f(k) is a function that depends only on k. Our main results can be listed as follows:

  • We describe an \(O(k^{3k+\frac{3}{2}}\cdot n^3)\)-time algorithm to test NodeTrix planarity with fixed sides for flat clustered graphs that are partial 2-trees. Informally, a flat clustered graph G is a partial 2-tree if the graph obtained by collapsing every cluster of G into a single vertex is a partial 2-tree.

  • When the flat clustered graph is not a partial 2-tree, NodeTrix planarity testing with fixed sides can still be solved in \(O(n^3)\) time for \(k = 2\), but it becomes NP-complete for any larger value of k.

  • Finally, we extend the above hardness result to the free sides model and show that NodeTrix planarity testing remains NP-complete when the maximum cluster dimension is larger than four. This is done by proving that NAE3SAT is NP-complete even for triconnected Boolean formulas, which may be a result of independent interest.

Our polynomial-time solution solves a special type of the planarity testing problem where the order of the edges around each vertex is suitably constrained to take into account the fact that a vertex of a matrix M has four copies along the four sides of M. It may be worth recalling that Gutwenger et al. [7] have considered an apparently similar problem. Namely, they studied planarity testing where the order of the edges around the vertices may not be arbitrarily permuted. Unfortunately, not only our problem does not fall in any of the cases addressed by Gutwenger et al., but it does not seem solvable by introducing a gadget of polynomial size that models the embedding constraints at each vertex. This characteristic associates NodeTrix planarity testing with other known variants of planarity testing, including clustered planarity, where the use of gadgets of polynomial size has been so far an elusive goal.

The rest of the paper is organized as follows. Preliminary definitions are in Sect. 2. Sections 3 and 4 describe a polynomial time algorithm for clustered 2-trees with bounded cluster-size. In Sect. 5 we show that for general flat clustered graphs and fixed sides NodeTrix planarity testing can be solved in polynomial time for \(k=2\) but it is NP-complete for \(k\ge 3\). In the same section we extend this completeness result to NodeTrix planarity testing of flat clustered graphs with free sides. Finally open problems can be found in Sect. 6. For reasons of space, some proofs are sketched or omitted and can be found in [6].

2 Preliminaries

We assume familiarity with basic definitions of graph theory and graph drawing and in particular with the notions of block-cut-vertex tree and of SPQR-tree (see, e.g., [4, 8]).

A flat clustered graph \(G=(V,E,\mathcal {C})\) is a simple graph with vertex set V, edge set E, and a partition \(\mathcal {C}\) of V into sets \(V_1,\dots ,V_h\), called clusters. An edge \((u,v) \in E\) with \(u \in V_i\) and \(v \in V_j\) is an intra-cluster edge if \(i=j\) and it is an inter-cluster edge if \(i\ne j\).

A NodeTrix representation of a flat clustered graph G is such that: (i) Each cluster \(V_i\) with \(|V_i|=1\) (called trivial cluster) is represented as a distinct point in the plane. (ii) Each cluster \(V_i\) with \(|V_i|>1\) (called non-trivial cluster) is represented by a symmetric adjacency matrix \(M_i\) (with \(|V_i|\) rows and columns), where \(M_i\) is drawn in the plane so that its boundary is a square with sides parallel to the coordinate axes. (iii) There is no intersection between two distinct matrices or between a point representing a vertex and a matrix. (iv) Each intra-cluster edge of a cluster \(V_i\) is represented by the adjacency matrix \(M_i\). (v) Each inter-cluster edge (uv) with \(u \in V_i\) and \(v \in V_j\) is represented by a simple Jordan arc connecting a point on the boundary of matrix \(M_i\) with a point on the boundary of matrix \(M_j\), where the point on \(M_i\) (on \(M_j\)) belongs to the column or to the row of \(M_i\) (resp. of \(M_j\)) associated with u (resp. with v).

A NodeTrix representation of a flat clustered graph G is planar if there is no intersection between any two inter-cluster edges (except possibly at common end-points) nor an intersection between an inter-cluster edge and a matrix. A flat clustered graph is NodeTrix planar if it admits a planar NodeTrix representation. Figure 1(a) is an example of a NodeTrix planar representation.

A formal definition of the problem investigated in the paper is as follows. Let \(G=(V,E,\mathcal {C})\) be a flat clustered graph with n vertices and let k be the maximum cardinality of a cluster in \(\mathcal {C}\). Clustered graph G is NodeTrix planar with fixed sides if it has a NodeTrix planar representation where for each inter-cluster edge, the sides of matrices it attaches to is specified as part of the input; G is NodeTrix planar with free sides if the sides of the matrices to which inter-cluster edges attach can be arbitrarily chosen.

Let \(M_i\) be the matrix representing cluster \(V_i\) in a NodeTrix representation of G; let v be a vertex of \(V_i\) and let (uv) be an inter-cluster edge. Edge (uv) can intersect the boundary of \(M_i\) in four points \(p_{v,{\textsc {t}}}, p_{v,{\textsc {b}}}, p_{v,{\textsc {l}}}\), and \(p_{v,{\textsc {r}}}\) since the row and column that represent v in \(M_i\) intersect the four sides of the boundary of \(M_i\). We call such points the top copy, bottom copy, left copy, and right copy of v in \(M_i\), respectively.

A side assignment for \(V_i \in \mathcal {C}\) specifies for each inter-cluster edge whether the edge must attach to the matrix \(M_i\) representing \(V_i\) in its top, left, right, or bottom side. More precisely, a side assignment is a mapping \(\phi _i\): \(\bigcup _{j\ne i}{E_{i,j}} \rightarrow \{\textsc {t}, \textsc {b}, \textsc {l}, \textsc {r}\}\), where \(E_{i,j}\) is the set of inter-cluster edges between the clusters \(V_i\) and \(V_j\) (\(V_i\) and \(V_j\) are adjacent if \(E_{i,j}\ne \emptyset \)). A side assignment for \(\mathcal {C}\) is a set \(\varPhi \) of side assignments for each \(V_i \in \mathcal {C}\).

We denote as \(G=(V,E,\mathcal {C},\varPhi )\) a flat clustered graph \(G=(V,E,\mathcal {C})\) with a given side assignment \(\varPhi =\{\phi _1,\phi _2,\dots , \phi _{|\mathcal {C}|}\}\). Let \(\varGamma \) be a NodeTrix representation of G such that, for every inter-cluster edge \(e=(u,v) \in E\) with \(u \in V_i\) and \(v \in V_j\), the incidence points of e with the matrices \(M_i\) and \(M_j\) representing \(V_i\) and \(V_j\) in \(\varGamma \) are exactly the points \(p_{u,{\phi _i(e)}}\) and \(p_{v,{\phi _j(e)}}\), respectively. We call \(\varGamma \) a NodeTrix representation of G consistent with \(\varPhi \). We say that \(G=(V,E,\mathcal {C},\varPhi )\) is NodeTrix planar if it admits a NodeTrix planar representation consistent with \(\varPhi \).

An inter-cluster edge is heavy if both its end-vertices belong to non-trivial clusters. It is light otherwise. A flat clustered graph is light if every inter-cluster edge is light. A 1-subdivision of a heavy edge \(e=(u,v)\) of a flat clustered graph \(G=(V,E,\mathcal {C})\) replaces e with a path \(u_0=u, u_1, u_2=v\) and defines a new flat clustered graph \(G'=(V',E',\mathcal {C}')\), where \(V' = V \cup \{u_1\}\), \(E' = E/e \cup \{(u_0,u_1),(u_1,u_2)\}\), and \(\mathcal {C}'= \mathcal {C} \cup \{u_1\}\). The light reduction of G is the flat clustered graph \(G'\) obtained by performing a 1-subdivision of every heavy inter-cluster edge of G. A consequence of Theorem 1 in [5] about the edge density of NodeTrix planar graphs, is that the light reduction \(G'\) of a NodeTrix planar flat clustered graph G has O(|V|) vertices and O(|V|) inter-cluster edges.

Property 1

A flat clustered graph G is NodeTrix planar if and only if its light reduction \(G'\) is NodeTrix planar.

Based on Property 1, in the remainder we shall assume that flat clustered graphs are always light and we call them clustered graphs, for short.

The frame of a clustered graph \(G=(V,E,\mathcal {C})\) is the graph F obtained by collapsing each cluster \(V_i \in \mathcal {C}\), with \(|V_i| > 1\), into a single vertex \(c_i\) of F, called the representative vertex of \(V_i\) in F. Let \(c_i\) and \(c_j\) be the two representative vertices of \(V_i\) and \(V_j\) in F, respectively. For every inter-cluster edge connecting a vertex of \(V_i\) to a vertex of \(V_j\) in G there is an edge in F connecting \(c_i\) and \(c_j\). Observe that the frame graph F of G is in general a multigraph; however, F is simple when G is light.

Since the NodeTrix planarity of a clustered graph implies the planarity of its frame graph, we will test NodeTrix planarity only on those clustered graphs that have a planar frame.

A 2-tree is a graph recursively defined as follows: (i) an edge is a 2-tree; (ii) the graph obtained by adding a vertex v to a 2-tree G and by connecting v to two adjacent vertices of G is a 2-tree. A (planar) graph is a partial 2-tree if it is a subgraph of a (planar) 2-tree. A biconnected partial 2-tree is a series-parallel graph. A clustered graph is a partial 2-tree if its frame is a partial 2-tree. We will sometimes talk about series-parallel clustered graphs when their frames are series parallel.

3 NodeTrix Representations and Wheel Reductions

The polynomial-time algorithms described in Sects. 4 and 5 are based on decomposing the planar frame F of a clustered graph \(G=(V,E,\mathcal {C},\varPhi )\) into its biconnected components and storing them into a block-cut-vertex tree. We process each block of F by using an SPQR decomposition tree that is rooted at a reference edge and visited from the leaves to the root. For each visited node \(\mu \) of the decomposition tree of a block of F we test whether the subgraph of G whose frame is the pertinent graph of \(\mu \) satisfies the planar constraints imposed by the side assignment on the inter-cluster edges. A key ingredient to efficiently perform the test at \(\mu \) is the notion of wheel replacement.

Let \(G=(V,E,\mathcal {C},\varPhi )\) be a clustered graph with side assignment \(\varPhi \) and let \(V_i \in \mathcal {C}\) be a cluster with \(k>1\) vertices. \(V_i\) admits k! permutations of its vertices and we associate a suitable graph to each such permutation. Let \(\pi _i = v_0, v_1, \dots , v_{k-1}\) be a permutation of the vertices of \(V_i\). The wheel of \(V_i\) consistent with \(\pi _i\) is the wheel graph consisting of a vertex v of degree 4k adjacent to the vertices of an oriented cycle \(v_{0,\textsc {t}},\) \(v_{1,\textsc {t}},\) \(\dots , v_{k-1,\textsc {t}}\), \(v_{0,\textsc {r}}, v_{1,\textsc {r}}, \dots , v_{k-1,\textsc {r}}\), \(v_{k-1,\textsc {b}}, v_{k-2,\textsc {b}}, \dots , v_{0,\textsc {b}}\), \(v_{k-1,\textsc {l}}, v_{k-2,\textsc {l}}, \dots , v_{0,\textsc {l}}\) where each edge of the cycle is oriented forward. Intuitively, this oriented cycle will be embedded clockwise to encode the constraints induced by a matrix \(M_i\) representing \(V_i\) when its left-to-right order of columns is \(\pi _i\). More precisely, a wheel replacement of cluster \(V_i\) consistent with \(\pi _i\) is the clustered graph obtained as follows: (i) remove \(V_i\) and all the inter-cluster edges incident to \(V_i\); (ii) insert the wheel \(W_i\) of \(V_i\) consistent with \(\pi _i\); and (iii) for each inter-cluster edge \(e=(u,v_j)\), with \(v_j \in V_i\), insert edge \((u,v_{j,\phi _i(e)})\) incident to \(W_i\). We call edge \((u,v_{j,\phi _i(e)})\) the image of edge \(e=(u,v_j)\).

Let \(G=(V,E,\mathcal {C},\varPhi , \varPi )\) be a clustered graph with side assignment \(\varPhi \) where \(\varPi \) is a set of permutations \(\{\pi _1, \pi _2, \dots , \pi _{|\mathcal {C}|}\}\), one for each cluster \(V_i\) (with \(i=1, \dots , |\mathcal {C}|\)). We call \(\varPi \) the permutation assignment of G and we say that G is NodeTrix planar with side assignment \(\varPhi \) and permutation assignment \(\varPi \) if G admits a NodeTrix planar representation with side assignment \(\varPhi \) where for each matrix \(M_i\) the permutation of its columns is \(\pi _i\). The wheel reduction of G consistent with \(\varPi \) is the graph obtained by performing a wheel replacement of \(V_i \in \mathcal {C}\) consistent with \(\pi _i\) for each \(i=1, \dots , |\mathcal {C}|\).

Theorem 1

Let \(G=(V,E,\mathcal {C},\varPhi , \varPi )\) be a clustered graph with side assignment \(\varPhi \) and permutation assignment \(\varPi \). G is NodeTrix planar if and only if the planar wheel reduction of G admits a planar embedding where the external oriented cycle of each wheel \(W_i\) is embedded clockwise.

Figure 1(a) and (b) show respectively a NodeTrix planar representation of a clustered graph G and the corresponding wheel reduction with its planar embedding.

Fig. 1.
figure 1

(a) A NodeTrix planar representation of a clustered graph. (b) The planar embedding of the corresponding wheel reduction. (c) Labeling of the vertices of \(W_{t_{\mu }}\); the complete internal and external sequences are highlighted.

Based on Theorem 1, we can test the graph \(G=(V,E,\mathcal {C},\varPhi )\) for NodeTrix planarity by exploring the space of the possible permutation sets \(\varPi \) and corresponding wheel reductions in search of a NodeTrix planar \(G=(V,E,\mathcal {C},\varPhi ,\varPi )\). Note that, if the maximum size of a cluster is given as a parameter k, every cluster \(V_i\) can be replaced by k! wheel graphs, one for each possible permutation of the vertices of \(V_i\). In order to test planarity, for any such wheel replacement \(W_i\), the cyclic order of the inter-cluster edges incident to the same vertex of \(W_i\) can be arbitrarily permuted. While each wheel reduction yields an instance of constrained planarity testing that can be solved with the linear-time algorithm described in [7], a brute-force approach that repeats this algorithm on each possible wheel reduction may lead to testing planarity on \(|\mathcal {C}|^{k!}\) different instances. Instead, for each visited node \(\mu \) of the decomposition tree T we compute a succinct description of the possible NodeTrix planar representations of the subgraph \(G_\mu \) of G represented by the subtree of T rooted at \(\mu \). This is done by storing for the poles of \(\mu \) those pairs of wheel graphs that are compatible with a NodeTrix planar representation of \(G_\mu \). How to efficiently compute such a succinct description will be the subject of the next sections.

4 Testing NodeTrix Planarity for Partial 2-Trees

In this section we prove that NodeTrix planarity testing with fixed sides can be solved in polynomial time for a clustered graph \(G=(V,E,\mathcal {C},\varPhi )\) when the maximum size of any cluster of \(\mathcal {C}\) is bounded by a constant and the frame graph is a partial 2-tree. This contrasts with the NP-hardness of NodeTrix planarity testing with fixed sides proved in [3] in the case where the size of the clusters is unbounded.

We first study the case of a clustered graph whose frame graph is a series-parallel graph, i.e., it is biconnected and its SPQR decomposition tree only has Q-, P-, and S-nodes. We then consider the case of partial 2-trees, i.e., graphs whose biconnected components are series-parallel.

4.1 Series-Parallel Frame Graphs

In this section we prove that NodeTrix planarity testing with fixed sides can be solved in \(O(k^{3k+\frac{3}{2}}\cdot n^2)\) time for clustered graphs whose frame graphs are series-parallel and have cluster size at most k.

Let \(G=(V,E,\mathcal {C},\varPhi )\) be a series-parallel clustered graph with side assignment \(\varPhi \) and let F be its frame graph. Let T be the SPQ decomposition tree of F rooted at any Q-node. To simplify the description and without loss of generality, we assume that every S-node of T has exactly two children. Let \(\mu \) be a node of T, and let \(s_\mu \), \(t_\mu \) be the poles of \(\mu \). Consider the pertinent graph \(F_\mu \) represented by the subtree of T rooted at \(\mu \) and let \(v_\mu \) be a pole of \(\mu \) (\(v_\mu \in \{s_\mu , t_\mu \}\)). Pole \(v_\mu \) in the frame graph F may correspond to a non-trivial cluster \(V_i\) of \(\mathcal {C}\). In this case, we call \(v_\mu \) a non-trivial pole of \(\mu \) and cluster \(V_i\) the pertinent cluster of \(v_\mu \).

The edges of \(F_\mu \) incident to \(v_\mu \) are the intra-component edges of \(v_\mu \). The other edges of F incident to \(v_\mu \) are the extra-component edges of \(v_\mu \). Each intra-component (extra-component) edge of \(v_\mu \) corresponds to an inter-cluster edge \(e'\) of G incident to one vertex of the pertinent cluster \(V_\mu \) of \(v_\mu \). We call \(e'\) an intra-component edge (extra-component edge) of \(V_\mu \). We associate k! wheel graphs to each non-trivial pole \(v_\mu \) of \(\mu \). Each of them is a wheel replacement of the pertinent cluster of \(v_\mu \), consistent with one of the k! permutations of its vertices.

Let \(v_\mu \) be a non-trivial pole of \(\mu \), let \(V_\mu \) be the pertinent cluster of \(v_\mu \), let \(\pi _\mu \) be a permutation of the vertices of \(V_\mu \), and let \(W_\mu \) be the wheel replacement of \(V_\mu \) consistent with \(\pi _\mu \). Every edge e incident to \(W_\mu \) such that e is the image of an inter-cluster edge \(e'\) of G is labeled either int or ext, depending on whether \(e'\) is an intra-component or an extra-component edge of \(V_\mu \). A vertex w of the external cycle of \(W_\mu \) is assigned one label of the set \(\{\texttt {void}, \texttt {int},\texttt {ext}, \texttt {int-ext}\}\) as follows. Vertex w is labeled void if no edge incident to w is the image of an inter-cluster edge. Vertex w is labeled int (resp. ext) if we have a label int (resp. ext) on every edge e incident to w such that e is the image of an inter-cluster edge. Otherwise, vertex w is labeled int-ext. See Fig. 1(c) for an example concerning the wheel \(W_{t_{\mu }}\) of Fig. 1(b); the dashed curve of Fig. 1(b) shows the subgraph of the wheel reduction corresponding to \(F_{\mu }\).

A clockwise sequence \(v_0, v_1, \dots , v_j\) of vertices of the external cycle of \(W_\mu \) is an external sequence of pole \(v_\mu \) consistent with \(\pi _\mu \) if \(v_0\) and \(v_j\) are labeled either ext or int-ext and all the other vertices of the sequence are labeled either void or ext. An external clockwise sequence of pole \(v_\mu \) is complete if it contains all the vertices of \(W_\mu \) that are labeled ext and int-ext. Note that a complete external sequence may contain many void vertices but no int vertex. Internal and complete internal sequences of pole \(v_\mu \) are defined analogously. Observe that a complete internal sequence and a complete external sequence of \(v_\mu \) may not exist when vertices labeled int and vertices labeled ext alternate more than twice when traversing clockwise the external cycle of \(W_\mu \), or when three vertices are labeled int-ext. A special case is when \(W_\mu \) has exactly two vertices \(w_1\) and \(w_2\) labeled int-ext and all other vertices are void. In this case, the clockwise sequence from \(w_1\) to \(w_2\) and the clockwise sequence from \(w_2\) to \(w_1\) are both complete internal and complete external sequences.

In order to test \(G=(V,E,\mathcal {C},\varPhi )\) for NodeTrix planarity, we implicitly take into account all possible permutation assignments \(\varPi \) by considering, for each non-trivial pole \(w_\mu \) of each node \(\mu \) of T, its k! possible wheels and by computing their complete internal and complete external sequences. We visit the SPQ decomposition tree T from the leaves to the root and equip each node \(\mu \) of T with information regarding the complete internal and complete external sequences of its non-trivial poles. Let \(\mu \) be an internal node of T, let \(v_\mu \) be a non-trivial pole of \(\mu \), let \(\pi _{v_\mu }\) be a permutation of the pertinent cluster \(V_\mu \) of \(v_\mu \), and let \(W_\mu \) be the wheel of \(V_\mu \) consistent with \(\pi _{v_\mu }\). We denote as \(ISeq(\mu , v_{\mu },\pi _{v_\mu })\) the complete internal sequence of \(v_\mu \) consistent with \(\pi _{v_\mu }\) in pole \(\mu \) and as \(ESeq(\mu , v_{\mu },\pi _{v_\mu })\) the complete external sequence of \(v_{\mu }\) consistent with \(\pi _{v_\mu }\) in pole \(\mu \). We distinguish between the different types of nodes of T.

Node \(\mu \) is a Q-node. Since G is light, at most one of its poles is non-trivial. Let e be an edge of F that is the pertinent graph of \(\mu \). One end-vertex of e is the representative vertex in F of the pertinent cluster of the non-trivial pole \(v_\mu \). In fact, edge e corresponds to an edge \(e'=(u,z)\) of G such that \(u \in V_\mu \) and z is a trivial cluster. The side assignment \(\phi _{v_\mu }\) defines whether e is incident to the top, bottom, left, or right copy \(u_W\) of u in the wheel \(W_\mu \) of \(V_\mu \). For any possible permutation \(\pi _{v_\mu }\) we have \(ISeq(\mu , v_\mu ,\pi _{v_\mu })=u_W\). If \(u_W\) is labeled int-ext, then \(ESeq(\mu , v_\mu ,\pi _{v_\mu })\) is the external cycle of \(W_\mu \) starting at \(u_W\) and ending at \(u_W\). Otherwise, traverse the external cycle of \(W_\mu \) starting at \(u_W\) and following the direction of the edges; \(ESeq(\mu , v_\mu ,\pi _{v_\mu })\) consists of all the encountered vertices from the first labeled ext to the last labeled ext.

Node \(\mu \) is a P-node. Let \(\nu _0, \nu _1, \dots , \nu _{h-1}\) be the children of \(\mu \). Observe that \(v_\mu \) is a non-trivial pole also for the children \(\nu _0, \nu _1, \dots , \nu _{h-1}\) of \(\mu \). We consider every permutation \(\pi _{v_\mu }\) such that \(\nu _0, \nu _1, \dots , \nu _{h-1}\) have both a complete internal sequence and a complete external sequence compatible with \(\pi _{v_\mu }\). The complete internal sequence of \(v_\mu \) consistent with \(\pi _{v_\mu }\) is the union of the complete internal sequences of the children \(\nu _0, \nu _1, \dots , \nu _{h-1}\), that is \(ISeq(\mu , v_\mu ,\pi _{v_\mu })= \displaystyle \cup _{i=0}^{h-1} ISeq(\nu _i,v_\mu ,\pi _{v_\mu })\).

To determine the complete external sequence of \(v_\mu \) consistent with \(\pi _{v_\mu }\) we consider the intersection of the complete external sequences of the children of \(\mu \). If this intersection consists of exactly one sequence of consecutive vertices, then \(ESeq(\mu , v_\mu ,\pi _{v_\mu })= \displaystyle \cap _{i=0}^{h-1} ESeq(\nu _i,v_\mu ,\pi _{v_\mu })\). Otherwise (i.e., the intersection is empty or it consists of more than one sequence of consecutive vertices), \(v_\mu \) does not have a complete external sequence consistent with \(\pi _{v_\mu }\).

Node \(\mu \) is an S-node. Let \(\nu \) be the child of \(\mu \) that shares the pole \(v_\mu \) with \(\mu \). We consider every permutation \(\pi _{v_\mu }\) such that \(\nu \) has both \(ISeq(\nu , v_\mu ,\pi _{v_\mu })\) and \(ESeq(\nu , v_\mu ,\pi _{v_\mu })\). The complete internal (external) sequence of \(v_\mu \) consistent with \(\pi _{v_\mu }\) is \(ISeq(\mu , v_\mu ,\pi _{v_\mu })=ISeq(\nu , v_\mu ,\pi _{v_\mu })\) (\(ESeq(\mu , v_\mu ,\pi _{v_\mu })=ESeq(\nu , v_\mu ,\pi _{v_\mu })\)).

To test G for NodeTrix planarity we execute a bottom-up traversal of T and, for each node \(\mu \) with poles \(s_\mu \) and \(t_\mu \), we check whether each possible pair \((\pi _{s_\mu }, \pi _{t_\mu })\) induces complete internal and external sequences for \(s_\mu \) and \(t_\mu \) that are ‘compatible’ with a planar embedding of the wheel reduction of G. If this is the case, by Theorem 1, G is NodeTrix planar, otherwise we reject G.

More formally, let \(\pi _{s_\mu }\) (\(\pi _{t_\mu }\), respectively) be a permutation such that \(s_\mu \) (\(t_\mu \), respectively) has both a complete internal sequence and a complete external sequence compatible with \(\pi _{s_\mu }\) (\(\pi _{t_\mu }\), respectively). We say that \((\pi _{s_\mu }, \pi _{t_\mu })\) is a compatible pair of permutations for \(\mu \) if either one of the poles is a trivial pole or one of the following cases applies.

Node \(\mu \) is a Q-node. In this case all k! possible pairs of permutations for \(s_\mu \) or \(t_\mu \) (recall that only one of them is non-trivial) are compatible for \(\mu \).

Node \(\mu \) is a P-node. Let \(\nu _0, \nu _1, \dots , \nu _{h-1}\) be the children of \(\mu \). Consider a pair of permutations \((\pi _{s_\mu }, \pi _{t_\mu })\); we recall that, for \(i=0,\dots ,h-1\), each \(\nu _i\) has poles \(s_\mu \) and \(t_\mu \). A first condition for pair \((\pi _{s_\mu }, \pi _{t_\mu })\) to be a compatible pair for \(\mu \) is that \((\pi _{s_\mu }, \pi _{t_\mu })\) is also a compatible pair for \(\nu _i\), with \(i=0,\dots ,h-1\). A second condition asks that the pair \((\pi _{s_\mu }, \pi _{t_\mu })\) defines opposite orders on the poles of \(\mu \). Namely, let \(W^s_\mu \) (resp., \(W^t_\mu \)) be the wheel of \(V_{s_\mu }\) (resp., \(V_{t_\mu }\)) consistent with \(\pi _{s_\mu }\) (resp., \(\pi _{t_\mu }\)). Traversing clockwise the external cycle of \(W^s_\mu \) starting from the first vertex of \(ESeq(\mu ,s_\mu ,\pi _{s_\mu })\), let \(ISeq(\nu _0,s_\mu ,\pi _{s_\mu })\), \(ISeq(\nu _1,s_\mu ,\pi _{s_\mu })\), ..., \(ISeq(\nu _{h-1},s_\mu ,\pi _{s_\mu })\) be the order by which the internal sequences are encountered. Pair \((\pi _{s_\mu }, \pi _{t_\mu })\) defines opposite orders on the poles of \(\mu \) if, traversing clockwise the external cycle of \(W^t_\mu \) starting from the first vertex of \(ESeq(\mu ,t_\mu ,\pi _{s_\mu })\), the order by which we encounter the internal sequences of \(\nu _0,\nu _1,\dots , \nu _{h-1}\) is the opposite one, i.e., the order is \(ISeq(\nu _{h-1},t_\mu ,\pi _{t_\mu })\), \(ISeq(\nu _{h-2},t_\mu ,\pi _{t_\mu })\), ..., \(ISeq(\nu _0,t_\mu ,\pi _{t_\mu })\).

Node \(\mu \) is an S-node. Let \(\nu _0\) and \(\nu _1\) be the children of \(\mu \) such that \(s_{\nu _0}=s_\mu \), \(t_{\nu _0}=s_{\nu _1}\), and \(t_{\nu _1}=t_\mu \). A pair \((\pi _{s_\mu }, \pi _{t_\mu })\) is a compatible pair for \(\mu \) if there exists a permutation \(\pi _{t_{\nu _0}}\) such that the pair \((\pi _{s_\mu }, \pi _{t_{\nu _0}})\) is compatible for \(\nu _0\) and the pair \((\pi _{t_{\nu _0}}, \pi _{t_\mu })\) is compatible for \(\nu _1\).

Figure 2 suggests that a NodeTrix planar representation of a clustered graph G defines a permutation assignment \(\varPi \) such that, for every node \(\mu \) of T, pair \((\pi _{s_\mu },\pi _{t_\mu })\) is a compatible pair for \(\mu \).

Fig. 2.
figure 2

(a) A NodeTrix planar representation \(\varGamma \) of \(G=(V,E,\mathcal {C},\varPhi )\). (b) \(\varGamma \) induces a permutation assignment and a planar embedding of a wheel reduction of G; the complete internal and external sequences for a pair of poles are also highlighted.

Lemma 1

Let \(G=(V,E,\mathcal {C},\varPhi )\) be a clustered graph with side assignment \(\varPhi \) and let T be the SPQ decomposition tree of the frame graph of G. Graph G is NodeTrix planar if and only if there exists a permutation assignment \(\varPi \) such that, for every node \(\mu \) of T with poles \(s_\mu \) and \(t_\mu \), we have that permutation \(\pi _{s_\mu } \in \varPi \) and permutation \(\pi _{t_\mu } \in \varPi \) form a compatible pair of permutations for \(\mu \).

Lemma 2

Let \(G=(V,E,\mathcal {C},\varPhi )\) be a series-parallel clustered graph with side assignment \(\varPhi \). Let k be the maximum size of any cluster in \(\mathcal {C}\) and let n be the cardinality of V. There exists an \(O(k^{3k+\frac{3}{2}} \cdot n^2)\)-time algorithm that tests whether G is NodeTrix planar with side assignment \(\varPhi \) and if so, it computes a NodeTrix planar representation of G consistent with \(\varPhi \).

Proof

Let F be the frame graph of G; for any possible choice of an edge e of F we repeat the following procedure. We construct the SPQ decomposition tree of G rooted at the Q-node whose pertinent graph is e. We visit T from the leaves to the root and test whether G has a permutation assignment \(\varPi \) such that \(G=(V,E,\mathcal {C},\varPhi ,\varPi )\) is NodeTrix planar. We first equip each non-trivial pole \(v_\mu \) of every node \(\mu \) of T with its possible complete internal and complete external sequences. The maximum number of complete internal sequences of \(v_\mu \) is k!. The same is true for the complete external sequences. If each complete (internal or external) sequence of pole \(v_\mu \) is encoded by means of its first and last vertex in the clockwise order around \(W_{v_\mu }\), then each complete internal or external sequence needs constant space. It follows that the intersection or the union of two complete internal or external sequences can be computed in constant time. Therefore, all complete internal and external sequences for each non-trivial pole of T can be computed in O(k!) time. Hence, the whole bottom-up traversal to equip all non-trivial poles with every possible complete internal/external sequence can be executed in \(O(k!\cdot n)\) time. We now test whether there exists a permutation assignment \(\varPi \) such that any node \(\mu \) of T has a compatible pair of permutations. To this aim, we look at the complete internal and external sequences for the pair of poles of the children of \(\mu \). For each pair \((\pi _{s_\mu }, \pi _{t_\mu })\) of permutations of the poles of \(\mu \) we equip \(\mu \) with the information about whether such pair is compatible for \(\mu \). This requires \(O(k!^2)\) space. If \(\mu \) is a Q-node, every pair of permutations \((\pi _{s_\mu },\pi _{t_\mu })\) is compatible for \(\mu \). It follows that all compatible pairs for \(\mu \) can be computed in O(k!) time (recall that one between \(s_{\mu }\) and \(t_{\mu }\) is non-trivial) and, hence, in \(O(k! \cdot n)\) time for all the Q-nodes of T. If \(\mu \) is a P-node with children \(\nu _0, \nu _1, \dots , \nu _{h-1}\), \(\pi _{s_\mu }\) is one of the permutations that equip \(s_\mu \), and \(\pi _{t_\mu }\) is one of the permutations that equip \(t_\mu \), testing whether the pair \((\pi _{s_\mu }, \pi _{t_\mu })\) is a compatible pair for \(\mu \) can be executed in O(h) time. It follows that all compatible pairs for \(\mu \) can be computed in \(O(k!^2 \cdot h)\) time and, hence, in \(O(k!^2 \cdot n)\) time for all P-nodes of T. If \(\mu \) is an S-node with children \(\nu _0\) and \(\nu _1\), \(\pi _{s_\mu }\) is one of the permutations that equip \(s_\mu \), and \(\pi _{t_\mu }\) is one of the permutations that equip \(t_\mu \), testing whether the pair \((\pi _{s_\mu }, \pi _{t_\mu })\) is a compatible pair for \(\mu \) can be executed in O(k!) time, corresponding to choosing all possible permutations for the pole shared between \(\nu _0\) and \(\nu _1\). It follows that all compatible pairs for \(\mu \) can be computed in \(O(k!^3)\) time and, hence, in \(O(k!^3 \cdot n)\) time for all S-nodes of T.

In conclusion, the time complexity of a bottom-up visit of T rooted at e is \(O(k!^3 \cdot n)\). By rooting T at all possible Q-nodes, we obtain an overall time complexity of \(O(k!^3 \cdot n^2)\). By Stirling’s approximation, \(k! \sim \sqrt{2\pi k}(\frac{k}{e})^k\) and thus a series-parallel clustered graph G with n vertices, side assignment \(\varPhi \), and maximum cluster size k can be tested for NodeTrix planarity in \(O(k^{3k+\frac{3}{2}} \cdot n^2)\) time. Note that the compatible pair of permutations stored at each node \(\mu \) of T implicitly define a planar embedding of a wheel reduction of G. It can be shown that it is possible to construct a NodeTrix planar representation of G in time proportional to the number of edges of G, which is \(O(n\cdot k)\) [5]. The statement of the lemma follows.   \(\square \)

4.2 Partial 2-Trees

We now consider clustered graphs whose cluster size is at most k and such that their frame graph is a partial 2-tree, i.e. it is a planar graph whose biconnected components are series-parallel. We handle this case by decomposing the frame graph into its blocks and we store them into a block-cut-vertex tree. The following theorem generalizes the result of Lemma 2.

Theorem 2

Let \(G=(V,E,\mathcal {C},\varPhi )\) be a partial 2-tree clustered graph with side assignment \(\varPhi \). Let k be the maximum size of any cluster in \(\mathcal {C}\) and let n be the cardinality of V. There exists an \(O(k^{3k+\frac{3}{2}}\cdot n^3)\)-time algorithm that tests whether G is NodeTrix planar with side assignment \(\varPhi \) and if so, it computes a NodeTrix planar representation of G consistent with \(\varPhi \).

5 General Planar Frame Graphs

In this section we study the problem of extending Theorem 2 to planar frame graphs that may not be partial 2-trees. We prove that NodeTrix planarity testing with fixed sides can be solved in polynomial time for maximum cluster size \(k=2\). However, the problem becomes NP-complete with fixed sides for \(k \ge 3\) and it remains NP-complete even in the free sides scenario for \(k \ge 5\).

Every block of the frame graph can be decomposed into its triconnected components by means of an SPQR decomposition tree. For each block, we adopt the same approach as for series-parallel graphs and look for a permutation assignment \(\varPi \) such that, for every pair of poles \(s_\mu \) and \(t_\mu \), \((\pi _{s_\mu },\pi _{t_\mu })\) forms a compatible pair for \(\mu \) when \(\mu \) is either a Q-node, a P-node, or an S-node. We extend the definition of compatible pairs of permutations for an R-node as follows.

Let \(G=(V,E,\mathcal {C},\varPhi )\) be a clustered graph with side assignment \(\varPhi \), let F be the frame graph of G, and let T be the SPQR decomposition tree of F. Let \(\mu \) be an R-node of T with poles \(s_\mu \) and \(t_\mu \). A pair of permutations \((\pi _{s_\mu },\pi _{t_\mu })\) forms a compatible pair for \(\mu \) if there exists a planar embedding of the skeleton \({{\mathrm{skel}}}(\mu )\) of \(\mu \) for which the following conditions hold: (i) For each vertex v of \({{\mathrm{skel}}}(\mu )\), let \(e_0, e_1, \dots e_{h-1}\) be the virtual edges of \({{\mathrm{skel}}}(\mu )\) incident to v in clockwise order around v. Each such edge \(e_i\) is associated with a child \(\nu _i\) of \(\mu \). There exists a permutation \(\pi _v\) such that the complete internal sequences \(ISeq(\nu _0,v,\pi _v),\) \(ISeq(\nu _1,v,\pi _v), \dots ,\) \(ISeq(\nu _{h-1},v,\pi _v)\) appear in this clockwise order around v. (ii) Every vertex v of \({{\mathrm{skel}}}(\mu )\) can be assigned a permutation \(\pi _v\) such that: \(\pi _v=\pi _{s_\mu }\) if \(v=s_\mu \) and \(\pi _v=\pi _{s_\mu }\) if \(v=t_\mu \), and for each virtual edge \(e=(u,v)\) in \({{\mathrm{skel}}}(\mu )\) that corresponds to a child \(\nu \) of \(\mu \), the permutation pair \((\pi _u,\pi _v)\) is compatible for \(\nu \).

Observe that, in the case of maximum cluster size \(k=2\), the possible permutations of the induced cluster \(V_{v}\) of a vertex v of \({{\mathrm{skel}}}(\mu )\) are exactly two, denoted by \(\pi ^+_{v}\) and \(\pi ^-_{v}\). In order to test whether \((\pi _{s_\mu },\pi _{t_\mu })\) forms a compatible pair for \(\mu \), we perform a traversal of \({{\mathrm{skel}}}(\mu )\) starting at \(s_\mu \). Permutation \(\pi _{s_\mu }\) and the clockwise order of the edges incident to \(s_\mu \) can impose to choose only one of the two permutations \(\pi ^+_w\) o \(\pi ^-_w\) available for each vertex w adjacent to \(s_\mu \) and corresponding to a non-trivial cluster of G. Each such w and its incident edges, in turn, propagate constraints on the possible permutations to their neighbors, till \(t_\mu \) is reached. Therefore, testing whether \(\pi _{s_\mu }\) and \(\pi _{t_\mu }\) form a compatible pair for \(\mu \) can be reduced to a suitable problem of labeling the edges and vertices of \({{\mathrm{skel}}}(\mu )\) and verifying that at the end \(s_\mu \) and \(t_\mu \) are labeled with \(\pi _{t_\mu }\) and \(\pi _{s_\mu }\).

Theorem 3

Let \(G=(V,E,\mathcal {C},\varPhi )\) be an n-vertex clustered graph with side assignment \(\varPhi \) such that the maximum size of any cluster in \(\mathcal {C}\) is two. There exists an \(O(n^3)\)-time algorithm that tests whether G is NodeTrix planar with the given side assignment and if so, computes a NodeTrix planar representation of G consistent with \(\varPhi \).

The proof of the following theorem is based on a reduction from (non-planar) NAE3SAT.

Theorem 4

NodeTrix planarity testing with fixed sides and cluster size at most k is NP-complete for any \(k \ge 3\).

Now, we extend the above hardness result to the free sides model and show that NodeTrix planarity testing remains NP-complete when the maximum cluster dimension is larger than four. This is done by proving that NAE3SAT is NP-complete even for triconnected Boolean formulas, which may be a result of independent interest.

Theorem 5

NAE3SAT is NP-complete for triconnected Boolean formulas.

Theorem 6

NodeTrix planarity testing with free sides and cluster size at most k is NP-complete for any \(k \ge 5\).

6 Open Problems

We conclude the paper by listing some open problems that, in our opinion, are worth investigating. (i) Study the complexity of NodeTrix planarity testing in the free sides scenario for values of k between 2 and 5. (ii) Study families of clustered graphs for which NodeTrix planarity testing is fixed parameter tractable in the free sides scenario. (iii) Determine whether the time complexity of the algorithms in Theorems 2 and 3 can be improved.