{'fraction_non_alphanumeric': 0.0289478672985782, 'fraction_numerical': 0.007336492890995261, 'mean_word_length': 4.6727605118829985, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Optimising Stochastic Routing for Taxi Fleets with Model Enhanced Reinforcement Learning

The future of mobility-as-a-Service (Maas)should embrace an integrated system of ride-hailing, street-hailing and ride-sharing with optimised intelligent vehicle routing in response to a real-time, stochastic demand pattern. We aim to optimise routing policies for a large fleet of vehicles for street-hailing services, given a stochastic demand pattern in small to medium-sized road networks. A model-based dispatch algorithm, a high performance model-free reinforcement learning based algorithm and a novel hybrid algorithm combining the benefits of both the top-down approach and the model-free reinforcement learning have been proposed to route the \emph{vacant} vehicles. We design our reinforcement learning based routing algorithm using proximal policy optimisation and combined intrinsic and extrinsic rewards to strike a balance between exploration and exploitation. Using a large-scale agent-based microscopic simulation platform to evaluate our proposed algorithms, our model-free reinforcement learning and hybrid algorithm show excellent performance on both artificial road network and community-based Singapore road network with empirical demands, and our hybrid algorithm can significantly accelerate the model-free learner in the process of learning.


Statement of Contribution/Potential Impact
In this paper, we propose methodologies for optimising vacant vehicle routing in a decentralised way to meet stochastic spatio-temporal demand patterns. The research is motivated by the grand challenge of urban mobility to meet increasing demands for highly efficient yet high-quality transport services with minimal costs. The difficulty of the problem stems from the stochastic spatio-temporal distribution of the commuter demand, on a large road network with complex structures. We design a set of methodologies for intelligent routing of taxi fleet with reinforcement learning primed with a top-down dispatch model, evaluated on both synthetic and empirical data for commuter demand patterns and road networks. The proposed methodologies can potentially benefit everyone in tackling the urban mobility challenges: shorter waiting time for commuters, higher profits for service providers, easy-to-implement and versatile solutions for government agencies, and less emissions to the environment. The methodologies presented in this paper are in time for

Introduction
Diversified transportation services are needed in urban cities with high population density to meet the demands of commuters with high-quality services -to transport from location A to B within designated time and with minimal costs. Traditional public transports including scheduled trains and buses serve large groups of commuters simultaneously, but follow fixed routes and pickup/drop-off locations on scheduled time, mostly in central areas where demand is high. Private vehicles on the other hand provide highly flexible and customised services for short to medium distance travel requests. But the utilisation rate for private vehicles is low, leading to high cost and increasing environmental concerns. The scalability for private vehicles is also highly constrained especially in metropolitan cities due to limited parking space and traffic congestion.
In recent decades, there have been substantial behavioural changes in using mobility as a service in urban cities. These include shared vehicles, bridging buses and real-time, on-demand shuttles. These bridging services fill the gap between scheduled public transports and private vehicles, that can balance between service efficiency and service quality. The idea of demand responsive transit (DRT) is not new, but attracts great attentions in recent years for the purpose of efficient city planning and environmental concerns. While the first DRT trial is implemented in Mansfield, Ohio, USA in 1970 [38], there has been a resurgence of DRT applications and trials recently throughout the world, especially in light of the new technological development including GPS, GIS solutions, tele-communications and smart devices. Examples including trials at Nijmegen-Arnhem region and Amsterdam of the Netherlands in 2016 [25] and 2017 [11], Inner East Sydney of Australia in 2018 [39], Sutton and Ealing of UK in 2019 [16] and Singapore in 2018 [24]. Meanwhile, DRT applications have been especially popular in airport transportation [40], healthcare [28], and disruption handling [23].
While DRT systems have been on trial for more than 50 years, some significant challenges hindered a wide adoption of DRT systems in urban transportation services. Firstly, most of DRT systems operate under a Dial-A-Ride scheme, requiring commuters to phone in with deterministic pickup and drop-off requests ahead of time. Even with the pervasive use of smartphones, the requirement of the commuters to have advanced travel plans is in many cases a big constraint. Secondly, DRT systems are designed to complement the scheduled train and bus services. Thus they often operate in relatively lower demand areas. Without an efficient planning, scheduling and routing algorithm, it is difficult for DRT to provide highquality services. Thirdly, DRT operating on large-scale complex networks requires a high-level central management, operation, booking and tracking system. This in turn pushes up the operation cost, rendering it economically infeasible for many potential commuters. model-based initialisation algorithm is then proposed, that incorporates the benefits of both the model-free RL, and an optimised initial estimation from model-based policies. Numerical experiments were conducted with agent-based modelling on artificial lattice road networks and community-based Singapore road network with both synthetic and empirical demand patterns. Experiments showed the effectiveness of the proposed dispatch algorithm, model-based effective policies, model-free RL and hybrid algorithm. Among them, the proposed hybrid algorithm showed best performance in both artificial network and Singapore road network, and can significantly accelerate the model-free learner in the process of training.
In the following parts of this paper, we begin with related works reviewed in Sec. 3. The research problem is formulated in Sec.4 and the simulated environment and the Markov Decision Process are illustrated in Sec.5. Sec.6 gives a thorough explanation on our proposed model-based methods, model-free RL and the hybrid approach. Sec.7 shows a brief summary of our experimental design and results are presented in Sec.8. Finally, we discuss our results and concludes with future outlooks at Sec.9.

Related Works
Vehicle routing problem is the general problem of dispatching a fleet of vehicles to serve a given set of demands, first proposed in [12]. Taxi routing as a special case of vehicle routing problem, consists of assigning m homogeneous vehicles and designing routes for n given commuters with specified pickup and drop-off requests between origins and destinations. The street-hailing taxis and DRT routing problem have long been studied under Dial-a-Ride Problem (DARP) [9]. Depending on whether all the requests are known beforehand or dynamically revealed during the service period, DARPs can be divided into static and dynamic cases, in which the vehicle routes are either pre-designed or real-time adjusted to meet demands. Depending on whether the information received at the time of decision is certain without imperfect information or further changes, DARP can be classified into deterministic and stochastic cases [20]. The optimisation objectives of this problem can be either minimising costs subject to full demand satisfaction or maximising demand satisfactions subject to vehicle supplies [9].
Within the four categories, the dynamic stochastic multi-vehicle DARP, applied to ride-hailing and delivery services, is considered to be one of the most difficult to solve, where the demands are revealed during service period and subject to dynamic traffic conditions, service request changes and cancellations. Various algorithms have been proposed to optimise service quality of real-life dynamic DARP applications while meeting the constraint of vehicle capacity, maximum route duration and service time for small-sized instances, including heuristics and fuzzy-logic [29,48], branch-and-bound [8], integrated offline and online phases for new request insertion [10], adaptive large neighbourhood search [18], hybrid tabu search and constraint programming [2]. A prediction module is proposed to solve stochastic information in dynamic DARP, which is to use given imperfect information to predict future scenarios needed for decision making [36,34]. Some variants of the dynamic DARP have also been investigated to understand the lower bound of competitiveness ratio, for example, Uber problem [13] and online k-taxi problem [7]. In recent years, emerging technologies including electrical vehicles and autonomous vehicles have opened up new opportunities and also imposed new challenges to the traditional DARP [35]. Some prospective studies have presented the formulation and algorithms for electric autonomous DARP on small instances [3], and for static autonomous DARP with ride-sharing variant and dynamic traffic [27].
In practice, taxi services includes both ride-hailing and street-hailing. The vacant taxis route to maximise demand satisfaction with pickup drop-off service requests revealed during service period either via ride-hailing (the taxi central management will assign taxis for booking requests using various taxi assignment algorithms or heuristics) or via street-hailing instantaneously. The challenge of street-hailing is that the demands are not explicitly phone-in by commuters but revealed only until a vacant taxi happens to pass by the commuters' origins before the commuters change their minds. The existing solutions mainly consists of two steps: first, to construct a model for demand prediction with a quantification of uncertainty; then, to formulate the routing problem with prediction uncertainty as an optimisation problem and solve by exact methods, heuristics and meta-heuristics [30,15,53]. A very recent study presented centralised and decentralised dispatch algorithms for autonomous taxis that can serve both reserved requests and immediate requests after departure using a network flow model [14]. In comparison with this work, our model-free RL approach does not require pre-knowledge of the demand patterns for immediate requests prediction, and our model-based approach does not require exact requests to be revealed to taxis. There are also a few studies apply RL and formulates the vacant taxi routing as a Markov Decision Process to plan for longterm rewards [19,49,53], including our previous work [51]. Compared with the existing studies and our previous work, we have significantly enhanced our routing performance by algorithm design and the hybrid approach allows for model-free RL fine-tuning upon existing methods with better final performance and significant higher sample-efficiency.
Though RL has not been widely applied in vacant taxi routing, it is widely considered as a strong AI paradigm with successful applications in games [32,44], robotics, navigation [26,55], natural language processing, computer vision, healthcare, smart grid, train rescheduling [43] and a lot of others. RL consists of a group of algorithms with their own advantages and trade-offs for different problems. A RL problem can be formulated with solution methods model-based or model-free, value-based or policy-based, on-policy or off-policy, with function approximation or not, and with sample backups or full backups. In general, model-based RL method learns value function to model the environment that the agents interact with, while model-free RL deals with unknown dynamical systems. Continuous attempts are proposed to combine the advantages of model-free and model-base RL approaches, including model predictive control [6] and guided policy search [26]. Various advanced approaches have also been proposed for reinforcement learning with function approximators, including some successful applied algorithms like deep Q-learning [33], policy gradient method [31], trust region policy gradient method [41], and proximal policy optimisation [42]. The fundamental trade-off of RL is exploration-exploitation. Designing better exploration strategy working for different RL schemes and problems is also an active area at the moment [37,5].

Problem Formulation
In our framework, an agent-based model simulates a fleet of taxis roaming on the road network based on a stochastic routing policy, picking up and delivering commuters generated in the road network from their origins to their respective destinations. The positions, behaviours and status of the taxis (vacant or occupied) are recorded and used as inputs for a separate RL algorithm, which is learned to optimise the routing policy in an iterative manner. The challenge in tackling this complex system with a large number of agents is to have a mathematical formulation that satisfies several requirements. Firstly, the formulation has to be flexible enough to easily incorporate realistic details of the transportation system. Secondly, it should allow highly efficient numerical simulations for reasonably large road network containing thousands of nodes. There are also generally up to thousands of taxis roaming in the network with sophisticated behaviours, delivering up to tens of thousands of commuters from their origins to destinations over each simulation period. Thirdly, the formulation needs to be fully integrated to RL algorithms, where the behaviours of the taxis as well as the "rewards" of their actions (to be defined more precisely later on) can be easily collected and analysed by the modern machine learning algorithm.
To that end, we abstract the road network with a connected directed graph denoted as G (N , E), where N represents the collection of nodes of the graph, and E is the collection of directed weighted edges. The nodes correspond to all pointsof-interest of a region (i.e. a city) where commuters can board or alight taxis. The edges are represented by an adjacency matrix A characterising the travel time on each road segment with respect to traffic conditions. For nodes pair i, j, the node j is directly connected from node i if and only if the taxi can drive from i to j without passing through any other nodes in G. In our definition of the adjacency matrix A ij , if j is not directly connected from i, A ij = 0; otherwise for i = j, A ij is the reciprocal of the travel time from i to j. When i = j, A ii = 1.
Two arrays are used to characterise commuters' behaviours: g i gives the probability of a commuter appearing and waiting at node i for each time step; M ij gives the probability of a commuter with origin at node i is going to the destination at node j. The constraints for these two arrays are given in Eq.(2) and Eq.(3). In principle, A ij , g i , M ij can all depend on time. In this paper we focus on the stationary case, and we will leave the time-dependent cases for the future works.
The routing algorithm we develop is entirely encapsulated in a stochastic policy matrix P ij for vacant taxis, which is also the decision variable of the optimisation. The stochastic routing policy defines the the probabilities of moving to a directly connected node j when a vacant taxi is located at i. If A ij = 0, P ij = 0. The P ii gives the probability of a vacant taxi staying at node i for one time step, which can be non-zero. For hired taxis, the routing follows shortest path on A −1 ij . A simple initial policy is the random policy, defined as P ij = 1/n i if P ij = 0. Here n i is the number of neighbouring nodes for each i where A ij = 0, including j = i.
Let n be the total number of commuters generated at each time step, the inputs for the large scale agent-based simulations are A ij , g i , M ij , P ij subjecting to the following constraints: There are two types of agents in the simulation: the taxis and the commuters. The behaviour of the commuters is rather simple. At every time step, we scan over every node in the network. There is a probability g i of increasing the queuing commuter at node i by 1. We can thus denote c i as the number of commuters waiting at node i. The commuters do not move around the network, and c i decreases by 1 when a vacant taxi reaches node i. Thus at time step t, the dynamical behaviour of c i is given by: where N vacant (i, t) is the number of vacant taxis at node i at time t. For total simulation time H, the total waiting time of the commuters can be calculated as: Let n c represents number of commuters generated at each time step, the average waiting time of all commuters is given by: The dynamics for the taxis are more complicated. We denote the location of the l th taxi by a time-dependent array k l 1 , k l 2 , d l , s l (t), when the taxi is in between two connected nodes k l 1 , k l 2 and moving towards k l 2 , with time distance d l from k l 1 (so the taxi is d l time steps away from k l 1 ). Thus d l ≤ A −1 . If d l = 0, the taxi is right at the node k l 1 . We use s l to indicate the status of the taxi, which in our simulation is either vacant (s l = v) or occupied (s l = o). We clearly have The formal dynamical equations are given as follows: If s l = v and no commuter is waiting at the node, k l 3 is chosen with probability P k l 2 k l 3 ; if s l = o, thenk l 3 is chosen from the shortest path to the destination of the commuter in the taxi. We can now define a reward function R for the taxis based on whether or not there is a commuter in the taxi. A simple example we use in Origin probability distribution g i Policy matrix P ij Destination probability distribution M ij Table 1. Notations of the Formulated Problem the paper is to give a unit reward to every occupied taxi for each time step. The reward function is further detailed in Sec.6.2.1. Now we can treat the task formally as an optimisation problem. Given a road network A ij , a stochastic taxi demand g i and M ij , and a fixed supply of N taxis, we would like to find the optimal taxi stochastic routing policy P ij as decision variables that maximise or minimise certain objective functions that we can freely define. Different objective functions can be defined based on prioritising different parties involved (e.g. the passengers, the taxi drivers, and the policy-makers). In this paper, we choose to maximise total reward defined in Eq. (27). The summarised notations are shown in Table. 1.

Agent-based Simulation.
We have designed and implemented a large scale microscopic agent-based simulation platform [52] for evaluation of the performance of P ij , using different A ij , g i , M ij as inputs. A collection of instances containing state information on the positions and actions of vacant taxis, together with relevant extrinsic rewards needed for reinforcement learning is generated from the simulation after running the simulation for finite time horizon H (measured in time steps). While different physical time unit can be used to correspond to each time step, in this study, each time step is taken to be one second for generality. The platform simulates the dynamics of two types of agents: the commuters and the taxis, and produces outputs characterising the performance of stochastic policy P ij from different perspectives using various performance metrics. We focus on average extrinsic reward and average waiting time of commuters in this paper, further explained in Sec.7.
The behaviours of commuters are determined by probability distributions g i and M ij , and the initial positions of all taxis are assigned to random nodes at the beginning of each epoch of the simulation. Vacant taxis will only pick up a commuter when the location of a vacant taxi and the origin of a waiting commuter coincides. The movements of the occupied taxis are computed efficiently by shortest path algorithm using our customised Contraction Hierarchy algorithm [52], while the movements of the vacant taxis will follow the stochastic routing policy P ij . Both real-time booking and road-side hailing with three potential status for the taxis: vacant, booked, and occupied, can be implemented. In this paper, we focus on street-hailing instead of real-time booking so taxis will not take bookings. But in scenarios where some of the taxis take bookings, the methods proposed in this paper can still be applied to route those vacant taxis available for both booking and street-hailing by potential commuters.

5.2.
The Markov Decision Process. The simulation platform can be used to evaluate policies P ij from top-down construction using model-based methods, or from bottom-up learning using reinforcement learning. An illustration of our proposed framework for optimising taxi routing policies is shown in Figure 1. The sequential decision makings of the taxis in above framework can be modelled as a Multi-agent Markov Decision Process (MMDP) involving a collective of taxis as agents, each with their own set of actions, operating in a common environment with the same shared goal (utility function) to achieve a fully cooperative system [4]. The challenge of a MMDP modelling of this problem (formulated in Sec.4) lies in the set of actions to be represented and the policies to be optimised, as each vacant taxi will perform their own policies and choose actions at every location in the road network accordingly. While all agents are improving their own policies concurrently, the environment faced by each agent may become non-stationary. And the joint action space increases exponentially with the number of agents [54], which may cause scalability issues in our problem when the number of taxis in systems is large.
To deal with the above challenges and to work for realistic taxi system with a large taxi fleet, we apply a "mean-field" approximation and model the given problem as a single-agent Markov Decision Process (MDP), assuming that each taxi will follow the same stochastic policy to be learned. Instead of each taxi as an agent, a learner to optimise routing policies P ij is formulated as the agent and the simulation that the learner interacts with is the environment. The resulting stochastic routing policies P ij is used to determine the routing decisions for each vacant taxi in system.
Mathematically, the modelled finite MDP is specified by (S, A, P, r, γ, ρ), where: S is a state space of the environment, A is an action space, P is a transition model P (s |s, a) as the probability of transition into state s from s by taking action a, r is a reward function where r(s, a) is the immediate reward in taking action a in state s, γ is a discount factor γ ∈ [0, 1], ρ is a starting state distribution over S. In this problem, the state S is given as the state of all taxis in system. The action A are decisions made for vehicles at each node on which adjacent node to move to. As a consequence of the actions, the agent receives reward r = r(s t , a t ), r ∈ R characterising the optimisation objective defined in Sec.4, and transit to the next state s according to transition model P . The construction of the reward function is further explained in Sec.6.2.1.
Let π : S → ∆(A) be a stochastic policy specifies the decision-making strategy in choosing the probability of actions for each taxi in system based on current state, where ∆(A) is the probability simplex over action space A, and a t ∼ π(·|s t ). π is represented as the policy matrix P ij in this problem. By following π, a distribution of a state-action sequence τ = (s 0 , a 0 , · · · , a H−1 , s H ) is denoted as Eq. (11), starting from state s 0 drawing from starting state distribution ρ, and for all subsequent Given a discount factor 0 γ 1, the value function for a policy P ij is defined as discounted sum of future rewards from starting state s over a finite horizon H, i.e.
The expected value of initial state is further defined as Eq. (13).
For a given policy π, the state-action value function (Q-value function) Q π and the advantage function A π are defined as Eq. (14) and (15).
The objective of the learning agent is to use ascent methods for the optimisation problem given as Eq. (16), which is to maximise expected value from the initial state over all policies.
where π in this study is parameterised by linear function approximator as where θ is a row stochastic matrix, θ s,a 0 and a∈A θ s,a = 1 for s ∈ S and a ∈ A.
It has been proved in [1] that V π θ (s) is non-concave in θ for the above parameterisation, so the standard solvers for convex optimisation problems are not applicable for this target problem. Throughout this paper, we will use RL approaches to optimise the routing policies based on policy gradient theorem [46] as follows.
Let R(τ ) be the total reward of state-action sequence τ on following π starting from s 0 , where in this problem, the reward R(τ ) is given by where R(s 0 , a 0 ) is defined by Eq. (27) in Sec.6.2.1. Then, Though the problem of this paper is formally framed as a MDP, the RL method proposed in this paper is based on Monte-Carlo method with undiscounted setting where γ → 1, which does not require the system to be Markovian. The details of the model-free reinforcement learning will be further explained in Sec.6.

Methodology
We present our proposed model-based approaches, model-free RL and hybrid learner in this section, based on the design shown in Figure 1. The performance of RL depends on 1) meaningful state space, action space and reward functions defined, 2) good designed algorithms to learn from data, and 3) efficient data collection by exploring the environment in a self-organised way from the above formulation. To achieve that, we first present our model-based routing policy constructed from top-down approach, which requires no sample data. We then demonstrate our design of RL algorithm and the construction of reward function. At the end, a simple and effective hybrid approach is described to initialise model-free RL with model-based effective policy.
6.1. Model-based Routing Policy. For this target problem, instead of learning a model of the dynamic function of environment (like in most model-based RL), we can construct routing policy from transportation theory using the MDP. In order to find the optimal P ij which allows us to route a vacant taxi at any location in a given road network, the intuition behind our proposed model-based dispatch algorithm is to direct the vacant taxis to a set of "hotspots" in the road network, which are identified either statically or dynamically. These hotspots are locations where the probability of finding a waiting commuter is high, so that vacant taxis are dispatched to these hotspots, which can be formally described by a dispatch matrix D ij : given a vacant taxi at node i, D ij gives the probability of the taxi being dispatched to node j (which potentially can be quite far away). The dispatch probability is also inversely proportional to the distance between i and j. There will also be some routing choice from node i to node j (the simplest being the shortest path between the two nodes). Once D ij and the routing choice are specified, the turn-by-turn routing of P ij as model-based routing policy can also be uniquely determined via microscopic simulations and sampling. Throughout this paper we assume shortest path routing between two nodes for D ij , as the specific choice of routing algorithm is not essential in this particular context. 6.1.1. Dispatch Algorithm for Hotspots. One of the common approaches for vacant taxi manoeuvring is a good algorithm for dispatching them to certain locations on the map where higher probabilities of commuter generation are expected (the hotspots). This is also implicitly the strategy of experienced taxi drivers. Following the problem statements and definitions in Sec. 4, we first propose models of efficient dispatch algorithm, using A ij , g i , M ij as inputs, to obtain an efficient dispatch matrix D ij . Physically, for a vacant taxi appearing at node i, D ij gives the probability for this vacant taxi to be dispatched to a (not necessarily adjacent) node j, with the constraint j D ij = 1. We also allow D ii = 0, implying the vacant taxi stay put at its location waiting for commuters to appear. If node j is far away from node i, the vacant taxi will be dispatched to node j via the shortest path obtained from the network adjacency matrix A −1 ij . Without loss of generality, here we only make D ij dependent on g i and A ij , and not explicitly dependent on M ij .
Let d ij be the shortest distance in terms of travel time between node i and j, as computed from the adjacency matrix A −1 ij . For i = j we set d ii = 1. A rather general dispatch model is given as follows: Intuitively, D ij should increase monotonically with g j , while decreasing monotonically with d ij . This is because if all other conditions are identical, we should have a higher probability of dispatching vacant taxis to nodes with higher rate of commuter generation, the so-called hotspots. On the other hand, for two nodes with the same rate of commuter generation, there should be a reduced probability to dispatch the vacant taxi to a node that is further away. Optimisation of Eq. (20) can be done by Taylor expanding f with respect to d −1 ij and g j , and tuning the expansion coefficients at different orders to maximise the utility functions computed from agent based simulations. Here we use a rather simple model with the lowest order expansion as follows: is the normalisation factor. The performance of this model has been satisfactory based on extensive agent-based numerical simulations shown in later section Sec.8.1. 6.1.2. Effective Routing Policy from Dispatch Model. One major difference between D ij and P ij for vacant taxi manoeuvring is that for the former, nodes i and j can be quite far away. On the other hand, P ij is only non-zero when nodes i and j are neighbours. The degrees of freedom for D ij is thus much larger and scale as the square of the network size. This makes optimising D ij a much more difficult problem, as compared to optimising P ij (whose degrees of freedom scale linearly with network size). On the other hand, when the vacant taxi is dispatched from node i to j, the path between nodes i and j is deterministic (and we choose the shortest path in this work). Effectively, given a specific A ij , g i , M ij , D ij there is still a statistical distribution for the choice of neighbouring nodes from any node i, if we look at a large number of vacant taxis arriving at node i (either as the destination of the dispatch, or as an intermediate node enroute to the dispatch destination), and how these vacant taxis choose the next node. We can thus generate an effective P ij via agent based simulations, and this particular P ij is unique and well-defined in the limit of long time simulations.
Formally, for a simulation time with a total number of discrete time-steps H, we denote n H i as the number of times when an vacant taxi lands on node i, and we do not distinguish between different taxis. Let p H ij be the number of times the vacant taxi at node i moves towards one of the neighbouring node j. The effective turn-by-turn routing policy is defined as follows: In this way, the effective policy can be unambiguously defined for almost any manoeuvring strategies. If the routing strategy for vacant taxis is a turn-by-turn policy P ij to start with, then obviously we will haveP ij = P ij . If the routing strategy is from a dispatch policy D ij , there is a unique one-to-one mapping from D ij tō P ij , given all other conditions are fixed. We can thus evaluate and compare the performances of D ij andP ij in a meaningful manner. More importantly,P ij can be used as an optimised initial state for reinforcement learning, as we will explain in the rest of this paper.

