Walking Through Waypoints

We initiate the study of a fundamental combinatorial problem: Given a capacitated graph $G=(V,E)$, find a shortest walk ("route") from a source $s\in V$ to a destination $t\in V$ that includes all vertices specified by a set $\mathscr{W}\subseteq V$: the \emph{waypoints}. This waypoint routing problem finds immediate applications in the context of modern networked distributed systems. Our main contribution is an exact polynomial-time algorithm for graphs of bounded treewidth. We also show that if the number of waypoints is logarithmically bounded, exact polynomial-time algorithms exist even for general graphs. Our two algorithms provide an almost complete characterization of what can be solved exactly in polynomial-time: we show that more general problems (e.g., on grid graphs of maximum degree 3, with slightly more waypoints) are computationally intractable.


Introduction
How fast can we find a shortest route, i.e., walk, from a source s to a destination t which visits a given set of waypoints in a graph, but also respects edge capacities, limiting the number of traversals? This fundamental combinatorial problem finds immediate applications, e.g., in modern networked systems connecting distributed network functions (see below for details). However, surprisingly little is known today about the fundamental algorithmic problems underlying walks through waypoints. The problem features interesting connections to the disjoint path problem, however, in contrast to disjoint paths, we (1) consider walks (of unit resource demand each time an edge is traversed) on capacitated graphs rather than paths on uncapaciatated graphs, and we (2) require that a set of specified vertices are visited. We refer to Figure 1 for two examples. Two shortest walks and their decompositions into three paths each: In both graphs, we walk through all waypoints from s to t by first taking the red, then the blue, and lastly the brown path. The existence of a solution in the left graph (e.g., a walk of length 7 in this case) relies on one edge incident to a waypoint having a capacity of at least two. In the right graph, it is sufficient that all edges have unit capacity. Note that no s − t path through all waypoints exists, for either graph.

Our Contributions
We initiate the study of a fundamental waypoint routing problem. We present polynomialtime algorithms to compute shortest routes (walks) through arbitrary waypoints on graphs of bounded treewidth and to compute shortest routes on general graphs through a bounded (but not necessarily constant) number of waypoints. We show that it is hard to significantly generalize these results both in terms of the family of graphs as well as in terms of the number of waypoints, by deriving NP-hardness results: Our exact algorithms cover a good fraction of the problem space for which polynomial-time solutions exist. More precisely, we present the following results: 1. Shortest Walks on Arbitrary Waypoints: While many vertex disjoint problem variants like Hamiltonian path, TSP, vertex disjoint paths, etc. are often polynomialtime solvable in graphs of bounded treewidth, their edge-disjoint counterparts (like the edge-disjoint problem), are sometimes NP-hard already on series-parallel graphs. As the Waypoint Routing Problem is an edge-based problem, one might first expect that the problem is NP-hard already on bounded treewidth graphs, similarly to the edge disjoint paths problem. Yet, and perhaps surprisingly, we prove that a shortest walk through an arbitrary number of waypoints can be computed in polynomial time on graphs of bounded treewidth. By employing a simple trick, we transform the capacitated problem variant to an uncapacitated edge-disjoint problem: the resulting uncapacitated graph has almost the same treewidth. We then employ a well-known dynamic programming technique on a nice tree decomposition of the graph. However, since the walk is allowed to visit a vertex multiple times, we cannot rely on techniques which are known for vertex-disjoint paths. Moreover, we cannot simply use the line graph of the original graph: the resulting graph does not preserve the bounded treewidth property (e.g., the line graph of a star is a complete graph). Accordingly, we develop new methods and tools to deal with these issues. 2. Shortest Walks on Arbitrary Graphs: We show that a shortest route through a logarithmic resp. a route through a loglog number of waypoints can be computed in randomized resp. deterministic polynomial time on general graphs, by reduction to the vertex-disjoint cycle problems in [2,3]. Again, we show that that this is almost tight, in the sense that the problem becomes NP-hard for any polynomial number of waypoints. This reduction shows that the edge-disjoint paths problem is not harder than the vertexdisjoint problem on general graphs, and the hardness result also implies that [2] is nearly asympotically tight in the number of waypoints which can be solved in polynomial time.

A Practical Motivation
The problem of finding routes through waypoints or specified vertices is a natural and fundamental one. We sketch just one motivating application, arising in the context of modern networked systems. Whereas traditional computer networks were designed with an "end-to-end principle" [4] philosophy in mind, modern networks host an increasing number of "middleboxes" or network functions, distributed across the network, in order to improve performance (e.g., traffic optimizers, caches, etc.), security (e.g., firewalls, intrusion detection systems), or scalability (e.g., network address translation). Moreover, middleboxes are increasingly virtualized (a trend known as network function virtualization [5]) and can be deployed flexibly at arbitrary locations in the network (not only at the edge) and at low costs. Accordingly, also more flexible routing schemes have been developed, enabled in particular by the software-defined networking paradigm [6], to route the traffic through these (virtualized) middleboxes to compose more complex network services (also known as service chains [7]). Thus, the resulting traffic routes can be modelled as walks, and the problem of finding shortest routes through such middleboxes (the waypoints) is an instance of WRP.

