The complexity of WRP on bounded-treewidth graphs is of particular interest: while vertex-disjoint paths and cycles problems are often polynomial-time solvable on bounded treewidth graphs (e.g., vertex disjoint paths [55], vertex coloring, Hamiltonian cycles [7], Traveling Salesman [13], see also the works by Bodlaender [11] and Fellows et al. [28]) many edge-disjoint problem variants are \({\mathsf {NP}}\)-hard (e.g., edge-disjoint paths [50], edge coloring [48]). Moreover, the usual line graph construction approaches to transform vertex-disjoint to edge-disjoint problems are not applicable as such transformations do not preserve bounded treewidth.
Against this backdrop, we show that indeed shortest routes through arbitrary waypoints can be computed in polynomial-time for bounded treewidth graphs.
Theorem 1
WRP can be solved in a runtime of \(n^{O(\texttt {tw}^2)}\)for n-vertex graphs of treewidth \(\texttt {tw}\).
In other words, WRP is in the complexity class XP [18, 20] w.r.t. treewidth. We obtain:
Corollary 1
WRP can be solved in a polynomial runtime for graphs of bounded treewidth \(\texttt {tw}= O(1)\).
Overview We describe our algorithm in terms of a nice tree decomposition, see Kloks [41, Def. 13.1.4] (Sect. 2.1). We transform the edge-capacitated problem into an edge-disjoint problem (with unit edge capacities Sect. 2.2), leveraging a simple observation on the structure of waypoint walks and preserving distances. We show that this transformation changes the treewidth by at most an additive constant. We then define the separator signatures (Sect. 2.3) and describe how to inductively generate valid signatures in a bottom up manner on the nice tree decomposition, applying the forget, join and introduce operations, as performed, e.g., by Kloks [41, Def. 13.1.5] (Sect. 2.4).
The correctness of our approach relies on a crucial observation on the underlying Eulerian properties of WRP in Lemma 2, allowing us to bound the number of partial walks we need to consider at the separator, see Fig. 3 for an example. Finally in Sect. 2.5, we bring together the different bits and pieces, and sketch how to dynamically program [10] the shortest waypoint walk on the rooted separator tree.
Treewidth Preliminaries
A tree decomposition\({{\mathcal{T}}}=(T,{{\mathcal{X}}})\) of a graph G consists of a bijection between a tree T and a collection \({{\mathcal{X}}}\), where every element of \({{\mathcal{X}}}\) is a set of vertices of G such that: (1) each graph vertex is contained in at least one tree node (the bag or separator), (2) the tree nodes containing a vertex v form a connected subtree of T, and (3) vertices are adjacent in the graph only when the corresponding subtrees have a node in common.
The width of \({{\mathcal{T}}}=(T,{{\mathcal{X}}})\) is the size of the largest set in \({{\mathcal{X}}}\) minus 1, with the treewidth of G being the minimum width of all possible tree decompositions.
A nice tree decomposition is a tree decomposition such that: (1) it is rooted at some vertex r, (2) leaf nodes are mapped to bags of size 1, and (3) inner nodes are of one of three types: forget (a vertex leaves the bag in the parent node), join (two bags defined over the same vertices are merged) and introduce (a vertex is added to the bag in the parent node). The tree can be iteratively constructed by applying simple forget, join and introduce types.
Let \({X_b}\in {{\mathcal{X}}}\) be a bag of the decomposition corresponding to a node \({b\in V(T)}\). We note that even though the node \({b}\) and the bag \({X_b}\) are different, there is a trade-off between readability and formality when differentiating between both. When it is clear from the context, we will slightly abuse notation, e.g., denoting the size of a bag \({X_b}\) by \({|{b}|}\), instead of \(|{X_b}|\). We further denote by \(T_{b}\) the maximal subtree of T which is rooted at bag \({X_b}\). By \(G[{b}]\) we denote the subgraph of G induced on the vertices in the bag \({X_b}\) and by \(G[T_{{b}}]\) we denote the subgraph of G which is induced on vertices in all bags in \(V(T_{b})\). We will henceforth assume that a nice tree decomposition \({{\mathcal{T}}}=(T,{{\mathcal{X}}})\) of G is given, covering its computation in the final steps of the proof of Theorem 1.
Unified Graphs
We begin by transforming our graphs into graphs of unit edge capacity, preserving distances and approximately preserving treewidth.
Definition 1
(Unification) Let G be an arbitrary, edge-capacitated graph. The unified graph \(G^u\) of G is obtained from G by the following operations on each edge \(e\in E(G)\): We replace e by c(e) parallel edges \(e_1,\ldots ,e_{c(e)}\), subdivide each resulting parallel edge by creating vertices \(v_i^e,i\in [c(e)]\)), and set the weight of each subdivided edge to w(e)/2 (i.e., the total weight is preserved). We set all edge capacities in the unified graph to 1. Similarly, given the original problem instance I of WRP, the unified instance \(I^u\) is obtained by replacing the graph G in I with the graph \(G^u\) in \(I^u\), without changing the waypoints, the source and the destination.
It follows directly from the construction that I and \(I^u\) are equivalent with regards to the contained walks. Moreover, as we will see, the unification process approximately preserves the treewidth. Thus, in the following, we will focus on \(G^u\) and \(I^u\) only, and implictly assume that G and I are unified. Before we proceed further, however, let us introduce some more definitions. Using Remark I, w.l.o.g., we can focus on graphs where for all \(e\in E\), \(c(e)\le 2\). The treewidth of G and \(G^u\) are preserved up to an additive constant.
Lemma 1
Let Gbe an edge-capacitated graph s.t. each edge has capacity at most 2 and let \(\texttt {tw}\)be the treewidth of G. Then \(G^u\) has treewidth at most \(\texttt {tw}+1\).
Proof
Let \({{\mathcal{T}}}=(T,{{\mathcal{X}}})\) be an optimal tree decomposition of G of width \(\texttt {tw}\). Let \({X_b}\) be an arbitrary bag of \({{\mathcal{T}}}\). We construct the tree decomposition \({{\mathcal{T}}}^u\) of \(G^u\) based on \({{\mathcal{T}}}\) as follows. First set \({{\mathcal{T}}}^u={{\mathcal{T}}}\). For every edge e of capacity 2 in G, which has its endpoints in \({X_b}\), we create 2 bags \(X_{b}^i\) (\(i\in \{1,2\}\)) and set \(X_{b}^i=X_{b}\cup v_i^e, i\in \{1,2\}\). Connect all bags \(X_{b}^i\) to \(X_{b}\) (i.e., \(X_{b}^i\)s are new children of \(X_{b}\)), creating a tree decomposition \({{\mathcal{T}}}^u\) of width \(\le \texttt {tw}+1\) of G. \(\square\)
Leveraging Eulerian Properties A key insight is that we can leverage the Eulerian properties implied by a waypoint route. In particular, we show that the traversal of a single Eulerian walk (e.g., along an optimal solution of WRP) can be arranged s.t. it does not traverse a specified separator too often, for which we will later choose the root of the nice tree decomposition.
Lemma 2
(Eulerian Separation)Let Gbe an Eulerian graph. Let \(S\)be an (A, B)separator of order \(|S|\)in G. Then there is a set of \(\ell \le 2|S|\)pairwise edge-disjoint walks\({{\mathcal{W}}}=\{W_1,\ldots ,W_\ell \}\)of Gsuch that
- (1)
For every \(W\in {{\mathcal {W}}}\), Whas both of its endpoints in \(A\cap B\).
- (2)
Every walk \(W\in {{\mathcal {W}}}\)is entirely either in G[A](as \({{\mathcal {W}}}_A\)) or in G[B](as \({{\mathcal {W}}}_B\)).
- (3)
Let \(\beta _A\)be the size of the set of vertices used by \({{\mathcal {W}}}_A\)as an endpoint in \(S\). Then,\({{\mathcal {W}}}_A\)contains at most \(\beta _A\)walks. Analogously, for\(\beta _B\) and \({{\mathcal {W}}}_B\).
- (4)
There is an Eulerian walk Wof Gsuch that:\(W:=W_1\oplus \ldots \oplus W_\ell\).
Proof
We know that G[A] and G[B] share the edges in \(G[S]\). For this proof, we arbitrarily distribute the edges in \(G[S]\), resulting in edge-disjoint \(G_A^{\prime}\) and \(G_B^{\prime}\), and respectively \(V(G_A^{\prime})=A\) and \(V(G_B^{\prime})=B\). As only the vertices in \(S\) can have odd degree in \(G_A^{\prime}\), we can cover the edges of \(G_A^{\prime}\) with open walks, starting and ending in different vertices in \(S\), and closed walks, not necessarily containing vertices of \(S\). If a vertex in \(S\) is the start/end of two different walks, we concatenate these walks into one, repeating this process until for all vertices \(v\in S\) the following holds: At most one walk starts or ends at v. Next, we recursively join all closed walks into another walk, with which they share some vertex, see also the work by Fleischner [30].
As every vertex in \(G_A^{\prime}\) has a path to a vertex in \(S\), we have covered all edges in \(G_A^{\prime}\) with \(\alpha _{A^{\prime}}\) (possibly closed) walks \({{\mathcal {W}}}_{A^{\prime}}\), with \(\alpha _{A^{\prime}} \le \beta _{A^{\prime}} \le |S|\). However, all remaining closed walks end in the separator and are pairwise vertex-disjoint from all other (possibly, closed) walks. We perform the same for \(G_B^{\prime}\) and obtain an analogous \({{\mathcal {W}}}_{B^{\prime}}\) with \(\alpha _{B^{\prime}} \le \beta _{B^{\prime}} \le |S|\) walks. Let us inspect the properties of the union of \({{\mathcal {W}}}_{A^{\prime}}\) and \({{\mathcal {W}}}_{B^{\prime}}\):
All walks have their endpoints in \(A \cap B\), respecting (1).
All walks are entirely in \(G[A^{\prime}]\subseteq G[A]\) or in \(G[B^{\prime}]\subseteq G[B]\), respecting (2).
At each \(v \in S\), at most one walk each from \({{\mathcal {W}}}_{A^{\prime}}\) and \({{\mathcal {W}}}_{B^{\prime}}\) has its endpoint, respecting (3).
There is no certificate yet that the walks respect (4).
As thus, we will now alter \({{\mathcal {W}}}_{A^{\prime}}\) and \({{\mathcal {W}}}_{B^{\prime}}\) such that their union respects (4).
W.l.o.g., we start in any walk W in \({{\mathcal {W}}}_{A^{\prime}}\) to create a set of closed walks \({{\mathcal {W}}}_{C^{\prime}}\). We traverse the walk W from some endpoint vertex \(v^{\prime} \in S\) until we reach its other endpoint \(v \in S\), possibly \(v^{\prime}=v\). As there cannot be any other walks in \({{\mathcal {W}}}_{A^{\prime}}\) with endpoints at v, and v has even degree, there are three options:
First, if W is a closed walk and \(E(W)=E(G)\), we are done. Second, if W is a closed walk and \(E(W) \ne E(G)\), it does not share any vertex with another walk in \({{\mathcal {W}}}_{A^{\prime}}\). Hence, there must be a walk or walks in \({{\mathcal {W}}}_{B^{\prime}}\) containing v. As v has even degree, we have two options: There could be a closed walk \(W^{\prime}\) in \({{\mathcal {W}}}_{B^{\prime}}\) containing v. Then, we set both endpoints of \(W^{\prime}\) to v, and as \(W^{\prime}\) does not share a vertex with any other walk in \({{\mathcal {W}}}_{B^{\prime}}\), we are done. Else, there is an open walk \(W^{\prime}\) which just traverses v, not having v as an endpoint. We then split \(W^{\prime}\) into two open walks at v, increasing \(\alpha _B\) and \(\beta _B\) by one.
Third, if W is an open walk, there must be an open walk in \({{\mathcal {W}}}_{B^{\prime}}\) whose start- or endpoint is v. We iteratively perform these traversals, switching between \({{\mathcal {W}}}_{A^{\prime}}\) and \({{\mathcal {W}}}_{B^{\prime}}\) eventually ending at v again in a closed walk, with every walk having an endpoint in v being traversed.
We now repeat this closed walk generation, each time starting at some not yet covered walk. Call this set of closed walks \({{\mathcal {W}}}_{C^{\prime}}\). If \({{\mathcal {W}}}_{C^{\prime}}\) contains only one closed walk, we found a traversal order of the walks in \({{\mathcal {W}}}_{A^{\prime}}\) and \({{\mathcal {W}}}_{B^{\prime}}\) that yields an Eulerian walk, respecting 4), finishing the argument for that case. Else, as the graph is connected, there must be two edge-disjoint walks \(W_{C_1}, W_{C_2} \in {{\mathcal {W}}}_{C^{\prime}}\) that share a vertex u, w.l.o.g., in \(G[A^{\prime}]\), with \(u \in W_{A_1} \in {{\mathcal {W}}}_{A^{\prime}}\), \(W_{A_1}\) being part of \(W_{C_1}\), and \(u \in W_{A_2} \in {{\mathcal {W}}}_{A^{\prime}}\), \(W_{A_2}\) being part of \(W_{C_2}\). Let \(W_{A_1}\) have the endpoints \(s_1,r_1\) and \(W_{A_2}\) have the endpoints \(s_2,r_2\). We now perform the following, not creating any new endpoints: We cut both walks \(W_{A_1}, W_{A_2}\) at u into two walks each. These four walks all have an endpoint in u, with the other four ones being \(s_1,s_2,r_1,r_2\). We now turn them into two walks again: First, concatenate \(s_1,u\) with \(u,s_2\) as \(W_{A_1}\), and then, concatenate \(r_1,u\) with \(u,r_2\) as \(W_{A_2}\). Now, we can obtain a single closed walk that traverses \(W_{C_1}\) and \(W_{C_2}\). Recursively iterating this process, we obtain a single closed Eulerian walk, respecting (1) to (4). \(\square\)
Signature Generation and Properties
We next introduce the signatures we use to represent previously computed solutions to subproblems implied by the separators in the (nice) tree decomposition. For every possible signature, we will determine whether it represents a valid solution for the subproblem, and if so, we store it along with an exemplary sub-solution of optimal weight.
In a nutshell, the signature describes endpoints of (partial) walks on each side of the separator. These partial walks hence need to be iteratively merged, forming signatures of longer walks through the waypoints.
Definition 2
(Signature) Consider a bag \({X_b}\in {{\mathcal {X}}}\). A signature \(\sigma\) of \({X_b}\) (\(\sigma _{{b}}\)) is a pair, either containing
- 1.
(1) an unordered tuple of pairs of vertices \(s_i,r_i \in {X_b}\), (2) a subset \({E_{{b}}\subseteq E(G[{b}])}\) with \(\sigma _{{b}}=\left( \left( \left( s_1,r_1\right) ,\left( s_2,r_2\right) ,\dots ,\left( s_\ell ,r_\ell \right) \right) ,E_{{b}}\right)\) s.t. \(\ell \le {|{b}|}\), or
- 2.
(1) \(\emptyset\), (2) \(\emptyset\), with \(\sigma _{{b}}=(\emptyset ,\emptyset )\), also called an empty signature \(\sigma _{{b},\emptyset }\).
Note that in the above definition we may have \(s_i=r_i\) for some i. We can now define a valid signature and a sub-solution, where we consider the vertex \(s=t\) to be a waypoint.
Definition 3
(Valid Signature, Sub-Solution) Let \({X_b}\in {{\mathcal {X}}}\) and let either \(\sigma _{{b}}=\left( \left\{ \left( s_1,r_1\right) ,\left( s_2,r_2\right) ,\dots ,\left( s_\ell ,r_\ell \right) \right\} ,E_{{b}}\right)\) or \(\sigma _{{b}} = \sigma _{{b},\emptyset }\) be a signature of \({X_b}\). \(\sigma _{{b}} \ne \sigma _{{{b}},\emptyset }\) is called a valid signature if there is a set of pairwise edge-disjoint walks \({{\mathcal {W}}}_{\sigma _{b}}=\{W_1,\ldots ,W_\ell \}\) such that:
- 1.
If \(W_i\) is an open walk then it has both of its endpoints on \((s_i,r_i)\), otherwise, \(s_i=r_i\) and \(s_i \in V(W_i)\).
- 2.
Let \(\beta\) be the size of the set of endpoints used by \(\sigma _{{b}}\). Then, it holds that \(\beta \ge \ell\).
- 3.
For every waypoint \(w \in V(T_{{b}})\) it holds that w is contained in some walk \(W_j, 1\le j \le \ell\).
- 4.
Every (pairwise edge-disjoint) walk \(W_j \in {{\mathcal {W}}}_{\sigma _{b}}\) only uses vertices from \(V(T_{{b}})\) and only edges from \(E(T_{{b}}) \setminus {\overline{E}}_{{b}}\), with \({\overline{E}}_{{b}} = E({{b}}) \setminus E_{{b}}\).
- 5.
Every edge \(e \in E_{{b}}\) is used by a walk in \({{\mathcal {W}}}_{\sigma _{b}}\).
- 6.
Among all such sets of \(\ell\) walks, \({{\mathcal {W}}}_{\sigma _{b}}\) has minimum total weight.
Additionally, if for a signature \(\sigma _{{b}} \ne \sigma _{{{b}},\emptyset }\) there is such a set \({{\mathcal {W}}}_{\sigma _{{b}}}\) (possibly abbreviated by \({{\mathcal {W}}}_{{b}}\) if clear from the context), we say that \({{\mathcal {W}}}_{\sigma _{{b}}}\) is a valid sub-solution in \(G[T_{{b}}]\). For some waypoint contained in \(G[T_{{b}}]\), we call a signature \(\sigma _{{{b}},\emptyset }\)valid, if there is one walk W associated with it, s.t. W traverses all waypoints in \(G[T_{{b}}]\), does not traverse any vertex in \(V({{b}})\), and among all such walks in \(G[T_{{b}}]\) has minimum weight. If \(G[T_{{b}}]\) does not contain any waypoints, we call the empty signature \(\sigma _{{{b}},\emptyset }\) valid, if there is no walk associated with it.
Lemma 3
(Number of different signatures)There are \(2^{O({|{b}|}^2)}\)different signatures for \({X_b}\in {{\mathcal {X}}}\).
Proof
There is only one empty signature, given the claimed order, it is safe to ignore it in counting. For the non-empty signatures, we know that they are consisting of a set of endpoints, and a set of edges, the task is to bound the total number of such sets.
There are at most \(2{|{b}|}\) endpoints and each vertex in a bag can be any of these \(2{|{b}|}\) endpoints, so there are at most \((2{|{b}|})^{|{b}|}\le 2^{{|{b}|}^2}\) different sets for choices of the endpoints. On the other hand, there are at most \(2^{{|{b}|}^2}\) ways to choose edges from a graph on \({|{b}|}\) vertices. Multiplying these two values gives an upper bound of \(2^{O({|{b}|}^2)}\) which satisfies the claim. \(\square\)
Programming the Nice Tree Decomposition
The nice tree decomposition directly gives us a constructive way to dynamically program WRP in a bottom-up manner. We first cover leaf nodes in Lemma 4, and then work our way up via forget (Lemma 5), introduce (Lemma 6), and join (Lemma 7) nodes, until eventually the root node is reached. Along the way, we inductively generate all valid signatures at every node.
Lemma 4
(Leaf nodes)Let \({b}\)be a leaf node in the nice tree decomposition \({{\mathcal {T}}}=(T,{{\mathcal {X}}})\). Then, in time O(1)we can find all the valid signatures of \({X_b}\).
Proof
We simply enumerate all possible valid signatures. As a leaf node only contains one vertex v from the graph, all possible edge sets in the signatures are empty, and we have two options for the pairs: First, \((\emptyset , \emptyset )\), second, \(\left( \left( v,v\right) ,\emptyset \right)\). The second option is always valid, but the first (empty) one is only valid when v is not a waypoint. \(\square\)
Lemma 5
(Forget nodes)Let \({b}\)be a forget node in the nice tree decomposition \({{\mathcal {T}}}=(T,{{\mathcal {X}}})\), with one child \(q = \text {child}({b})\), where we have all valid signatures for \(X_q\). Then, in time \(2^{O({|{b}|}^2)}\)we can find all the valid signatures of \({X_b}\).
Proof
Let \(v \in G\) be the vertex s.t. \(V({b}) \cup \left\{ v\right\} = V(q)\). We create all valid signatures for \({X_b}\) as follows: First, if the empty signature is valid for \(X_q\), it is also valid for \({X_b}\). Second, for \(\sigma _{b}= ({{\mathcal {P}}},E_{b})\), with some (s, r) pairs \({{\mathcal {P}}}\) to be a valid signature for \({X_b}\), there needs to be a valid signature \(\sigma _q = ({{\mathcal {P}}},E_{b}\cup E^{\prime})\), where \(E^{\prime}\) is a subset of all edges incident to v from E(G[q]). For correctness, consider the following: In all valid (non-empty) signatures of \({X_b}\), all walks need to have their endpoints in \(V({b})\). As v can only be reached from vertices in \(V(G) \setminus V(T_{b})\) via vertices in \(V({b})\), any walk between vertices of \(V(G) \setminus V(T_{b})\) and v must pass \(V({b})\), i.e., the corresponding signature of \(X_q\) can be represented as a signature of \({X_b}\), with possible additional edges. Checking every of the \(2^{O({|{b}|}^2)}\) valid signatures of the child as described can be done in time linear in the signature size \(O({|{b}|}^2)\), with \(2^{O({|{b}|}^2)}\cdot O({|{b}|}^2) = 2^{O({|{b}|}^2)}\). \(\square\)
Lemma 6
(Introduce nodes)Let \({b}\)be an introduce node in the nice tree decomposition\({{\mathcal {T}}}=(T,{{\mathcal {X}}})\), with one child \(q = \text {child}({b})\), where we have all valid signatures for \(X_q\). Then, in time \({|{b}|}^{O({|{b}|}^2)}\)we can find all the valid signatures of \({X_b}\).
We will exploit the following property for the proof of Lemma 6.
Property 1
Let \({b}\)be an introducenode, where qis a child of \({b}\), with \(V({b}) = V(q) \cup \left\{ v\right\}\). Then vis not adjacent to any vertex in \(V(T_{b}) \setminus V({b})\).
Proof
(Proof of Lemma 6) Let \(v \in G\) be the vertex s.t. \(V(q) \cup \left\{ v\right\} = V({b})\). Recall that v can only have neighbors in \(V({b})\) from \(V(T_{b})\) (Property 1). From valid signatures of \(X_q\), we will then create all valid signatures of \({X_b}\).
Suppose there is a valid signature \(\sigma _{b}\) and its valid sub-solution \({{\mathcal {W}}}_{b}\). Then we argue how \({{\mathcal {W}}}_{b}\) can be obtained from some \(\sigma _q\) and its valid-subsolution \({{\mathcal {W}}}_q\). That is we perform a case distinction, whether the node v is in the sub-solution \({{\mathcal {W}}}_{b}\) or not. The latter is the easy case, for the former we argue how v will be part of the solution and how we can employ the existing sub-solutions in \({{\mathcal {W}}}_q\) to obtain \(\sigma _{b}\). Thus, in the rest of the proof we assume there is \({{\mathcal {W}}}_{b}\) and we explain how it is built on the existing sub-solutions of q. We perform this in two steps. First we explain how to convert this imaginary valid sub-solution \({{\mathcal {W}}}_{b}\) into an intermediate sub-solution \({{\mathcal {W}}}_{q^{\prime}}\) (not necessary a valid one) and then we explain how to modify \({{\mathcal {W}}}_{q^{\prime}}\) to obtain a valid sub-solution \({{\mathcal {W}}}_{q}\).
From \(\sigma _{b}\) and \({{\mathcal {W}}}_{b}\), we now iteratively build a signature \(\sigma ^{\prime}_q\) and \({{\mathcal {W}}}_q^{\prime}\), which in the end will represent \(\sigma _q\) and \({{\mathcal {W}}}_q\). A first thought is that by removing all walks from \({{\mathcal {W}}}_{b}\) and \(\sigma _{b}\) that contain v, we initialize \(\sigma ^{\prime}_q\) and \({{\mathcal {W}}}_q^{\prime}\). \(\sigma ^{\prime}_q\) is already a signature for \(X_q\), as it cannot contain v as an endpoint any more, it contains at most |q| walks, but it might not be valid yet.
However, \(\sigma ^{\prime}_q\) and \({{\mathcal {W}}}_q^{\prime}\) already satisfy Conditions 1, 2, 4 from Definition 3. I.e, all endpoints of walks are still in V(q), there are at most as many walks as the size of the set of vertices in V(q) used as endpoints, the walks only use the edges they are allowed to.
It is left to satisfy Conditions 3 (all waypoints are covered), 5 (all edges specified in the signature are used) and 6 (optimality) from Definition 3. For Condition 5, we can assume that later we adjust \(\sigma ^{\prime}_q\) appropriately. We cover Condition 3 next:
If v is a waypoint, we do not need to cover it in \(\sigma ^{\prime}_q\). However, the walks \({{\mathcal {W}}}_q^{\prime}\) might not cover all further waypoints. Denote by \({{\mathcal {W}}}_v\), the set of all walks in \({{\mathcal {W}}}_{b}\) containing v. Clearly these are the only walks of \({{\mathcal {W}}}_{b}\) that are not contained in \({{\mathcal {W}}}_q^{\prime}\): Together with \({{\mathcal {W}}}_q^{\prime}\), they satisfy Condition 3, but they can use the vertex v and edges incident to v. Thus, let \({{\mathcal {W}}}_v^{\prime}\) be the set of walks obtained from \({{\mathcal {W}}}_v\) after removing all edges incident to v and the vertex v, possibly splitting up every walk into multiple walks. For every walk (possibly consisting of just a single vertex) in \({{\mathcal {W}}}_v^{\prime}\) holds: its endpoints are in V(q).
We now add the walks \({{\mathcal {W}}}_v^{\prime}\) to \({{\mathcal {W}}}_q^{\prime}\), one by one, not violating Conditions 1, 2, 4 (and implicitly, 5). After this process, we will also have visited all waypoints, satisfying Condition 3. We start with any walk \(W \in {{\mathcal {W}}}_v^{\prime}\): If W just consists of one vertex u, there can be two cases: First, if u is not an endpoint of a walk \(W^{\prime} \in {{\mathcal {W}}}_q^{\prime}\), then we add W as a walk to \({{\mathcal {W}}}_q^{\prime}\), increasing \(\beta _q^{\prime}\) and \(\ell _q^{\prime}\) from Condition 2 by one, still holding \(|q| \ge \beta _q^{\prime} \ge \ell _q^{\prime}\). Second, if u is an endpoint of a walk \(W^{\prime} \in {{\mathcal {W}}}_q^{\prime}\), we concatenate W and \(W^{\prime}\), keeping \(\beta _q^{\prime}\) and \(\ell _q^{\prime}\) identical. The case of W being a walk from \(u\in V(q)\) to \(y \in V(q)\) is similar: First, if both u, y are not endpoints of walks from \({{\mathcal {W}}}_q^{\prime}\), we add W to \({{\mathcal {W}}}_q^{\prime}\). Second, if both u, y are endpoints of walks from \({{\mathcal {W}}}_q^{\prime}\), we use W to concatenate them. If the result is a cycle, we pick w.l.o.g. u as both new endpoints. Third, if w.l.o.g. u is an endpoint of a walk \(W \in {{\mathcal {W}}}_q^{\prime}\), but y is not, we concatenate W, \(W^{\prime}\).
We now obtained \({{\mathcal {W}}}_q^{\prime}\) (and implicitly, \(\sigma _q^{\prime}\)) that satisfy Conditions 1 to 5 from Definition 3, and it is left to show Condition 6 (optimality). Assume there is a \({{\mathcal {W}}}_{{\overline{q}}}\) with smaller length than \({{\mathcal {W}}}_q^{\prime}\), both for \(\sigma _q^{\prime}\). Observe that when reversing our reduction process, the parts of the walks in \(G[V_q] \setminus E(G[q])\) are not relevant to our construction, only the signature \(\sigma _q^{\prime}\) as a starting point. As thus, we can algorithmically (implicitly described in the previous parts of the introduce case) derive all valid solutions and signatures for \({b}\).
It is left to investigate the runtime: For every possible signature of the child (\(2^{O({|{b}|}^2)}\) many), we combine them with every possible edge set (\(2^{O({|{b}|}^2)}\) combinations). Then, like unique balls (edges) into bins (walks), we distribute the edges over the walks, also considering all \(O({|{b}|})\) combinations with empty walks, in \({|{b}|}^{O({|{b}|}^2)}\) combinations. For every walk, we now obtained an edge set that has to be incorporated into the walk, where we can check in time \(O({|{b}|}^2)\) if it is possible and also what the new endpoints have to be (possibly switching both). If the walk is closed, we can pick \(O({|{b}|})\) different endpoints. All these factors, also the signature size and the number of signatures, are dominated by \({|{b}|}^{O({|{b}|}^2)}\), with \({|{b}|}\ge 2\). \(\square\)
Lemma 7
(Join nodes) Let \({b}\)be a join node in the nice tree decomposition \({{\mathcal {T}}}=(T,{{\mathcal {X}}})\), with the two children \(q_1 = \text {child}({b})\)and \(q_2 = \text {child}({b})\), where we have all valid signatures for \(X_{q_1}\)and \(X_{q_2}\). Then, in time \(n^{O({|{b}|})} \cdot 2^{O({|{b}|}^2)}\)we can find all the valid signatures of \({X_b}\).
Our proof for join nodes consists of two parts, making use of the following fact: For a given valid signature of \({X_b}\), two valid sub-solutions with different path traversals have the same total length, if the set of traversed edges is identical. As thus, when trying to re-create a signature of \({X_b}\) with a valid sub-solution, we do not need to create this specific sub-solution, but just any sub-solution using the same set of endpoints and edges. We show:
- 1.
We can partition the edges of a valid sub-solution into two parts along a separator, resulting in a valid signature for each of the two parts, where each sub-solution uses exactly the edges in its part.
- 2.
Given a sub-solution for each of the two parts separated, we can merge their edge sets, and create all possible signatures and sub-solutions using this merged edge set.
Proof of Lemma 7
Let \(\sigma _{b}\) be a valid non-empty signature of \({X_b}\) with edge set \(E_{b}\), with valid sub-solution \({{\mathcal {W}}}_{b}\). Our task is to show that we obtain \(\sigma _{b}\) from some valid signatures \(\sigma _{q_1}, \sigma _{q_2}\), with valid sub-solutions \({{\mathcal {W}}}_{q_1}, {{\mathcal {W}}}_{q_2}\).
Claim 1
Given valid \(\sigma _{b}\), \({{\mathcal {W}}}_{b}\), then there must be valid \(\sigma _{q_1}, \sigma _{q_2}\), \({{\mathcal {W}}}_{q_1}, {{\mathcal {W}}}_{q_2}\), such that \(E({{\mathcal {W}}}_{q_1}) \cup E({{\mathcal {W}}}_{q_2}) = E({{\mathcal {W}}}_{b})\).
Claim 2
Given valid \(\sigma _{q_1}, \sigma _{q_2}\), \({{\mathcal {W}}}_{q_1}, {{\mathcal {W}}}_{q_2}\), we show that we can create every possible valid signature of \({X_b}\)which has a sub-solution of edge set \(E({{\mathcal {W}}}_{q_1}) \cup E({{\mathcal {W}}}_{q_2})\)in \(n^{O(\texttt {tw})}\cdot 2^{O({|{b}|}^2)}\).
Proof of Claim 1
Arbitrarily partition \(E_{b}\) into some \(E_{q_1}\) and \(E_{q_2}\). Then, consider \(E^{{{\mathcal {W}}}}_{q_1} = \left( E({{\mathcal {W}}}_{b}) \cap E(T_{q_1})\right) \setminus E_{q_2}\) and \(E^{{{\mathcal {W}}}}_{q_2} = \left( E({{\mathcal {W}}}_{b}) \cap E(T_{q_1})\right) \setminus E_{q_1}\), i.e., the edges of the subwalks corresponding to each child, obtained by the arbitrary partition of \(E_{b}\).
For both \(E^{{{\mathcal {W}}}}_{q_1}\) and \(E^{{{\mathcal {W}}}}_{q_2}\), we now generate valid signatures and sub-solutions, where the edges of the signatures are already given by \(E_{q_1}, E_{q_2}\). W.l.o.g., we perform this task for \(E^{{{\mathcal {W}}}}_{q_1}\): Starting at some vertex \(v_1 \in V(q_1)\), generate a walk by traversing yet unused incident edges, until no more unused incident edges are left, ending at some \(v_2 \in V(q_1)\), possibly \(v_1=v_2\) and the used edge set may be empty.
Perform this for all vertices in \(V(q_1)\) not yet used as endpoints, possibly generating walks consisting just of a vertex and no edges. However, at most \(|V(q_1)|\) walks will be generated, as every endpoint of a walk will not be an endpoint for another walk. Note that if there is any uncovered set of edges of \(E^{{{\mathcal {W}}}}_{q_1}\), they form a set of edge-disjoint cycles, where at least one these cycles will share a vertex with some walk, as only vertices in \(V(q_1)\) can have odd degree w.r.t. the edge set. Then, we can integrate this cycle into a walk, iterating the process until all edges are covered. Denote the resulting valid signature by \(\sigma _{q_1}\) with edge set \(E_{q_1}\). We perform the same for \(E^{{{\mathcal {W}}}}_{q_2}\). Hence, starting from a valid signature \(\sigma _{b}\) with edge set \(E_{b}\), we created two valid signatures \(\sigma _{q_1}\) and \(\sigma _{q_2}\) for the two children of t, with \({{\mathcal {W}}}_{q_1}, {{\mathcal {W}}}_{q_2}\) such that \(E({{\mathcal {W}}}_{q_1}) \cup E({{\mathcal {W}}}_{q_2}) = E({{\mathcal {W}}}_{b})\).
Proof of Claim 2
Given \({{\mathcal {W}}}_{q_1}, {{\mathcal {W}}}_{q_2}\), we have to construct every possible \({{\mathcal {W}}}_b\) with \(E_{{{\mathcal {W}}}_b} = E({{\mathcal {W}}}_{q_1}) \cup E({{\mathcal {W}}}_{q_2})\), which in turn implies its valid signature \(\sigma _b\).
In order to do so, we create every possible (\(2^{O({|{b}|}^2)}\) many) signature \(\sigma\) of \({X_b}\), possibly not valid ones as well. However, every such signature \(\sigma\) can be checked if it can have a sub-solution using the edges \(E({{\mathcal {W}}}_{q_1}) \cup E({{\mathcal {W}}}_{q_2})\). We can obtain the answer to this question via a brute-force approach: We assign every edge from \(E({{\mathcal {W}}}_{q_1}) \cup E({{\mathcal {W}}}_{q_2})\) to one of the endpoint pairs of \(\sigma\), with \(|E({{\mathcal {W}}}_{q_1}) \cup E({{\mathcal {W}}}_{q_2})| = O(n^2)\). For a given \(\sigma\) with at most \({|{b}|}\) walks, the number of possibilities are thus in \(O((n^2)^{{|{b}|}})=n^{O({|{b}|})}\). For every endpoint pair \((s_i,r_i)\) of the at most \({|{b}|}\) walks, we can check in time linear in the number of edges if the assigned edge set can be covered by a walk between \(s_i\) and \(r_i\): namely, does the edge set form a connected component where all vertices except for \(s_i \ne r_i\) have even degree (or, in the case of \(s_i = r_i\), do all vertices have even degree)? When we create a signature multiple times, we can keep any sub-solution of minimum length. In total, the runtime is in \(2^{O({|{b}|}^2)}\cdot n^{O(\texttt {tw})}\).
It remains to cover the case of \(\sigma _{b}\) being empty. By definition, a valid sub-solution to an empty signatures does not traverse any vertex in \(V({b})\). As such, the only way to obtain a valid signature \(\sigma _{b}\) in a join is if both valid \(\sigma _{q_1}, \sigma _{q_2}\) are empty, with, w.l.o.g., \({{\mathcal {W}}}_{q_2}\) empty too. Then, \(\sigma _{b}= \sigma _{q_1}\), with \({{\mathcal {W}}}_{{b}} = {{\mathcal {W}}}_{q_1}\). \(\square\)
Putting it All Together
We now have all the necessary tools to prove Theorem 1:
Proof
Dynamically programming a nice tree decomposition Translating an instance of WRP to an equivalent one with \(s=t\) and unit edge capacities only increases the treewidth by a constant amount, see Remark II and Lemma 1. Although it is \({\mathsf {NP}}\)-complete to determine the treewidth of a graph and compute an according tree decomposition, there are efficient algorithms for constant treewidth [12, 54]. Furthermore, Bodlaender et al. [14] presented a constant-factor approximation in a time of \(2^{O(\texttt {tw})}\cdot O(n)\), also beyond constant treewidth: Using their algorithm \(O(\log \texttt {tw})\) times (via binary search over the unknown treewidth size), we obtain a tree decomposition of width \(O(\texttt {tw})\). Following [41], we generate a nice tree decomposition of treewidth \(O(\texttt {tw})\) with \(O(\texttt {tw}n) = O(n^2)\) nodes in an additional time of \(O(\texttt {tw}^2n) = O(n^3)\). The time so far is \(2^{O(\texttt {tw})}\cdot O(n \log \texttt {tw})+O(\texttt {tw}^2n)\).
We can now dynamically program WRP on the nice tree decomposition in a bottom-up manner, using Lemma 4 (leaf nodes), Lemma 5 (forget nodes), Lemma 6 (introduce nodes), and Lemma 7 (join nodes). The time for each programming of a node is at most \(O(\texttt {tw})^{O(\texttt {tw}^2)}\) or \(n^{O(\texttt {tw})} \cdot 2^{O(\texttt {tw}^2)}\), meaning that we obtain all valid signatures with valid sub-solutions at the root node r, in a combined time of \(n^{O(\texttt {tw}^2)}\), specifically:
$$\begin{aligned} (O(\texttt {tw})^{O(\texttt {tw}^2)} + n^{O(\texttt {tw})} \cdot 2^{O(\texttt {tw}^2)})\cdot O(\texttt {tw}\cdot n) + 2^{O(\texttt {tw})}\cdot O(n\log \texttt {tw})+O(\texttt {tw}^2n). \end{aligned}$$
Obtaining an optimal solution If an optimal solution I to WRP exists (on the unified graph with \(s=t\)), then the traversed edges \(E^*\) and vertices \(V^*\) in I yield an Eulerian graph \(G^*=(V^*,E^*)\). With each bag in the nice tree decomposition having \(O(\texttt {tw})\) vertices, we can now apply (the Eulerian separation) Lemma 2: There must be a valid signature of the root r whose sub-solution uses exactly the edges \(E^*\). As thus, from all the valid sub-solutions at r, we pick any solution to WRP with minimum weight, obtaining an optimal solution to WRP. \(\square\)