Model-free Reinforcement Learning with Model-based Initialisation.
Top-down approaches in constructing P ij can be highly efficient using no data samples on the states s t , given a specific A ij , g i , M ij , but they generally do not yield optimal turn-by-turn maneuvring policies. Model-free RL, on the other hand, can optimise the policies variationally, starting with any specific initial policy using policy gradient based methods. To combine the benefits of model-based approach and model-free RL, we propose to train a model-free RL from either random policy or the effective policy from dispatch algorithm as our initialisation policy. Thus, we can use RL to obtain high performance routing policies either initialised from a random policy without the information on A ij , g i , M ij , or from model-based policies constructed from top-down approaches.
6.2.1. Model-free Reinforcement Learning. Our model-free RL is initialised with some specific policies, which are then updated by Actor-Critic Method with linear function approximators and on-policy policy gradient [45]. To improve the performance and sample efficiency, Proximal Policy Optimisation (PPO) [42] is used to optimise a "surrogate" objective function using stochastic gradient ascent to update policy P ij based on data sampled from P ij . An exploration bonus is further introduced to encourage the learning agent to visit novel states even when the environmental extrinsic reward is sparse. Policy Optimisation: More concretely, we employ Advantage Actor-Critic (A2C) [31] combined with PPO as a RL framework which serves as a well-performed baseline for a lot of discrete and continuous benchmarks, for example Atari, 3D humanoid, and MuJoCo Physics engine. In general, advantage actor-critic has two networks named as actor and critic accordingly. The actor is to learn the optimised policy using a policy network, as defined in Eq. (19), and the critic is to evaluate the policy created by the actor and suggest the adjustment using a value network with calculated advantage, as defined in Eq. (14) and (15. PPO is to used to reduce the variance of vanilla policy gradient by reducing reinforcement learning to a numerical optimisation problem on the policy. In essence, the policy matrix P ij (θ) is parameterised by actor parameter vector θ, where θ are trainable weights to maximise future rewards. An "surrogate" objective is maximised subject to the constraint that the distribution of the policy before update P ij (θ old ) is close to the distribution of update policy P ij (θ). Hence, the objective can be modified to penalise changes to the policy that moves too far from the P ij (θ old ). Formally, the objective to be optimised is shown as: where is a small hyperparameter to be tuned, r t (θ) is the probability ratio Pij (θ old )(at|st) .Â t is the estimated advantage at time t from the critic, which captures how a particular policy is better than the others at a given state. The expectation in equation 23 is the empirical average of samples from the distribution of P ij (θ old )(a t |s t ), using importance sampling to estimate expectation of P ij (θ)(a t |s t ).
The processing of policy optimisation is shown in Fig. 2. The PPO algorithm in A2C style is explained in detail in [42]. Combining Intrinsic and Extrinsic Reward: For this problem of taxi routing, the extrinsic reward is defined by bestowing a unit reward for every time step when a commuter is in taxi, for each taxi operating in the road network, characterising the optimisation objective defined in Sec.4. There is no punishment for vacant taxis cruising. The extrinsic reward at each time t is formally defined as cumulative future reward from time t to finite horizon H, shown in the following Eq. (25).
Well-performed policy in RL maintain a right balance of maximising extrinsic rewards (exploitation) and trying out new states (exploration), especially when the extrinsic rewards are sparse and the target task is temporally extended. Without proper exploration method, the proposed RL algorithm may converge to suboptimal solutions without attempting enough novel actions for potentially higher expected rewards. Though finding optimal exploration strategies under large, infinite MDPs (like this problem) is theoretically intractable, many exploration strategies are proposed to practically solve this problem, including optimistic exploration [5,17,47], Thompson sampling style algorithms [37], information gain style algorithms [22], etc. We adopt a random network distillation (RND) approach [5] to construct our intrinsic rewards, which is a heuristic estimation of state counts via prediction errors as exploration bonus. Generally, the intuition behind this approach is to encourage the agent to visit novel states by telling if the current state is novel or not. The RND approach takes inspirations of count-based optimistic exploration and information gain approach. This approach can also handle large input states where most states are visited at most once, as compared to the other approaches.
Specifically, the RND includes two networks: a target network and a predictor network. The target network takes input state to an embedding f * (s, a) = f ψ (s, a), where ψ is a random parameter vector. The predictor network is trained by gradient descent to minimise the Mean Squared Error (MSE) between output prediction f φ (s, a) and the embedding f ψ (s, a). The prediction error R i (s, a) = ||f φ (s, a) − f ψ (s, a)|| 2 is set as the intrinsic reward (exploration bonus).
The final reward function is a linear combination of the extrinsic reward and intrinsic reward. The reward function proposed does not tell the vehicles anything about where the commuters are and how to reach the potential commuters. Further normalisation has been done for the intrinsic reward to divide it by a running estimate of standard deviation, so as to keep the intrinsic reward within a reasonable scale when combined with the extrinsic reward. The mathematical representation of the combined reward is in Eq. (27), where R e and R i are extrinsic reward and intrinsic reward respectively, n s represents the number of total observed states and the corresponding number of actions, σ is the normalisation parameter, and R is the total reward.
6.2.2. Initialising Model-free Reinforcement Learning. In practice, the model-based routing policies leverage the full knowledge of the environment and the MDP, but the best-performing dispatch algorithm (non-committed normalised dispatch algorithm as shown in Sec.8.1) still in most cases lags behind the pure model-free learners especially when the road network size is small and/or the normalised entropy of given demand pattern is also relatively small. The reasons may lie in the mismatch between the optimal state-action distribution and the dispatch algorithm guided state-action distribution as a result of open-loop control algorithm.
To combine the benefits of model-free learners and model-based routing policies, we first use imitation learning to train a model-free RL agent to imitate the modelbased routing policy as an initialisation, and then further train the model-free learner to gather on-policy data in order to minimise the mismatch between the gathered data state-action distribution and the learned state-action distribution. The model-based routing policy P ij generated from Sec.6.1 is first collected to train a initial policy of our model-free learner described in Sec.6.2.1. The policy network parameterised by θ is trained to match the trained policyP ij (θ) to the target effective policy P ij . Let n be the number of nodes in road network G, and let J represent the number of direct connections from i where i = j and A ij = 0, the objective is to minimise cross entropy loss as Eq.(28) between the model-based target policy and trained policy, using the Adam optimiser. (28) argmin The trained policy is used as initial policy of our model-free learner. After initialisation, on-policy data is collected at each optimisation iteration to update learned policy P ij (θ) parameterised by θ using model-free RL proposed. The process is carried out until the optimisation objective based on average hiring time of taxis for each second meets expectation.

Experiments
The performance of our proposed reinforcement learning methods have been evaluated on large scale simulation platform described in Sec.5.1. Linear function approximators, optimised by the Adam optimiser, are used for both value network and policy network. At each epoch, a large number of instances consisting of vacant taxis' positions, choices of actions, as well as the extrinsic rewards of such actions over horizon H, are generated from the simulation.
Experiments were conducted on two types of datasets: an artificial road network where the commuter demands g i and origins/destinations M ij were randomly generated, and a community-based Singapore road network with both random and empirical commuter demands g i . The community-based Singapore road network covers the entire Woodlands, Sembawang, Simpang, Mandai and Yishun areas at the north of Singapore, as shown in Figure 3. The network consists of 2591 nodes and 5833 edges. Empirical commuter demands g i were generated from trip data of a weekday in 2018. Figure 3. Community-based Singapore road network for experiment. The size of the node represents g i , indicating the probability of generating a commuter at each second in percentage.
The benchmark tasks include evaluations of the produced routing policy on road network specified in the following Table 2. The artificial road networks consist of square lattices with random bi-directional edge weights. g i is non-uniform and generated randomly with normalised entropy η within (0.6, 0.8) representing randomness of the information, calculated by Eq. (29) and (30), where p i is normalised g i that sum up to 1 and n represents the number of nodes of given road network. M ij is generated uniformly -at each origin i in network, the probability of generating a commuter to any other destination node j is draw from a uniform distribution unif ∼ {0, 1}, and M ii = 0. Note that with many different realisations of the commuter generation and M ij patterns are tested, the results are qualitatively very similar.
Setting Network Type Nodes Taxis In our implementation, the performance metrics used for evaluation are the average extrinsic reward over the simulation horizon H denoted as Eq.(31), and average waiting time of all commuters given by Eq. (7). In general maximising the average reward of taxis will result in minimising the average waiting time of commuters, especially in our experimental scenarios where the origins and the length of the trip have no correlations. For simplification, the average extrinsic rewardR e is named as reward during the discussion of the results in Sec.8.

Results
We first examine the design decisions for our model-based approaches and modelfree RL, presented in Sec.8.1 and 8.2, using artificial road network and randomised g i and M ij . We then compared our model-based and model-free approaches, as well as our model-free RL with model-based initialisation to demonstrate the effectiveness of our hybrid approach using both artificial road network and community-based Singapore road network with empirical demands, presented in Sec.8.3.

8.1.
Model-based Routing Policy from Dispatch Algorithm. Multiple dispatch algorithms have been proposed and compared based on 1) whether the taxis are committed to dispatch to the target node to serve commuters (do not serve other commuters during their travels) and 2) whether normalisation factor λ i in Equation 21 has been used. Experiments were conducted to evaluate the performance of the proposed dispatch algorithms on artificial network of 100 nodes (experiment setting S1). The performance of four dispatch algorithms: committed dispatch, committed normalised dispatch, non-committed dispatch, and non-committed normalised dispatch in terms of average waiting time of commuters are shown in Figure 4. From the comparison, non-committed normalised dispatch algorithm outperforms the other algorithms and is selected to be used to derive effective policy P ij to initialise model-free RL. Number of Taxis Log of Average Waiting Time qq qq qq qq qq qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq qq qq qq qq qq qq qqq qqq qq qqq qqq qqq qqqq qqqq qqqq qqqq qqqq qqqqq qq qq qq qq qq qq qq q q q q q q q q q q q q q q q q q q q q q q q q q qq q qq qq qq qq qqq qqq qqq qqq qqqq qqqq qqqq qqqqq qqqqq qqqqq qqqqqq qqqqqq q qq qq qq qq qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq    Figure 6. The results show that the final performance (after training 1000 epochs) in terms of reward and average waiting time of commuters between learned policies from model-free RL, and model-free RL with initialisation, are similar. Both are better than policy derived from non-committed normalised dispatch algorithm, effective policy and random policy. This is especially true when the average waiting time of commuters are relatively long when demand exceeds supply.
Regarding the efficiency of learning, both the model-free RL and the hybrid approach can learn a fairly good policy with better performance than random policy and effective policy from model-based approach very quickly (within 200 epochs), as shown in Figure 7. Even with similar converged performance at the end as in Figure 6, the hybrid approach with model-based initialisation can be much more sample-efficient in learning compared with randomised initialisation. A reasonable reward can be achieved by significantly less training epochs (less than 100 epochs of training). Note that each epoch entails a simulation run of 50, 000 seconds (simulation time) with maximum 512, 000 data samples collected, detailed in Appendix.
We have previously identified a transition between the oversaturated phase when demand exceeds supply, and the undersaturated phase when supply exceeds demand, when the structure of road network is given, as discussed in our previous work on phase transition in taxi dynamics [52]. The phase transition is also shown in Figure 6 that in the oversaturated phase the average waiting time of commuters is affected exponentially with increased number of taxis, while in the undersaturated phase it is affected sub-linearly. In practice, we are more interested in optimising vacant taxi routing in the oversaturated phase to meet the service requirements of commuters efficiently. When the random policy for vacant taxis can already achieve low average waiting time in the undersaturated phase, there is no much room left for optimisation and the redundancy of taxis on roads creates more problems than they save. Specifically for these benchmark tasks, we are mainly evaluating the performance of our proposed algorithm when the number of taxi is less than 50 for lattice network of 100 nodes (experiment setting S1) and less than 150 for lattice network of 1089 nodes (experiment setting S2).
8.4. Evaluation on Singapore Road Network. The performance of our proposed approaches is also evaluated on real community-based Singapore road network as described in Sec.7. We compare the results using both randomised demands and empirical demands with taxi numbers ranging from 30 to 200, as shown in Figure 8. Results demonstrate a consistently better performance of proposed hybrid approach, in compare with all the other approaches on a medium-sized real-world road network of 2591 nodes. Figure 8 also shows that when the normalised entropy of the empirical demands is larger as compared with random demands (the  empirical demands of these areas are more uniformly distributed spatially with less "hotspots"), the number of taxis needed to operate on the road network can be significantly less, but still with higher average hiring time of taxi drivers (reward) and lower average waiting time of commuters when using efficient routing policies proposed in this work.
By comparing the efficiency of proposed hybrid approach and pure model-free approach on Singapore road network (shown in Figure 9), the hybrid approach can achieve much higher final performance and uses significantly less data samples and training epochs, especially when using empirical demand data (for which the normalised entropy is larger compared to the randomised demands).

