NP-hardness of shortest path problems in networks with non-FIFO time-dependent travel times

We study the complexity of earliest arrival problems on time-dependent networks with non-FIFO travel time functions, i.e. when departing later might lead to an earlier arrival. In this paper, we present a simple proof of the weak NP -hardness of the problem for travel time functions deﬁned on integers. This simpliﬁes and reproduces an earlier result from Orda and Rom. Our proof generalizes to travel time functions deﬁned on rational numbers and also implies that, in this case, the problem becomes harder, i.e. is strongly NP -hard. As arbitrary functions are impractical for applications, we also study a more realistic problem model where travel time functions are piecewise linear and represented by a sequence of breakpoints with integer coordinates. We show that this problem formulation is strongly NP -hard, too. As an intermediate step for this proof, we also show the strong NP -completeness of SubsetProduct on rational numbers. © 2022 The Author. Published by Elsevier B.V. This is an open access article under the CC BY license (http://creativecommons.org/licenses/by/4.0/).


Introduction
Finding shortest paths in time-dependent networks is an important problem with numerous applications.A prominent example would be routing in road networks with traffic predictions, i.e. when the travel time of a road segment depends on the time of the day at which the segment is traversed.Another example is routing packets through computer networks when link capacities and delays depend on the time.The core problem in these applications is, given a source vertex, a target vertex and a departure time, to obtain the path with the earliest arrival at the target.This path is sometimes also referred to as a minimum delay path.
A critical property which time-dependent networks may or may not exhibit is the first-in-first-out (FIFO) property.Informally, this property holds when it is not possible to arrive earlier by departing later.For networks where this property holds, the earliest arrival problem can be E-mail address: tim.zeitz@kit.edu.solved with a variation of Dijkstra's algorithm [1].However, realistic networks may not always adhere to the FIFO property.For example in road networks, when an important tunnel can only be traversed during certain times, one may have to drive a longer detour when arriving too early while the tunnel has not yet opened.Of course, it may be possible to avoid such a detour by waiting.Likewise, non-FIFO networks can be transformed into FIFO networks when waiting is possible all the time at any vertex.However, allowing waiting at arbitrary locations and times is not always a realistic modeling assumption.Cars cannot park at arbitrary locations and network packets may be dropped when buffers become full.In this paper, we therefore study the complexity of the earliest arrival problem in networks with non-FIFO travel times when waiting is not allowed.
Related work Time-dependent shortest path problems were studied extensively in the past, both from a theoretic and practical perspective.As an extensive overview is beyond the scope of this work, we refer to the survey in [2].Most practical works assume that all travel times https://doi.org/10.1016/j.ipl.2022.1062870020-0190/© 2022 The Author.Published by Elsevier B.V. This is an open access article under the CC BY license (http://creativecommons.org/licenses/by/4.0/).adhere to the FIFO property or that arbitrary waiting is allowed [3][4][5][6].An exception is [7] where routing for truck drivers considering temporary driving bans is studied.
The complexity of the earliest arrival problem in non-FIFO time-dependent networks has been studied before, most prominently by Orda and Rom [8,9].In [8], they present several time-dependent shortest path algorithms and study different waiting policies.They prove that under certain assumptions allowing waiting at the source vertex is sufficient to find a path with the same arrival as the fastest path when arbitrary waiting is allowed.Also, they show that in some cases, the path with the earliest arrival may use an infinite number of hops.Many recent works [4,5,10,2] cite [8] stating that the earliest arrival problem in non-FIFO time-dependent networks is NP-hard.However, the paper just states that the hardness can be shown (second paragraph of Section 3.2) but does not provide any evidence.Some works [7,6,3] state the hardness referring to an unpublished manuscript by Orda and Rom [11].We were not able to find this manuscript in any public source but could only obtain it through personal contact with authors.In this manuscript, Orda and Rom proved the weak NP-hardness of the time-dependent earliest arrival problem with travel time functions defined on integers and forbidden waiting by reduction from Finite-FunctionGeneration. They also show that the problem can be solved in pseudo-polynomial time.However, since the proof is quite complex and was apparently never published, we believe that independently reproducing this result is a valuable contribution.
Contribution We contribute a simple proof of the weak NP-hardness of the earliest arrival problem on networks with time-dependent travel times defined on integers when waiting is forbidden.Additionally, this proof implies that the problem becomes strongly NP-hard when the functions are defined on rational numbers.Further, we show that the problem remains strongly NP-hard when we limit ourselves to a more practical travel time function model where functions are piecewise linear and given as a sequence of breakpoints with integer coordinates, but the computation is performed in the rational number domain.As an intermediate result we show that SubsetProduct on rational numbers is strongly NP-complete.

Preliminaries
We consider directed graphs G = (V , E) with n = |V | vertices and m = |E| edges.We use uv as a short notation for edges.Each edge uv has a travel time function f tt uv which maps a departure time τ to a travel time f tt uv (τ ) at that departure.We consider both functions defined on integers f : Z → Z and on rational numbers f : Q → Q. Realistic travel times are non-negative but here we also allow negative travel times for technical reasons.Sometimes, it is more practical to consider the arrival time function f at uv (τ ) = τ + f tt uv (τ ).For example, for two edges uv and v w, the travel time function for traversing them successively is f tt uv (τ ) + f tt v w (τ + f tt uv (τ )) while in arrival time representation the result is just the composition A travel time function f tt has the first-in-first-out (FIFO) property when the following holds: Assuming continuous functions, time intervals where the FIFO property is violated have slopes < −1 in travel time representation and slopes < 0 in arrival time representation.
A sequence of vertices P = (v 1 , . . ., v k ) where v i v i+1 ∈ E is called a path.Paths may be non-simple, i.e. contain the same vertex multiple times.We denote by P i, j = (v i , . . ., v j ), 1 ≤ i < j ≤ k a subpath of P .The travel time of a path P = (v 1 , v 2 , . . ., v k ) can be obtained recursively: We assume that the functions are given in some welldefined compact representation, for example piecewise constant or piecewise linear, which can be evaluated in polynomial time.For the first part of the paper, we leave the concrete function class unspecified.In the second part we use piecewise linear functions represented by a sequence of breakpoints.We define the travel times before the first and after the last breakpoints to equal the travel time of the first and last breakpoint, respectively.

Complexity results
In this section we present our complexity results.We start with the simplified NP-hardness proof for TDEA Z .Theorem 2. TDEA Z is weakly NP-hard.
Proof.We prove NP-hardness by reduction from the weakly NP-complete problem SubsetSum [12].A Subset-Sum instance consists of a multiset A of integers a i and a target value B. 1 The goal is to decide whether there is a subset A ⊆ A such that a∈ A a = B. We construct our TDEA Z instance as follows: The instance has vertices to v i .The first one denoted as e i has constant travel time zero and the second one denoted as e i constant travel time a i .We insert a final edge v k t with the following non-FIFO travel time function: To prove that the problem is not strongly NP-hard, we now give a pseudo-polynomial algorithm.Algorithm 1 shows the procedure in pseudo-code.The algorithm is a time-expanded variation of the shortest path algorithm of Bellman and Ford [13].Instead of a distance array, it maintains a 2-dimensional array indicating whether it is possible to reach a vertex at a given time.Instead of scanning edges |V | times, edges are relaxed for each instant between τ dep and τ max .This leads to a running time in O(τ max • |E|) which makes the algorithm pseudopolynomial in the input size.
For simplicity, we describe the algorithm under the assumption that all travel times are strictly positive.Travel times of zero can be handled by repeating the loop in line 4 |V | times.
We prove correctness inductively.We show that in step τ of the loop in line 3 for all vertices v, all possible arrival times τ ≤ τ have been correctly marked in R. Clearly, the base case holds, because in the absence of zero travel times, s is the only vertex reachable at τ dep .Assume the induction hypothesis for τ − 1.For any path (s, . . ., u, v) of Wojtczak showed in [14] that many common weakly NP-hard problems, including SubsetSum, become strongly NP-hard when defined on rational numbers.As our proof generalizes to rational numbers without modification, we get the following corollary: Corollary 3. TDEA Q is strongly NP-hard.
We now restrict ourselves to a function class used in many practical implementations: piecewise linear functions represented as a sequence of breakpoints.Evaluating the function at a time between two breakpoints is implemented through linear interpolation.As input data usually comes at a limited resolution, we assume that all breakpoint coordinates can be represented by integers.Nevertheless, the result of a linear interpolation may be a rational number.Thus, when performing the computation in the integer domain, one has to round.However, practical implementations often need to compute travel time functions for paths, for example to find the shortest travel time function between two nodes, i.e. solve profile queries.In the integer domain, this is very difficult because of the rounding.Therefore, many practical implementations [4,3,6] approximate computation in the continuous domain by using floating point numbers.This lead us to the question if TDEA Q on piecewise linear functions with integer coordinates is weakly or strongly NP-hard.
With piecewise linear functions with integer breakpoints, we cannot easily construct constant travel time functions with arbitrary rational travel times.Thus, the generalizing the reduction from SubsetSum is difficult.However, we can encode rational numbers in the slope of arrival time function and exploit that when compositing linear functions, the result function's slope is equal to the product of the slopes of the composed functions.In the following, we show the strong NP-hardness with a two-step reduction from SubsetProduct on rational numbers as an intermediate problem.On integers, SubsetProduct is weakly NP-complete [12,15]. 2 However, as we now show, when allowing rational numbers, the problem becomes strongly NP-complete.SubsetProduct is defined as follows: Definition 4 (SubsetProduct).Given a finite multiset of positive numbers A and a positive number B, is there a subset A ⊆ A such that a∈ A a = B? Theorem 5. SubsetProduct on rational numbers is strongly NP-complete.

Proof.
A guessed solution for SubsetProduct can be verified in polynomial time.In the worst case, all numerators and denominators in the solution would have to be multiplied with each other.Thus, SubsetProduct is in NP even with rational numbers.
For hardness, we reduce from the ExactCoverBy3Sets problem.It is strongly NP-complete due to [12] and defined as follows: Definition 6 (ExactCoverBy3Sets (X3C)).Given a set X = {x 1 , . . ., x k } with k being a multiple of 3, and a collection C of 3-element subsets of X , does C contain an exact cover C for X , where C ⊆ C and every element in X occurs in exactly one element of C ?
For the transformation, we first generate the first 2k + 1 primes.We refer to these primes in two groups of each k primes {p 1 , . . ., p k } and {p 1 , . . ., p k } and one final prime number p * .Generating these primes is possible in polynomial running time [14].We construct the set A = A X ∪ A C from one number for each element in X and one number for each 3-element set in C : 2 Garey and Johnson [12] state that SubsetProduct on positive integers is strongly NP-complete by reduction from ExactCoverBy3Sets with reference to private communication with A.C. Yao in 1978.This is somewhat surprising since there is no obvious reason why the pseudo-polynomial dynamic programming algorithm for SubsetSum should not be applicable to SubsetProduct.This strongly suggests that the problem is only weakly NP-complete and that the original reduction proved only weak hardness.Otherwise, this would prove P = NP.While we were unable to obtain the original proof, other realizations of the same reduction can be found online [16].This reduction uses a number exponential in the input size for the target product B. Clearly, this admits a pseudo-polynomial algorithm.As it turns out, on integers, the problem is only weakly NP-hard.Johnson's NP-completeness column later contains a correction [15].
Assume that the X3C instance admits a set C ⊆ C which covers X .Consider the set A = A X ∪ A C containing all elements from A X and all elements from A C corresponding to elements form C .By construction, the product over all numbers in A equals p * : It follows that the SubsetProduct admits a feasible subset, too.
Conversely, assume S is a fulfilling subset for the Sub-setProduct instance.First, since a k is the only element which contains p * as a factor, it must be contained in S .Secondly, note that if S contains any element from A X , it has to contain all elements in A X to cancel out the p i prime factors.The product of all elements in A X is equal to p * • x i ∈X p i .For the total product of all elements in S to be equal to p * , the product of the remaining elements in S has to equal exactly x i ∈X p −1 i .This can only be the case when the elements of C corresponding to these remaining elements in S form an exact cover of X .Thus, the X3C instance admits a feasible cover.
With the strong hardness of SubsetProduct on rational numbers, we can now prove our main result.Theorem 7. TDEA Q with piecewise linear functions represented by a sequence of breakpoints is strongly NP-hard even when all input numbers are integers.
q * be our SubsetProduct instance.First, we sort A in ascending order, i.e.
We then construct the TDEA Q instance as follows: Similarly to the hardness proof for TDEA Z , we build a graph with k + 2 vertices and two parallel edges e i and e i between v i−1 and v i for 1 ≤ i ≤ k and a final non-FIFO edge between v k and t.All edges e i get constant travel time zero.The edges e i get a time-dependent travel time function which has slope p i q i in the arrival time representation.The final edge has a travel time function with breakpoints (0, p * + 1) and (p * , 0).The topology is the same as in the previous proof as illustrated in Fig. 1.We set τ dep = q * and τ max = p * .We pick the breakpoints for the e i functions in such a way that the arrival time function has the correct slope at least for all times in [0, max(p * , q * )].Thus, with s i = max(p * ,q * ) q i the edge e i will have the arrival time function breakpoints (0, 0) and (s i q i , s i p i ).This transformation has polynomial running time and also all numbers are polynomial bounded in the size of the SubsetProduct instance.Some of these arrival time functions have slope < 1 and thus for τ ∈ [0, τ max ] we get f at (τ ) < τ .This means the corresponding travel time functions have negative travel times.We can obtain an equivalent instance without negative weights as follows: Let e i be an edge with a breakpoint (x, y) in the travel time function where y < 0. We increase the travel times of both e i and e i by the constant c = −y.Additionally, the departure times coordinates of breakpoints in every following travel time function must be increased by c, i.e. for (x, y) a breakpoint of a travel time function of an edge with head v j where j > i, this breakpoint will be set to (x + c, y).Also, τ max must be increased by c.Even though negative travel times are not necessary, we still use them during the rest of the proof because it simplifies the calculations.This also applies to travel times of zero which can be avoided similarly.
Suppose the SubsetProduct instance admits a subset A such that the product of all elements in A is B. We consider the st-path which uses e i when p i q i ∈ A and e i otherwise.When visiting vertex v i−1 at instant τ i−1 and traversing the edge e i with arrival time breakpoints (0, 0) and (s i q i , s i p i ) with τ i−1 ≤ s i q i , the arrival time at v i can be computed by linear interpolation: The final edge has a travel time of 0 at p * which leads to an arrival of p * at t which shows, that the TDEA Q instance admits a feasible path given that our assumption on the τ i holds.This assumption is valid because the elements of A and thus the slopes of the edges are ordered ascendingly.For all time is negative, and we arrive earlier than we started, so τ i < q * holds.Once edges with p i q i > 1 are reached, the τ i grow monotonically.But since the final result p * is within the desired range, all intermediate τ i have to be, too.Thus, the assumption holds for all τ i .
Conversely, assume the TDEA Q instance admits a path P with the desired arrival time.This is only possible when τ k = p * because before p * , the arrival time function has a strictly negative slope and after p * a strictly positive slope.With the same argument as in the previous paragraph, we get that all τ i ≤ max(p * , q * ).Hence, the following equation holds: τ dep • a i ∈P s i p i s i q i = τ max = p * which is equivalent to a i ∈P p i q i = p * q * .Thus, the set A = { p i q i | a i ∈ P } is a fulfilling subset for the SubsetProduct instance.
So far, we only discussed NP-hardness but not inclusion in NP.On first glance, it appears likely that the TDEA problem lies in NP because verifying path lengths takes running time linear time in the path length.However, this is not sufficient because solutions might have superpolynomial length in the input size.Consider a graph with two vertices s and t, one loop edge at s with constant travel time 1 and one st edge with travel time 0 at instant 2 k and travel time 2 k+1 during the rest of the time as depicted in Fig. 2. For an instance with τ dep = 0 and τ max = 2 k , the solution is a path which uses the loop at s 2 k times.A naive encoding of this solution would already be exponentially bigger than the (binary encoded) input.Even if it would be possible to show that a compact encoding of solutions is always possible, one would still need to find a way to evaluate the travel time of this path in polynomial running time in the input size.Whether this is possible likely strongly depends on the involved function classes.Therefore, the question remains open.Nevertheless, since we only used acyclic graphs in our reductions, we can still conclude that when only allowing simple paths, the TDEA problem is NP-complete.

Conclusion
In this work, we presented a simple transformation from SubsetSum to the TDEA Z problem which confirms its weak NP-hardness.Relating our proof to a recent result on the strong NP-hardness of SubsetSum on rational numbers showed that TDEA Q on arbitrary rational functions is strongly NP-hard, too.Finally, we showed that the problem remains strongly NP-hard for a typical practical model when the travel times are piecewise linear functions defined on rational numbers but all coordinates are integers.

Declaration of competing interest
The authors declare that they have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.

1 Function 2 R 6 if u = t then 7 return true; 8 RAlgorithm 1 :
Data: R[u][τ ]: 2-dimensional array of booleans indicating whether it is possible to arrive at vertex u at time τ Data: G = (V , A): Directed graph with travel time functions f tt e for each e ∈ E TimeExpandedBellmanFord(s, t, τ dep , τ max ): [s][τ dep ] ← true; 3 for τ ∈ [τ dep , τ max ] do 4 for uv ∈ E do 5 if R[u][τ ] then [v][τ + f tt uv (τ )] ← true; Time-expanded Bellman-Ford algorithm.travel time τ − τ dep the vertex u was reachable at a time τ < τ .Thus, R[u][τ ] was correctly set, the outgoing edges of u were relaxed and R[v][τ ] will also be set which completes the inductive step.Repeating the loop in line 4 |V | times would additionally allow intermediate paths of travel time zero with up to |V | vertices, which clearly suffices to solve this case, too.

Fig. 2 .
Fig. 2. Example graph with a shortest path with an exponential number of hops.