Efficient Computation of Optimal Temporal Walks under Waiting-Time Constraints

Node connectivity plays a central role in temporal network analysis. We provide a comprehensive study of various concepts of walks in temporal graphs, that is, graphs with fixed vertex sets but edge sets changing over time. Taking into account the temporal aspect leads to a rich set of optimization criteria for"shortest"walks. Extending and significantly broadening state-of-the-art work of Wu et al. [IEEE TKDE 2016], we provide an algorithm for computing optimal walks that is capable to deal with various optimization criteria and any linear combination of these. It runs in $O (|V| + |E| \log |E|)$ time where $|V|$ is the number of vertices and $|E|$ is the number of time edges. A central distinguishing factor to Wu et al.'s work is that our model allows to, motivated by real-world applications, respect waiting-time constraints for vertices, that is, the minimum and maximum waiting time allowed in intermediate vertices of a walk. Moreover, other than Wu et al. our algorithm also allows to search for walks that pass multiple subsequent edges in one time step, and it can optimize a richer set of optimization criteria. Our experimental studies indicate that our richer modeling can be achieved without significantly worsening the running time when compared to Wu et al.'s algorithms.


Introduction
Computing shortest paths in networks is arguably among the most important graph algorithms. It is relevant in numerous application contexts and used as a subroutine in a highly diverse set of applications. While the respective problem has been studied for static graphs for decades, over the last years there has been an intensified interest in studying shortest path computations in temporal graphs-graphs where the vertex set remains static, but the arc set may change over time (in discrete time steps). Related Work. The theory of temporal graphs is a relatively young but active field of research (Holme 2015;Holme and Saramäki 2012;Holme and Saramäki 2013;Holme and Saramäki 2019). Many of the basic concepts of temporal graphs such as temporal connectivity (Kempe et al. 2002;Nicosia et al. 2012;Axiotis and Fotakis 2016;Mertzios et al. 2019) or s-z-separation ) are based on the notion of temporal paths and walks. The concept of optimal temporal walks plays Fig. 1 A temporal graph (with time-labeled arcs called time-arcs) with maximum waiting time four in which the only temporal walk from A to C visits B twice a central role in the definition of temporal graph metrics such as eccentricity, diameter, betweenness and closeness centrality (Pan and Saramäki 2011;Santoro et al. 2011;Kim and Anderson 2012;Buß et al. 2020).
An early algorithm for computing optimal temporal walks is due to Xuan et al. (2003). They computed temporal walks under different optimization criteria, namely foremost, fastest, and minimum hop-count. Wu et al. (2016) followed up by introducing algorithms for computing optimal walks for the optimization criteria foremost, reverse-foremost, fastest, and shortest on temporal graphs with no waiting-time constraints. Their algorithms run in linear and quasi-linear time with respect to the number of time-arcs, provided that transmission times on time-arcs are greater than zero. Concerning timedependent multicriteria optimal path computation, there has been research in the related field of route planning (Bast et al. 2016).
The study of minimum-and maximum-waiting-time constraints in vertices has not received much attention in the context of temporal walks even though they are considered as important extensions to the temporal walk model (Holme and Saramäki 2012;Pan and Saramäki 2011). One of the first papers to consider waiting-time constraints in the context of paths is due to Dean (Dean 2004). Dean showed that time-dependent shortest path problems with waiting constraints can be solved in polynomial time. Dean's setting is closely related to waiting-time constraints for optimal temporal walks. In more recent work, Modiri et al. (2019) and Kivelä et al. (2018) studied the changes in reachability when introducing maximum-waiting time constraints for temporal walks using so-called event graphs. Lastly, Casteigts et al. (2019) have very recently shown that finding optimal temporal paths under maximum-waiting-time constraints is NP-hard.
In the so-called multistage setting, where multiple graphs over the same vertex set are considered without a (temporal) ordering, paths have been studied by .
Our Contributions. We analyze the running time complexity of computing optimal temporal walks under waiting-time constraints. To this end, we develop and (theoretically and empirically) analyze an algorithm for finding an optimal walk from a source vertex to each vertex in the temporal graph under waiting-time constraints. Our algorithm runs in quasi-linear time in the number of time-arcs. This implies that the additional consideration of waiting-time constraints on temporal walks does not increase the asymptotic computational complexity of finding optimal temporal walks. Moreover, our algorithm can compute optimal walks not only for single optimality criteria but also for any linear combination of these. In experiments on real-world social network data sets, we demonstrate that in terms of efficiency our algorithm can compete with state-of-the-art algorithms by Wu et al. (2016). Their algorithms only run on temporal graphs without waiting-time constraints, which do optimize only one criterion (and not a linear combination). Additionally, our algorithm allows transmission times being zero (hence, allowing to pass multiple arcs in one time step) while the algorithms of Wu et al. request transmission times on arcs to be greater than zero.
Organization of the Paper. In "Modeling of optimal temporal walks" section, we discuss temporal graphs, temporal walks, and the various corresponding optimality criteria, starting with an extensive motivating example in the context of disease spreading. In "Formal definitions" section, we introduce definitions and notations used throughout the paper. We continue in "Transformation" section by presenting two simple linear-time transformations to eliminate transmission times and minimum waiting times in the temporal graph without loosing any modeling power. In "Algorithm" section, we design and analyze an algorithm for computing optimal walks under maximum-waiting-time for any linear combination of these. Finally, in "Experimental results" section, we demonstrate the efficiency of our algorithm on realworld data sets. We compare our running times with the running times of the algorithms of Wu et al. (2016). We further examine the impact of different maximum-waiting-time values on the existence and structure of optimal temporal walks.

