1 Introduction

Simulation is an indispensable tool in order to analyse and optimize complex services with dynamically changing demand and supply, all embedded into a dynamic environment. In the case of taxi services in large cities, a reliable simulation approach must model all these elements both at the microscopic level of detail (i.e., individual customers and vehicles are simulated) and in the large-scale (regional, or at least city-wide) scope. The high dynamism of taxi demand is a result of almost all requests being immediate trips with an unspecified destination. For example, partially independent taxi drivers who can choose which rank to wait at, reject serving a request, or decide upon their working hours, account for the limited control over the stochastic supply side. Finally, urban traffic, being the environment for taxi services, implies stochastic time-dependent travel times.

Once the simulation model is ready, analysis and optimization may begin, for instance, by changing the dispatching algorithm, scaling demand and supply, or relocating taxi ranks. As far as the authors know, out of many taxi simulation models (Lee et al. 2004; Alshamsi et al. 2009; Wang et al. 2009; Seow et al. 2010; Cheng and Nguyen 2011), the microscopic ones, though limited in scope, were created for Singapore, Barcelona and Mielec, Poland only. In the case of Singapore, two distinct simulation studies were carried out. Lee et al. (2004) used Paramics to simulate taxi dispatching in Singapore’s Central Business District, whereas Seow et al. (2010) coupled the NTuCab taxi dispatching software with the MITSIMLab microscopic traffic simulator. For the Bacelona case, a multi-agent simulation implemented in MATLAB was used (Salanova et al. 2013; Salanova and Estrada 2015).

This paper presents two microscopic simulation models built for the cities of Berlin (with the neighbouring Brandenburg region) and Barcelona, which are then used to assess the performance of two real-time rule-based taxi dispatching strategies on large scale. The approach, discussed in Sec. 7, originates from an earlier work on simulating taxis in Mielec, Poland (Maciejewski and Nagel 2013a, b) by means of MATSim, a multi-agent transport simulation. Because MATSim allows simulating millions of agents both physically (fast queue-base traffic simulation) and mentally (rich behavioural model for trip planning), a large-scale, realistic simulation of taxis is possible, which makes this approach distinct.

2 Taxi supply and demand in Berlin

Currently, the Berlin taxi market consists of some 7600 vehicles licensed to operate in the city. They are organised in 3000 taxi companies employing roughly 18,000 taxi drivers. To model Berlin’s taxi supply and demand, in this paper, trajectories of Berlin’s biggest radio taxi operator, Taxi Berlin, are used. Overall, they have some 5700 vehicles working within their range, most of them equipped with GPS trackers that submit their current location and occupation status in a flexible interval (depending on the vehicle’s occupation status, but at least once every 60 s). These data are, among others, mainly used for travel time prediction in Berlin (Ebendt et al. 2012). With the current occupation status of the vehicle also being submitted, a zone-based matrix of demand for each hour can be generated and used for the demand side of the simulation. On the supply side only the amount of vehicles logged into the system at each second is known, not the actual length of each vehicle or driver shift. This is due to data anonymization by regular reassignment of IDs to vehicles. Furthermore, the amount of vehicles per zone in each occupation status is known in intervals of five minutes.

For the simulation purposes, the supply and demand data of one week (15 April–22 April 2014) were provided, of which the timeframe between Tuesday 4:00 am and Wednesday 4:00 am has been picked for simulation.Footnote 1 Figure 1 shows the amount of taxis and requests served during the timeframe investigated. Overall, 27,376 trips were registered. The vehicle supply adjusts to the demand for taxi trips. There is a strong morning peak followed by two somewhat smaller peaks in the afternoon and evening.

Fig. 1
figure 1

Hourly request submissions and active taxicabs in Berlin

