Scheduling activities with time-dependent durations and resource consumptions

In this paper we study time-dependent scheduling problems where activities consume a resource with limited availability. Activity durations as well as resource consumptions are assumed to be time-dependent and the resource can be replenished between activities. Because of the interaction of time-dependent activity durations and resource consumptions, scheduling policies based on starting all activities as early as possible may fail due to unnecessarily high resource consumptions. We propose a dynamic discretization discovery algorithm that generates a partially time-expanded network during the search. We propose preloading techniques allowing to significantly reduce the computational effort if the approach is embedded in an iterative solution procedure that frequently evaluates activity sequences that start with the same activities. We evaluate our approaches on a case of routing a fleet of electric vehicles in which vehicles can recharge batteries during the route.

considered when scheduling activities and it must be ensured that all activities can be executed without running out of energy (see, e.g., Pelletier et al. 2016). Similarly, the time required by a human operator can be seen as a resource that is consumed throughout the execution of activities and which is limited by work regulations (see, e.g., Federal Motor Carrier Safety Administration 2011, European Union 2003. Also machine times may be limited between preventive maintenance processes or inspection intervals, for example, aircrafts must be inspected before a total flight time of a given limit is reached (Legal Information Institute 2020).
In this paper we study the problem of scheduling a sequence of activities where activities consume a limited resource throughout execution. We assume that both activity durations and resource consumptions depend on the time of execution. A major cause of time-dependent activity durations and resource consumption is congestion, which can have a significant impact on the duration required to complete certain activities. In the 15 largest urban areas in the United States, for example, travel times on freeways are 44 percent higher during peak periods than during free flow times (Schrank et al. 2019). Similarly, in warehouses and manufacturing facilities, congestion can occur due to space limitations and narrow aisles (Zhang et al. 2009). Thus the time required for picking activities or moving a forklift may vary over the course of the day. Time-dependent durations may also occur for other reasons. For example, the total trip duration of a public transport user includes waiting time until the next scheduled departure and the actual travel time. Thus, the total trip duration depends on the time of the day and can be represented as time-dependent function (Rest and Hirsch 2016). In satellite imagery, as another example, the relative position of the satellite to an object on the earth surface depends on the position of the satellite in the orbit and the time required to tilt the satellite accordingly can be represented by a time-dependent function (Liu et al. 2017).
Time-dependent activity durations can have various ramifications that have received very little attention in the scientific literature. Consider, for example, the case of electric forklifts or vehicles.
If activity durations and energy consumptions are time-dependent, the timing of the activities can be of particular importance in order to ensure that the total energy consumption of a sequence of activities stays below the total energy provided by the battery. Similarly, in the case of limited working times, the total working time of an operator may exceed the maximum working time allowed if most activities are conducted during peak-hours. Thus, activities may have to be shifted away from peak-hours in order not to exceed the legal limits on the working time. Therefore, the commonly used scheduling policy to schedule activities as early as possible may fail due to unnecessarily high resource consumptions.
Sometimes resources can be regenerated after they have been consumed. For example, an electric battery can be recharged, a human operator can take a rest as required by working regulations, or a maintenance process can reset the machine time available until the next maintenance is needed. In order to accommodate for such cases, we also study the problem of jointly scheduling activities and replenishments.
The contributions of this paper are: 1) we introduce the time-dependent activity scheduling problem with resource constraints; 2) we show that an optimal solution can easily be found if activity durations fulfil the the so-called first in first out (FIFO) property, i.e the property that an earlier start time implies an earlier or equal completion time, and resource consumption functions are non-decreasing in time; 3) we propose a dynamic discretization discovery algorithm for solving the problem in the more general case of non-monotonous consumption functions; 4) we extend the approach to the case where resources can be replenished between activities; 5) we propose an acceleration technique for iterative problem solving by preloading vertices of the partially expanded network obtained from a previous iteration; 6) we propose new benchmark instances for time-dependent vehicle routing with electric vehicles; 7) we evaluate the algorithms on these benchmark instances.