Modeling of optimal temporal walks
Before we introduce our basic concepts relating to temporal graphs and walks, we start with a more extensive discussion of a motivating example from the disease spreading context.
Disease Spreading Motivating Example. Pandemic spread of an infectious disease is a great threat to global health, potentially associated with high mortality rates as well as economic fallout (Salathé et al. 2010). Understanding the dynamics of infectious disease spreading within human proximity networks could facilitate the development of mitigation strategies.
A large part of the study required to understand the dynamics of infectious diseases is the analysis of transmission routes through proximity networks (Salathé et al. 2010). Classical graph theory can be used to model the main structure of a network: Each person in the network is represented by a node and an arc between two nodes indicates the possibility of an infection from one person to the other. However, the time component plays a crucial role in the analysis of transmission routes of a potential disease as shown in the following example: Example 1 Studying a proximity network as shown in Fig. 2a  In addition to what has been said so far, the infectious period of a disease also has to be taken into account when computing potential transmission routes through the network, implying the minimum time a person has to be infected before she becomes contagious herself and the maximum time a person can be infected before she is no longer contagious: Temporal Graphs. These are capable of modeling both properties elaborated in the two examples above. Temporal graphs are already a frequently used model in the prediction and control of infectious diseases (Masuda and Holme 2013;Holme 2016). Temporal graphs-also referred to as temporal networks (Nicosia et al. 2013;Holme and Saramäki 2012), evolving graphs (Xuan et al. 2003), or time-varying graphs (Santoro et al. 2011;Casteigts et al. 2012)-are graphs where the arc set changes over time; thus, they can capture the dynamics within a proximity network.
In this paper, we will consider the following temporal graph model: A temporal graph consists of a set of vertices, a set of time-arcs, and a lifetime. A time-arc is a (directed) arc between two vertices that is associated with a time stamp at which the contact occurs and a transmission time that indicates the amount of time to traverse the arc. Furthermore, each vertex v is assigned an individual minimum waiting time α(v) and maximum waiting time β(v).
The application areas of temporal graphs are numerous: In addition to human and animal proximity networks, they are used in communication networks, traffic networks, and distributed computing, to name a few application areas (Holme and Saramäki 2012;Holme and Saramäki 2013;Holme and Saramäki 2019).
In our running disease spreading example, we are interested in transmission routes of an infectious disease. These transmission routes can revisit a person in the proximity network due to possible reinfection (Barabási 2016). Hence, the transmission routes can contain cycles which needs to be considered in the choice of concepts representing these routes.

Temporal Walks & Optimal Temporal Walks.
Within the temporal graph model, temporal walks-also called journeys (Xuan et al. 2003;Nicosia et al. 2013)-are the fundamental concept that represents the transmission routes in our running example.
A temporal walk is a sequence of time-arcs which connects a sequence of vertices and which are non-decreasing in time. A temporal path is a temporal walk where all vertices are pairwise distinct. Maximumwaiting-time constraints have significant impact on temporal walks. In a temporal graph with constraints on the maximum waiting time, one can be forced to make detours because the maximum waiting time in a vertex is exceeded. As a consequence, there can be two vertices A and C such that any temporal walk from A to C is not a path, as shown in Fig. 1.
be a temporal graph with maximum-waiting-time constraints. Then there can exist two vertices s, z ∈ V such that no s-z-walk is a temporal path.
We are interested in temporal walks within our proximity network in general, but wish to place emphasis on temporal walks that optimize certain properties. A plethora of criteria can be optimized as a consequence of the time aspect. Possible criteria (with the chosen names in brackets) include: arrival time (foremost), departure time (reverseforemost), duration (fastest), transmission time (shortest), number of time-arcs (minimum hop-count), time-arc cost (cheapest), probability (most-likely), and waiting time (minimum waiting time). Next, we provide examples for all properties from their respective fields of application.

