1 Introduction

Crossing minimization is an important task for the construction of readable drawings. The problem of minimizing the number of crossings in a given graph is a well-known \(\mathcal {NP} \)-complete problem [8]. A very successful heuristic for minimizing the number of crossings in a topological drawing of a graph G is to start with a spanning planar subgraph H of G and to iteratively insert the remaining edges into a drawing of H. The edge insertion problem for a planar graph G and two vertices \(s,t \in V(G)\) asks to find a drawing \(\varGamma +st\) of \(G+st\) with the minimum number of crossings such that the induced drawing \(\varGamma \) of G is planar. The problem comes with several variants depending on whether the drawing \(\varGamma \) can be chosen arbitrarily or is fixed [9, 10]. In the planar topological case both problems can be solved in linear time. More general problems such as inserting several edges simultaneously [2] or inserting a vertex together with all its incident edges [1] have also been studied.

All these approaches have in common that they focus on topological drawings where edges are represented as arbitrary curves between their endpoints. By contrast, we focus on geometric embeddings, i.e., planar straight-line drawings, and the corresponding rectilinear crossing number. In this scenario we are only aware of a few heuristics that compute straight-line drawings of general graphs [12, 13]. Clearly, if a geometric embedding \(\varGamma \) of the input graph G is provided as part of the input, there is no choice left; we can simply insert the straight-line segment from s to t into the drawing and count the number of crossings it produces. If, however, only the combinatorial embedding is specified, but one may still choose the outer face and choose the vertex positions so that this results in a straight-line drawing with the given combinatorial embedding, then the problem becomes interesting and non-trivial. We call this problem geometric edge insertion.

Contribution and Outline. We show several results on the complexity of geometric edge insertion with a fixed combinatorial embedding. Namely, we give a linear-time algorithm for the case that the maximum degree \(\varDelta \) of G is at most 5 (Sect. 3). For the general case, we give a \((\varDelta -2)\)-approximation that runs in linear time. Moreover, we give an efficient algorithm for testing in special cases whether there exists a way to insert the edge st so that it does not produce more crossings than when we allow to draw it as an arbitrary curve (Sect. 4). Finally, we give a randomized FPT algorithm that tests in \(O(4^k n)\) time whether an edge can be inserted with at most k crossings (Sect. 5).

Fig. 1.
figure 1

(a) The extended dual (red + blue) of the primal graph (grey) and the red vertices corresponding to s and t. (b) Labeling induced by the blue path. (Color figure online)

2 Preliminaries

Let \(G=(V, E)\) be a planar graph with a given combinatorial embedding where only the choice of the outer face is free. Additionally, let s and t be two distinct vertices with \(st \not \in E\). Denote by \(G+st\) the graph G together with the edge st. We want to insert the edge st into the embedded graph G. That is, we seek a straight-line drawing \(\varGamma \) of G (with the given embedding) such that st can be inserted into \(\varGamma \) with a minimum number of crossings. In \(\varGamma \), the edge st starts at s, traverses a set of faces and ends in t. Topologically, this corresponds to a path \(p(\varGamma )\) from s to t in the extended dual \(G^\star _{st}\) of G, i.e., in the dual graph \(G^\star \) plus s and t connected to all vertices of their dual faces; see Fig. 1a. The number of crossings in \(\varGamma +st\) corresponds to the length of the path minus two. However, not all st-paths in \(G^\star _{st}\) are of the form \(p(\varGamma )\) for a straight-line drawing \(\varGamma \) of G.

Fig. 2.
figure 2

Ratio between length of the shortest st path and the length of a shortest consistent st-path. The solid black edges induce a graph of maximum degree 6. Red vertices have label L, blue vertices have label R. (a) The shortest path from s to t in \(G^\star _{st}\) is not consistent. (Color figure online)

A labeling of G is a mapping \(l:V \rightarrow \{L, R\}\) that labels vertices as either left or right. Consider an edge uv of G that is crossed by a path p such that u and v are to the left and to the right of p, respectively. The edge uv is compatible with a labeling l if \(l(u)=L\) and \(l(v) =R\). A path p of \(G^\star _{st}\) and a labeling l of G are compatible if l is compatible with each edge that is crossed by p. A path p is consistent if there is a labeling of G that is compatible with p. Eades et al. [4] show the following result.

Proposition 1

(Eades et al. [4],Theorem 1). An st-path in \(G^\star _{st}\) is of the form \(p(\varGamma )\) if and only if it is consistent, where \(\varGamma \) is a geometric embedding of G.

