1 Context

Stimulating people to switch their means of transportation from individual to public alternatives is an important point in addressing the problem of mobility in Brazilian cities. A study by CNI RSB - Urban Mobility, 2015Footnote 1 indicates that only 24% of the Brazilian population use buses to commute. Nevertheless, bus riding is the most widespread public transportation option in the country. One of the reasons preventing more people from adopting this transport mode is the lack of clear and updated information. In this sense, powerful passenger information tools help to increase its attractiveness.

Using an online Trip Planner, the passenger is given a list of route options in the public transport network to go from his current place (or any other starting point) to a desired location. Each option defines a value for every criterion the passenger wishes to minimize, such as the time of arrival, the number of transfers and the total walking distance. Instead of minimizing his arrival time at his destination, the passenger can also provide a target arrival time and the tool maximizes his departure time.

Section 2 describes the features of our Trip Planner, which is continuously available in several Brazilian cities (FlorianópolisFootnote 2, GuarujáFootnote 3 and São Bernardo do CampoFootnote 4). Section 3 formulates the Trip Planner by Departure Time as a multi-objective problem. Section 4 shows why this problem and the Trip Planner by Arrival Time are equivalent problems and how they can be solved using the same algorithm. In Sect. 5 we present an A*-based algorithm to solve the problem. Section 6 shows the influence of an A* parameter on both the algorithm performance and the solution quality and we finally draw some conclusions and perspectives for future work in Sect. 7.

2 The multi-objective bus passenger Trip Planning Problem

In the problem tackled in this paper, the passenger expects to find some trip options for his journey from an origin to a destination, considering the city bus network, all the route schedules and the current bus positions. The data about the bus route network and the bus schedules is given by the bus company offering the service, and is treated here as static data at the time of the passenger request.

The user needs to specify the following information:

  • origin (current) location (it may be automatically picked out from the user’s smartphone location),

  • desired destination location,

  • departure (ready) time (and date, as the bus company defines specific bus schedules for different day types, such as weekday, Saturday, Sunday, etc.). By default, it is set to the present date and time.

The tool then suggests some bus trip options, each one containing the following information:

  • bus routes to be used along the trip,

  • for each transfer: alighting time from the previous bus and boarding time onto the next bus,

  • departure time from origin location (it may be after the “ready” time given by the user),

  • arrival time at destination location,

  • total walking time and distance.

For a request with a desired departure time close to the present time, the current positions of buses (available through GPS) and traffic conditions update the static daily bus schedule considered to generate the trip plan options. See (Jariyasunant et al. 2010) for a similar inclusion of real time conditions.

All passengers wish to arrive as soon as possible at their destination, but some may want to avoid transfers as much as possible or prefer short walks, even if this means a later arrival time. Furthermore, several bus routes usually share common sections, which allows passengers to have backup options in case of an unpredictable event such as an accident slowing down the traffic and preventing them from performing their next transfer. Therefore, the Trip Planning tool should provide a broad range of options for the passenger.

Figures 1, 2 and 3 depict some options of passenger trips for a request made at 21:45 between the neighbourhoods of Córrego Grande and Lagoa da Conceição in Florianópolis, Brazil. Table 1 gives a summary of the objective values for every option. Each one is the best with respect to a specific criterion. If a passenger wishes to arrive as fast as possible, he would certainly choose the option depicted in Fig. 1. On the other hand, if he wants to avoid transfers and minimize the risk of delays, he will probably choose the option given in Fig. 3.

Table 1 Objective values for the Trip Planning request example
Fig. 1
figure 1

Earliest Arrival Problem, with one transfer

Fig. 2
figure 2

Option with a short walking distance and one transfer

Fig. 3
figure 3

Direct ride option, arriving after both previous options

3 Trip Planning by Departure Time and extensions

In this section, the problem introduced previously is described formally. For a matter of clarity, all the time-related variables or constants are denoted by Greek letters.

After a literature review in Sect. 3.1, the Trip Planning by Departure Time (or TPDT) is formulated in Sects. 3.2, 3.3 and 3.4. The last sections (3.5 and 3.6) describe possible additional features of this problem.

3.1 Literature review

A Shortest Path Problem as described by Zhao et al. (2008), Nannicini et al. (2011), Idri et al. (2017) or an Earliest Arrival Problem (see Yang et al. 2012; Wang et al. 2015) only aims to minimize the arrival time at a destination. However, we also consider the number of transfers and the total walking distance as relevant criteria for the passenger. Bast et al. (2015) give a comprehensive review of similar problems and algorithms to solve them.

The graph defined to perform the search is usually either time-expanded (as for Jariyasunant et al. 2010; Wang et al. 2015) or time-dependent.