Foremost.
A foremost walk is a temporal walk that has the earliest arrival time. Computing a foremost walk from a source vertex to all vertices in the proximity network determines the speed with which an infectious disease could spread. Reverse-Foremost. A reverse-foremost walk is a temporal walk that exhibits the latest possible departure time. Computing a reverse-foremost walk from a source vertex to all vertices in the proximity network estimates the latest possible point in time at which an infectious disease could start spreading and still permeates the entire network. Fastest. A fastest walk is a temporal walk which exhibits the minimum travel duration, that is, the minimum difference between departure and arrival times. For an appropriate motivation, we leave proximity networks and consider the field of flight networks. Airports represent vertices, time-arcs represent flights from one airport to another. The time stamp of a time-arc indicates the departure time of a flight, the transmission time of the arc indicates the flight duration. The minimum waiting time in the vertices signifies the minimum time required to spend in an airport to catch a connecting flight. Within flight networks, the duration is often the criterion passengers aim to minimize in order to streamline their journeys. Shortest. A shortest walk is a temporal walk that minimizes the sum of transmission times on the time-arcs. In the context of flight networks, a shortest walk is a flight connection with the minimum time spent airborne. Minimum Hop-Count. A minimum-hop-count walk is a temporal walk which minimizes the number of time-arcs. Within a flight network, passengers also aim to minimize their number of connecting flights to avoid lengthy boarding procedures and the risk of missing connecting flights. Cheapest. For a given cost function on the time-arcs, a cheapest walk is a temporal walk with the minimum sum of costs over all time-arcs. The benefits of the minimization of this property within flight networks are obvious: Weighing long travel times and multiple connections against the cheapest fare is the oldest consideration in the book for many air travelers. Most-Likely. For given probabilities on the time-arcs, a most-likely walk is a temporal walk with the highest probability. One application lies in disease spreading: For every contact there is a certain likelihood for an infectious disease to be transmitted depending on the proximity of the persons or the body contact between them. Thus, a most-likely walk is a transmission route with the highest probability for the infectious disease to be spread under the simplifying assumption of stochastic independence. The respective probabilities of the time-arcs within the walk are multiplied. Minimum Waiting Time. The minimum-waiting-time walk is a temporal walk whose total sum of waiting times over all intermediate vertices is minimum. Routing packets through a router network prioritizes minimum waiting times of packages in the routers to improve the overall performance of the network.

Formal definitions
In this section, we formally introduce the most important concepts related to temporal graphs, temporal walks, and formalize our optimality criteria. We start with some basic mathematical definitions. We refer to an interval [ a, b] as a contiguous ordered set of discrete time steps: Temporal Graphs. A temporal graph is a graph whose arc set changes over time. We remark that the central modeling aspect in our work-the minimum and maximum waiting times-is so far not commonly part of the definition of temporal graphs. A timearc (v, w, t, λ) ∈ E is a directed connection from v to w with time stamp t and transmission time λ, that is, a transmission from v to w starting at time step t and taking λ time steps to cross the arc. The departure time in vertex v is t; the arrival time in vertex w is then t + λ. The two waiting-time functions α : V → N and β : V → N assign each vertex a minimum and maximum waiting time, respectively. The minimum waiting time α(v) is the minimum time a person has to stay in a vertex v before she can move on in the temporal graph. The maximum waiting time β(v) is the maximum time a person can stay in a vertex v before she is no longer allowed to move further in the graph. A temporal Then, for the ease of presentation, we neglect α and we write arcs as triples (v, w, t) ∈ E for instantaneous graphs.
In Table 1, we introduce some notation for temporal graphs.

Temporal Walk.
A temporal walk is a walk in a temporal graph such that the time stamps of the visited time-arcs of a temporal walk are non-decreasing in time. Additionally, the transmission time and the waiting-time constraints have to be taken into account.