Related Work
The Waypoint Routing Problem is closely related to disjoint path problems arising in many applications [8,9,10]. Indeed, assuming unit edge capacities and a single waypoint w, the problem of finding a shortest walk (s, w, t) can be seen as a problem of finding two shortest (edge-)disjoint paths (s, w) and (w, t) with a common vertex w. More generally, a shortest walk (s, w 1 , . . . , w k , t) in a unit-capacity graph can be seen as a sequence of k + 1 disjoint paths. The edge-disjoint and vertex-disjoint path problem (sometimes called min-sum disjoint paths) is a deep and intensively studied combinatorial problem. Today, we have a fairly good understanding of the feasibility of k-disjoint paths: for constant k, polynomial-time algorithms for general graphs have been found by Ohtsuki [11], Seymour [12], Shiloah [13], and Thomassen [14] in the 1980s, and for general k it is NP-hard [15], already on seriesparallel graphs [16], i.e., graphs of treewidth at most two. However, the optimization problem (i.e., finding shortest paths) continues to puzzle researchers, even for k = 2. Until recently, despite the progress on polynomial-time algoritms for special graph families like variants of planar graphs [17,18,19] or graphs of bounded treewidth [20], no subexponential time algorithm was known even for the the 2-disjoint paths problem on general graphs [19,21,22].
A recent breakthrough result shows that optimal solutions can at least be computed in randomized polynomial time [23]; however, we still have no deterministic polynomial-time algorithm for the 2-disjoint shortest paths problem. Both existing feasibile and optimal algorithms are often impractical [12,23,24,25], and come with a high runtime. We also note that there are results on the min-max version of the disjoint paths problem, which asks to minimize the length of the longest path. The min-max problem is believed to be harder than min-sum [19,26].
The problem of finding shortest (edge-and vertex-disjoint) paths and cycles through k waypoints has been studied in different contexts already. The cycle problem variant is also known as the k-Cycle Problem and has been a central topic of graph theory since the 1960's [27]. A cycle from s through k = 1 waypoints back to t = s can be found efficiently by breadth first search, for k = 2 the problem corresponds to finding a integer flow of size 2 between two vertices, and for k = 3, it can still be solved in linear time [28,29]; a polynomialtime solution for any constant k follows from the work on the disjoint path problem [30]. The best known deterministic algorithm to compute feasible (but not necessarily shortest) paths is by Kawarabayashi [3]: it finds a cycle for up to k = O((log log n) 1/10 ) waypoints in deterministic polynomial time. Björklund et al. [2] presented a randomized algorithm based on algebraic techniques which finds a shortest simple cycle through a given set of k vertices or edges in an n-vertex undirected graph in time 2 k n O (1) . In contrast to these works, we assume capacitated networks and do not enforce routes to be edge or vertex disjoint, but rather consider (shortest) walks.
Regarding capacitated graphs, researchers have explored the admission control problem variant: the problem of admitting a maximal number of routing requests such that capacity constraints are met. For example, Chekuri et al. [31] and Ene et al. [32] presented approximation algorithms for maximizing the benefit of admitting disjoint paths in bounded treewidth graphs with both edge and vertex capacities. Even et al. [33,34] and Rost et al. [35] initiated the study of approximation algorithms for admitting a maximal number of routing walks through waypoints. In contrast, we focus on the optimal routing of a single walk.
In the context of capacitated graphs and single walks, the applicability of edge-disjoint path algorithms to the so-called ordered Waypoint Routing problem was studied in [36,37], where the task is to find k + 1 capacity-respecting paths (s, w 1 , ), (w 1 , w 2 ), . . . , (w k , t). An extension of their methods to the unordered Waypoint Routing problem via testing all possible k! orderings falls short of our results: For general graphs, only O(1) waypoints can be considered, and for graphs of bounded treewidth, only O(log n) waypoints can be routed in polynomial time [36]; both results concern feasibility only, but not shortest routes. In this work, we provide algorithms for O(log n) waypoints on general graphs and O(n) waypoints in graphs of bounded treewidth, in both cases for shortest routes.
Lastly, for the case that all edges have a capacity of at least two and s = t, a direct connection of WRP to the subset traveling salesman problem (TSP) can be made [37]. In the subset TSP, the task is to find a shortest closed walk that visits a given subset of the vertices [1]. As optimal routes for WRP and subset TSP traverse every edge at most twice, optimal solutions for both are identical when ∀e ∈ E : c(e) ≥ 2. Hence, we can make use of the subset TSP results of Klein and Marx, with a runtime of (2 O( √ k log k) + max ∀e∈E ω(e)) · n O(1) on planar graphs. Klein and Marx also point out applicability of the dynamic programming techniques of Bellman and of Held and Karp, allowing subset TSP to be solved in a runtime of 2 k · n O (1) . For a PTAS on bounded genus graphs, we refer to [38]. We would like to note at this point that the technique for s = t of Lemma 20 does not apply if all edges must have a capacity of at least two. Similarly, it is in general not clear how to directly transfer s = t XX:5 TSP results to the case of s = t, cf. [39]. Notwithstanding, as WRP can also handle unit capacity edges (to which subset TSP is oblivious), WRP is a generalization of subset TSP.