Spiess and Florian (1989) use a time-expanded graph for frequency-based bus transit and introduce the concept of optimal strategies to reach a destination node in a stochastic network. Attanasi et al. (2013) and Gentile (2017) model such strategies as hyperpaths in a hypergraph defining mixed frequency-based and schedule-based multimodal transit services. Comi et al. (2017) present a “weighted time-based” approach introducing a utility function that balances several attributes: on-board time, waiting time, transport mode, etc. The authors explicitly show that the resulting solutions match the user’s preferences in about 90% of the cases. Nonetheless, these preferences have to be configured beforehand (through a poll or at least a small form). This can be cumbersome for the passenger, especially if he is an unfrequent user of the Trip Planner. In addition, we chose a multi-objective approch given that a utility-based algorithm can lack the information on each objetive individually. For example, a Pareto-based method is able to provide the passenger with more diverse route options, including, for every criterion, the best option with respect to this criterion. On the other hand, depending on the preference setting, a utility-based algorithm could fail to find the least-walking option, or the fewest-transfers option, but return only balanced options. As for the graph type, time-expanded graphs can be too large and memory-consuming for the Trip Planner to be able to deal with several requests per second ( Pyrga et al. (2008)).

Among the time-dependent approaches, Cooke and Halsey (1966) and Dreyfus (1969) propose a generalized Dijkstra algorithm to solve the mono-objective time-dependent Shortest Path Problem. Zhao et al. (2008) present an A* algorithm where the heuristic function takes the current time as a parameter. Nannicini et al. (2011) introduce a bidirectional A* search on large-scale networks. Idri et al. (2017) use an A* algorithm on a heuristically restricted search space in a multimodal network. Brodal and Jacob (2004) model the timetable through a time-dependent network so that their problem can be solved using Dijkstra-like methods. All the previous time-dependent approaches have the single objective of minimizing the arrival time or the total cost. Mandow and De La Cruz (2010) present a multi-objective A*-based method in which the heuristic function is defined on every criterion, and Sanders and Mandow (2013) find all Pareto-optimal paths using a parallel label-setting algorithm; both papers search a multi-objective Shortest Path without considering any transit timetable. Berger et al. (2009) propose speed-up techniques for a bi-criteria (travel time and number of transfers) path search in a schedule-based railway transit network.

To the best of our knowledge, no other schedule-based Trip Planner proposes an approach based on both A*-guidance and Pareto-dominance to solve the problem. Our paper contributes to the literature by tackling this problem using both methods.

3.2 Graph and timetable

The network presented here is time-dependent where the transit-time function is given by the bus timetables stored as distinct data structures instead of being explicitly included into the graph.

The bus route network is defined in a directed graph \(G = (V,E)\) where V is the set of vertices (all the possible reference locations and bus stops) and E is the set of directed edges, made of:

  • a set \(E_R\) of route edges, and

  • a set \(E_W\) of walking edges.

Sets \(E_R\) and \(E_W\) are disjoint and such that \(E = E_R \cup E_W\). Every edge e in \(E_R\) is a street section between two successive bus stops in at least one route path. The set of all the bus routes that have edge e inside their path are denoted by R(e), and R is the set of all bus routes. In addition, every walking edge e in \(E_W\) is such that \(R(e) = \emptyset\) and is associated with a walking distance d(e) and a walking duration \(\delta (e)\).

A path is a sequence of nodes in V: \(P_V = (v_1 v_2 \cdots v_i v_{i+1} \cdots )\) such that \(\forall i \ge 1, (v_i v_{i+1}) \in E\). A route path is such that \(\forall i \ge 1, (v_i v_{i+1}) \in E_R\), whereas a passenger path can be made of edges from both \(E_R\) and \(E_W\). By extension, path \(P_V\) can also be seen as a sequence of edges denoted by \(P_E\). Formally, for any edge \(e \in P_E, \exists i, e = (v_i v_{i+1})\). In the following, we use the generic notation P to denote both the sequence of nodes and the sequence of edges.

Each bus route \(r \in R\) of the bus company is defined by its path of length \(m_r\) along the geographical network, which is the sequence of \(m_r\) nodes (or bus stops) in V through which it goes : \(P_r = (v^r_1 v^r_2 \cdots v^r_{m_r})\), where for each i such that \(1 \le i \le m_r - 1\), \((v^r_i v^r_{i+1}) \in E_R\) and \(r \in R(v^r_i v^r_{i+1})\). Each bus route \(r \in R\) is associated with a sequence of \(n_r\) bus trips. Each bus trip is a bus ride along the bus route at a certain time of the day. It is defined by the list of the \(m_r\) times at which the bus arrives at each bus stop along the route path related with the trip. Formally, if r is a bus route, its u-th trip can be defined by the times \(\theta ^r_{u,v^r_1}, \theta ^r_{u,v^r_2}, \cdots , \theta ^r_{u,v^r_{m_r}}\) where \(1 \le u \le n_r\), and \(\forall i, 2 \le i \le m_r, \theta ^r_{u,v^r_i}\) is the time the bus reaches bus stop i. We suppose here that the bus layover is zero at every intermediate stop, meaning that the bus leaves just after it arrives.

The bus route’s first and last stops are usually specific locations, called bus terminals, with more space and facilities for the bus drivers to park their bus and rest that allow passengers to sit down and get information about the next buses to leave. Some routes can also have bus terminals as intermediate stops.

In summary, all the bus trips of a given route r define a matrix \(\theta ^r\) of \(n_r\) lines and \(m_r\) columns of trip times from the first node of the route path to the last node. This matrix is the complete daily timetable for route r, and strictly increases linewise and columnwise: for each u such that \(1 \le u \le n_r\) and for each i such that \(1 \le i \le m_r\),