The extracted taxi demand is aggregated into 518 zones. Within the city boundaries, these zones correspond to the city quarters defined by the city administration as Lebensweltlich orientierte Räume (LOR) (Senate Department for Urban Development and the Environment 2015). In the outskirts, community boundaries are used instead. The zone with the highest amount of trips starting or ending is the one around Berlin’s major airport, Tegel. Within 24 h, 3799 trips to and from the airport were registered. Most other trips are either ending or beginning in the city centre. Figure 2 shows the origin of taxi trips within the city centre. Idle vehicles tend to aggregate at taxi ranks. Within Berlin, there are roughly 400 of them in operation. Figure 3 provides an overview of rank locations and the average number of idle taxis in each zone. Also in this figure, the area around Tegel airport is clearly notable for the highest amount of idle vehicles. Despite a relatively high demand, waiting times for drivers of several hours are not uncommon there. A detailed FCD analysis is also available (Bischoff et al. 2015).

Fig. 2
figure 2

Spatial distribution of daily taxi demand in Berlin

Fig. 3
figure 3

Average amount of idle taxis per zone in Berlin

3 Taxi supply and demand in Barcelona

The taxi sector in Barcelona comprises of 10,523 taxi licenses, from which 5 % belong to private companies and the 95 % to individuals. The number of taxi licenses has been frozen since 2005 (one license per 275 inhabitants). However, the number of driver licenses has increased significantly over the last years (13,136 in 2010, with the rate of drivers to vehicles of 1.26, while this rate was 1.14 in 2007). The demand for taxi services has been estimated by the Metropolitan Taxi Institute (IMT) as more than 200,000 trips per day, which corresponds to 1.52 % of the total number of trips in the wider area (roughly 13,000,000 trips daily). Salanova (2013) estimates the demand for taxi trips at 60,000,000 trips per year based on the GPS trackers collecting origin and destination of trips during the last ten years. On the supply side, the input data has been calculated by Salanova (2013) based on the data provided by the IMT surveys where all the drivers participated.

For the simulation purposes, FCD data recorded for a subfleet of GPS-monitored taxicabs between March 2011 and December 2012 were used, giving precise spatio-temporal information about pickups and dropoffs for 233,509 taxi trips, out of which 126,765 were inner-city weekday (i.e., between Monday 5:00 am and Friday 5:00 am) trips. Figure 4 shows the distribution of destinations for this subset of trips.

Fig. 4
figure 4

Spatial distribution of destinations for weekday inner-city taxi trips in Barcelona

Since this demand is synthetic and does not represent any specific day, the supply (i.e., fleet size) was adjusted using time-dependent (hourly) request-to-taxi ratios typical for weekdays.Footnote 2 Figure 5 shows the hourly profiles of demand and supply during a weekday.

Fig. 5
figure 5

Hourly request submissions and active taxicabs in Barcelona

4 Comparison of scenarios

A comparison of the main properties of both case studies is provided in Table 1. Although the Berlin scenario encompasses an almost five times larger area than that of the Barcelona scenario, the size of the network measured in links and nodes is similar. On average, there are 1.7 times more working taxis and 4.7 times more submitted requests in Barcelona (oversupply is very specific to the taxi market in Berlin). This leads to a significant disproportion in the mean hourly workload between scenarios. In both cities most of the taxi demand concentrates around the city centre and the airport. As a result, despite the huge differences in terms of geographical scope, the average duration of ordered taxi trips is similar; taxi trips are only 2 min (25 %) longer in Berlin.

Table 1 Scenario comparison

5 Online taxi dispatching

The formulation of the dispatching process was derived from an earlier formulation used by Maciejewski (2014a, b) for optimizing taxi services in Mielec, Poland. The description below covers immediate requests with unknown destinations, i.e., customers want taxis to arrive as soon as possible and they specify the destination after being picked up, which corresponds to the overwhelming majority of requests in Berlin. However, this type of request is more challenging in terms of online optimization since the provision of the demand data is maximally postponed. As for the supply side, the formulation includes time windows, which in comparison to the original model, add complexity.