Paper Organization
The remainder of this paper is organized as follows. In Section 2 we present our results for bounded treewidth graphs and Section 3 considers general graphs. We derive different NP-hardness results in Section 4 and conclude in Section 5. In order to improve presentation and due to space constraints, some technical contents are deferred to the Appendix.

Walking Through Waypoints on Bounded Treewidth Graphs
The complexity of the Waypoint Routing Problem on bounded treewidth graphs is of particular interest: while vertex-disjoint path and cycle problems are often polynomial-time solvable on bounded treewidth graphs (e.g., vertex disjoint paths [30], vertex coloring, Hamiltonian cycles [40], Traveling Salesman [41], see also [42,43]) many edge-disjoint problem variants are NP-hard (e.g., edge-disjoint paths [16], edge coloring [44]). Moreover, the usual line graph construction approaches to transform vertex-disjoint to edge-disjoint problems are not applicable as bounded treewidth is not preserved under such transformations.
Against this backdrop, we show that indeed shortest routes through arbitrary waypoints can be computed in polynomial-time for bounded treewidth graphs. I.e., the Waypoint Routing Problem is in the complexity class XP [45,46]. We obtain: The remainder of this section is devoted to the proof of Theorem 1. Let us first provide a brief proof outline. We will describe our algorithm in terms of a nice tree decomposition [47,Definition 13.1.4]. We first transform the edge-capacitated problem into an edge-disjoint problem (on a unified graph), 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 used separator signatures 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 [47,Definition 13.1.5]. The correctness of our approach relies on a crucial observation on the underlying Eulerian properties of the Waypoint Routing Problem in Lemma 5, allowing us to bound the number of partial walks we need to consider at the separator, see Figure 2 for an example. Finally, we bring together the different bits and pieces, and sketch how to dynamically program [48] the shortest waypoint walk on the rooted separator tree.

Preliminaries
A tree decomposition T = (T, X) of a graph G consists of a bijection between a tree T and a collection X, where every element of 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 T = (T, X) is the size of the largest set in X minus 1, with the treewidth of G being the minimum width of all possible tree decompositions of G.
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 b ∈ X be a bag of the decomposition corresponding to a vertex b ∈ V (T ). We denote by T t the maximal subtree of T which is rooted at bag b. By G[b] we denote the subgraph of G induced on the vertices in the bag 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 T = (T, X) of a graph G is given, covering its computation in the final steps of the proof of Theorem 1 in Section 2.4.

Unified Graphs
We begin by transforming our graphs into graphs of unit edge capacity, preserving distances and approximately preserving treewidth.