$$\begin{aligned} \text{ if } i\le \, & {} m_r-1 \text{ then } \theta ^r_{u,v^r_{i+1}} > \theta ^r_{u,v^r_i} \end{aligned}$$
(1)
$$\begin{aligned} \text{ if } u\le \, & {} n_r-1 \text{ then } \theta ^r_{u+1,v^r_i} > \theta ^r_{u,v^r_i} \end{aligned}$$
(2)

Inequality (1) states that the duration between two successive stops is positive, whereas inequality (2) ensures that the trips in the matrix are sorted in increasing order of their first stop time. This inequality also ensures that the trips do not overlap: if a bus departs before another one, it will not arrive after the other in any subsequent bus stop, which is a reasonable practical assumption usually called FIFO property. The contrary would mean that buses of the same route overtake one another, which is operationally avoided.

Figure 4 and Table 2 depict an example of a graph and a timetable on a simple network, with two bus routes performing three trips overall.

Fig. 4
figure 4

Example of a Trip Planner graph with three intermediate nodes and two bus routes

Table 2 Example of a timetable for the previous graph, including two trips for route \(r_1\) and a single trip for route \(r_2\)

3.3 Solution description

The user defines a source node s and a target node t. He also chooses a time \(\varGamma\) which is the date and time he is ready to start from node s.

A Trip Planning option (or solution option) is composed of:

  • a passenger path P of q nodes \(P_V = (v_1 v_2 \cdots v_q)\) and \(q-1\) edges \(P_E = ((v_1 v_2) (v_2 v_3) \cdots (v_{q-1} v_q))\),

  • the arrival time at each node of the path \(\gamma _1, \gamma _2, \cdots , \gamma _q\),

  • the index of the route taken at each step \(r_1, r_2, \cdots , r_{q-1}\) (\(r_i\) is the route on edge \((v_i v_{i+1})\)),

  • the index of the trip taken at each step \(u_1, u_2, \cdots , u_{q-1}\).

In the following, the expression “passenger path” can refer to a whole solution option, meaning that this path also contains all the other attributes (arrival times, routes and trips).

These option attributes are subject to the following constraints:

  • \(v_1 = s\), \(v_q = t\), \(\gamma _1 = \varGamma\),

  • \(\forall i, 1 \le i \le q-1, \gamma _i < \gamma _{i+1}\),

  • \(\forall i, 1 \le i \le q-1\), if edge \((v_i v_{i+1}) \in P_E \cap E_W\) (walking edge), then we have \(\gamma _{i+1} = \gamma _i + \delta (v_i v_{i+1})\) and by convention \(r_i = u_i = 0\).

  • \(\forall i, 1 \le i \le q-1\), if edge \((v_i v_{i+1}) \in P_E \cap E_R\) (route edge) then:

    • \(r_i \in R(v_i v_{i+1})\) (\(r_i\) is one of the routes going through edge \((v_i v_{i+1})\)),

    • \(1 \le u_i \le n_{r_i}\) (\(u_i\) is one of route \(r_i\)’s trips),

    • \(\gamma _{i+1} \ge \theta ^{r_i}_{u_i,v_{i+1}}\) (arrival at node \(v_{i+1}\)),

    • \(\gamma _i \le \theta ^{r_i}_{u_i,v_i}\) (departure from node \(v_i\)): the passenger must arrive at node i before trip \(u_i\) of route \(r_i\) leaves this node. He can achieve this either by riding in the same trip (in which case it is an equality), or from another route, or even walking.

The arrival time at the next node in the case of a route edge could also be stated as exactly \(\gamma _{i+1} = \theta ^{r_i}_{u_i,v_{i+1}}\) because there is no reason to choose a higher value for \(\gamma _{i+1}\). It is written here as an inequality for reasons of symmetry with the departure time constraint.

A passenger boarding can be seen as an index i along path P such that \(r_i \ne 0\) and \(r_i \ne r_{i-1}\): the path is going through a route edge on i and this route is not the same as the previous one (which can possibly be a walk). The number of boardings b(P) of a passenger path P is the number of times a route \(r_i\) is such that \(r_i \ne 0\) and \(r_i \ne r_{i-1}\) along the path.

Let \(R^*(P)\) be the sequence of all bus routes along P: \(R^*(P) = (r_i)_{0 \ne r_i \ne r_{i-1}}\). Then b(P) is simply the size of \(R^*(P)\): \(b(P) = |R^*(P)|\).

3.4 Objectives

The number of transfers is exactly \(b(P)-1\) (or 0 if \(b(P) = 0\), but pure walking paths are disconsidered), so minimizing the number of transfers is the same as minimizing b(P).

Given a final passenger path P, the objective is to minimize several criteria:

  • the arrival time \(\gamma (P) = \gamma _q\),

  • the number of boardings b(P),

  • the total walking distance \(d(P) = \sum _{e \in P_E \cap E_W} d(e)\).

It is also possible to minimize the total trip fare, which depends on the bus types covering the bus routes along the passenger’s path. For example, a passenger will pay an extra fare in a so-called executive bus with air conditioning. Moreover, in some cities, when a passenger buys a ticket, he may be able to ride several trips within a time window using a single fare. After this time window, he will need to pay another fare if he has to take another bus. The fare calculation will not be considered here so as to maintain a concise formulation.

In the two following sections, we describe some possible extensions to the TPDT.

3.5 Transfer delay constraint