In order to minimize the number of crossings of \(\varGamma +st\), we look for a consistent st-path of minimum length in \(G^\star _{st}\). Given a path p, it is easy to check whether p is consistent. Figure 2 shows that the ratio between the length of a shortest st-path and the length of a shortest consistent st-path can be arbitrarily large. Thus, our goal is to find short consistent st-paths.

Let \(H=(V', E')\) be a directed acyclic graph. A path \(p = \langle v_1, v_2, \dots , v_k\rangle \) is a directed path if for each \(1 \le i < k\), \(v_iv_{i+1} \in E'\). It is undirected if for each \( 1 \le i < k\), either \(v_iv_{i+1} \in E'\) or \(v_{i+1}v_i \in E'\). We refer to the number |p| of edges of a path as the length of p. Two paths p and \(p'\) are edge-disjoint if they do not share an edge. Two paths p and \(p'\) of an embedded graph are non-crossing if at each common vertex v, the edges of p and \(p'\) incident to v do not alternate in the cyclic order around v in the graph induced by p and \(p'\). We denote by p[uv] the subpath of a path p from u to v.

3 Bounded Degree

The shortest st-path of the graph in Fig. 2a is not consistent. Note that the maximum vertex degree is 6. In this section, we show that every shortest st-path in graphs of bounded degree 3 is consistent, and that in each planar graph with vertex degree at most 5, there is a shortest st-path that is consistent. Finally, we prove that there is a consistent st-path of length \((\varDelta - 2) l \) in a graph with maximum vertex degree \(\varDelta \) and a shortest st-path of length l in \(G^\star _{st}\).

Let p be an st-path in \(G^\star _{st}\) and let \(e^\star \) be an edge of p. An endpoint u of the primal edge e of \(e^\star \) is left of \(e^\star \) if it is locally left of p on e (Fig. 1b). A vertex v of G is left (right) of p if v is left (right) of an edge of p. We now consider a labeling extended by two more labels \(LR, \bot \). We define the labeling \(l_p\) induced by p as follows. Each vertex that is left and right of p gets the label LR. The remaining vertices that are either left or right of p get labels L and R, respectively. Vertices neither left nor right of p get the label \(\bot \). Obviously, there is a labeling l of G compatible with p if and only if \(l_p\) does not use the label LR. The proof of the following lemma can be found in the full verison on arXiv [14].

Theorem 2

Let G be a planar embedded graph of degree at most 3. Then every shortest st-path in \(G^\star _{st}\) is consistent.

Theorem 3

Let G be a planar embedded graph with maximum degree 5. Then there is a shortest st-path in \(G^\star _{st}\) that is consistent.

Fig. 3.
figure 3

Inconsistent path around (a) a degree-4 vertex and (b,c) a degree-5 vertex.

Proof

Let p be a shortest st-path in \(G^\star _{st}\). We call an edge e of p good if the vertices left and right of it do not have label LR in the labeling \(l_p\) induced by p.

If p is not consistent, then let e denote the last edge of p that is not good. Then an endpoint v of the primal edge corresponding to e has label LR. Without loss of generality, we may assume that v lies left of e. Since \(l_p(v) = LR\), there is an edge \(e'\) of p that has v to its right. By the choice of e, it follows that \(e'\) lies before e on p. We now distinguish cases based on the degree of v.

If \(\deg (v) \le 3\), then we find that p enters or leaves a face twice, which contradicts the assumption that it is a shortest st-path.

If \(\deg (v) = 4\), we denote the edges around v in clockwise order as \(e_1,\dots ,e_4\) such that \(e'\) crosses \(e_1\). Moreover, we denote the faces incident to v in clockwise order as \(f_1,\dots ,f_4\) where \(f_1\) is the starting face of \(e'\).

Since no face has two incoming or two outgoing edges of p, it follows that \(e' = f_1f_2\) crosses \(e_1\) and \(e = f_4f_3\) crosses \(e_3\); see Fig. 3a. Let \(p'\) be the path obtained from p by replacing the subpath \(p[f_1,f_4]\) by the edge \(f_1f_4\) that crosses \(e_4\). Since p is a shortest path, it follows that \(f_2=f_4\). By construction, it is \(l_{p'}(v) = L\). Observe that \(p'[f_4,t] = p[f_4,t]\) lies inside the region \(\rho \) bounded by \(p[f_1,f_4]\) and a curve connecting \(f_1\) and \(f_4\) that crosses \(e_4\). The only vertex inside this region whose label changed is v. Therefore, the path \(p'[f_1,t]\) consists of good edges, and we have thus increased the length of the suffix of the shortest path that consists of good edges.

Now assume that \(\deg (v) = 5\). We denote the edges around v as \(e_1,\dots ,e_5\) in clockwise order such that \(e'\) crosses \(e_1\). We further denote the faces incident to v in clockwise order as \(f_1,\dots ,f_5\) such that \(e'\) starts in \(f_1\). Since no face has two incoming or two outgoing edges, it follows that either e crosses \(e_4\) from \(f_5\) to \(f_4\) or e crosses \(e_3\) from \(f_4\) to \(f_3\).

If e crosses \(e_3\), then we consider the path \(p'\) obtained from p by replacing the subpath \(p[f_2,f_3]\) by the edge that crosses \(e_3\); see Fig. 3b. As above, it follows that \(f_2=f_4\) and v is a cutvertex and that \(p'[f_1,t]\) consists of good edges.

If e crosses \(e_4\), then we obtain \(p'\) by replacing \(p[f_1,f_5]\) by the single edge that crosses \(e_5\); see Fig. 3c. As above, we find that \(f_2 = f_5\) and v is a cutvertex and that \(p'[f_1,t]\) consists of good edges.

Thus, in all cases, we increase the length of the suffix of the shortest path consisting of good edges. Eventually, we thus arrive at a shortest path whose edges are all good and that hence is consistent.    \(\square \)

Theorem 4

Let \(G=(V, E)\) a planar embedded graph with maximum vertex-degree \(\varDelta \) and let p be a shortest st-path in \(G^\star _{st}\) with \(s, t \in V\). Then there is a consistent path of length at most \((\varDelta -2) |p|\).

Fig. 4.
figure 4

Inconsistent path around a degree k vertex.

Proof

Let p be an st-path in \(G^\star _{st}\). Assume that p is not consistent. Then there is a shortest prefix \(p_2 = p[s, f_2] = p[s, f_1] \cdot f_1f_2\) of p that is not consistent; refer to Fig. 4. Let v be a vertex incident to the primal edge of \(f_1f_2\) with \(l_{p_2}(v) = LR\). Without loss of generality let \(f_1, f_2, \dots , f_k\) be the faces around v in counterclockwise order, i.e., v lies left of \(f_1f_2\).

Since \(p_2\) is not consistent, there is a second edge of \(p_2\) that crosses a primal edge incident to v. Let e be the last edge of \(p[s, f_1]\) that crosses a primal edge incident to v. Since \(p_2\) is the shortest inconsistent prefix of p, v lies right of e, i.e., \(e = f_{i+1}f_i\) for some i with \( 2 < i \le k - 1\). Moreover, let \(f_j\) be the first vertex in clockwise order from \(f_i\) that lies on the path \(p[f_2, t]\). Note that such a vertex \(f_j\) exists, since at the latest \(f_2\) satisfies the condition.

Let q be the path \(f_i f_{i-1} \cdots f_j\). We obtain a path \(p'\) from p by replacing \(p[f_i, f_j]\) by q, i.e., \(p' = p[s,f_i] \cdot q \cdot p[f_j,t]\). Note that, since \(f_j\) is the first vertex in clockwise order on \(p[f_2, t]\), \(p'\) is a simple path. Since q does not contain the edges \(f_kf_1\) and \(f_1 f_2\), and \(p[f_i,f_j]\) contains at least one edge, the path \(p'\) has length at most \(|p| + (k - 2) - 1\). We claim that the prefix \(p'_j = p'[s,f_j]\) is consistent.

Then, since \(p'[f_j, t]\) is a subpath of \(p[f_2, t]\) and \(p'[s,f_j]\) is consistent, it follows that we have decreased the maximum length of a suffix of the path whose removal results in an inconsistent path. Since this suffix has initially length at most |p|, we inductively find a consistent st-path of length at most \((\varDelta - 2) |p|\).

It remains to prove that \(p'[s, f_j]\) is consistent. Since \(p[s, f_2]\) is the shortest inconsistent prefix of p, the prefix \(p[s, f_1]\) is consistent. Therefore, v is right of \(p[s, f_i] = p'[s, f_i]\). By construction, v is right of q. Thus, we have \(l_{p'_j}(v) = R\). The only vertices w of G with \(l_{p'_j}(w) = LR\) can be neighbors of v, as otherwise \(p[s, f_1]\) would not be consistent.

Consider the region \(\rho \) enclosed by the path \(p[f_i, f_1]\) and \(f_1, f_k, \dots , f_i\) that contains v; refer to Fig. 4. The prefix \(p[s, f_1] = p'[s, f_1]\) lies outside of \(\rho \) and the path q lies entirely in \(\rho \). Moreover, in case that vw is crossed by \(p'[s, f_i]\), w lies outside of \(\rho \). On the other hand, if q crosses an edge vw, then w lies inside \(\rho \). Thus, in both cases we immediately get that \(l_{p'_j}(w) = L\). Therefore, the prefix \(p'[s, f_j]\) is consistent.    \(\square \)

4 Consistent Shortest st-paths

In Sect. 3 we showed that every shortest st-path in the extended dual \(G^\star _{st}\) of a graph G with vertex degree at most 3 is consistent. For every graph of maximum degree 5, there is a shortest st-path \(G^\star _{st}\) that is consistent. On the other hand, Fig. 2 shows that, starting from degree 6, there are graphs whose shortest st-paths are not consistent. In this section we investigate the problem of deciding whether \(G^\star _{st}\) contains a consistent shortest st-path. As a consequence of Proposition 1 this problem is in \(\mathcal {NP} \).

In Lemma 5 we show that finding a consistent st-path p in \(G^\star _{st}\) is closely related to finding two edge-disjoint paths in G. Especially, we are interested in two edge-disjoint paths where the length of one is minimized. Eilam-Tzoreff [5] proved that this problem is in general \(\mathcal {NP} \)-complete. In planar graphs the sum of the length of two vertex-disjoint paths can be minimized efficiently [11]. In general directed graphs the problem is \(\mathcal {NP} \)-hard [7]. Finding two edge-disjoint paths in acyclic directed graphs is \(\mathcal {NP} \)-complete [6].

The closest relative to our problem is certainly the work of Eilam-Tzoreff. In fact their result can be modified to show that it is \(\mathcal {NP} \)-hard to decide whether a graph contains two edge-disjoint st-paths such that one of them is a shortest path. We study this problem in the planar setting with the additional restriction that s and t lie on a common face of the subgraph \(G_{sp}\) of \(G^\star _{st}\) that contains all shortest paths from s to t.

Lemma 5

An st-path p in \(G^\star _{st}\) is consistent if and only if there is an st-path \(p'\) in \(G^\star _{st}\) that is edge-disjoint from p and that does not cross p.

Fig. 5.
figure 5

(a) The green regions are right of p (blue) and the blue left of p. (b) The outer region that is not bounded by maximal subpaths of p and \(p'\). (Color figure online)

Proof

The paths p and \(p'\) define a set of regions in the plane. Since p and \(p'\) are non-crossing, each region is bounded by one maximal subpath of p and one maximal subpath of \(p'\) (Fig. 5). We label each region \(\rho \) with either L or R, depending on whether \(\rho \) lies left or right of the unique maximal subpath of p on its boundary. We define a labeling l of G by giving each vertex v the label of the region \(\rho \) that contains it. We claim that l is compatible with p.

Since p and \(p'\) are edge-disjoint, every primal edge connects vertices of the same or adjacent regions. Moreover, by construction, vertices of adjacent regions have different labels. Thus all vertices left of p have label L and all vertices right of p have label R. That is l is compatible with p, i.e., p is consistent.

Fig. 6.
figure 6

(a) The line g through the segment st induces a path in \(G^\star _{st}\). (b) Modification of the undirected path \(p'\) edge-disjoint from p.

Conversely, assume that p is consistent. By Proposition 1 there is a straight-line drawing of G such that the segment st intersects the same edges as p and in the same order (Fig. 6a). Let g be the line that contains the segment st. Each edge of G intersects g at most once. Thus, the complement of st in g defines a path from s to t in \(G^\star _{st}\) that is edge-disjoint from p and does not cross p.    \(\square \)

Thus, we now consider the problem of finding a consistent shortest st-path as an edge-disjoint path problem in \(G^\star _{st}\). Our proof strategy consists of three steps. Step (1) We first show that the problem is equivalent to finding two edge-disjoint paths p and q in a directed graph \(\overrightarrow{G}_{{st}}\) such that p is directed and q is undirected. Step (2) We modify \(\overrightarrow{G}_{{st}}\) such that p is a path in a specific subgraph \(G_{sp}\) and q lies in the subgraph \(\overline{G_{sp}}\). These two graphs may share an edge set \(\hat{E}\) such that each edge in \(\hat{E}\) can be an edge of p or of q. Moreover, we find pairs of edges e and \(e'\) in \(\hat{E}\) such that the path p in \(G_{sp}\) (the path q in \(\overline{G_{sp}}\)) contains either e or \(e'\). Step (3) Finally, we use these properties to reduce our problem to 2-SAT.

We begin with Step 1. A directed graph \(\overrightarrow{G}_{{st}}=(V' \cup \{s, t\}, E')\) is st-friendly if \(G^\star _{st}\) contains a consistent shortest st-path if and only if \(\overrightarrow{G}_{{st}}\) contains a directed st-path p and an undirected st-path \(p'\) that is edge-disjoint from p and does not cross p. We obtain an st-friendly graph \(\overrightarrow{G}_{{st}}= (\overrightarrow{V}, \overrightarrow{E})\) from \(G^\star _{st}\) as follows. Denote by \(G_{sp}\) the directed acyclic graph that contains all shortest paths from s to t in \(G^\star _{st}=(V, E)\). If an edge \(uv \in E\) is an edge of \(G_{sp}\), we add it to \(\overrightarrow{G}_{{st}}\). For all remaining edges uv, we add a subdivision vertex x to \(\overrightarrow{G}_{{st}}\) and add the directed edges xuxv to \(\overrightarrow{G}_{{st}}\) in this direction. We claim that \(\overrightarrow{G}_{{st}}\) is st-friendly.

Let p be a consistent shortest st-path in \(G^\star _{st}\). By Lemma 5 there is a path \(p'\) in \(G^\star _{st}\) that is edge-disjoint from p and does not cross p. By construction p corresponds to a directed path in \(G_{sp}\) and p corresponds to an undirected path in \(\overrightarrow{G}_{{st}}\). Conversely, due to the directions of the edges xvxu, every directed st-path q in \(\overrightarrow{G}_{{st}}\) is a directed path in \(G_{sp}\), and therefore it is a shortest st-path in \(G^\star _{st}\). If there is an undirected path \(q'\) that is edge-disjoint from q and does not cross q, we obtain a path \(p'\) from \(q'\) by contracting edges incident to split vertices x. Hence, \(\overrightarrow{G}_{{st}}\) is st-friendly.

We consider the following special case, where s and t lie on a common face o of the subgraph \(G_{sp}\) of \(\overrightarrow{G}_{{st}}\). Without loss of generality, let o be the outer face of \(G_{sp}\) and let t lie on the outer face of \(\overrightarrow{G}_{{st}}\). We denote by \(p_{\mu }\) and \(p_{\lambda }\) the upper and lower st-path of \(G_{sp}\) on the boundary of o. A vertex v of \(G_{sp}\) is an interior vertex if v does not lie on o. An edge uv of \(G_{sp}\) is an interior edge if u and v are interior vertices. An edge e of \(G_{sp}\) is a chord if both its endpoints lie on o but e is not an edge on the boundary of o.

Lemma 6

For a directed st-path p and an undirected st-path \(p'\), that are edge-disjoint and non-crossing, there is an undirected st-path \(p''\) that is edge-disjoint from p, does not cross p, and that does not use interior vertices of \(G_{sp}\).

Proof

Since p and \(p'\) are non-crossing, there are two distinct vertices uv on \(p_{\lambda }\) or on \(p_{\mu }\), say \(p_{\mu }\), such that the inner vertices of \(p'[u,v]\) lie in the interior of \(G_{sp}\); refer to Fig. 6b. Moreover, since \(p'\) and p are non-crossing, the region enclosed by \(p'[u,v]\) and \(p_{\mu }[u,v]\) does not contain a vertex of p in its interior. Therefore, we obtain \(p''\) by iteratively replacing pieces in the form of \(p'[u,v]\) by \(p_{\mu }[u,v]\).    \(\square \)

Fig. 7.
figure 7

(a) The red directed path can be circumvented with the blue directed path via vertex v. (b) The red path consists of avoidable edges. (Color figure online)

This finishes Step 1, and we continue with Step 2. In the following, we iteratively simplify the structure of \(G_{sp}\) while preserving st-friendliness of \(\overrightarrow{G}_{{st}}\). Due to Lemma 6, the graph \(G_{sp}/e\), obtained from contracting an edge e of \(G_{sp}\), is st-friendly, if e is an interior edge. This may generate a separating triangle xyz. Let v be a vertex in the interior of xyz and let p be a directed st-path that contains v. Then, p contains at least two vertices of xyz. Hence, p can be rerouted using an edge of xyz. Thus, the graph after removing all vertices in the interior of xyz is st-friendly. After contracting all interior edges of \(G_{sp}\), each neighbor of an interior vertex of \(G_{sp}\) lies either on \(p_{\lambda }\) or on \(p_{\mu }\). The remaining edges are edges on \(p_{\lambda }\cup p_{\mu }\) and chords.

Consider three vertices xyz that lie in this order on \(p_{\lambda }\) (\(p_{\mu })\) and two interior vertices v and \(v'\), with \(xv, v'y, vz \in \overrightarrow{E}\); refer to Fig. 7a. Note that v and \(v'\) can coincide. Then, every directed st-path p that contains y also contains x and z. Hence, p can be rerouted through the edges xvvz and as a consequence of Lemma 6, the graph \(G_{sp}-v'y\) is st-friendly. Analogously, if \(G_{sp}\) contains the edge \(yv'\), \(G_{sp}-yv'\) remains st-friendly. We call such edges circumventable.

We refer to edges of a subpath \(p_{\lambda }[x, z]\) (\(p_{\mu }[x,z]\)) as avoidable if there exists an interior vertex v with \(xv, vz \in \overrightarrow{E}\) (Fig. 7b). If there exists a directed path p that uses an avoidable edge ab it can be rerouted by replacing the corresponding path \(p_{\lambda }[x,z]\) with the edges xvvz. Thus, we can split the edge ab with a vertex c and we direct the resulting edges from c towards a and b, respectively, and remove the edge ab from \(\overrightarrow{G}_{{st}}\). Finally, we iteratively contract edges incident to vertices with in- and out-degree 1, and we iteratively remove vertices of degree at most 1, except for s and t. Since all interior edges of \(G_{sp}\) are contracted, circumventable interior edges are removed and avoidable edges are replaced, each 2-edge connected component of \(G_{sp}\) is an outerplanar graph whose weak dual (excluding the outer face) is a path; compare Fig. 8a. Each face f of \(G_{sp}\), with \(f\not =o\), contains at least one edge \(e_\lambda \) of \(p_{\lambda }\) and one edge \(e_\mu \) on \(p_{\mu }\). Moreover, every directed st-path contains either \(e_\lambda \) or \(e_\mu \). We refer to the edge sets \(E_{f,\lambda } = E(f) \cap E(p_{\lambda })\) and \(E_{f, \mu } = E(f) \cap E(p_{\mu })\) as interior partners.

Fig. 8.
figure 8

(a) Interior partners decoded by color of 2-edge connected component of \(G_{sp}\). (b) Split a vertex x on the boundary of \(H^\star _{st}\).

Property 7

Choosing a directed st-path in \(G_{sp}\) is equivalent to choosing for each face f of \(G_{sp}\) one of the interior partners \(E_{f,\mu }\) or \(E_{f,\lambda }\) such that the following condition holds. Let \(f_1, f_2\) be two adjacent faces that are separated by a chord e that ends at \(p_{\lambda }\) (\(p_{\mu }\)) such that \(f_1\) is right of e (left of e), then the choice of \(E_{f_2, \mu }\) (\(E_{f_2, \lambda }\)) implies the choice of \(E_{f_1, \mu }\) (\(E_{f_1, \lambda }\)).

In the following, we modify the exterior of \(\overrightarrow{G}_{{st}}\), i.e., \(\overline{G_{sp}}= \overrightarrow{G}_{{st}}- E(G_{sp})\), with the aim to obtain an analog property for the choice of the undirected path. We refer to edges of \(\overline{G_{sp}}\) as exterior edges. A vertex in \(V(\overline{G_{sp}}) \setminus V(G_{sp})\) is an exterior vertex.

Since the undirected path is not allowed to cross the directed path, we split each cut vertex x into an upper copy \(x_\mu \) and a lower copy \(x_\lambda \). We reconnect edges of \(p_{\lambda }\) and \(p_{\mu }\) incident to x to \(x_\lambda \) and \(x_\mu \), respectively. Exterior edges incident to x that are embedded to the right of \(p_{\lambda }\) are reconnected to \(x_\lambda \). Likewise, edges embedded to the left of \(p_{\mu }\) are reconnected to \(x_\mu \). Note that this operation duplicates bridges of \(G_{sp}\). Thus, we forbid the undirected path to traverse these duplicates. Observe that after this operation the outer face o of \(G_{sp}\) is bounded by a simple cycle.

Let x be a vertex on o that is incident to an exterior edge. In this case, we insert a vertex y to \(\overrightarrow{G}_{{st}}\) and we remove each exterior edge ux from \(\overrightarrow{G}_{{st}}\) and insert as a replacement edges yx and yu; see Fig. 8b. We refer to the edge yx as a barrier. Since the barrier yx is directed from y to x, the modification preserves the st-friendliness of \(\overrightarrow{G}_{{st}}\). We now exhaustively contract exterior edges that are not barrier edges, and remove vertices in the interior of separating triangles.

Fig. 9.
figure 9

(a) If the undirected path contains z, it can be rerouted to use vertex v. (b) The color coding of the faces indicate the exterior partners.

Recall that s and t lie on a common face o of the subgraph \(G_{sp}\) of \(\overrightarrow{G}_{{st}}\) and t lies on the outer face of \(G_{sp}\). Let v be an exterior vertex such that its neighbor x comes before its neighbor y on \(p_i, i = \lambda , \mu \), refer to Fig. 9a. Let z be a vertex between x and y on \(p_i\) that is connected to a vertex \(v'\) such that the edge \(v'z\) (\(zv'\)) lies in the interior of the region bounded by yvx and \(p_i[x,y]\). Consider a directed st-path p in \(G_{sp}\) and an undirected st-path \(p'\) in \(\overrightarrow{G}_{{st}}\) that is edge-disjoint from p, that does not cross p and that contains \(v'\). Due to Lemma 6 we can assume, that \(p'\) does not contain an interior vertex of \(G_{sp}\). Thus, it contains x and y. We obtain a new path \(p''\) by replacing the subpath \(p'[x,y]\) by vxvy. Since vxvy are exterior edges, \(p''\) and p are edge-disjoint and non-crossing. Thus, the graph \(\overrightarrow{G}_{{st}}-v'z\) (\(\overrightarrow{G}_{{st}}- zv'\)) is st-friendly. After removing all such edges, for any two neighbors x and y of an exterior vertex v, the paths o[xy] and o[yx] each contains either s and t. Hence, the region bounded by yvx and o[xy] contains a second exterior vertex \(v'\) if and only if o[xy] contains either s or t.

Hence, the dual of \(\overline{G_{sp}}\), with the dual vertex of o removed, is a caterpillar C, refer to Fig. 9b. In case that s or t is incident to an exterior vertex v, we can assume that the undirected path \(p'\) contains the edge sv (vt). Thus, for simplicity, we now assume that neither s nor t is connected to an exterior vertex. Let a and b be the vertices in C whose primal faces are incident to s and t, respectively. Then every undirected st-path in \(\overline{G_{sp}}\) from s to t traverses the primal faces of the simple path q from a to b in C. Let f be a primal face of a vertex on q. Since we inserted the barrier edges to \(\overrightarrow{G}_{{st}}\), every face contains at least one edge \(e_\lambda \) of \(p_{\lambda }\) and one edge \(e_\mu \) of \(p_{\mu }\). Therefore, every undirected st-path in \(\overline{G_{sp}}\) either contains \(e_\lambda \) or \(e_\mu \). We refer to the sets \(E_{f,\lambda } = E(f) \cap E(p_{\lambda })\) and \(E_{f,\mu } = E(f) \cap E(p_{\mu })\) as exterior partners.

Property 8

Choosing an undirected st-path in \(\overline{G_{sp}}\) is equivalent to choosing for each face \(f \not = o\) of \(\overline{G_{sp}}\) one of the exterior partners \(E_{f,\lambda }\) or \(E_{f, \mu }\).

This finishes Step 2, and we proceed to Step 3. The problem of finding a directed st-path p and an undirected st-path \(p'\) in \(\overrightarrow{G}_{{st}}\) reduces to a 2-SAT instance as follows. For each exterior and interior partner we introduce variables \(x_f\) and \(x_g\), respectively, where f and g correspond to the faces of the partners. If \(x_f\) is true, \(p'\) contains the edge of \(E_{f, \lambda }\), otherwise it contains \(E_{f,\mu }\). The conditions on the choice of p in Property 7 can be formulated as implications. Let \(E_{f, \mu }\) an \(E_{f, \lambda }\) be exterior partners and let \(E_{g, \mu }\) and \(E_{g,\lambda }\) be interior partners. In case that \(E_{f,\lambda } \cap E_{g,\lambda } \not =\emptyset \), either p can contain edges of \(E_{g,\lambda }\) or \(p'\) can contains edges of \(E_{f,\lambda }\) but not both. Thus, \(x_f\) and \(x_g\) are not allowed to be true at the same time, i.e., \(x_f = \overline{x_g}\). Hence, we have the following Theorem.

Theorem 9

If s and t lie on a common face of \(G_{sp}\), it is decidable in polynomial time whether \(\overrightarrow{G}_{{st}}\) has a directed st-path and an undirected st-path that are edge-disjoint and non-crossing.

Corollary 10

If s and t lie on a common face of \(G_{sp}\), it is decidable in polynomial time whether \(G^\star _{st}\) contains a consistent shortest st-path.

5 Parametrized Complexity of Short Consistent st-Paths

In this section we show that edge insertion can be solved in FPT time with respect to the minimum number of crossings of a straight-line drawing of \(G+st\) where G is drawn without crossings and has the specified embedding. Let l be an arbitrary labeling of G. Observe that l defines a directed subgraph of \(G^\star _{st}\) by removing each edge whose dual edge has endpoints with the same label and by directing all other edges e such that the endpoint of its primal edge left of e has label L and its other endpoint has label R. We denote this graph by \(G^\star _{st}(l)\). Obviously, a shortest st-path in \(G^\star _{st}(l)\) is compatible with l, and thus a corresponding drawing exists. Clearly, given the labeling l a shortest st-path in \(G^\star _{st}(l)\) can be computed in linear time by a BFS.

Now assume that the length of a shortest consistent path in \(G^\star _{st}\) is k. We propose a randomized FPT algorithm with running time \(O(4^k n)\) for finding a shortest consistent path in \(G^\star _{st}\), based on the color-coding technique [3].

The algorithm works as follows. First, we pick a random labeling of G by labeling each vertex independently with L or R with probability 1 / 2. We then compute a shortest path in \(G^\star _{st}(l)\). We repeat this process \(4^k\) times and report the shortest path found in all iterations.

Clearly the running time is \(O(4^k n)\). Moreover, each reported path is consistent, and therefore the algorithm outputs only consistent paths. It remains to show that the algorithm finds a path of length k with constant probability.

Consider a single iteration of the procedure. If the random labeling l is compatible with p, then the algorithm finds a path of length k. Therefore the probability that our algorithm finds a consistent path of length k is at least as high as the probability that p is compatible with the random labeling l. Let \(V_L,V_R \subseteq V\) denote the vertices of V that are left and right of p, respectively. Clearly it is \(|V_L|,|V_R| \le k\). A random labeling l is consistent with p if it labels all vertices in \(V_L\) with L and all vertices in \(V_R\) with R. Since vertices are labeled independently with probability 1 / 2, it follows that \(\Pr [ p\) is consistent with \(l] = (1/2)^{|V_L|} \cdot (1/2)^{|V_R|} \ge (1/2)^{2k} = (1/4)^k\).

Therefore, the probability that no path of length k is found in \(4^k\) iterations is at most \((1-(1/4)^{k})^{4^k}\), which is monotonically increasing and tends to \(1/e \approx 0.368\). Thus the algorithm succeeds with a probability of \(1-1/e \approx 0.632\). The success probability can be increased arbitrarily to \(1-\delta \), \(\delta > 0\) by repeating the algorithm \(\log (1/\delta )\) times. The probability that each iteration fails is then bounded from above by \((1/e)^{\log 1/\delta } = 1/e^{\log {1/\delta }} = \delta \). E.g., to reach a success probability of \(99\%\), it suffices to do \(\log 100 \le 5\) repetitions. The algorithm can be derandomized with standard techniques [3].

Theorem 11

There is a randomized algorithm \(\mathcal A\) that computes a consistent path of length k if one exists with a success probability of \(1-\delta \). The running time of \(\mathcal A\) is \(O(\log (\delta ^{-1}) 4^k n)\).

6 Conclusion

We have shown that the problem of finding a short consistent st-paths in \(G^\star _{st}\) is tractable in special cases and fixed-parameter tractable in general. Whether \(G^\star _{st}\) has a short consistent st-path is equivalent to the question of whether \(G^\star _{st}\) has two edge-disjoint and non-crossing st-paths, where the length of one path is minimized. Surprisingly, this is related to yet another purely graph theoretic problem: does a directed graph G have two edge-disjoint paths where one is directed and the other is only undirected? By the result of Eilam-Tzoreff [5] the former problem is in general \(\mathcal {NP} \)-hard. For planar graphs the computational complexity of these problems remains an intriguing open question.

In this paper, we only considered planar graphs with a fixed combinatorial embedding. Allowing for arbitrary embeddings opens new perspectives on the problem and is interesting future work.