Definition 2 (Temporal Walk) Given a temporal graph G = (V , E, T, α, β) and two vertices s, z ∈ V , a temporal walk of length k from s to z is a sequence
A temporal path is a temporal walk where all vertices are pairwise distinct. We use the notation P = ( for a temporal walk or a temporal path, that is, a sequence of k time-arcs. The value of k is the length of P and for each i ∈[ k] the tuple The value of λ i is the time needed to traverse the time-arc, that is, one arrives at time step t i + λ i at v i .
Optimal Temporal Walk. Due to the time aspect, there are several, potentially contradicting criteria that can be optimized in a temporal walk. We formally define the criteria that were already motivated in "Modeling of optimal temporal walks" section. Table 1 Frequently used notation for a temporal graph G. The first part shows global variables, the second part shows frequently used local variables

from s to z is called optimal if it minimizes or maximizes a certain value among all temporal walks from s to z:
criterion min / max optimization value Note that the most-likely criterion can easily be transformed into cheapest. For the mostlikely criterion, the cost values of the time-arcs represent probabilities, implying c(e) Hence, we neglect considering the most-likely criterion separately. We further call a tem- from s to z an optimal temporal walk with respect to a linear combination with δ 1 , . . . , Minimum Waiting Time among all temporal walks from s to z.

Transformation
To simplify the presentation of the forthcoming algorithm in "Algorithm" section for computing optimal temporal walks, we design it to run only on instantaneous temporal graphs, that is, temporal graphs with no transmission times (λ = 0 for all (v, w, t, λ) ∈ E) and no minimum-waiting-time constraints (α(v) = 0 for all v ∈ V ). This is no restriction since we can eliminate these with the following transformation.
Transformation 1 (Remove α and λ.) Let G = (V , E, T, α, β) be a temporal graph and let c : We now show that any temporal graph can be transformed by Transformation 1 into an equivalent instantaneous temporal graph in linear time such that any optimal temporal walk in the instantaneous temporal graphs directly corresponds to an optimal temporal walk in the original graph and vice versa. To this end, we have to slightly adapt the formula for the linear combination as shown in the following proposition. For δ 1 , . . . , δ 7 ∈ Q + 0 , there exists a temporal walk P : from s to z in G which is optimal with respect to a linear combination of δ 1 , . . . , δ 7 if and only if the temporal walk from s to z in G is optimal with respect to the new formula for a linear combination of our optimality criteria defined as follows: c(e i ) Cheapest Transformation 1 runs in O(|V | + |E|) time.
Proof We will show that any temporal walk P in G corresponds to a temporal walk P in G such that lin(P) = lin T (P ) and vice versa. To this end, observe that each vertex v ∈ V E has an in-going and an out-going arc and the vertex set V = V \ V E is an independent set in G . Hence, each temporal walk in G from s to z alternately uses vertices in V and V E . Since each vertex in V E represents an arc in G, each temporal walk in G has a unique representation in G and vice versa. It remains to show that lin(P) = lin T (P ) − C for any temporal walk P in G where C is a constant only depending on the last vertex in P. Observe that by construction each vertex v i in P is the same vertex as v 2i in P and the arc is represented by the vertex v 2i and the arcs e 2i−1 and e 2i . It Observe that (δ 1 + δ 3 ) · A(v 2k ) is independent of the temporal walk P and hence any optimal walk P in G corresponds to an optimal temporal walk P in G . Lastly, notice that Transformation 1 runs in O(|V | + |E|) time.
The algorithm for computing optimal temporal walks that we will introduce in the forthcoming section will find temporal walks optimizing the formula lin T (·) introduced in Proposition 1. For instantaneous temporal graphs, where we do not have to use Transformation 1, optimizing according to lin T (·) is not a drawback as stated in the following (recall that the definitions of lin and lin T depend on the parameters δ 1 , . . . , δ 7 ): E, T, β) be an instantaneous temporal graph and let c : E → N be a cost function. Let further P :

Algorithm
In this section, we present a single-source optimal-walks algorithm with respect to any linear combination of our optimality criteria. That is, given a temporal graph G = (V , E, T, β), a cost function c : E → N, and a source vertex s ∈ V , we compute optimal temporal walks with respect to any linear combination with δ 1 , . . . , δ 7 ∈ Q from s to all vertices in the temporal graph (if they exist). To this end, we first apply Transformation 1 to G to obtain an instantaneous temporal graph. Algorithm 1 then performs for each t ∈[ T] three main steps: GraphGeneration. Generate graph G which only contains the arcs present at time step t and add arcs from s to each vertex v in G that has been reached within the last β(v) time steps. ModDijkstra. Run a modified version of Dijkstra's algorithm to compute for each v in G the optimal walk from s to v that arrives at time step t (if it exists). Update. Update a list storing information on optimal walks from s to each v ∈ V . More precisely, for each v ∈ V a list of tuples of arrival times and corresponding optimal values is updated.
Efficiently storing and accessing the value of an optimal walk from s to v that arrives at a certain time step t is the heart of the algorithm. We can maintain this information in O(|E|) time during a run of Algorithm 1 such that this information can be accessed in constant time, leading to the following theorem: Theorem 1 With respect to any linear combination of the optimality criteria, optimal temporal walks from a source vertex s to each vertex in a temporal graph G = (V , E, T, β) can be computed in O(|V | + |E| log |E|) time.
Algorithm Details. Let G be a temporal graph with a cost function c : E → N and let s ∈ V be the source. We can apply Transformation 1 to (G , c ) to obtain (G = (V , E, T, β), c, c λ , ind, A) where G is an instantaneous temporal graph. If G is already an instantaneous temporal graph, then we set c = c , c λ ≡ 0, ind ≡ 1, and A ≡ 0 as justified by Observation 2.