When switching buses, the passenger could be prompted to arrive earlier than the next bus by a given amount of time (e.g. at least three minutes). This gives the passenger convenient boarding and alighting times and helps to decrease the risk of losing the next transfer if the current bus gets late. This minimum time is called transfer delay duration and is denoted by T.

It is possible to enforce that, whenever \((v_i v_{i+1}) \in P_E \cap E_R\) (route edge) and \(r_i \ne r_{i-1}\) (passenger boards onto a new bus at \(v_i\)), the following constraint holds: \(\gamma _i \le \theta ^{r_i}_{u_i,v_i} - T\).

3.6 Transfer location preference

In the case of a transfer between two routes sharing a common section (same sequence of stops), passengers usually choose to switch buses as early as possible to avoid the situation when the next bus of the transfer gets past the current one. Note that this situation does not contradict the FIFO property defined in Sect. 3.2, as buses from distinct routes can overtake one another. In addition, bus terminals provide facilities (clear information, platforms for the disabled, etc.) to improve the comfort, speed and safety for their waiting period. Therefore, passengers may prefer to wait for their bus at the terminal to perform their scheduled transfer.

This transfer location preference is modelled as follows: consider a passenger path P defined by its nodes \(P_V = (v_1 v_2 \cdots v_q)\). Suppose that for two points g and h in the path such that \(1< g< h < q\), there are two routes x and y such that \(\forall i, g \le i < h, \{x, y\} \subset R(v_i v_{i+1})\). That is, routes x and y share the same subpath between nodes \(v_g\) and \(v_h\). Fig. 5 depicts this common section for routes x and y.

Fig. 5
figure 5

Possible transfer locations incoming from route x and outgoing through route y

Suppose further that \(r_{g-1} = x\) and \(r_h = y\), meaning that the passenger has to switch between a bus of route x and a bus of route y at some node between \(v_g\) and \(v_h\), and suppose that this transfer is possible in any of those nodes. For this to be true, trips \(u_{g-1}\) on route x and \(u_h\) on route y are such that at any node in the common subpath, trip \(u_{g-1}\) arrives before trip \(u_h\), considering the transfer security threshold T (recall its definition in Sect. 3.5), meaning that the passenger has enough time to switch between both buses. Formally, \(\forall i\) such that \(g \le i \le h, \theta ^x_{u_{g-1}, v_i} \le \theta ^y_{u_h, v_i} - T\).

Then the following holds:

  • If the sequence of nodes \(v_g \cdots v_h\) contains no bus terminal, the transfer between routes x and y must be performed at node \(v_g\). In other words: \(\forall i, g \le i < h, r_i = y\) and \(u_i = u_h\).

  • If the sequence of nodes \(v_g \cdots v_h\) contains at least one bus terminal (e.g. \(v_{z_1}, v_{z_2}, \cdots\)), the transfer between routes x and y is performed at the first bus terminal in the sequence, denoted by \(v_{z_1}\):

    • \(\forall i, g \le i \le z_1-1, r_i = x\) and \(u_i = u_{g-1}\).

    • \(\forall i, z_1 \le i < h, r_i = y\) and \(u_i = u_h\).

4 Trip Planning by arrival time

In the Trip pPanning by arrival time (TPAT), instead of being available at a given time and minimizing his arrival time at his destination (see the TPDT problem described above), the passenger may be interested in finding out when he should leave his current place to arrive at some other place at a given time. For example, what time do I have to leave home so that I can get to work at 08:00 AM?

Formally, if the date and time the passenger wishes to arrive at node t is \(\varGamma\), the path arrival time is constrained to \(\gamma _q = \varGamma\) (with the same notations as previously), and the departure time \(\gamma _1\) should be maximized (which is the only difference to the TPDT objectives).

Theorem 1

The TPDT and the TPAT are computationally equivalent: from any instance of one problem, we can build an instance of the other problem such that any optimal solution in the problem can be matched with an optimal solution in the other problem.

The idea of the proof is similar as the forward and backward search introduced by Wu and Hartley (2004). Here, both the graph and the route timetables are reverted, and the trip plan is requested from the original target to the original source. We show here that TPDT \(\le _p\) TPAT (TPDT reduces polynomially to TPAT) by mapping this instance of the TPDT into an instance of the TPAT. We could show similarly that TPAT \(\le _p\) TPDT.

Figure 6 and Table 3 depict the TPAT graph and timetable corresponding to the TPDT graph and timetable given in Fig. 4 and Table 2.

Fig. 6
figure 6

Definition of the TPAT graph with reversed arcs

Table 3 Definition of the TPAT timetable, with reversed and negated times

Proof

Consider an instance of the TPDT described above and formulated in Sect. 3.

The TPDT is described by its graph \(G = (V,E)\) where \(E = E_R \cup E_W\) and by its set of bus routes R, each of which (\(r \in R\)) is defined by its path \(P_r\) and its timetable \(\theta ^r\). As stated above, a solution option between nodes s and t is defined by its path \(P_V = (v_i)_{i=1}^q\), its arrival times at each node \((\gamma _i)_{i=1}^q\), its route at each step \((r_i)_{i=1}^{q-1}\) and its trip at each step \((u_i)_{i=1}^{q-1}\).