Definition 3 (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 ∈ E(G): We replace e by c(e) parallel edges e 1 , . . . , e c(e) , subdivide each resulting parallel edge by creating vertices v e i , i ∈ [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 the Waypoint Routing Problem, 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 Lemma 19, w.l.o.g., we can focus on graphs where for all e ∈ E, c(e) ≤ 2. The treewidth of G and G u are preserved up to an additive constant.

Lemma 4.
Let G be an edge capacitated graph such that each edge has capacity at most 2 and let tw be the treewidth of G. Then graph G u has treewidth at most tw + 1.
Proof. Let T = (T, X) be an optimal tree decomposition of G of width tw. Let X b be an arbitrary bag of T . We construct the tree decomposition T u of G u based on T as follows. First set T u = T . For every edge e of capacity c in G, which has its endpoints in This creates a tree decomposition T u of width ≤ tw + 1 of G.

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.

Let β A be the size of the set of vertices used by W A as an endpoint in s. Then, W A
contains at most β A walks. Analogously, for β B and W B .

Proof. G[A] and G[B] share the edges in G[s]. For this proof, we arbitrarily distribute the edges in
As only the vertices in s can have odd degree in G A , we can cover the edges of G A 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 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, cf. [49].
As every vertex in G A has a path to a vertex in s, we have covered all edges in G A with α A (possibly closed) walks W A , with α A ≤ β A ≤ |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 and obtain an analogous W B with α B ≤ β B ≤ |s| walks. Let us inspect the properties of the union of W A and W B : All walks have their endpoints in A ∩ B, respecting 1.
At each v ∈ s, at most one walk each from W A and W B has its endpoint, respecting 3. There is no certificate yet that the walks respect 4.
As thus, we will now alter W A and W B such that their union respects 4.
W.l.o.g., we start in any walk W in W A to create a set of closed walks W C . We traverse the walk W from some endpoint vertex v ∈ s until we reach its other endpoint v ∈ s, possibly v = v. As there cannot be any other walks in W A 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 ) = E(G), it does not share any vertex with another walk in W A . Hence, there must be a walk or walks in W B containing v. As v has even degree, we have two options: There could be a closed walk W in W B containing v. Then, we set both endpoints of W to v, and as W does not share a node with any other walk in W B , we are done. Else, there is an open walk W which just traverses v, not having v as an endpoint. We then split W into two open walks at v, increasing α B and β B by one.
Third, if W is an open walk, there must be an open walk in W B whose start-or endpoint is v. We iteratively perform these traversals, switching between W A and W B 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 W C . If W C contains only one closed walk, we found a traversal order of the walks in W A and W B that yields an Eulerian walk, respecting 4, finishing the argument for that case. Else, as the graph is connected, there must be Let W A1 have the endpoints s 1 , r 1 and W A2 have the endpoints s 2 , r 2 . We now perform the following, not creating any new endpoints: We cut both walks W A1 , W A2 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 A1 , and then, concatenate r 1 , u with u, r 2 as W A2 . Now, we can obtain a single closed walk that traverses W C1 and W C2 . Recursively iterating this process, we obtain a single closed Eulerian walk, respecting 1 to 4.

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 proper/valid solution for the subproblem, and if so, 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.
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 7 (Valid Signature and Sub-Solution
is an open walk then it has both of its endpoints on (s i , r i ), otherwise, s i = r i and s i ∈ V (W i ).

2.
Let β be the size of the set of endpoints used by σ b . Then, it holds that β ≥ .

For every waypoint
Among all such sets of walks, W σ b has minimum total weight. Proof. There are at most 2 O(|b| 2 ) ways to choose edges from a graph of order |b|. To distribute up to 2|b| endpoints of walks over |b| vertices, we can temporarily add 2|b| empty endpoints, meaning there are at most (4|b|) 4|b| possibilities. The empty signature only adds one further possibility.

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 (containing only one vertex) in Lemma 9, and then work our way up via forget (Lemma 10), introduce (Lemma 11), and join (Lemma 12) nodes, until eventually the root node is reached. Along the way, we inductively generate all valid signatures at every node. We will exploit the following property. Due to space constraints, some proofs are deferred to the Appendix.
. From these valid signatures of q, we will then create all valid signatures of b. Thus, we can pick some valid signature σ b (possibly empty), with complete knowledge of a valid sub-solution W b . By showing how to obtain a valid signature σ q with valid-subsolution W q from σ b and W b , the process can then be reversed -as we know all such σ q and W q . From σ b and W b , we now iteratively build a signature σ q and W q , which in the end will represent σ q and W q . First, by removing all walks from W b and σ b that contain v, we initialize σ q and W q . σ q is already a signature for 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, σ q and W q already satisfy Conditions 1, 2, 4 from Definition 7. 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 7. For Condition 5, we can assume that later we adjust σ q appropriately. We cover Condition 3 next: If v is a waypoint, we do not need to cover it in σ q . However, the walks W q might not cover all further waypoints. Consider all the walks W v in W b not contained in W q , minus possibly the walk just consisting of v: Together with W q , they satisfy Condition 3, but they can use edges incident to v and v. Thus, let W v be the set of walks obtained from 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 W v holds: Its endpoints are in V (q).
We now add the walks W v to W q , 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 ∈ W v : If W just consists of one vertex u, there can be two cases: First, if u is not an endpoint of a walk W ∈ W q , then we add W as a walk to W q , increasing β q and q from Condition 2 by one, still holding |q| ≥ β q ≥ q . Second, if u is an endpoint of a walk W ∈ W q , we concatenate W and W , keeping β q and q identical. The case of W being a walk from u ∈ V (q) to y ∈ V (q) is similar: First, if both u, y are not endpoints of walks from W q , we add W to W q . Second, if both u, y are endpoints of walks from W q , 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 ∈ W q , but y is not, we concatenate W , W .
We now obtained W q (and implicitly, σ q ) that satisfy Conditions 1 to 5 from Definition 7, and it is left to show Condition 6 (optimality). Assume there is a W q with smaller length than W q , both for σ q . Observe that when reversing our reduction process, the parts of the walks in G[V q ] \ E(G[q]) are not relevant to our construction, only the signature σ q 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 cover 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| ≥ 2. Our proof consists of two parts, making use of the following fact: For a given valid signature of 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 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, deferred to the Appendix:

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. We can now dynamically program the Waypoint Routing Problem on the nice tree decomposition in a bottom-up manner, using Lemma 9 (leaf nodes), Lemma 10 (forget nodes), Lemma 11 (introduce nodes), and Lemma 12 (join nodes). The runtime for each programming of a node is at most O(tw) O(tw 2 ) or n O(tw) · 2 O(tw 2 ) , meaning that we obtain all valid signatures with valid sub-solutions at the root node r, in a combined runtime of:

Putting it All Together
Obtaining an optimal solution. If an optimal solution I to the Waypoint Routing Problem 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(tw) vertices, we can now apply (the Eulerian separation) Lemma 5: 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 the Waypoint Routing Problem.

Walking Through Logarithmically Many Waypoints
While the Waypoint Routing Problem is generally NP-hard (as we will see below), we show that a shortest walk through a bounded (not necessarily constant) number of waypoints can be computed in polynomial time. In the following, we describe reductions to shortest vertex-disjoint [2, 3] 1 cycle problems, where the cycle has to pass through specified vertices. As we study walks on capacitated networks instead, we first introduce parallel edges. Interestingly, two edges are sufficient, see Lemma 19 in the appendix. Similarly, for edge weights ω(e), we replace every edge e with a path of length ω(e). Lastly, to obtain a simple graph with unit edge weights and unit capacities, we place a vertex on every edge, removing all parallel edges while being distance-preserving.
The transformation of the edge-disjoint cycle problem variant into a vertex-disjoint route problem variant, and accounting for waypoints, however requires some additional considerations. The standard method to apply vertex-disjoint path algorithms to the edgedisjoint case, e.g., [53,16,54] 2 , is to take the line graph L(G) of the original graph G. Then, each edge is represented by a vertex (and vice versa), i.e., a vertex-disjoint path in the line graph directly translates to an edge-disjoint walk (and vice versa), but possibly changing the graph family. However, the line graph construction raises the question of where to place the waypoints. For example, consider a waypoint vertex of degree 3, which is transformed into 3 vertices in the line graph: which of these vertices should represent the waypoint?
For the case of 2 disjoint paths, Björklund and Husfeldt [23, p.214] give the following idea: "add an edge to each terminal vertex and apply [the] Algorithm [...] to the line graph of the resulting graph". Their method is sufficient for s, t, but for the remaining waypoints, we also need to add extra vertices to the line graph: To preserve shortest paths, every shortest "pass" through the line graph representation of a vertex v should have the same length, no matter if the waypoint was already visited or not. As thus, we add δ(v) further vertices to the line graph, one on each edge connecting two edge representations in the line graph, as in Figure 3.
Next, recall that the algorithm by Björklund et al. [2] computes cycles, whereas in WRP, we are interested in walks from s to t, where s may not equal t. However, due to Remark II (Lemma 20), we can assume that s = t.
Given this construction, using Björklund et al.'s shortest simple cycle algorithm, we have: Theorem 13. For a general graph G with polynomial edge weights, a shortest walk through k ∈ O(log n) waypoints can be computed in randomized polynomial time, namely 2 k n O (1) .
Similarly, we can also adapt the result by Kawarabayashi [3] to derive a deterministic algorithm to compute feasible (but not necessarily shortest) walks: Theorem 14. For a general graph G with polynomial edge weights, a walk through k ∈ O (log log n) 1/10 waypoints can be computed in deterministic polynomial time.
A formal treatment of the above construction ideas is deferred to the appendix.

NP-Hardness
Given our polynomial-time algorithms to compute shortest walks through arbitrary waypoints on bounded treewidth graphs as well as to compute shortest walks on arbitrary graphs through a bounded number of waypoints, one may wonder whether exact polynomial time solutions also exist for more general settings. In the following, we show that this is not the case: in both dimensions (number of waypoints and more general graph families), we inherently hit computational complexity bounds. Our hardness results follow by reduction from a special subclass of NP-hard Hamiltonian cycle problems [56,57]: Theorem 15. WRP is NP-hard for any graph family of degree at most 3, for which the Hamiltonian Cycle problem is NP-hard.
Proof of Theorem 15. Let G = (V, E) be a graph from a graph family of degree at most 3 for which the Hamiltonian cycle problem is NP-hard (e.g., [56,57,58,59]), set all edge capacities to 1, take an arbitrary vertex v ∈ V , and set s : Consider a route R (a feasible walk) which starts and ends at v and visits all other vertices. We claim that R is a Hamiltonian cycle for G; on the other hand, it is clear that if there is a Hamiltonian cycle of G then it satisfies the requirements of R. We start at v and walk along R, directing edges along the way. Every vertex in the resulting graph has at least one outgoing directed edge and at least one incoming directed edge. On the other hand, as the edge capacities are 1, R cannot reuse any edge, so the number of directed edges on every vertex must be even: in fact, the number of incoming edges equals the number of outgoing edges. The maximum degree of G is 3, according to the last two observations, every vertex appears in exactly two edges of the walk R. As R induces a connected subgraph and all its vertices are of degree two, we conclude that R is a single cycle. As R visits all vertices in G, thus it is also a Hamiltonian cycle.
We have the following implication for grid graphs [57,58,59] of maximum degree 3, and can use similar ideas for the class of 3-regular bipartite planar graphs. Due to space constraints, both proofs are deferred to the appendix.

Corollary 16.
For any fixed constant r ≥ 1 it holds that WRP is NP-hard on grid graphs of maximum degree 3, already for k ∈ O(n 1/r ) waypoints.

Corollary 17.
For any fixed constant r ≥ 1 it holds that WRP is NP-hard on 3-regular bipartite planar graphs, already for k ∈ O(n 1/r ) waypoints.
We note that our proof techniques also apply to the k-Cycle problem studied by Björklund et al.. [2], whose solution is polynomial for logarithmic k. All possible edge disjoint solutions are also vertex-disjoint, due to the restriction to a maximum degree of 3.

Corollary 18.
For any fixed constant r ≥ 1 it holds that the k-Cycle problem is NP-hard on 1) 3-regular bipartite planar graphs and 2) grid graphs of maximum degree 3, respectively, already for k ∈ O(n 1/r ).