Let \(N=\{1,\ldots ,n\}\) be the set of taxi requests (customers). The following sequence of events is related to serving each request \(i \in N\) and is illustrated in Fig. 6. Taxi customer i calls a taxi (event \(E^\mathrm {call}_i\), time \(\tau ^\mathrm {call}_i\)) specifying the pickup location, \(p_i\). Since only immediate requests are considered, the customer’s desired departure time is \(\tau ^\mathrm {dep}_i = \tau ^\mathrm {call}_i\). A selected taxi is dispatched towards \(p_i\) at time \(\tau ^\mathrm {disp}_i\) (event \(E^\mathrm {disp}_i\)), and immediately after arrival, the pickup starts (event \(E^\mathrm {pick0}_i\), time \(\tau ^\mathrm {pick0}_i\)). Once the passenger is picked up (event \(E^\mathrm {pick1}_i\), time \(\tau ^\mathrm {pick1}_i\)), he or she specifies the destination, \(d_i\), and the taxi sets out immediately. After reaching \(d_i\), the dropoff begins (event \(E^\mathrm {drop0}_i\), time \(\tau ^\mathrm {drop0}_i\)). Once the passenger gets out (\(E^\mathrm {drop1}_i\), time \(\tau ^\mathrm {drop1}_i\)), the taxi is ready to serve another request. Due to the stochasticity of taxi dispatching, times \(\tau ^\mathrm {call}_i\), \(\tau ^\mathrm {dep}_i\), \(\tau ^\mathrm {disp}_i\), \(\tau ^\mathrm {ready}_i\), \(\tau ^\mathrm {pick0}_i\), \(\tau ^\mathrm {pick1}_i\), \(\tau ^\mathrm {drop0}_i\) and \(\tau ^\mathrm {drop1}_i\) are estimated until the respective events take place, and are therefore subject to change.

Fig. 6
figure 6

A taxi driver’s schedule and a passenger’s plan

Request \(i \in N\) is open if it either has not been planned yet, \(\tau ^\mathrm {disp}_i\) is not set, or is planned to be served in the future, \(\tau ^\mathrm {disp}_i > \tau ^\mathrm {curr}\), where \(\tau ^\mathrm {curr}\) denotes the current time. Let L be the list of all open requests ordered by \(\tau ^\mathrm {dep}_i\). Each request i is inserted into L on submission, \(E^\mathrm {call}_i\), and removed from L on taxi dispatch, \(E^\mathrm {disp}_i\).

Let \(M=\{1, \ldots , m\}\) be the set of vehicles. Each vehicle \(k \in M\) is available at location \(o_k\) within the time window \([a_k, b_k)\). It is assumed that vehicles do not cruise and remain at the dropoff location of the last served customer. When no request has been assigned to k, \(o_k\) is k’s initial location and \(a_k\) is the time the taxi starts operating. Otherwise, \(o_k\) is the dropoff location, \(d_i\), and \(a_k\) is the time the dropoff ends, \(\tau ^\mathrm {drop1}_i\), of the last request assigned to k, i. Since \(d_i\) remains unknown till \(\tau ^\mathrm {pick1}_i\), both \(o_k\) and \(a_k\) are unknown temporarily as well, with the restriction that \(a_k > \tau ^\mathrm {curr}\). Let \(M^\mathrm {I}\subseteq M\) be the set of all idle vehicles; vehicle \(k \in M\) is idle if \(a_k \le \tau ^\mathrm {curr}< b_k\).

6 Rule-based heuristics

Two heuristic dispatching strategies were used to manage the fleet of taxis. Neither strategy uses information about the destinations of the busy vehicles to predict their future availability; thus, the choice of taxis to be dispatched is limited to idle taxis, \(M^\mathrm {I}\).

The first heuristic, called nearest-idle-taxi, mimics the approach used by many taxi companies. It always serves awaiting requests in the FIFO order by dispatching the nearest idle taxi, \(k^* \in M^\mathrm {I}\), to the first request in L, L[1]. By default, the nearest taxi is defined according to the travel time criterion, that is

$$\begin{aligned} k^* = \mathop{\mathrm{arg\,min}}\limits_{k \in M^\mathrm {I}}{t^\mathrm {O}_{k,L[1]}\left( \tau ^\mathrm {curr}\right) }, \end{aligned}$$
(1)

where \(t^\mathrm {O}_{ki}(t), k \in M, i \in N\) is the travel time from \(o_k\) to \(p_i\), given the departure time, t.

The strategy reacts to the following events:

  • \(E^\mathrm {call}_i\) — if \(M^\mathrm {I}\ne \oslash\), vehicle \(k^*\) is dispatched to request i

  • \(E^\mathrm {drop1}_i\) — if \(L \ne \langle \rangle\), vehicle k, after having completed request i, is dispatched to request L[1]