From this TPDT we build a TPAT instance as follows: let \(G' = (V', E')\) be its graph where \(E' = E'_R \cup E'_W\) is such that:

  • \(V' = V\) (same nodes as in the TPDT graph),

  • \(|E'| = |E|\) and \(\forall e=(ij) \in E, e'=(ji) \in E'\) (TPDT arcs are reverted), where \(R(e') = R'(e)\) (the set of routes \(R'\) is defined just below), \(e \in E_W \Leftrightarrow e' \in E'_W\) and if \(e \in E_W\) then \(\delta (e') = \delta (e)\) and \(d(e') = d(e)\) (same walking duration and distance for both arcs).

Furthermore, for each TPDT route \(r \in R\) we associate a TPAT route \(r' \in R'\) such that:

  • its path \(P_{r'} = (v^r_{m_r} v^r_{m_r-1} \cdots v^r_1) = (v^r_{m_r-i+1})_{i=1}^{m_r}\) where route r’s path is \(P_r = (v^r_1 v^r_2 \cdots v^r_{m_r})\) (TPDT route paths are reverted),

  • each trip \(u, 1 \le u \le n_r\) of route r is associated to a trip \(u' = n_r - u + 1\) of route \(r'\) such that: \(\forall i, 1 \le i \le m_r\), let \(i'=m_r-i+1\). Then \(1 \le i' \le m_r\) and \(\theta ^{r'}_{u',v_{i'}^r} = - \theta ^r_{u,v_i^r}\) (TPDT timetable is reverted and negated).

The timetable matrix then maintains its linewise and columnwise time-increase property:

  • \(\theta ^{r'}_{u'+1,v_{i'}^r} - \theta ^{r'}_{u',v_{i'}^r} = -\theta ^r_{u-1,v_i^r} + \theta ^r_{u,v_i^r} > 0\),

  • \(\theta ^{r'}_{u',v_{i'+1}^r} - \theta ^{r'}_{u',v_{i'}^r} = -\theta ^r_{u,v_{i-1}^r} + \theta ^r_{u,v_i^r} > 0\).

From a TPDT s-t solution option, we define a TPAT t-s solution option as follows:

  • its path \(P'_V = (v'_1 v'_2 \cdots v'_q) = (v_q v_{q-1} \cdots v_1)\) (reversed TPDT path),

  • its arrival times at each node \(\forall i, 1 \le i \le q, \gamma '_i = - \gamma _{q-i+1}\),

  • its route and trip at each step \(\forall i, 1 \le i \le q-1, r'_i = r_{q-i}\) and \(u'_i = u_{q-i}\).

We show that the TPAT solution option complies with the rules described in Sect. 3.3, except the specific TPAT requirement that \(\gamma '_q = -\gamma _1 = -\varGamma\) is the maximum expected arrival time at the last TPAT node s:

  • \(v'_q = v_1 = s\) (node s is the destination of the TPAT we defined)

  • \(v'_1 = v_q = t\)

  • \(\forall i, 1 \le i \le q-1, \gamma '_{i+1} - \gamma '_i = -\gamma _{q-i} + \gamma _{q-i+1} > 0\)

  • \(\forall i, 1 \le i \le q-1\), if \((v'_i v'_{i+1})\) is a walking edge then \((v_{q-i} v_{q-i+1})\) is a walking edge in the original TPDT graph, therefore:

    $$\begin{aligned} \gamma '_{i+1}= & {} -\gamma _{q-i} = - (\gamma _{q-i+1} - \delta (\gamma _{q-i} \gamma _{q-i+1})) = - \gamma _{q-i+1} + \delta (v'_i v'_{i+1})\\= \, & {} \gamma '_i + \delta (v'_i v'_{i+1}) \end{aligned}$$

    Besides, \(r'_i = r_{q-i} = 0\) and \(u'_i = u_{q-i} = 0\).

Suppose now that \((v'_i v'_{i+1})\) is a route edge. So is \((v_{q-i} v_{q-i+1})\) in the TPDT graph. Then:

  • \(r_{q-i} \in R(v_{q-i} v_{q-i+1})\), which means \(r'_i \in R(v'_i v'_{i+1})\). Also, as \(u_{q-i}\) is a trip from route \(r_{q-i}\), \(u'_i\) is a trip from route \(r'_i\) (in other words: \(1 \le u'_i \le n_{r'_i}\)).

  • \(\gamma _{q-i} \le \theta ^{r_{q-i}}_{u_{q-i}, v_{q-i}}\) (departure from \(v_{q-i}\)). Given that, by definition:

    \(\gamma '_{i+1} = - \gamma _{q-i}\) and \(\theta ^{r_{q-i}}_{u_{q-i}, v_{q-i}} = - \theta ^{r'_i}_{u'_i, v'_{i+1}}\), we finally have \(\gamma '_{i+1} \ge \theta ^{r'_i}_{u'_i, v'_{i+1}}\), which is the arrival time constraint at \(v'_{i+1}\).

  • \(\gamma _{q-i+1} \ge \theta ^{r_{q-i}}_{u_{q-i}, v_{q-i+1}}\) (arrival at \(v_{q-i+1}\)). Similarly:

    \(\gamma '_i = - \gamma _{q-i+1}\) and \(\theta ^{r_{q-i}}_{u_{q-i}, v_{q-i+1}} = - \theta ^{r'_i}_{u'_i, v'_i}\), which yields \(\gamma '_i \le \theta ^{r'_i}_{u'_i, v'_i}\) (departure time constraint from \(\gamma '_i\)).

We still need to show that a solution option of the TPAT instance is optimal with respect to a given criterion if and only if the corresponding TPDT solution option is optimal with respect to the same criterion. In fact, we show that both the number of boardings and the walking distance are the same values in both problems. Regarding the departure time (in the TPAT) or arrival time (in the TPDT), they are opposite one another, so maximizing one will minimize the other one. Recall that every criterion is described in Sect. 3.4.

First consider the number of boardings in the TPDT b(P) and the number of boardings in the TPAT \(b(P')\). Recall that, by definition, \(b(P) = |R^*(P)|\) where \(R^*(P) = (r_i)_{0 \ne r_i \ne r_{i-1}}\) is the sequence of all the routes along P. Then similarly \(b(P') = |R^*(P')|\). As by definition \(R^*(P')\) has the same elements as \(R^*(P)\) in reverse order, its size is the same as \(R^*(P)\). Then \(b(P) = b(P')\).

The walking distance is also simple to calculate: in the TPAT instance its definition is \(\sum _{e \in P'_E \cap E'_W} d(e)\). As the arcs in \(P'_E \cap E'_W\) are the same as those in \(P_E \cap E_W\), but they are just reversed and with the same walking distance, \(\sum _{e \in P'_E \cap E'_W} d(e) = \sum _{e \in P_E \cap E_W} d(e)\).

To complete the proof, we finally show that the departure time in the TPAT and the arrival time in the TPDT have opposite values. Recall that \(\forall i, 1 \le i \le q, \gamma '_i = - \gamma _{q-i+1}\). Especially for \(i=1\), \(\gamma '_1 = - \gamma _q\), which means that maximizing \(\gamma '_1\) is the same as minimizing \(\gamma _q\). \(\square\)

This theorem and proof also introduce a way to solve the TPAT using an already implemented TPDT algorithm. By reverting the input data (graph and timetable) and applying the TPDT algorithm, and finally reverting the solution option back to the original values, we are able to solve the TPAT as efficiently as the TPDT, using the algorithm described in the next section.

5 A*-guided algorithm with Pareto dominance-based elimination

The solution process for the problem described in Sect. 3 is guided by an A* procedure over the graph defined by the bus route network. For that, we use a trip time matrix similar to the one introduced by Delling et al. (2012). As in Dijkstra’s Shortest Path Problem, labels are selected among a set of open labels and expanded over the graph during the solving process. Each label L is related to a given node \(v_l\) of the network and its path \(P_l = (v_1 v_2 \cdots v_l)\) of length l (with \(v_1=s\)) and contains the same information as for a solution option path P, namely: the time of arrival at the current node \(\gamma _l\), the number of transfers b(L) and the total walking distance d(L).

During its processing, the algorithm maintains a priority queue of open labels and in the main loop, an open label is selected and expanded, creating new open labels defined from the label node’s outgoing edges that are in turn inserted in the priority queue.

5.1 Label expansion

A label expansion is the generation of new labels from the current label and all the neighbour edges, using all the bus routes available on these edges as well as the walking edges.

The selection for the next label to be expanded is based on the minimum expected arrival time at the target node t and considers the objective of minimizing the arrival time \(\gamma _q\) as a driver for the search. Consequently, the first solution options found are among the Earliest Arriving ones overall, regardless of the values of the other objectives.

The expected arrival time at the target node t from label L is defined as \(\lambda (L) = \gamma (L) + \tau (v_l, t)\), where:

  • \(\gamma (L) = \gamma _l\) is the arrival time at the label node \(v_l\) (see its definition in Sect. 3.3),

  • \(\tau (v_l, t)\) is an estimate of the duration of a ride between \(v_l\) and t.

The time on the path’s first node is \(\gamma _1 = \varGamma\) and if \(l \ge 2\), \(\gamma _l\) depends on the kind of incoming edge:

  • if \((v_{l-1} v_l) \in E_W\) then \(\gamma _l\) is computed using the value \(\gamma _{l-1}\) from the father label: \(\gamma _l = \gamma _{l-1} + \delta (v_{l-1} v_l)\),

  • if \((v_{l-1} v_l) \in E_R\) then \(\gamma _l\) is the time read in the timetable matrix corresponding to a route \(r_{l-1}\) and a trip \(u_{l-1}\) on node \(v_l\): \(\gamma _l = \theta ^{r_{l-1}}_{u_{l-1}, v_l}\) where \(r_{l-1} \in R(v_{l-1} v_l)\) and \(1 \le u_{l-1} \le n_{r_{l-1}}\).

The duration of a ride between any node v and the target node t is estimated as \(\tau (v, t) = \frac{d(v,t)}{\sigma }\), where:

  • d(vt) is the geographical distance between nodes v and t,

  • \(\sigma\) is a speed parameter called A* speed.

The value \(\sigma = 0\) means that the next label to be expanded is chosen only according to its distance to the target node (and disconsidering its current time), whereas setting \(\sigma = +\infty\) means chosing according to the label’s current time and disconsidering its geographical proximity. Any value in between balances both attributes. This value should be chosen carefully: unless this value is sufficiently high, the expected arrival time at the target \(\lambda (L)\) is not guaranteed to be a lower bound of the actual arrival time at t of any s-t path generated from label L. For example, if we set \(\sigma\) as the maximum possible speed for a city bus (e.g. 80 km/h), \(\lambda (L)\) will always be a lower bound for the actual arrival time at t for any label generated from L which proves the admissibility of our A*-based heuristic. However, chosing a too high value can provide a poor lower bound in most cases as a bus will not always be available at once at the node and it will rarely go straight to the target node at maximum speed. The tradeoff between the algorithm’s processing time and the solution quality through choices of values for \(\sigma\) will be discussed in Sect. 6.

When creating a new label from the current label and all the current node’s neighbour edges, we need to determine which will be the first possible trip of each outgoing route at the time given by the label. Recall that for each route \(r \in R\), each column of matrix \(\theta ^r\) (sequence of trip departure times in the same node) is sorted in increasing order, as stated in inequality (2). In case of a transfer, the next possible trip of each route going through a given node can be found solving a binary search over the trips in the route timetable. Otherwise, the trip of the next label can be the same as the current label’s trip.

5.2 Stopping conditions

Unlike usual A* algorithms, our algorithm does not stop at the first solution option it finds. Instead, it carries on the search until it finds some acceptable solution options that, for each criterion, have a better or “similar” value when compared to the first option found. “Similar” here means that a higher value is tolerated if the difference with the reference value is low. The maximum difference is predetermined for each criterion. For example, independently of the values for the other criteria, it will eventually reject an option with five transfers when the first solution option found has a single one. On the other hand, a solution option with two transfers (only one more than the first option) but better values for the other criteria is considered as acceptable.

The algorithm main loop stops whenever:

  • no more labels are available to be expanded (empty priority queue),

  • the number of solution options (s-t paths) found so far have reached a predefined quantity (e.g. 10 options),

  • the number of expanded labels have reached a predefined quantity (e.g. 100,000 expanded labels).

The last condition is similar to a time limit condition but the fact of using the number of expanded labels instead of an actual time limit (e.g. 1 s) allows the algorithm to remain deterministic, i.e. to always return the same answer given the same input. The value for the maximum number of expanded labels is tuned beforehand according to each city bus network, so that the processing time for most requests is less than 1 s.

5.3 Heuristic label pruning

Beside the stopping conditions, some labels are pruned during the algorithm processing if one of the following values of the label is much higher compared to the value of the first option found:

  • its estimated time to target \(\lambda (L)\) (e.g. over 1h30),

  • its number of boardings b(L) (e.g. over 2 more boardings),

  • its total walking distance d(L) (e.g. over 1 km).

The first solution option found is used as a reference for this heuristic label pruning as it is one of the most likely to be chosen by the passenger, being one of the earliest arriving solution options. Once the label selection in the main loop is guided by the minimum expected arrival time to target, meaning that the expected arrival time to target is expected to rise along the successive label selections, the first condition can also be triggered as a stopping condition for the main loop.

In order to avoid pruning labels with just slightly worse criterion values which can turn out to be very good options later, we introduce an equality threshold for two criteria: the arrival time (90 s) and the walking distance (30 s). For instance, two labels are considered to have a similar arrival time if the difference between their respective arrival times is lower than 90 s. In practice, when deciding between two possible solution options arriving with a difference of less than 90 s, the passenger will doubtlessly consider the other criteria (number of transfers, walking distance) to make up his mind.

5.4 Pareto dominance

Each time a new label is generated through its predecessor’s expansion, it is submitted to a Pareto dominance-based elimination on its node. This label is compared, for every criterion, to all the previously generated non-dominated labels on the same node and coming from the same bus route. When comparing each objective value, the same thresholds as the ones described previously are considered. Whenever a label is not worse than another one on every criterion but is better for at least one criterion, it is said to dominate the other label. Every dominated label is discarded from the graph.

Figure 7 plots feasible options or labels (squares and circles).

Fig. 7
figure 7

Example of Pareto frontier considering two criteria: arrival time and total walking distance

The green squares are the Pareto-optimal options of this set of points, and the solid line depicts the Pareto frontier. Every option in the upper right corner (red circles) is dominated by at least one Pareto-optimal option. When considering the threshold to compare the options, the Pareto frontier becomes the strip between the original Pareto frontier and the dashed line to its right. In this case, the option depicted by the red square becomes Pareto-optimal.

If two non-dominated labels have the same sequence of bus routes (recall the definition of \(R^*(P)\) in Sect. 3.4), their last transfer is compared according to the transfer location preference introduced in Sect. 3.6. If one of the transfers is preferable (at a terminal while the other one is not, or at a previous node), the label corresponding to the other one is discarded.

6 Results and choice of value for the A* speed

Tests were performed in two Brazilian cities where our Trip Planner is available for the population: Florianópolis and Guarujá. Table 4 gives an insight on the size of the problems related to these cities.

Table 4 Problem size for the tested cities

For both cities, we ran the algorithm for a set of previously chosen origin-destination locations over the network and for requests at a specific day and several times along the day, so as to cover the whole timetable. The origin-destination pairs in the test were chosen according to their high processing time over a big set of randomly chosen origin-destination pairs, for a request at a specific time. The running times were obtained on a standard PC with 8GB RAM and 4-core Intel i7-4510U CPU, 2.00GHz, 4MB cache.

Figure 8 depicts the tests carried on in Florianópolis with the speed parameter \(\sigma\) of the A* heuristic (see Sect. 5) varying between 0 and \(+\infty\). Each point in the chart is an average value over a set of 180 requests as described above (several origin-destination pairs and several times along the day). The average number of solution options gives an insight of the quality of the algorithm. Obviously, similar solution options, such as two options with the exact same routes and trips but distinct get on/off stops, are considered only once.

Fig. 8
figure 8

Influence of the speed parameter of the A* procedure on the processing time and number of solution options in Florianópolis, Brazil

Figure 8 shows that in Florianópolis, the average processing time increases with the A* speed, but the number of solution options decreases after a maximum value obtained around \(\sigma = 10\). Interestingly, this value of the A* speed does not make the A* heuristic function admissible because it will not always give a lower bound on the actual arrival time at the target location. This is especially the case when, considering a label location and time, there is a bus just about to arrive at this location that can take the passenger directly to the target location (as it will probably drive faster than 10 km/h). However, the tests empirically show that this value is among the best ones for the variety of options and yields an acceptable processing time (around 1140 ms).

Figures 9 and 10 show maps of label expansion for the cases \(\sigma = 3\) and \(\sigma = 10\), respectively, for the same request as the example in Sect. 2. The origin and destination of the request are the green and red squares, and each expanded label during the algorithm is depicted as a circle with a color gradient between yellow and purple, depending on the step in which the label was expanded (purple for a later step). The higher the value of \(\sigma\), the more labels are expanded along the algorithm even if some label expansions look useless. This explains why the average processing time tends to rise for high values of the A* speed \(\sigma\).

Fig. 9
figure 9

Label expansion map for a request in Florianópolis and \(\sigma = 3\)

Fig. 10
figure 10

Label expansion map for a request in Florianópolis and \(\sigma = 10\)

Figure 11 plots a similar chart as above for the tests run in Guarujá over a set of 650 requests for each value of the A* speed \(\sigma\). In this case, both the number of solution options and the processing time remain somewhat constant for \(\sigma > 20\). For \(\sigma < 20\), the number of options rises continuously but unlike the Florianópolis case, the processing time peaks around \(\sigma = 2\) (its value is then less than 800 ms) and after \(\sigma = 20\) it remains quite constant at about 450 miliseconds. The peak can be explained by the fact that the number of daily trips per route (36.94) is higher than for Florianópolis (25.67): for a small value of \(\sigma\), the algorithm focuses on the label geographical proximity. At a given node, it is likely to expand more labels from a given route on later trips so that it gets geographically closer to the destination node. The constant behaviour after \(\sigma = 20\) (instead of rising) can be explained by the small graph for Guarujá: labels do not expand as much as in the Florianópolis case before the algorithm reaches one of the stopping conditions.

As for Florianópolis, \(\sigma = 10\) is a good setting but for Guarujá it seems that \(\sigma = 20\) or higher is slightly better. These values of the A* speed parameter \(\sigma\) give a good balance between the processing time and the solution quality in both cases.

Fig. 11
figure 11

Influence of the speed parameter of the A* procedure on the processing time and number of solution options in Guarujá, Brazil

From the Guarujá test details, we noted that distinct values of \(\sigma > 20\) are very likely to return exactly the same options, unlike the Florianópolis case. The processing time is also always lower in Guarujá than in Florianópolis (which can be explained by the problem sizes given in Table 4), but the average number of options is higher in Guarujá. This is certainly because of the structure of the bus route network: in Guarujá there are lots of routes sharing subroutes with each other, whereas in Florianópolis some remote areas are served by a single route.

7 Conclusion and perspectives

In this paper, we described a multi-objective Bus Passenger Trip Planning Problem and explained how it can be solved, either for its arrival time or departure time version, through an A*-based algorithm where Pareto-dominated labels are discarded. The tests show that using the right value for the A* speed (10 for Florianópolis, 20 for Guarujá) optimizes the algorithm performance as well as the quantity and quality of the options given to the user.

We focused on the impact of changing the A* speed value over the solution quality. Other parameters, such as the equality threshold values, also have a significant influence on the result and could be tested in the same way. We are also aware that the algorithm may be even more powerful with some improvements, such as preprocessed transfer options, with no need of constant lookup in the timetable. Furthermore, in the A* procedure, the estimated time from a given node to the target could be computed using the bus route network and the timetable so as to get a better lower bound and possibly to avoid the need of an A* speed parameter. However, the way this has to be performed should be carefully elaborated because the algorithm’s A* admissibility is somewhat deteriorated by the stopping conditions, the Pareto-dominance and the fact that the A* evaluation function is based on a single criterion.

Still, our Trip Planning tool has been continuously available in several Brazilian cities for several years and provides a wide range of solution paths within a couple of seconds or less. Whoever uses the Trip Planning tool, even longtime users of the bus transit network, can come up with some surprising route options. It is a good incentive for public transport in traffic-crowded cities like Florianópolis: being the home city of the authors, we can only confirm the benefit of having a reliable Trip Planning tool which contributes to the better use of bus transportation.