Algorithm 1: Computes optimal walks.
Input: An instantaneous temporal graph G = (V , E, T, β), two cost functions c, c λ , two vertex functions ind, A, and a source vertex s ∈ V . Output: For each v ∈ V the specific length of an optimal s-v walk. Variables : opt(v) stores the value of an optimal walk from s to v within time interval [ 0, t]; is a sorted list [ (opt a 1 , a 1 ), . . . , (opt a k , a k )] where opt a i is an optimal value of a walk from s to v that arrives at time a i with t + β(v) ≤ a i ≤ t. δ 1 , ..., δ 7 linear combination of the optimality criteria foremost, reverse-foremost, fastest, shortest, cheapest, minimum hop-count, and minimum waiting time, respectively.
, t) and delete redundant tuples (see Lemma 1) 8 return opt / * GraphGeneration step: Generate graph G which only contains the arcs present at time step t and add arcs from s to each vertex v in G that has been reached within the last β(v) time steps. * / 9 function generateGraph(G t ): / * ModDijkstra step: Returns all vertices V with an arrival time exactly at time step t and their optimization value d : For given δ 1 , . . . , δ 7 ∈ Q, Algorithm 1 for all v ∈ V now computes an optimal walk P = We have shown in Proposition 1 that an optimal walk with respect to lin T (P) in G directly corresponds to an optimal walk with respect to lin(P) in the original temporal graph G . For each vertex v ∈ V \ {s}, Algorithm 1 stores in opt(v) the value of an optimal walk from s to v and in L(v) a list of all relevant arrival times from s to v with their optimal values. In the beginning, opt(v) = ∞ and L(v) is an empty list (Line 1 in Algorithm 1). Then, for each time step t and each v ∈ V , Algorithm 1 computes the optimal walk from the source s to v that arrives in time step t (if it exists). Thus, Algorithm 1 performs for each t ∈ {1, . . . , T} the following steps: GraphGeneration. Generate a static graph G with GenerateGraph (Line 3 and Lines 9 to 19). This graph consists of the static graph G t = (V t , E t ), that is, the static graph induced by all time-arcs with time stamp t, and the source vertex s. The weight of an arc (v, w) ∈ E t is set to δ 4 · c λ (v, w) + δ 5 · c(v, w) + δ 6 . If further v = s, then we have to add (δ 2 + δ 3 ) · (T − t) to take the departure time in s into account for the criteria reverse-foremost and fastest, see Line 12.
Additionally, non-existing arcs from s to each vertex v ∈ V t are added if there exists a temporal walk from s to v that arrived not later than β(v) time steps ago. Let opt a be the optimal value among all walks that arrive within the time interval [ t − β(v), t] and let a be the corresponding arrival time in v. Additionally, the minimum waiting time A(v) plus the additional waiting time (t − a) in v has to be taken into account if ind(v) = 1. Hence, the weight of arc (s, v) is set to opt a + δ 7 · ind(v) · (t − a + A(v)), see Line 18. Let E r be the set of these additional arcs. Then, G =

ModDijkstra. Run a modified Dijkstra Algorithm on G with modDijkstra (Line 4 and
Lines 20 to 31). Instead of computing a shortest walk (using the original Dijkstra Algorithm) in G, compute a shortest walk among all walks that end in an arc of E t . This represents a temporal walk that arrives in time step t with optimal value. The function modDijkstra returns the set V of vertices that can be reached within G via an arc in E t and the function opt t : V → N that maps each vertex v ∈ V to its optimal value of a walk from s to v arriving exactly at time t. Update. For each v ∈ V , set the optimum opt(v) to the minimum of its current value and the optimal value of a newly computed walk, that is, opt(v) := min{opt(v), δ 1 · t + δ 3 · (t − T) + opt t (v)} (Line 6). Herein, we have to add the arrival time t that has not been taken into account in the calculation of the optimal value because it is the same for all walks found at time step t. Add the tuple (opt t (v), t) to list L(v) (Line 7).
After the Update step for time step t, the list L(v) contains all tuples (opt ar , ar) such that there exists a walk from s to v that arrives at time ar ∈[ t − β(v), t] with its optimal cost value opt ar . We want to have constant-time access to the optimal value of a walk that arrives in v within time interval [ t − β(v), t]. This can be achieved by deleting tuples from list L(v) that are redundant, that is these tuples are not meaningful for the correct computation of optimal walks. Let [ (opt a 1 , a 1 ), . . . , (opt a k , a k )] be such a list for a time step t with t − β(v) ≤ a 1 < . . . < a k ≤ t. A tuple (opt ar , ar) is redundant if there exists a tuple with an arrival time greater than ar such that its optimal value is smaller than opt ar plus the additional waiting time. This is shown with the following lemma: Lemma 1 For a time step t ∈ {1, . . . , T} and a vertex v ∈ V , if there are two tuples (opt a i , a i ), (opt a j , a j ) ∈ L(v) with a i < a j and

