Consider transfers.txt
Right now, we only account for direct switches between connections. We should add transfers to the mix to allow routing on a full network.
Transfers come in guaranteed transfers (transfer time == 0) and minimum transfer_time transfers. Both can be handled the same by storing all transfers for a stop.
We can probably optimise the routing quite a bit, if we identify all reasonable transfer locations in advance.
A transfer is only reasonable at station x+1 if we can reach an earlier train at x+1 that we couldn't reach at x or can switch to a line that did not exist at x. So if lines(x) != lines(x+1) || \exists(line) : get_earliest_departure(line,x+1) < get_earliest_departure(line,x), we consider transferring. This is only the case if some line overtakes another between x,x+1. So transfers are necessary only if a line a exists that overtakes line b between x,x+1.
Otherwise we could have done the transfer at x.
This allows for an analysis of all stops for possible transfers. We simply scan all lines that are present at x and x-1 and see if the current line overtakes any other line between x-1 and x. If so, or if x contains a new line, we mark x as transfer location.
Transfers to include:
- [ ] station to station + same stop transfers, if not already part of transfers.txt, given they fulfil any of the following
- [ ] same line:
previous(this) != next(reverse(this))(the opposing direction services a stop that we did not reach ourselves) - [ ] new lines become available
- [ ] lines overtake at this stop (stop a and stop b are serviced by two lines, one line reaches a later but b prior to the other line)
- [ ] ensure that ^ covers all required transfers
As a second part of this, we could think about splitting lines that have multiple stop lists into different lines, as to have only a single list of stops per line. This might simplify handling later on.
The basic feature (minimum transfer time transfers) landed in https://github.com/mapbox/directions-transit/pull/42.
We are missing timed transfers and processing of transfers that are required due to lines having overtaking departures.