This strategy does not look into the future to predict the availability of busy taxis and create schedules.Footnote 3 Therefore, even distance-based measures, such as straight-line distance, can be applied to determine \(k^*\). Being very simple, it allows fast, real-time taxi dispatching. However, the main drawback is its poor performance under high demand; when \(\left| M^\mathrm {I}\right| \rightarrow 0\), \(k^*\) may be on the opposite side of a city.

To address this problem, a demand-supply balancing strategy was used. It classifies the system state into the two following mutually-excluding categories: oversupply (\(M^\mathrm {I}\ne \oslash \wedge L = \langle \rangle\)) and undersupply (\(M^\mathrm {I}= \oslash \wedge L \ne \langle \rangle\)) and handles these two situations differently. In the former case, the requests are processed as in the first algorithm, whereas in the latter case, vehicle k is dispatched to the nearest awaiting request, \(i^* \in L\). Given the time-based distance measure, k is assigned to serve \(i^*\) such that

$$\begin{aligned} i^* = \mathop{\mathrm{arg\,min}}_{i \in L}{t^\mathrm {O}_{k,i}\left( \tau ^\mathrm {curr}\right) }. \end{aligned}$$
(2)

The demand-supply balancing strategy reacts to the following events:

  • \(E^\mathrm {call}_i\)—if \(M^\mathrm {I}\ne \oslash\), vehicle \(k^*\) is dispatched to request i

  • \(E^\mathrm {drop1}_i\)—if \(L \ne \langle \rangle\), vehicle k, after having completed request i, is dispatched to request \(i^*\)

The demand-supply balancing strategy was based on the assignment rules for scheduling of automated guided vehicles studied by Egbelu and Tanchoco (1984). They proposed order-initiated and vehicle-initiated assignment rules. The former are applied upon request submission (here, \(E^\mathrm {call}_i\)), whereas the latter are executed upon request completion (here, \(E^\mathrm {drop1}_i\)). Under low demand, the balancing strategy serves requests immediately as they arrive (request-initiated planning). However, in an overloaded system, the focus is shifted from the FIFO processing order to maximizing vehicle utilization by dispatching vehicles that have become idle to the nearest awaiting requests (vehicle-initiated planning). This results in increased throughput, and consequently, reduces the amount of time passengers await taxis.

7 Simulation setup

MATSim (Horni et al. 2016) was used as the simulation platform. In general, it allows for running agent-based transport simulations, and its primary purpose is activity-based travel demand modelling. Typically, simulation in MATSim is an iterative process of simulating a sequence of days, each consisting of: (1) trip planning, (2) traffic simulation (network loading), and (3) performance assessment. The experience gained over time, let agents improve their performance. The simulation process ends after the system reaches a state of relaxation (i.e., equilibrium).

Due to the growing set of extensions, MATSim’s core functionality can be extended to serve many purposes. In this study, the DVRP (Dynamic Vehicle Routing Problem) extension (Maciejewski 2016) was used to simulate taxis. The vehicle routing model implemented in this extension covers a wide range of problem types, offering such features as one-to-one and one-to-many (many-to-one) topologies, multiple depots, dynamic requests, non-homogeneous requests and vehicles, time windows, time-dependent stochastic travel times and costs, network-based routing, and vehicle monitoring and diversion.

The DVRP extension provides the connection between MATSim and the optimization algorithm. It listens to simulation events, monitors the state of simulation, binds driver behaviour to the schedules computed by the optimizer and coordinates interaction between drivers, passengers and dispatchers. It also facilitates optimization by providing the functionality of least-cost path/tree search. For a detailed description of the DVRP extension, the reader is referred to Maciejewski (2016).