Related work
Resources that are consumed throughout the course of activities can be found in various scheduling problems. Often a capacity limit is given on such resources and the total consumption must not exceed the capacity. In the case where each activity has a constant resource consumption, the total resource consumption can easily be obtained by summing up the constants. This is for example the case in the capacitated vehicle routing problem (see, e.g., Irnich et al. 2014) where the maximum load of the vehicle can be interpreted as a resource that is depleted by the customer demands. In the multi-trip vehicle routing problem (see, e.g., Fleischmann 1990, Taillard et al. 1996, Cattaruzza et al. 2014, this full capacity of the resource can be restored when the vehicle returns to the depot. Schiffer et al. (2019) provide a recent review of vehicle routing problems in which vehicle routes include stops for replenishments, refueling, and breaks.
For route planning problems with battery-powered vehicles (see, e.g., Pelletier et al. 2016), the energy consumption of the vehicles depends on the distance travelled. Therefore, minimising route distances will help to create routes that can be conducted without running out of energy. Recharging In the vehicle routing and truck driver scheduling problem (see, e.g., Tilk and Goel 2020, Goel and Vidal 2014, Prescott-Gagnon et al. 2010, Goel 2009), vehicle routes have to be generated in such a way that all customers can be visited within time windows and all routes can be executed without violating government regulations with respect to driving time limits. According to these regulations, truck drivers have to take breaks and rest periods at regular intervals. The remaining time without a break or rest period can be regarded as a resource that is consumed when driving. Although the driving time between two customers is assumed to be a given constant, time windows for customer visits may make it impossible to always drive as long as allowed by the regulations and only take breaks or rests when the legal driving time limits are reached. Instead, determining feasibility of each route requires the solution of a truck driver scheduling problem (see, e. g., Savelsbergh 2009, Goel 2014;2010, Goel and Kok 2012, Goel and Rousseau 2012. Minimising schedule durations is an even more complicated problem that is studied, for example, by Kok et al. (2011), Goel (2012ba), and Rancourt et al. (2013).
Most of the above-mentioned studies assume that activity durations are given as constant values. In many real-life applications, however, the duration of activities depends on the time of the day. Scheduling problems with time-dependent processing times have been surveyed by Cheng et al. (2004) and Alidaee and Womer (1999). Vidal et al. (2015) review activity scheduling problems in which timing decisions are of particular importance and possibly time-dependent. Stecco et al.
(2008) study a scheduling problem where setups with a time dependent duration are required between pairs of jobs and formulate the problem as a time-dependent traveling salesman problem. The time-dependent traveling salesman problem is also studied, e.g., by Nannicini et al. (2012), Montero et al. (2017), Cordeau et al. (2014, Taş et al. (2016). Vu et al. (2020) apply dynamic discretization discovery, originally proposed by Boland et al. (2017), for the time-dependent traveling salesman problem with time windows. Dynamic discretization discovery works on a time-expanded network, where only a small fraction of the vertices in the time-expanded networks is actually generated. For the case of arc costs which are non-decreasing in time, Vu et al. (2020) provide criteria allowing to prove optimality of a solution in the partially expanded network. He et al. (2019) also apply dynamic discretization discovery, but for the time-dependent shortest path problem. For the case of piecewise linear travel times satisfying the FIFO property, they propose an improvement of the dynamic discretization discovery based on an observation in Foschini et al. (2012) allowing to explore only a small fraction of breakpoints of the arc travel time functions.
A survey on vehicle routing problems with time-dependent travel times given by Gendreau et al. (2015). Dabia et al. (2013) present an exact approach for the time-dependent vehicle routing problem. Hashimoto et al. (2008) propose a method to determine an optimal time schedule for a route where travel times and costs are piecewise linear and lower semi-continuous time-dependent functions. Visser and Spliet (2020) show how ready time functions can be determined efficiently by composition of piecewise linear travel time functions.
The research concerning time-dependent activity duration and the consumption of limited resources which may have to be replenished is scarce. Drezet and Billaut (2008) analyse a project scheduling problem with time-dependent activity requirements and workers, which obey French workforce regulations and have various skill sets. A mixed-integer programing formulation and heuristic solution approaches are presented. For home health care, Rest and Hirsch (2016) present a scheduling approach considering break requirements for healthcare personnel assuming that staff members use a combination of walking and public transport. Travel times with public transport are modelled as time-dependent functions, where staff members may have to wait for the next tram, train, or metro. The scheduling of breaks is conducted based on heuristic rules. Kok et al. (2011) present a mixed-integer program for the problem of finding a schedule of minimal duration for a truck driver who must take breaks as required by European Union regulations. The problem is extended by timedependent travel times and used as a subproblem for route evaluations within an insertion heuristic.
The subproblem is solved with a general purpose mixed-integer programming solver. Kleff (2019) studies the problem of finding a time-dependent shortest path from an origin to a destination in which breaks can be taken at parking lots in the network. The driving time is limited by European Union regulations. An approach combining forward exploration from the origin to a parking lot and backwards exploration from the destination to a parking is presented.

Problem description
Let us consider a sequence of activities (1, 2, . . . , n) to be conducted in the given order and without preemption. The time-dependent duration and resource consumption of each activity i are given by functions τ i (t i ) and ρ i (t i ), respectively, where t i refers to the start time of the activity. Each activity i must start within a given time interval [e i , l i ] and the cumulative resource consumption must not exceed a given quantity Q. With θ i (t i ) = t i + τ i (t i ) for all i ∈ {1, ..., n}, the time-dependent activity scheduling problem (TDASP) can be represented by minimise θ n (t n ) (1) subject to The objective (1) is to minimise the completion time. Constraint (2) demands that the start time of any activity must not be before the completion time of the previous activity. Constraint (3) requires that the cumulative resource consumption does not exceed the available amount. Lastly, the domain of the variables is given by (4).
Throughout this paper we assume that the completion time functions θ i (·) are non-decreasing for all i ∈ {1, ..., n}, meaning that completion times satisfy the FIFO property. Without loss of generality we assume in the remainder of this paper that time windows are restricted in such a way that θ i (e i ) ≤ e i+1 and θ i (l i ) ≤ l i+1 for all 1 ≤ i < n.
Lemma 1 Assume we have a sequence t 1 , t 2 , . . . , t n with t 1 = e 1 and t i = max{θ i−1 (t i−1 ), e i } for each 1 < i ≤ n. If ρ i (·) is non-decreasing for 1 ≤ i ≤ n and constraints (2) to (4) are satisfied, then t 1 , t 2 , . . . , t n is an optimal solution of the TDASP. If any of the constraints (2) to (4) is violated no feasible solution exists.
Proof. As the completion time functions θ i (·) are non-decreasing by the FIFO property, the proof is trivial for non-decreasing resource consumption functions ρ i (·).
Resource consumption functions can be non-decreasing in scheduling problems with deterioration (see, e.g., Mosheiov 1994). However, in other cases, the resource consumption may, e.g., depend on congestion levels and vary throughout the day. In such cases it may be possible to reduce the total resource consumption by delaying the start time of some of the activities. In the following sections we present solution approaches for cases in which resource consumption functions are not monotonous.

Time-expanded networks
An approximation of the solution of the TDASP can be obtained by discretising time and modelling the problem as a time-expanded network. Let us assume we are given a parameter ε > 0 for which e i and l i are a multiple of ε for each activity i. Then, we can create for each activity i and each and only if t i+1 ≥ θ i (t i ). Figure 1 illustrates such a time-expanded network with vertex sets V i for each 1 ≤ i ≤ n.  instead of q (i,t) in the algorithm, however, the used notation allows us in the following sections to use different values of q (i,t) to accelerate the search.
The algorithm is similar to an A*-Algorithm for shortest path problems (Hart et al. 1968). However, labels are not related to objective function values. Instead, labels indicate the cumulative resource consumption until the start of each activity at a particular time. The algorithm starts with initializing a set of verticesV for which the label is permanently set. It tentatively sets all labels associated to the first activity to zero, and all other labels to infinity. As long as there is a vertex in V \V which has a label allowing to conduct the activity without exceeding the capacity, the algorithm selects such a vertex (i, t) ∈ V \V according to a lexicographical ordering on the lower bound on the completion time of the last activity, the activity index, and the time associated to the vertex. The lexicographical ordering is necessary to ensure that all relevant predecessors are considered before selecting a vertex. The selected vertex is inserted inV . If the selected vertex belongs to the last activity, the algorithm terminates. Otherwise, non-permanent labels of the next activity are updated if their value can be reduced. Whenever a label is updated, the predecessor p v for the vertex is updated so that the solution can be reconstructed by a function solution V , (q v , v , p v ) v∈V . If a solution is found, this function returns the vertices of the solution obtained by selecting the earliest vertex (n, t) with (n,t) + q (n,t) ≤ Q and iterating through its predecessors. If no solution is found, the function returns (1, ∞), . . . , (n, ∞) . For brevity reasons we omit a detailed description of this trivial function. Proof. Assume that vertex (i, t) is selected in an iteration of the algorithm. Due to the FIFO property, each potential predecessor of (i, t) must have been selected in an earlier iteration. Thus, (i,t) represents the minimal cumulative resource consumption before conducting activity i at time t. If (n, t) is selected and (n,t) + q (n,t) ≤ Q, then t is the earliest time for which (n,t) + q (n,t) ≤ Q. Thus, the solution obtained by backtracking the predecessors is optimal. If the algorithm terminates without

Dynamic Discretization Discovery
The difficulty in solving the TDASP with discretized times is that the number of vertices in the timeexpanded network can become very large for small values of ε, i.e. the parameter influencing the granularity of the time discretization. In order to reduce the number of vertices we now show how to solve the TDASP with discretized times on a partially expanded network similar to the dynamic discretization discovery approach by Vu et al. (2020) for the time-dependent traveling salesman problem with time windows. Unlike Vu et al. (2020), who assume that arc costs are non-decreasing in time, we assume that resource consumption functions can be non-monotonous.
In the remainder of this section we will refer to a partially expanded network if the set of vertices V is a subset of the vertices of the fully expanded network and the set of edges is obtained by con- . Our approach will generate and modify such partially expanded networks with the following properties.
Property 1 guarantees that for each activity i, a vertex representing the earliest and latest start time is included in the partially expanded network. For every vertex, its immediate successor is included in the partially expanded network if Property 2 is satisfied. Because of Property 3, each vertex (i, t) is assigned a value q (i,t) , which is a lower bound on the actual resource consumption of the activity for any start time between t and t − ε, where t refers to the next vertex of activity i.
With these properties we can make the following observation.

Lemma 3
The optimal solution of a TDASP restricted to a partially expanded network satisfying Properties 1 to 3 is a lower bound on the optimal solution of the fully expanded TDASP with discretized times.
Proof. Assume that vertices (1, t 1 ), . . . , (n, t n ) correspond to an optimal solution of the fully expanded TDASP with discretized times. Because of Properties 1 and 2, we can find a path (1, t 1 ), . . , (n, t n ) is feasible for the TDASP restricted to the partially expanded network and has a completion time that is smaller or equal to the solution of the fully expanded TDASP with discretized times.
Lemma 4 Assume that the path (1, t 1 ), . . . , (n, t n ) corresponds to an optimal solution of the TDASP restricted to a partially expanded network satisfying Properties 1 to 3. Furthermore, assume that Then, the path corresponds to an optimal solution of the fully expanded TDASP with discretized times.
is feasible for the TDASP with discretized times. Because of Lemma 3 we can conclude that the path corresponds to an optimal solution of the TDASP with discretized times.
We can use Algorithm 2 to create an initial partially expanded network. According to Property 1, the algorithm adds vertices corresponding to each activity at the start and end of the time window. Data: return (1, t 1 ), . . . , (n, t n ) 16 end Algorithm 3: Dynamic discretization discovery algorithm Algorithm 3 solves the TDASP with discretized times by dynamically creating a time-expanded network. The algorithm starts by initialising the network using Algorithm 2. Then it iterates until a solution of the TDASP with discretized times is found. Each iteration begins with finding a solution of the TDASP restricted to the partially expanded network using Algorithm 1. If there is an activity i in the solution that begins at a time t such that ρ i (t) > q (i,t) , then the total consumption associated with the solution may exceed the capacity. Therefore, a new vertex is added to the partially expanded network between (i, t) and the next vertex of activity i. The time for the new vertex is selected in such a way that the value of q (i,t i ) is increased when adding the new vertex.
If a feasible solution exists, the algorithm either terminates with the optimal solution, or adds at least one vertex to the partially expanded network in each iteration. Therefore, the algorithm is guaranteed to terminate with the optimal solution. In the worst case, the algorithm may have to fully expand the network. However, in general, the algorithm can be expected to require only a fraction of the vertices.

Replenishments
So far we assumed that the resource cannot be used after it has been consumed by the activities. This is the case, for example, if electric batteries cannot be recharged or if maximum working hours or operating times are reached. In many cases, however the resource can be regenerated. For example, electric batteries can be recharged, workers are allowed to work again after taking a sufficiently long break, or machines can be used again after some maintenance has been conducted. In this section we consider an extension of the TDASP in which the resource can be replenished between the end of an activity and the begin of the next activity. We assume that the time required to fully replenish a resource after conducting activity i can be determined by a consumption-dependent and non-decreasing replenishment function ∆ i (Q i ), where Q i is the cumulative resource consumption after completing activity i.
The resulting time-dependent activity scheduling problem with replenishments (TDASPR) is to minimise θ n (t n ) subject to In this problem Q i is a variable representing the cumulative resource consumption between the last replenishment and completion of activity i, and y i is a binary variable representing whether the resource is replenished after conducting activity i. The objective function is the same as in the case without replenishments. Constraint (6) is analogous to Constraint (2) but includes the replenishment duration if necessary. Constraints (7) and (8) ensure that the cumulative resource consumption is correctly determined and Constraints (9) restricts the domains of the variables.
The special case where replenishments must or must not be taken after some of the activities is covered in Appendix B.

Replenishments in time-expanded networks
In the following we show how dynamic discretization discovery can be used to solve the TDASPR.
For this, we replace Algorithm 1 by Algorithm 4 which dynamically adds new vertices corresponding to a fully replenished resource to the partially expanded network.
Whenever a vertex (i, t) with i < n is selected in Algorithm 4, the algorithm determines the earliest replenishment time t * after conducting activity i at time t. If t * ≤ l i+1 , the vertex (i + 1, t * ) is added to V using algorithm DDD :: addRecursive. Then, all labels for vertices with a time prior to t * are updated if their value can be reduced and all labels for vertices with a later time are set to zero.
Lemma 5 Assume that Algorithm 4 is applied to a partially expanded network satisfying Properties 1 to 3. Then, the solution of the algorithm is a lower bound on the solution in the fully expanded network.
Proof. Let us first note that the solution returned by Algorithm 4 is the same as the solution returned by Algorithm 4 without Line 9. For the ease of argumentation, we therefore base our proof on a variant of Algorithm 4 without Line 9. Let (1, t 1 ), . . . , (n, t n ) denote an optimal solution in the fully expanded network. LetV denote the set of permanently labelled vertices after execution of this variant of the algorithm, including the vertices that may have been added to V during the course of the algorithm. Let (1,t 1 ), . . . , (n,t n ) ∈V denote the vertices returned by the algorithm. Analogously Let (1, t 1 ), . . . , (n, t n ) denote the vertices inV for which t i is the largest time not exceeding t i for each i ∈ {1, . . . , n}. These vertices can be found because of Property 1. As θ i is non-decreasing for each i ∈ {1, . . . , n}, Property 2 guarantees that θ i (t i ) ≤ t i+1 for i ∈ {1, . . . , n − 1}.
Assume, that in the optimal solution (1, t 1 ), . . . , (n, t n ), the first replenishment is conducted just before starting activity j. Because of Property 3, we have . Therefore, there is a vertex (j, t) ∈V with t ≤ t j and (j,t) = 0. By definition we have t ≤ t j ≤ t j and we can conclude that (j,t j ) = 0. Analogously we can show that t 1 ), . . . , (n, t n ) is conducted just before starting activity k. We can apply this argument repeatedly to conclude that the capacity is not exceeded along the path (1, t 1 ), . . . , (n, t n ) and that (n,t n ) +q (n,t n ) ≤ Q.
Thus,t n ≤ t n ≤ t n .
Lemma 6 Assume that the path (1, t 1 ), . . . , (n, t n ) corresponds to a solution created by Algorithm 3 using Algorithm 4. Furthermore, assume that q (i,t i ) = ρ i (t i ) for each 1 ≤ i ≤ n. Then, the path corresponds to an optimal solution of the fully expanded TDASPR with discretized times.
Proof. For each 1 ≤ i ≤ n let (i,t i ) denote the corresponding label created by the algorithm. Let i be any activity index with (i,t i ) = 0. For any activity index j > i such that no replenishment is conducted between i and j, we have Q ≥ (j,t j ) + q (j,t j ) = j k=i q (k,t k ) = j k=i ρ k (t k ). Therefore, the duration of any replenishment is sufficiently long and the capacity is never exceeded between replenishments. Thus, (1, t 1 ), . . . , (n, t n ) is a feasible path in the fully expanded network. Because of Lemma 5 we can conclude that the path corresponds to an optimal solution of the TDASP with discretized times.

Preloading of vertices
Assume we have already solved the problem for a sequence of activities (1, . . . , n) and we want to solve the problem for a sequence (1, . . . , n, n + 1, . . . , m). It is likely that some of the vertices that are generated when scheduling activities (1, . . . , n) are also generated when scheduling activities (1, . . . , n, n + 1, . . . , m). We can reduce the computational effort associated to finding such vertices again by preloading them before starting the solution process for sequence (1, . . . , n, n + 1, . . . , m).
On the other hand, preloading all of the vertices generated when determining a schedule for activities (1, . . . , n) may create an unnecessary computational overhead, because only a share of the vertices can be expected to be required to find a solution for activities (1, . . . , n, n + 1, . . . , m).
To balance the tradeoff between salvaging previous computational effort and avoiding unnecessary overhead by adding too many vertices, we propose to preload all vertices of the solution path for sequence (1, . . . , n) to our partially expanded network after initialization and before starting the solution process. In order to ensure that q (i,t) = ρ i (t) for all vertices preloaded, we also add the immediate successors. As all vertices are added using the function DDD :: addRecursive, Properties 1 to 3 maintain satisfied. Consequently, the optimality conditions for all vertices on the previous solution path are satisfied.
The benefit of adding these vertices after initialization of the partially expanded network is that the total number of vertices generated by the dynamic discretization discovery may be drastically reduced for those cases where the solution for sequence (1, . . . , n, n + 1, . . . , m) overlaps with the solution for sequence (1, . . . , n). In some cases, however, preloading may cause a small overhead because vertices may be recursively added that are not needed for the solution process.

Evaluation
This paper is motivated by an industry project on last-mile deliveries with electric vehicles, where a homogeneous fleet of electric delivery vehicles is used to deliver parcels within metropolitan areas, i.e., regions consisting of densely populated city centres and less-populated surrounding territories.
Traffic conditions depend both on the particular area as well as the time of the day with morning and afternoon peak hours. With increasing distance to the city centres, the impact of peak hours on travel times decreases. Thus, the time-dependency of travel times is not homogeneous and delays caused by congestion can be avoided by circumventing city centres during peak hours. Current electric vehicles have minimal consumption per unit distance at moderate speeds while the consumption increases towards very low or high velocities. Therefore, the energy consumption of the vehicles is related to travel speeds, which in turn depend on the congestion level. All vehicles leave the depot fully charged and have to return to the depot before running out of energy. They can recharge the battery at the depot as well as at public charging infrastructure.
Due to confidentiality reasons, we are not allowed to evaluate our approaches on instances obtained from data of our project partners. Therefore, we generate artificial instances for the timedependent vehicle routing problem with replenishments having the characteristics described above.
Our instances are based on the well-known instances for the vehicle routing problem with time windows by Solomon (1987). These instances have customer locations distributed in the Euclidean plane and are subdivided into instance sets with clustered customer locations (C1 and C2), randomly distributed customer locations (R1 and R2), and mixed locations (RC1 and RC2). indicate high congestion levels during morning and afternoon peak-hours.
We assume a city centre in each quadrant of the Euclidean plane where congestion is maximal.
In order to consider that the level of congestion decreases with increasing distance to the city centres, we calculate a location-dependent congestion factor γ(x, y) ∈ [0, 1] by the Gaussian function based on the distance to the city centres. Figure 3 shows the location-dependent congestion factors, the customer locations (shown as •), and the location of the depot (shown as ×) for the different subsets of instances proposed by Solomon (1987). Low values of γ(x, y) indicate low sensitivity to congestion and are illustrated in light color. High values of γ(x, y) indicate high sensitivity to congestion and are illustrated in dark color. We can see that all instances comprise customers located in areas prone to congestion and others in areas where congestion is negligible. Even if two customers are located in areas without significant congestion, the direct path from one to the other may traverse congested areas during peak-hours.
For each integer valued point (x, y), we calculate the time required to travel a unit distance at a time t by where τ free (x,y) is the congestion-agnostic time necessary to travel a unit distance at point (x, y). The factor min 0.8, γ(x, y) in (10) is used to generate homogeneous travel times in an area around the city centres. The maximum travel time close to a city centre is five times the free flow travel time. The instances are heuristically solved using an adaptation of the savings algorithm (Clarke and Wright 1964), where routes are evaluated using the approaches presented in this paper. Since vehicles and the corresponding driver are the main cost-components in last-mile delivery operations, we optimize over the total number of vehicles first and, as a second criterion, over the total completion time. The latter includes, in particular, the time to return to the depot. In order to allow recharging of the battery at the depot or at public charging stations we allow vehicles to take a detour via a charging station whenever the increase in the travel distance does not exceed √ 2 times the direct distance between delivery locations. If multiple charging stations satisfy this criterion, then the charging station with the smallest detour is chosen. The delivery companies partnering in the project expressed that they want to avoid short and possibly avoidable stops at charging stations. By setting the duration of the replenishment to a constant value we penalize recharging when the energy level of the battery is still high.
We implemented our algorithms in C++ and ran the experiments on a single core of an Intel Core i7-7700HQ CPU with 2.80GHz. For comparison purposes we ran experiments using CPLEX for solving for the mixed integer program provided in Appendix A.    Instances belonging to sets C1, R1, and RC1, have a smaller freight capacity and a shorter planning horizon compared to instances belonging to sets C2, R2, and RC2. Therefore, more vehicles are used for instances of sets C1, R1, and RC1 than for instances of sets C2, R2, and RC2. Thus routes for instances in sets C1, R1, and RC1 visit fewer customers and the approach requires significantly less computational effort than for instances of sets C2, R2, and RC2.
With fewer stops per route, the likelihood of running out of electric energy is much smaller. In fact, the solutions for instances of sets R1 and RC1 have no recharging stops at all, because these instances have a very short planning horizon, leaving little time to sensibly recharge batteries. For instances in sets C2, R2, and RC2, the freight capacity and planning horizons are larger. Therefore, less vehicles are used and many more routes make use of the possibility to recharge the batteries.
With an increasing number of charging stations, the number of alternative routes via charging stations increases and so does the computational effort required for evaluating these alternatives. We can see that preloading of vertices helps stabilizing the runtime of the algorithm and leads to significantly shorter computation times for instances with many charging possibilities. With preloading of vertices, the dynamic discretization discovery approach is able to (heuristically) solve almost all of the instances except for instance r211 with five charging stations per city within the run time limit.
Without run time limit, instance r211 with five charging stations per city can be solved in 8027.5 sec- onds.
An interesting observation from an application point of view is that the possibility to recharge the battery during a route can significantly reduce the number of vehicles required as well as the total completion time. Table 2 indicates that for instances in sets C2, R2, and RC2, the number of routes required can be reduced by approximately one third if vehicles can recharge batteries while they are on route. This demonstrates the importance of considering replenishments within scheduling.
Furthermore, it can be seen that the number of vehicles required is not significantly reduced with an increasing number of charging stations. In fact, the possibility to recharge the battery at the depot already accounts for the main benefit in terms of the number of vehicles required. Additional public charging infrastructure may furthermore reduce the detour required to reach a charging station and thus can contribute to smaller total completion times and less routes requiring replenishments.

Conclusions
In this paper we introduce a time-dependent activity scheduling problem in which activities consume a limited resource during execution and activity durations and resource consumptions are timedependent. Moreover, we study the case in which the resource can be replenished between conducting subsequent activities. We propose a dynamic discretization discovery algorithm which is based on partially time-expanded networks which are dynamically filled with additional vertices. The dynamic discretization discovery algorithm can be used for general duration and consumption functions and only requires the first-in-first-out property for activity durations. For the case that the dynamic discretization discovery is embedded in an iterative solution procedure that frequently evaluates activity sequences that start with the same activities, we propose to preload the partially expanded network with vertices generated in previous iterations. This preloading of vertices can significantly reduce the computational effort required.
We evaluate our approaches on a case of determining routes for a fleet of electric delivery vehicles for last-mile deliveries. Our experimental results indicate that the dynamic discretization discovery algorithm is magnitudes faster than the commercial solver CPLEX using a mixed integer program-ming formulation of the problem. Furthermore, our experiments show that for our instances, which are motivated by the real-life case of last-mile delivery operations, the possibility to recharge batteries en-route can significantly reduce the number of vehicles required and the total completion time. In this appendix we provide a formulation of the TDASPR under the assumption that functions τ i (t), θ i (t), and ρ i (t) are non-negative, piecewise linear, and lower semi-continuous for each 1 ≤ i ≤ n and that the replenishment duration ∆ i is a constant for each 1 ≤ i ≤ n. Like before we assume that the FIFO property holds, i.e., that θ i (t) is non-decreasing. Note that we do not require τ i (t), θ i (t), and ρ i (t) to be continuous. This allows us to consider applications such as durations of trips conducted with public transport services where discontinuities occur when the scheduled departure time is missed and waiting time until the next scheduled departure needs to be considered.
Let S τ i and S ρ i denote the set of piecewise linear segments of τ i and ρ i . For each linear segment s ∈ S τ i ∪ S ρ i , let e s and l s denote the start and end of the segment and let a s denote the slope and b s the intercept of the respective linear function. Thus, if the start time t i of activity i is within segment s ∈ S τ i , then τ i (t i ) = a s t i + b s . With this, the problem can be modelled with binary variables x i,s indicating whether segment s ∈ S τ i of the duration function or segment s ∈ S ρ i of the consumption function is used for activity i. A binary variable y i indicates whether the resource is replenished after conducting the activity i, linear variables d i and q i indicate the duration and resource consumption of activity i, and t i indicates the start time of activity i. Linear variables t i,s indicate time values for activity i associated to segment s ∈ S τ i of the duration function or for segment s ∈ S ρ i of the consumption function. The TDASP with piecewise linear duration and consumption functions can be formulated as a mixed-integer program by minimise t n + d n subject to The objective (11) is to minimise the completion time. Constraint (12a) ensures that for each activity exactly one of the time segments is selected. Constraints (12b) and (12c) ensure that t i,s is zero if x i,s = 0 and t i,s ∈ [e s , l s ] if x i,s = 1, and that the start time of activity i is set accordingly.
Note that the boundary values of [e s , l s ] might not belong to the segment s because we do not require continuity of the functions. Due to the lower semi-continuity, however, this is not a problem in an optimal solution. The duration d i of activity i can be obtained by constraint (12d). Because of constraint (12e), the start time of any activity must not be before the completion time of the previous activity plus the time required for a potential replenishment. Constraints (13a) to (13d) are analogous to constraints (12a) to (12d) for the resource consumption. Constraint (13e) requires that the cumulative resource consumption of any sequence of activities does not exceed Q unless the resource is replenished. Lastly, the domain of the binary variables is given by (14) and (15).

B Restrictions on replenishments
A variation of the TDASPR, in which replenishments are forbidden or required after certain activities, can be obtained by constraining the binary variables indicating the choice of whether to conduct a replenishment or not. This can be achieved by adding a constraint y i = 0 or y i = 1 for each activity i which prohibits or requires a replenishment after its completion in the problems given by (5) to (9) or (11) to (15).
If a replenishment is not allowed after an activity, we can avoid replenishments by adapting Algorithm 4 in such a way that the earliest time after the replenishment t * is set to a value that exceeds l i+1 in line 10.
Let us now consider the case that a replenishment is required after activity i. In this case Property 2 loses its relevance for all vertices of activity i, because the property does not consider the duration of the required replenishment. The main purpose of Property 2 was to ensure that the vertex representing the earliest possible time at which the next activity can be conducted is included in the partially expanded network. In Algorithm 4, this is achieved by line 12 which includes a vertex for the next activity and the earliest time after the required replenishment. We can adapt Algorithm 4 in such a way that lines 14 to 19, which update the labels assuming that no replenishment is conducted, are skipped if a replenishment is required. Furthermore, the condition in line 22 of function DDD :: addRecursive can be changed in such a way that the recursive insertion of vertices is terminated if a replenishment is required after the current activity. With these changes our approach can be used to solve the TDASPR with required replenishments even if Property 2 does not hold for activities requiring a replenishment.

C Detailed results
Tables 3 to 7 show detailed results of our computational experiments. The first column gives the name of the instance. The results for the approach based on dynamic discretization discovery with replenishments (DDD) are given in columns 2 to 5. The results for the dynamic discretization discover approach with replenishments and preloading (DDD-PL) are given in columns 6 to 9. The results for the approach using CPLEX for solving for the mixed integer program (MIP) are given in columns 10 to 13. For each approach, the total computation time is given in the column titled CPU, the number of vehicles required is given in the column titled Veh., the total completion time is given in the column titled Compl., and the number of replenishments at service stations is given in the column titled Repl.. Dashes in the columns for MIP indicate that no solution was found within the time limit of 7200 seconds. For the dynamic discretization discovery approaches DDD and DDD-PL, the results violating the time limit are written in italic.