UrbanAnalyst / gtfsrouter

Routing and analysis engine for GTFS (General Transit Feed Specification) data
https://urbananalyst.github.io/gtfsrouter/
80 stars 17 forks source link

interpretation results of different start time #77

Closed AlexandraKapp closed 3 years ago

AlexandraKapp commented 3 years ago

How far is the timetable searched to find the best route?

with this example, Hbf - Gesundbrunnen setting start_time to 8:00, 8:05 or 8:15, when does it stop searching the timetable for better connections? The RE that takes 3min leaves at 8:32 just to understand, why the 8:15 query finds the RE even though there are also earlier connections and the 8:00 does not find the RE even though its the fastest connection (but of course half an hour later)

library(gtfsrouter)
packageVersion("gtfsrouter")
#> [1] '0.0.4.177'

gtfs <- extract_gtfs(file.path("vbb_202010.zip"))
#> > Unzipping GTFS archive
#> v Unzipped GTFS archive
#> > Extracting GTFS feedv Extracted GTFS feed 
#> > Converting stop times to secondsv Converted stop times to seconds 
#> > Converting transfer times to secondsv Converted transfer times to seconds
ttable <- gtfs_timetable(gtfs, day = "tuesday")

iso <- gtfs_traveltimes(ttable, "Berlin Hauptbahnhof", start_time = 8*3600)
iso[iso$stop_name == "S+U Gesundbrunnen Bhf (Berlin)", ]
#>       duration ntransfers      stop_id                      stop_name stop_lon
#> 13721 00:14:42          2 060007102721 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 13722 00:14:42          2 060007102722 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 13723 00:14:42          2 060007102723 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 13724 00:12:42          1 060007102724 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 19367 00:17:42          2 000008011102 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 21314 00:17:42          2 450009007102 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 23140 00:17:42          2 710009990056 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 24494 00:17:42          2 710009007102 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 27900 00:16:42          2 070101002524 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 27924 00:16:42          2 070101002563 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 27929 00:16:42          2 070101002568 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 32171 00:15:42          2 070201083101 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 32172 00:15:42          2 070201083102 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#>       stop_lat
#> 13721 52.54864
#> 13722 52.54864
#> 13723 52.54864
#> 13724 52.54864
#> 19367 52.54864
#> 21314 52.54864
#> 23140 52.54864
#> 24494 52.54864
#> 27900 52.54864
#> 27924 52.54864
#> 27929 52.54864
#> 32171 52.54864
#> 32172 52.54864

iso <- gtfs_traveltimes(ttable, "Berlin Hauptbahnhof", start_time = 8*3600 + 5*60)
iso[iso$stop_name == "S+U Gesundbrunnen Bhf (Berlin)", ]
#>       duration ntransfers      stop_id                      stop_name stop_lon
#> 13721 00:11:42          2 060007102721 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 13722 00:11:42          2 060007102722 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 13723 00:11:42          2 060007102723 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 13724 00:09:42          1 060007102724 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 19367 00:14:42          2 000008011102 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 21314 00:14:42          2 450009007102 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 23140 00:14:42          2 710009990056 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 24494 00:14:42          2 710009007102 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 27900 00:13:42          2 070101002524 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 27924 00:13:42          2 070101002563 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 27929 00:13:42          2 070101002568 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 32171 00:12:42          2 070201083101 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 32172 00:12:42          2 070201083102 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#>       stop_lat
#> 13721 52.54864
#> 13722 52.54864
#> 13723 52.54864
#> 13724 52.54864
#> 19367 52.54864
#> 21314 52.54864
#> 23140 52.54864
#> 24494 52.54864
#> 27900 52.54864
#> 27924 52.54864
#> 27929 52.54864
#> 32171 52.54864
#> 32172 52.54864

iso <- gtfs_traveltimes(ttable, "Berlin Hauptbahnhof",, start_time = 8*3600 + 15*60)
iso[iso$stop_name == "S+U Gesundbrunnen Bhf (Berlin)", ]
#>       duration ntransfers      stop_id                      stop_name stop_lon
#> 13721 00:07:42          2 060007102721 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 13722 00:08:00          1 060007102722 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 13723 00:08:00          1 060007102723 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 13724 00:08:00          1 060007102724 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 19367 00:03:00          0 000008011102 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 21314 00:07:00          1 450009007102 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 23140 00:07:00          1 710009990056 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 24494 00:07:00          1 710009007102 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 27900 00:07:00          1 070101002524 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 27924 00:07:00          1 070101002563 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 27929 00:07:00          1 070101002568 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 32171 00:09:00          1 070201083101 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#> 32172 00:09:00          1 070201083102 S+U Gesundbrunnen Bhf (Berlin) 13.38837
#>       stop_lat
#> 13721 52.54864
#> 13722 52.54864
#> 13723 52.54864
#> 13724 52.54864
#> 19367 52.54864
#> 21314 52.54864
#> 23140 52.54864
#> 24494 52.54864
#> 27900 52.54864
#> 27924 52.54864
#> 27929 52.54864
#> 32171 52.54864
#> 32172 52.54864