Summary and Outlook
In summary, we presented in this paper methodologies in optimising vacant taxi routing for street-hailing in response to a stochastic demand pattern, so as to maximise the average time of hiring of taxis, and thus reducing the average waiting time of commuters. A model-based dispatch algorithm, a model-free RL based on PPO and RND, and a hybrid RL approach with model-based initialisation are proposed and evaluated under various experimental scenarios using a largescale agent-based simulation. In general, the proposed model-free RL with modelbased initialisation achieves best final performance on both artificial road network and Singapore road network with empirical demands, and are much more sample efficient than pure model-free RL approach. The sample efficient hybrid approach developed here is compelling, especially for useful applications in managing large taxi fleet with human drivers, as well as intelligent routing software for driverless taxis in the near future. The methodologies proposed can be potentially applied to a wide context in urban transportation and logistics problems with stochastic demands, such as dynamic reallocation of shared resources and last-mile delivery.  Our proposed model-free RL uses only the positions and actions of all taxis with extrinsic rewards to learn and optimise routing policy on a given road network. With training epochs less than 200, even if the street-hailing demand pattern is not given, our model-free RL can in most cases achieve high performance compared to model policies, including dispatch policy with given demand patterns. This method is good for vacant vehicle routing when the demand patterns and the dynamics of the environment are too complex to be modelled or to be predicted.
The model-based methods we proposed are not as effective as model-free RL on their owns in most of our experimental settings. However, they offer extremely sample efficient way to derive routing policies with reasonably good performance, when the dynamics of the demand-and-supply can be modelled. They are also useful for real-world tasks when real-time optimisation is needed, long-term training is infeasible or data required for model-free RL is hard to get. Based on the model-free RL and the model-based top-down approach, we then design a hybrid approach using model-free RL with model-based initialisation to combine the benefits of RL and proposed dispatch algorithm. While lattice network is a regular graph, real-world road network with empirical demands may encode more complex dynamics. The proposed hybrid approach is versatile in multiple scenarios under artificial and real road networks of different complexities, and with different size of taxi fleet, which demonstrates its potential in a general setting. The hybrid approach is simple and effective in terms of design and implementation, thus can be widely applied to real-world applications to enhance performance of existing solutions based on heuristics or meta-heuristics, or to accelerate learning process for model-free learner with better performance and less data samples. The on-policy RL approaches proposed in this paper can also be readily extended to consider changing traffic conditions (i.e. congestion) or demand patterns (i.e. peak or off-peak demand) in many real-world problems, by modifying the road network adjacency matrix according to the empirical data and update routing policies accordingly.
The methodologies presented in this paper could have wider applications beyond taxi systems, for a wide range of empirical and synthetic systems. For future work, we will work on incorporating time-dependent traffic conditions and demand patterns for real-world impact. We will also extend the agent-based simulation and the proposed model-based and model-free approaches to cases with ride-sharing, for the optimal routing and route-matching between shared commuters. Our ultimate goal is to optimise routing of demand-responsive transit system in a hybrid form consisting of real-time booking, street-hailing, as well as ride-sharing.