then (opt a i , a i ) is redundant and can be removed from L(v).
Proof After all time-arcs with time stamp t have been processed, Algorithm 1 only considers time-arcs with time stamp t > t. In the generated graph G (Line 3), the algorithm adds an arc from Furthermore, let (opt, a) be the optimal value and the arrival time of a walk from s to v that arrives within time Then, the weight of the arc (s, v) is set to this value. Since a i < a j ∈[ t − β(v), t ] and opt a i + δ 7 · ind(v) · (a j − a i ) ≥ opt a j , we know that Hence, the tuple (opt a i , a i ) is not needed in the list L(v) at time step t and can be removed.
Hence, (a 1 , opt a 1 ) contains the optimal value and arrival time of a walk that arrives within time interval [ t − β(v), t] and minimizes opt + δ 7 · ind(v)(t − a + A(v)). It follows that finding opt = min{opt a | (opt a , a) ∈ L(v)} in Line 18 takes constant time. The deletion of redundant tuples takes O(|E|) time during the whole run of Algorithm 1. With these considerations at hand, we can derive the following lemma. For each generated graph G, modDijkstra is executed in O(|E t | log |E t |) time. The updates of opt and L afterwards run in O(|V t |) time. Note that |V t | is the number of vertices that have at least one in-going or out-going time-arc at time step t. Consequently, it holds that |V t | ≤ 2|E t |.
Due to the sorting of L(v), maintaining these lists in Lines 15 and 7 takes O(|E|) time during the whole run of the algorithm as shown Lemma 1. In the list L(v), we delete at most as many elements as there are time-arcs in the temporal graph. Recall that if (opt a , a) ∈ L(v), then there exists a time- arc (w, v, a) ∈ E.
We can analyze the running time by Hence, Algorithm 1 runs in O |V | + |E| log |E| time.
Next, we show the correctness of Algorithm 1. We prove that for every time step t and for every vertex v, Algorithm 1 computes an optimal walk from s to v that arrives at time step t (if it exists).