Conclusion
Motivated by the more general routing models introduced in modern software-defined and function virtualized distributed systems, we initiated the algorithmic study of computing shortest walks through waypoints on capacitated networks. We have shown, perhaps surprisingly, that polynomial-time algorithms exist for a wide range of problem variants, and in particular for bounded treewidth graphs. In our dynamic programming approach to the Waypoint Routing Problem, parametrized by treewidth, we provided fixed-parameter tractable (FPT) algorithms for leaf, forget, and introduce nodes, but an XP algorithm for join nodes. In fact, while we do not know whether our problem can be expressed in monadic second-order logic MSO2, we can show that simply concatenating child-walks for join nodes does not result in all valid parent signatures.
We believe that our paper opens an interesting area for future research. In particular, it will be interesting to further chart the complexity landscape of the Waypoint Routing Problem, narrowing the gap between problems for which exact polynomial-time solutions do and do not exist. Moreover, it would be interesting to derive a lower bound on the runtime of (deterministic and randomized) algorithms on bounded treewidth graphs.

A Deferred Claims and Proofs from the Model Section 1.1
The idea for the following Lemma 19 can already be found in [1, Fig. 1 Proof. Proof by contradiction. Construct an edge-weighted multigraph U as follows. The vertices of U are exactly the vertices of R. For every edge e = {u, v} which appears x times in R, insert edges e 1 , . . . , e x with endpoints u, v and the same weight as e, to U ; note that there can be parallel edges in U . As R is a walk with start vertex s and end vertex t, the graph U contains an Eulerian walk which can be obtained by following R with respect to the new edges. Thus, every vertex in V (U ) \ {s, t} has an even degree and s, t have odd degrees. For the sake of contradiction, suppose there are two vertices u, v ∈ V (U ) s.t. there are edges e 1 , . . . , e x between them s.t. x > 2. We remove e 1 , e 2 from E(U ) to obtain U . The resulting graph is still connected, every vertex except s, t has even degree, and the graph contains an Eulerian walk P which starts at s and ends at t. But this walk has a smaller total length than R, and it also visits all the waypoints. Contradiction to our assumption that R is a shortest walk.
Proof. We start with the first claim: By placing v into all bags, the treewidth increases at most by one. For the second claim, we start with the case that there is a shortest solution of length 1 in G. Then, we can amend this route in G to obtain a solution of length 1 + 2. If a shorter solution were to exist in G , we would also obtain a shorter solution in G. The reverse case holds analogously, with special coverage of the case that the original WRP only contains s, t and no further waypoints: Then, due to the placement of waypoints in G where s, t were placed in G, finding a shortest route of length 1 + 2 in G is equivalent to finding a shortest route of length 1 in G of the original WRP.

B Deferred Proofs for Programming the Nice Tree Decomposition
Proof of Lemma 9 (Leaf nodes). 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, none, second, ((v, v)). The second option is always valid, but the first (empty) one is only valid when v is not a waypoint.

Proof of Lemma 10 (Forget nodes). Let
. We create all valid signatures for b as follows: First, if the empty signature is valid for q, it is also valid for b. Second, for σ b = (P, E b ), with some (s, r) pairs P to be a valid signature for b, there needs to be a valid signature σ q = (P, Proof of Lemma 12 (Join nodes). Let σ b be a valid non-empty signature of b with edge set E b , with valid sub-solution W b . Our task is to show that we obtain σ b from some valid signatures σ q1 , σ q2 , with valid sub-solutions W q1 , W q2 .
Claim 2. Given valid σ q1 , σ q2 , W q1 , W q2 , we show that we can create every possible valid signature of b which has a sub-solution of edge set Proof of Claim 1. Arbitrarily partition E b into some E q1 and E q2 . Then, consider , the edges of the subwalks corresponding to each child, obtained by the arbitrary partition of E b .
For both E W q1 and E W q2 , we now generate valid signatures and sub-solutions, where the edges of the signatures are already given by E q1 , E q2 . W.l.o.g., we perform this task for E W q1 : Starting at some vertex v 1 ∈ 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 ∈ 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 W q1 , 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 σ q1 with edge set E q1 . We perform the same for E W q2 . Hence, starting from a valid signature σ b with edge set E b , we created two valid signatures σ q1 and σ q2 for the two children of t, with W q1 , W q2 such that Proof of Claim 2. Given W q1 , W q2 , we have to construct every possible W b with E W b = E(W q1 ) ∪ E(W q2 ), which in turn implies its valid signature σ b .
In order to do so, we create every possible (2 O(|b| 2 ) many) signature σ of b, possibly not valid ones as well. However, every such signature σ can be checked if it can have a sub-solution using the edges E(W q1 ) ∪ E(W q2 ). We can obtain the answer to this question via a brute-force approach: We assign every edge from It remains to cover the case of σ b being empty. Recall that by definition, a valid subsolution to an empty signatures does not traverse any vertex in V (b). As such, the only way to obtain a valid signature σ b in a join is if both valid σ q1 , σ q2 are empty, with, w.l.o.g., W q2 being empty too. Then, σ b = σ q1 , with W b = W q1 .

4.
For each e ∈ L R (E) contained in any K δ(v) (v), not incident to any v a. Replace e by a path of two edges and one vertex.

C Adapting Vertex-Disjoint Path Methods to WRP
Our proof of Theorems 13 and 14 will be a direct implication of Corollary 22, for which in turn we need the following Theorem 21. We note that all required proof ideas are already described in Section 3, but we still repeat them briefly in the following. For our construction, we will use an extended waypoint-aware line graph L R (G) construction in Algorithm 1. The fundamental idea is as follows: Similar to the line graph, we place vertices on the edges, implying that every edge may only be used once. Then, the original vertices are expanded into sufficiently large cliques, also containing the waypoint, s.t. any original edge-disjoint walk can also be performed by a path through the clique vertices. For an illustration of the so-called clique expansion, we refer again to Figure 3.

Theorem 21.
Consider an instance I of WRP on G = (V, E). If an edge-disjoint route R of length 1 , solving I, exists on G, then there is a vertex-disjoint path P from s to t through all waypoints of length 5 1 on L R (G). Conversely, if such a P of length 2 exists on L R (G), then there is a R for I of length ≤ 2 /5.
Proof of Theorem 21. Given a graph with integer edge weights and capacities, we first transform it into a graph G with unit edge weights and capacities, while being distancepreserving. First, we replace each edge with a capacity ≥ 1 with two parallel edges of identical weight, cf. Lemma 19. Second, each edge e with a weight of ω(e) is replaced by a path of length ω(e), which yields a distance-preserved graph with unit capacities. Third and last, to remove parallel edges, we place a vertex on every edge, obtaining the desired graph properties.
We now start with the case that an edge-disjoint route R of length 1 exists in G, solving I. We translate R into a vertex-disjoint path P in L R (G) of length 5 1 as follows: First, every edge e ∈ E is represented by a path of length 3 in L R (G), resulting in a length of 3 1 if we could pass through the "clique-expansions" K δ(v) (v) for free. Second, observe that all shortest paths through these K δ(v) (v) have a length of 2 -with sufficient vertex-disjoint paths to represent all crossings through v ∈ V performed by R. If v ∈ R contains a waypoint (or s, t), we let one of the crossings in L R (G) pass through v . When starting on s or ending on t, the path-length through the respective is K δ(v) (v) is only 1. As such, we showed the existence of a path P from s to t through all waypoints in L R (G) with a length of 3x + 2(x − 1) + 1 + 1 = 5 1 .
It is left to show that if such a P of length 2 exists on L R (G), then there is a R, solving I, of length ≤ 2 /5. We can think of P as follows: It starts in some K δ(v1) (v 1 ) on s, passes through some K δ(v2) (v 2 ), . . . , K δ(vr) (v r ) connected by paths of length 3, until it ends in some K δ(vr+1) (v r+1 ) on t. In this chain, the K δ(vi) (v i )s do not need to be pairwise disjoint. Observe that every of these paths of length 3 between the K δ(v) (v)s in L R (G) directly maps to an edge in G. By also mapping the v ∈ V to the extended K δ(v) (v)s, we obtain a one-to-one mapping between edge-disjoint walks in G and vertex-disjoint paths in L R (G), where the extended K δ(v) (v)s are contracted to a single vertex. Following the thoughts for the first case, we can shorten P to a path P such that every subsequent traversal of a K δ(vi) (v i ) in the chain only has a length of 2, which is shortest possible, with the paths through K δ(v1) (v 1 ) and K δ(vr+1) (v r+1 ) having a length of 1 each (except for the case of r = 0, which means we can set |P | = 0). Performing the translation of the first case in reverse, we obtain a solution W for I of length |P |/5 ≤ |P |/5 = y/5.
The statement of Theorem 21 also has implications for shortest solutions. If there is a shortest vertex-disjoint path in L R (G) of length 2 , but there exists a solution in G of length x 1 < 2 /5, then a solution of length less than 2 would also exist in L R (G), a contradiction.
Let us also briefly consider runtime implications. When modifying the graph G = (V, E) to be a simple graph G = (V , E ) with unit edge capacities and unit weights, let f (n) ≥ 1 be the largest edge weight ω(e) in G. It then holds that |V | and |E | are each at most |V | + 4|E|f (n). When considering L R (G ) = (V R , E R ), we obtain an upper bound (by a large margin) of 7|V | 2 + 48|V ||E|f (n) + 96|E| 2 (f (n)) 2 for both |V R | and |E R |, respectively. We further bound this term from above (again, by a large margin) via 199|V | 4 (f (n)) 2 . While this bound can be improved by careful inspection, especially in the size of the exponent, it suffices for the purposes of polynomiality.

Corollary 22.
Let A be an algorithm that finds a shortest vertex-disjoint solution for a path from s to t = s through all specified (waypoint) vertices, with the largest edge weight being of size f (n), in a runtime of a(k, |V |, f (n)). Using the waypoint line graph construction, algorithm A can be used to find a shortest solution to WRP in a runtime of a k, 199|V | 4 (f (n)) 2 , 1 .
In particular, if A has a runtime of 2 k n O(1) to find a cycle through k specified vertices in an n-vertex graph, we can obtain a runtime of 2 k (199n 4 (f (n)) 2 ) O (1) for WRP. If f (n) is a constant-value function or a fixed polynomial, this reduces to 2 k n O(1) for n ≥ 2. Similarly, if a is a polynomial function w.r.t. k, |V |, f (n), it will also be a polynomial function in n for the transformed WRP instances with inputs k, 199n 4 (f (n)) 2 , 1, assuming f (n) is a constant-value function or a fixed polynomial, as we can assume k < n.

D Deferred Proofs from Section 4
Proof of Corollary 16. Reduction from [57] which shows that the Hamiltonian cycle problem is NP-hard on grid graphs of maximum degree 3. Our reduction will not change these properties of the graph. Now fix some arbitrary r ∈ R ≥1 , setting r = r . For simplicity, we restrict ourselves to the grid graphs G of maximum degree 3 obtained in [57] by Buro's NP-hardness reduction. Restricting to G allows us to follow the arguments from [57] to obtain an appropriate embedding in polynomial time. 3 For any WRP on G ∈ G with k < n waypoints W, create a grid drawing in the plane. From this drawing, from all vertices with the smallest x-coordinates, pick the vertex v with the smallest y coordinate. Say v has coordinates (x(v), y(v)). By construction, v has at most a degree of two and there are no vertices with a smaller x-coordinate than v. As such, we can create a vertex v with coordinates (x(v) − 1, y(v)), and connect it to v with an edge of unit capacity. Observe that the set of solutions for WRP was not altered: Once v is visited, no walk can ever leave it. We now extend this idea, creating a path of length n r , placing its vertices at the coordinates (x(v) − 2, y(v)), (x(v) − 3, y(v)), . . . . Denote this extended graph by G = (V , E ) and observe that its main properties are preserved, however, k ∈ O(|V | 1/r ).
Proof of Corollary 17. Reduction from [56] which shows that the the Hamiltonian cycle problem is NP-hard on 3-regular bipartite planar graphs, denoted by G 3 . Observe that we can assume unit edge capacities, without losing the NP-hardness property. Again, our reduction will not change these properties of the graph, and analogously, we fix some arbitrary r ∈ R ≥1 , setting r = r . We can pick any edge e = (u, w) in a graph G 3 ∈ G 3 and replace the edge with a path of length three and capacity one, denoting the added vertices by v and v . The graph is still bipartite and planar, but v and v violate the 3-regularity. Notwithstanding, the feasibility of WRP stays unchanged: The "capacity" of the path between u and w via v and v is still one. Now, we create two full binary trees T, T with a roots T v , T v , each having 2 r − 1 vertices and 2 r −1 leaves. We can connect T v to v and T v to v , preserving bipartiteness and planarity. A small examplary construction can be found in Figure 4, already illustrating the next construction steps as well. Observe that all vertices except the leaves of T, T have a degree of exactly three. Next, we pick a standard embedding of T, T in the plane, s.t., w.l.o.g., the leaves v 1 , . . . , v 2 r −1 have coordinates (0, 1), . . . , (0, 2 r −1 ), similar for the leaves of T with (0, 2 r −1 + 1), . . . , (0, 2 · 2 r −1 ). We now place a vertex v m (1,2) , . . . , v m (2 r −1 −1,2 r −1 ) between each consecutive pair of leaves of T , 2 r −1 − 1 in total, same for T with vertices v m (1,2) , . . . , v m (2 r −1 −1,2 r −1 ) . Next, we connect these 2 · 2 r −1 − 2 vertices V m & V m with each leaf vertex next to them, also v 2 r −1 with v 1 and v 1 with v 2 r −1 , forming a cycle C through all leaves and the new 2 · 2 r −1 − 2 vertices. All vertices, except the aforementioned V m & V m with a degree of 2, have a degree of 3. Due to the bipartite property, one can color the (former) leaf vertices and V m & V m , with, e.g., blue and red: W.l.o.g., we pick red for the (former) leaves of T and V m , blue for the (former) leaves of T and V m . As the last construction step, we connect V m and V m , as follows, inside the inner face of the cycle C: First the two outermost vertices, v m 1,2 with v m (2 r −1 −1,2 r −1 ) , then going analogously inwards, lastly connecting v m (2 r −1 −1,2 r −1 ) and v m 1,2 . Denote this extended graph by G 3 = (V 3 , E 3 ) and observe that its main properties are preserved, however, k ∈ O(|V 3 | 1/r ).