Created on 2021-02-11 by the reprex package (v0.3.0)

mpadge commented 3 years ago

The function now returns start times as well (from idea in #75), which gives these results:

library (gtfsrouter)
packageVersion ("gtfsrouter")
#> [1] '0.0.4.178'

gtfs <- extract_gtfs("vbb.zip")
#> ▶ Unzipping GTFS archive
#> ✔ Unzipped GTFS archive
#> ▶ Extracting GTFS feed✔ Extracted GTFS feed 
#> ▶ Converting stop times to seconds✔ Converted stop times to seconds 
#> ▶ Converting transfer times to seconds✔ Converted transfer times to seconds
gtfs <- gtfs_timetable(gtfs, day = "tuesday")
from <- "Berlin Hauptbahnhof"
#to <- "S+U Gesundbrunnen Bhf (Berlin)"
to <- c ("060007102724", "000008011102")

iso0 <- gtfs_traveltimes (gtfs, from = from, start_time = 8 * 3600)
iso0 [iso0$stop_id %in% to, ]
#>       start_time duration ntransfers      stop_id
#> 13724   08:09:00 00:12:42          1 060007102724
#> 19367   08:09:00 00:17:42          2 000008011102
#>                            stop_name stop_lon stop_lat
#> 13724 S+U Gesundbrunnen Bhf (Berlin) 13.38837 52.54864
#> 19367 S+U Gesundbrunnen Bhf (Berlin) 13.38837 52.54864

iso1 <- gtfs_traveltimes (gtfs, from = from, start_time = 8 * 3600 + 5 * 60)
iso1 [iso1$stop_id %in% to, ]
#>       start_time duration ntransfers      stop_id
#> 13724   08:09:00 00:09:42          1 060007102724
#> 19367   08:09:00 00:14:42          2 000008011102
#>                            stop_name stop_lon stop_lat
#> 13724 S+U Gesundbrunnen Bhf (Berlin) 13.38837 52.54864
#> 19367 S+U Gesundbrunnen Bhf (Berlin) 13.38837 52.54864

iso2 <- gtfs_traveltimes (gtfs, from = from, start_time = 8 * 3600 + 15 * 60)
iso2 [iso2$stop_id %in% to, ]
#>       start_time duration ntransfers      stop_id
#> 13724   08:27:00 00:08:00          1 060007102724
#> 19367   08:27:00 00:03:00          0 000008011102
#>                            stop_name stop_lon stop_lat
#> 13724 S+U Gesundbrunnen Bhf (Berlin) 13.38837 52.54864
#> 19367 S+U Gesundbrunnen Bhf (Berlin) 13.38837 52.54864

Created on 2021-02-12 by the reprex package (v1.0.0)

I'll report back on further reasons why these differences might actually arise.

mpadge commented 3 years ago

I think that has resolved the major problem, which was related to transfers. Normal connections could be joined if they arrived at an arrival station prior to the listed departure time of a given timetable line, but that check was not implemented in the same way for transfers, which meant that some transfers were being connected which transferred to a departure station at a later time than the listed departure. That's now fixed and gives this for the first two of the above results:

library (gtfsrouter)
packageVersion ("gtfsrouter")
#> [1] '0.0.4.184'

gtfs <- extract_gtfs("vbb.zip")
#> ▶ Unzipping GTFS archive
#> ✔ Unzipped GTFS archive
#> ▶ Extracting GTFS feed✔ Extracted GTFS feed 
#> ▶ Converting stop times to seconds✔ Converted stop times to seconds 
#> ▶ Converting transfer times to seconds✔ Converted transfer times to seconds
gtfs <- gtfs_timetable(gtfs, day = "tuesday")
from <- "Berlin Hauptbahnhof"
#to <- "S+U Gesundbrunnen Bhf (Berlin)"
to <- c ("060007102724", "000008011102")

iso0 <- gtfs_traveltimes (gtfs, from = from, start_time = 8 * 3600)
iso0 [iso0$stop_id %in% to, ]
#>       start_time duration ntransfers      stop_id
#> 13724   08:09:00 00:12:42          1 060007102724
#> 19367   08:09:00 00:17:42          2 000008011102
#>                            stop_name stop_lon stop_lat
#> 13724 S+U Gesundbrunnen Bhf (Berlin) 13.38837 52.54864
#> 19367 S+U Gesundbrunnen Bhf (Berlin) 13.38837 52.54864

iso1 <- gtfs_traveltimes (gtfs, from = from, start_time = 8 * 3600 + 5 * 60)
iso1 [iso1$stop_id %in% to, ]
#>       start_time duration ntransfers      stop_id
#> 13724   08:09:00 00:12:42          1 060007102724
#> 19367   08:09:00 00:17:42          2 000008011102
#>                            stop_name stop_lon stop_lat
#> 13724 S+U Gesundbrunnen Bhf (Berlin) 13.38837 52.54864
#> 19367 S+U Gesundbrunnen Bhf (Berlin) 13.38837 52.54864

The final one is still different, so I'll re-open again until that has been resolved:

iso2 <- gtfs_traveltimes (gtfs, from = from, start_time = 8 * 3600 + 15 * 60)
iso2 [iso2$stop_id %in% to, ]
#>       start_time duration ntransfers      stop_id
#> 13724   08:27:00 00:08:00          1 060007102724
#> 19367   08:27:00 00:03:00          0 000008011102
#>                            stop_name stop_lon stop_lat
#> 13724 S+U Gesundbrunnen Bhf (Berlin) 13.38837 52.54864
#> 19367 S+U Gesundbrunnen Bhf (Berlin) 13.38837 52.54864

Created on 2021-03-03 by the reprex package (v1.0.0)

mpadge commented 3 years ago

There we go:

library (gtfsrouter)
packageVersion ("gtfsrouter")
#> [1] '0.0.4.186'

gtfs <- extract_gtfs("vbb.zip")
#> ▶ Unzipping GTFS archive
#> ✔ Unzipped GTFS archive
#> ▶ Extracting GTFS feed✔ Extracted GTFS feed 
#> ▶ Converting stop times to seconds✔ Converted stop times to seconds 
#> ▶ Converting transfer times to seconds✔ Converted transfer times to seconds
gtfs <- gtfs_timetable(gtfs, day = "tuesday")
from <- "Berlin Hauptbahnhof"
#to <- "S+U Gesundbrunnen Bhf (Berlin)"
to <- c ("060007102724", "000008011102")

iso0 <- gtfs_traveltimes (gtfs, from = from, start_time = 8 * 3600)
iso0 [iso0$stop_id %in% to, ]
#>       start_time duration ntransfers      stop_id
#> 13724   08:09:00 00:12:42          1 060007102724
#> 19367   08:27:00 00:03:00          0 000008011102
#>                            stop_name stop_lon stop_lat
#> 13724 S+U Gesundbrunnen Bhf (Berlin) 13.38837 52.54864
#> 19367 S+U Gesundbrunnen Bhf (Berlin) 13.38837 52.54864

iso1 <- gtfs_traveltimes (gtfs, from = from, start_time = 8 * 3600 + 5 * 60)
iso1 [iso1$stop_id %in% to, ]
#>       start_time duration ntransfers      stop_id
#> 13724   08:09:00 00:12:42          1 060007102724
#> 19367   08:27:00 00:03:00          0 000008011102
#>                            stop_name stop_lon stop_lat
#> 13724 S+U Gesundbrunnen Bhf (Berlin) 13.38837 52.54864
#> 19367 S+U Gesundbrunnen Bhf (Berlin) 13.38837 52.54864

iso2 <- gtfs_traveltimes (gtfs, from = from, start_time = 8 * 3600 + 15 * 60)
iso2 [iso2$stop_id %in% to, ]
#>       start_time duration ntransfers      stop_id
#> 13724   08:19:00 00:12:42          1 060007102724
#> 19367   08:27:00 00:03:00          0 000008011102
#>                            stop_name stop_lon stop_lat
#> 13724 S+U Gesundbrunnen Bhf (Berlin) 13.38837 52.54864
#> 19367 S+U Gesundbrunnen Bhf (Berlin) 13.38837 52.54864

Created on 2021-03-03 by the reprex package (v1.0.0)