For the simulation of taxis in Berlin, a network based on the OpenStreetMap data is used. It represents the road network in Berlin and the surrounding area of Brandenburg. The network consists of 11,353 nodes and 24,350 links. Using car traffic based on an earlier simulation (Neumann 2014), time-specific link travel times were generated without having to simulate all background traffic. This keeps the simulation runtime reasonable, as only taxi traffic must be considered. The extracted demand data from FCD were converted into plans for MATSim agents. Locations for origins and destinations within the zones were randomly distributed as were the actual departure times within each hour. This resulted in 27,386 agent plans with exactly one taxi trip each. With this demand, the overall stress on the system is low. However, to accommodate a comparably high share of black-market rides in Berlin (30–40 % according to estimations) (Sauer 2014), a scaling factor of 1.5 for the taxi demand seems reasonable. Moreover, taxi demand may be much higher due to bad weather conditions, public transport breakdowns, trade fairs or other events. For example, during a recent strike (15 October 2014) in the overground railway system, our data show the amount of taxi trips doubled during the afternoon peak with the taxi supply only increasing by about 20 %. On that particular day, a scaling factor for the original demand of 2.5 would be appropriate. To depicture all these fluctuations, the authors decided to scale up the demand step-wise up to 5.0 while keeping the original spatiotemporal distribution of requests.

A similar procedure was used to create a simulation scenario for taxi dispatching in Barcelona. The Barcelona road network model was extracted from the OpenStreetMap data. Consisting of 12,687 nodes and 23,648 links, the network is similar in size to that of Berlin. To provide high simulation performance, time-dependent link travel times were used instead of simulating the whole road traffic. The inner-city weekday taxi trips (Sec. 3) were modelled as taxi legs of 126,765 MATSim’s agents, each having one taxi trip. The supply side (expressed in vehicle hours) was scaled by factors between 0.4 and 2.0, aiming at both executing a sensibility analysis of the system performance for different taxi fleet sizes and determining the minimum number of taxis needed for serving all taxi trips at a reasonable level of service.

8 Results

Out of several different performance measures proposed by Maciejewski and Nagel (2013b), the following two are analysed in this section:

  • the average passenger wait time, representing the customers’ perspective,

    $$\begin{aligned} T_\mathrm {W}= \sum _{i \in N} (\tau ^\mathrm {pick0}_i - \tau ^\mathrm {dep}_i) / n, \end{aligned}$$
  • the average pickup trip time, representing the drivers’ perspective,

    $$\begin{aligned} T_\mathrm {P}= \sum _{i \in N} (\tau ^\mathrm {pick0}_i - \tau ^\mathrm {disp}_i) / n. \end{aligned}$$

Computational experiments were carried out 20 times for each individual setting (i.e., both the strategy and demand/supply scaling).

Figure 7 presents the results obtained for the Berlin case at different levels of demand. Up to the scaling factor of 2.5 both approaches have comparable performance in terms of \(T_\mathrm {W}\) and \(T_\mathrm {P}\). This is because at low demand only the request-initiated assignments are carried out, i.e., the nearest idle taxi is dispatched to each newly submitted request (the same behaviour in both strategies). However, when the system is overloaded, only vehicle-initiated planning takes place, which leads to significant differences in the performance of both methods, as the balancing strategy uses a different rule and tries to minimize the pickup trip times instead of serving requests in the FIFO order. As a result, the nearest-idle-taxi strategy fails for the tripled demand (\(T_\mathrm {W}\) increases to almost 50 min), whereas the balancing approach efficiently handles even the quadrupled demand (\(T_\mathrm {W}\) is below 10 min).

Fig. 7
figure 7

Average wait time, \(T_\mathrm {W}\), and pickup trip time, \(T_\mathrm {P}\), at each demand level in Berlin

The results obtained at different taxi supply levels for the Barcelona case are shown in Fig. 8. For the scaling factor of 1.0 and above, the results for both strategies are comparable. However, the reduction of the fleet size by only 20 % causes noticeable differences in dispatching performance. At the scaling factor of 0.6, the nearest-idle-taxi strategy does not provide a sufficient level of service (\(T_\mathrm {W}\) exceeds 50 min), whereas the other approach preforms reasonably well even when half of the fleet is in service (\(T_\mathrm {W}\) is about 10 min).

Fig. 8
figure 8

Average wait time, \(T_\mathrm {W}\), and pickup trip time, \(T_\mathrm {P}\), at each supply level in Barcelona