Lemma 3 For a time step t ∈[ T] and a vertex v ∈ V , Algorithm 1 computes the optimal value of a temporal walk from s to v that arrives exactly in time step t.
Proof The proof is by induction on the time step t ∈ {1, . . . , T}. In the beginning, L(v) is empty. For t = 1, the algorithm generates a graph G = (V 1 ∪ {s}, E 1 ). For all arcs (s, w) ∈ E 1 , the weights are set to for the other arcs (v, w) ∈ E 1 the weights are set to Note that if there is an optimal temporal walk arriving in time step 1, then there also exists an optimal temporal walk arriving at time step 1. Now if there is an optimal walk P = from s to a vertex v ∈ V that arrives exactly in time step 1, then there exists a path P = ( Algorithm 1 finds in modDijkstra the path P , adds (opt 1 (v), 1) to L(v) and sets Note that A(v i ) = 0 for i ∈[ k − 1] by Transformation 1 in time step 1. If there exists an optimal path P * in G, then this directly translates to the existence of a temporal path P that arrives also in time step 1 with a smaller optimal value than P, contradicting the assumption that P is optimal. Now, let us assume that for all time steps t ∈ {1, . . . , t} Algorithm 1 computed the optimal value opt of a walk from s to v ∈ V that arrives exactly in time step t and added If for time step t + 1 a vertex v ∈ V has no in-going time-arc with time step t + 1, then there cannot exist a temporal walk from s to v that arrives exactly in time step t + 1. Thus, only vertices in V t+1 are candidates for a temporal walk that arrives exactly in time step t + 1.
Let v ∈ V t+1 be a vertex such that there is a temporal walk from s to v that arrives exactly in time step t + 1.
be an optimal walk from s to v that arrives exactly in time step t + 1 with the optimal value Assume towards a contradiction that Algorithm 1 does not find a walk from s to v with optimal value lin T (P).
First consider the case that t i = t + 1 for all i ∈[ k], that is, all time-arcs of the temporal walk P have time stamp t + 1. Then, we can assume that P is a temporal path. Hence there exists a path P = ( Algorithm 1 finds in modDijkstra the path P , adds (opt t+1 (v), t + 1) to L(v), and updates opt(v) to the minimum of opt(v) and Note again that A(v i ) = 0 for i ∈[ k − 1] if t i−1 = t i by Transformation 1. Hence, we find a walk from s to v at time step t + 1 with optimal value lin T (P), contradicting our assumption.
Now assume for P that there exists an ∈ {1, . . . , k − 1} such that for j ∈[ ] it holds that t j < t + 1 and for j ∈ {i + 1, . . . , k} it holds that t j = t + 1. The temporal walk is an optimal subwalk from s to v that arrives exactly in time step t , otherwise P is not optimal because it could be improved by replacing P . The subwalk P has an optimal value By our induction hypothesis, the tuple (opt t (v ), t ) was added to L(v ). If the tuple (opt t (v ), t ) is not in L(v ) in time step t + 1, then due to Lemma 1 there must be another tuple (optˆt (v ) Otherwise P is not optimal because it could be improved by replacing P by the temporal walk represented by (optˆt(v ),t).
Now consider the generated graph G = (V t+1 ∪{s}, E t+1 ∪ E r ). The arc sequence P t+1 = E t+1 ) and, thus, contained in G. The arc a = (s, v ) is contained in E r with weight Thus, there is a walk from s to v in G and modDijkstra on G returns the vertex v because a k ∈ E t+1 with the optimal value Note that by Transformation 1 A(v i ) = 0 for i ∈[ + 1, k − 1] if t i−1 = t i . Consequently, the tuple (opt t+1 (v), t + 1) is added to L(v) and opt(v) is set to the minimum of its current value and This is a contradiction to our assumption.
Lastly, observe that the algorithm only computes temporal walks that are contained in G as it only uses arcs from G t which all correspond to temporal walks in G (single arcs or longer walks starting in s). Thus, for t ∈ {1, . . . , T}, Algorithm 1 computes an optimal temporal walk from s to v ∈ V that arrives exactly in time step t.
Based on this statement, we can finally prove the correctness of Algorithm 1. This concludes the proof of Theorem 1.
Lemma 4 Algorithm 1 computes optimal walks from a given source vertex s to all vertices.
be a walk with minimum lin T (P) among all temporal walks from s to a vertex v. The walk P is also an optimal walk from s to v that arrives exactly in time step t k . This is computed by Algorithm 1 in time step t k as shown in Lemma 3.

Experimental results
We implemented Algorithm 1 and performed experimental studies including comparisons to existing state-of-the-art algorithms by Wu et al. (2016). Note that the algorithms by Wu et al. (and our algorithm as well) are Dijkstra-like algorithms adjusted to the specific temporal setting. A notable difference is that our algorithm stops the graph exploration if no more vertex can be visited, whereas the algorithms by Wu et al. (2016) always iterate over all time-arcs. We show that our algorithm-while being able to solve a more general problem-can compete with these algorithms on real-world instances for the special case of computing temporal walks with no maximum-waiting-time constraints. We further examine the influence of different maximum-waiting-time values on the existence and structure (e.g., the number of cycles) of optimal temporal walks and on the running time of Algorithm 1.

Setup and statics
We implemented Algorithm 1 in C++ (v11) and performed our experiments on an Intel Xeon E5-1620 c omputer with 64 GB of RAM and four cores clocked at 3.6 GHz each. The operating system was Debian GNU/Linux 7.0 where we compiled the program with GCC v7.3.0 on optimization level -O3. We compare Algorithm 1 to the algorithms of Wu et al. (2016) using their C++ code and testing it on the same hardware and with the same compiler. We tested our algorithm on the same freely available data sets as Wu et al. (2016) from the well-established KONECT library (KONECT 2017). The graphs are listed in Table 2 with some relevant statistics.

Findings
In the following, we first compare Algorithm 1 to the algorithm by Wu et al. (2016) in terms of running times in our experiments. In the second part, we analyze the effects of different maximum-waiting-time values β on Algorithm 1.

Comparison
When comparing with the algorithms by Wu et al. (2016), we only use the runs with no maximum-waiting-time constraints (β ≡ T) and we tested all algorithms on the same set of randomly chosen starting vertices. In the experiments, we could only measure a very small effect of the optimization criteria on the running time. This even holds for linear combinations. The only exception was the computation of foremost which was a bit faster in comparison to the computation of the other criteria. For this reason we only include two examples here. We chose foremost and shortest as these are the two criteria where Algorithm 1 performed the best and the worst compared to the algorithms by Wu et al. (2016), respectively. The respective findings are illustrated in the box plots in Fig. 3. As one can observe in Fig. 3, Algorithm 1 has a larger variance and, therefore, is more dependent on the choice of starting vertices. The reason is that even for β ≡ T, that is, no maximum waiting time constraints, not all vertices can reach all other vertices by temporal walks in the considered graphs: Algorithm 1 only considers arcs that start in vertices that were already visited and, hence, if many verices are not reached then the algorithm stops. In contrast, the algorithm by Wu et al. (2016) always considers the whole sorted time-arc list and, therefore, has almost no variance in the running time.
The high variance is also the reason why our algorithm has a higher average running time but a comparable median running time: On average, the algorithm by Wu et al. (2016) is 16.4 times faster for computing the foremost walk and 7.6 times slower for shortest walks. Considering the median running times, however, our algorithm is 5.8 times faster for the foremost walk but the algorithm by Wu et al. (2016) is 1.2 times faster for shortest walks. The higher average running time is a clear weakness of our algorithm. We believe, however, that the algorithm is still a valuable contribution as it solves more general problems: it can easily combine multiple optimization criteria and it can cope with maximum waiting times and instantaneous arcs, that is, arcs with λ = 0.
When looking at the time to read the data we can observe that our algorithm takes roughly twice to thrice the time for preprocessing compared to the algorithms by Wu et al. This is due to the fact that for each arc in the input graph Transformation 1 constructs a new vertex and a new arc and so the resulting graph is almost thrice the size. The time to read in the data is much larger than the time of the actual algorithm and so Algorithm 1 The boxes represent the 25% to 75% percentile of running times over the 100 runs for different sources on the respective temporal graph and the line within the boxes illustrates the 50% percentile (the median). The whiskers on the top and the bottom represent the best and worst running times, respectively. We only depict the running times of the algorithms after the data has been read in and was preprocessed by Transformation 1. The two plots with the crosses show the running times of reading in the input and preprocessing it takes roughly thrice the time of the algorithms by Wu et al. (2016) if preprocessing is taken into account.
Finally, we compared the running time of Algorithm 1 with a single optimization criterion against the same algorithm with a linear combination of all criteria considered. Figure 4 displays the average and median running time for β ≡ T on all considered data sets.
As expected, the linear combination of optimization criteria does not change the running time compared to a single criterion.

Effect of different maximum waiting-time values β
We next analyze the impact that the maximum-waiting-time constraint β has on Algorithm 1. Decreasing β can have two different effects: First, it can make temporal walks invalid as the maximum allowed waiting time in a vertex is exceeded. Thus, with small βvalues certain vertices can only reach few vertices by temporal walks. The second effect is that a temporal walk is invalidated but can be fixed by a detour that starts and ends in the vertex in which the maximal waiting time was exceeded.
We first investigate the second effect. To this end, we partition the optimization criteria into two categories: The first category contains all optimization criteria for which a detour has no negative effect on the solution. These are foremost, reverse-foremost, fastest, and minimum waiting time. Since the solution for, e. g., fastest is only depending on the first and last time-arc of the temporal walk, adding a cycle somewhere in between does not change the solution. Minimum waiting time plays a special role here as this value can decrease when adding intermediate cycles. The second category contains all other optimization criteria, that is, those for which a detour has a negative effect on the solution. These are minimum hop count, cheapest, and shortest. Since we could not measure significant differences for the different optimization criteria within a category, we only display one figure for each category in Fig. 5. 2 We remark that in the first category we implemented the algorithm such that irrelevant cycles (cycles which do not change the optimality value) are kept in the solution. Hence  Figure 5 (two bottom plots) show that the different categories behave very similarly when it comes to the running-time dependence on the value of β. It seems to be more likely that the first effect we described in the beginning of this subsection (that decreasing β-values can make temporal walks invalid as the maximum allowed waiting time in a vertex is exceeded) is more important for explaining the running times. With very small β-values, a vertex can only reach few other vertices and hence only few time-arcs are considered by Algorithm 1. With increasing β-values, there seems to be a critical value (around 0.1% − 10% of the lifetime of the temporal graph) where suddenly much more connections appear and hence the running time increases drastically. This observation is affirmed by Fig. 6, which shows that (almost) independently of the input graph, the running time is linearly depending on the number of vertices that are visited.
We believe that the difference for small β-values comes from the initialization which is again more depending on the input graph compared to the algorithms by Wu et al. This would explain, why our algorithms have a higher running time variance.

Conclusion
Building on and widening previous work of Wu et al. (2016), we provided a theoretical and experimental study of computing optimal temporal walks under waiting-time constraints.

Fig. 5
Impact of different β-values on the number of cycles, the running time, and the number of vertices that can be reached by temporal walks from the chosen starting vertices. Each data point represents 100 runs for a specific β-value for randomly selected starting vertices in the same graph (the same vertices where used for all β-values). The symbol of the data point represents the input graph, the color represents the average number of visited vertices, and the x-coordinate represents the chosen β-value (for the sake of comparability in terms of β-value divided by the graphs lifetime). The y-coordinate represents in the two upper plots the average number of cycles in optimal walks to all reached vertices and in the bottom two plots the average running time for each source vertex. A line connects all data points that use the same graph. The two plots on the left side show results for foremost walks and the two plots on the right side show results for cheapest walks The performed experiments indicate the practical relevance of our approach. As to future challenges, recall that moving from walks to paths would yield NP-hard optimization problems (Casteigts et al. 2015). Hence, for the path scenario the study of approximation, fixed-parameter, or heuristic algorithms is a natural next step. For the scenario considered in this work, note that we did not study the natural extension to Pareto-optimal walks (under several optimization criteria). Moreover, for (temporal) network centrality measures based on shortest paths and walks, counting or even listing all optimal temporal walks or paths would be of interest. First results in this direction indicate that for several Fig. 6 Average number of visited vertices and its influence on the average running time for foremost. Each data point represents 100 runs of our algorithm for foremost for one of the considered graphs for a specific β-value. The x-coordinate represents the average number of visited vertices and the y-coordinate indicates the average running time optimization criteria counting temporal paths is computationally hard even without waiting time constraints; in contrast, counting temporal walks seems easier (Rad et al. 2017;Buß et al. 2020).