In general, under high load, the first strategy is extremely myopic as it dispatches vehicles only by looking at the first request in the queue, even though the selected vehicle could be utilized more effectively if dispatched to another request. On the other hand, the other strategy takes into account all awaiting requests and sends the idle vehicle to the closest request which reduces \(T_\mathrm {P}\) and consequently increases the system throughput. Because all requests are immediate, \(T_\mathrm {P}\) is a component of \(T_\mathrm {W}\), thus, achieving relatively small \(T_\mathrm {P}\) generally leads to smaller \(T_\mathrm {W}\). This relation may be observed in Figs. 7 and 8, where keeping \(T_\mathrm {P}\) below 5 min enables the balancing strategy to serve much higher demand. Interestingly, \(T_\mathrm {P}\) drops at high undersupply (the demand scaling of 5.0 for Berlin, and the supply scaling of 0.45 for Barcelona) and is expected to drop even further as the undersupply grows, as the average distance to the nearest open request shrinks. Moreover, the balancing strategy instantaneously switches between the dispatching rules, even during short interleaving periods of undersupply and oversupply, reducing the risk of getting into larger undersupply.

The shift of focus from fairness (FIFO order) to maximising throughput by going to the nearest customer, carries a risk of (temporal) starvation of customers located in less attractive locations (i.e., where no taxi arrives). This, however, was not observed in simulations conducted for both cities. According to Figs. 9 and 10, under high demand, the balancing strategy performs better also in relation to the 95th percentile of the passenger wait time. Despite the apparent lack of fairness, even an ‘unlucky’ passenger (represented by \(T_\mathrm {W95}\)) is served quicker than an ‘average’ passenger (represented by \(T_\mathrm {W}\)) when no balancing is used.

Fig. 9
figure 9

Average wait time, \(T_\mathrm {W}\), and the 95th percentile, \(T_\mathrm {W95}\), at each demand level in Berlin

Fig. 10
figure 10

Average wait time, \(T_\mathrm {W}\), and the 95th percentile, \(T_\mathrm {W95}\), at each supply level in Barcelona

The results also show that regardless of the dispatching strategy, the fleets are oversized in both cities. The FCD analysis revealed the demand-to-supply ratio to be around 0.7 requests per vehicle hour for Berlin (most likely due to numerous taxi rides being unregistered, as mentioned Sec. 7), and 1.8 for Barcelona. Figure 11 shows a high quality of service (i.e., \(T_\mathrm {W}< 5.0\) min) is attainable even at the ratio of 2.2 requests per vehicle hour for Berlin and 3.3 for Barcelona. Despite the similarities between both case cities (e.g., the size of both networks), the differences in the dispatching performance are quite visible. This is mainly the effect of scale: as the average distance from a given request to the nearest idle taxi, and from a given taxi to the nearest waiting request, drops with the growing number of idle taxis and waiting requests, respectively.

Fig. 11
figure 11

Average wait time, \(T_\mathrm {W}\), in relation to different demand-to-supply ratios in Berlin and Barcelona

9 Conclusions

Dispatching a fleet of thousands of vehicles in order to serve tens or hundreds of thousands of requests daily, poses a challenging optimization problem. The problem is inherently dynamic, as almost all requests are immediate and without pre-specified destinations.

By means of large-scale microscopic simulation run in MATSim, and the dynamic routing functionality offered by the DVRP module, a realistic simulation model of the taxi services in Berlin and Barcelona was developed. This allowed a detailed benchmarking of two rule-based dispatching strategies to be carried out, out of which the second was able to efficiently serve both low and high demand.

Combining both simplicity and efficiency, rule-based dispatching is a very attractive and, thus, overwhelmingly popular approach for management of a fleet of taxis in the real world. However, their apparent disadvantage is the limited planning horizon; the selected decision is the best among all possible single moves, without considering potential sequences of moves. Therefore, the authors plan to use the microscopic taxi model of Berlin and Barcelona to study in detail other, more sophisticated dispatching algorithms, the best of which could be later applied to managing a real fleet. The results of the microscopic model will be also useful for providing guidelines to the taxi policy decision makers in both cities about the number of taxis operating in each city.