UrbanAnalyst / gtfsrouter

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

max_transfers does not work as expected #47

Closed mpadge closed 3 years ago

mpadge commented 3 years ago
library (gtfsrouter)
gtfs <- extract_gtfs("vbb.zip") # full Berlin VBB feed
#> ▶ 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 = "thurs")
from <- "Alexanderplatz"
to <- "Berlin, Helene-Weigel-Platz"

r1 <- gtfs_route (gtfs, from = "Alexanderplatz", to = to,
                  start_time = 9 * 3600,
                  earliest_arrival = TRUE)
r2 <- gtfs_route (gtfs, from = "Alexanderplatz", to = to,
                  start_time = 9 * 3600,
                  earliest_arrival = FALSE)
r1
#>    route_name                       trip_name                       stop_name
#> 1          S7               S Ahrensfelde Bhf S+U Alexanderplatz Bhf (Berlin)
#> 2          S7               S Ahrensfelde Bhf    S+U Jannowitzbrücke (Berlin)
#> 3          S7               S Ahrensfelde Bhf           S Ostbahnhof (Berlin)
#> 4          S7               S Ahrensfelde Bhf    S+U Warschauer Str. (Berlin)
#> 5          S7               S Ahrensfelde Bhf         S Ostkreuz Bhf (Berlin)
#> 6          S7               S Ahrensfelde Bhf         S Nöldnerplatz (Berlin)
#> 7          S7               S Ahrensfelde Bhf    S+U Lichtenberg Bhf (Berlin)
#> 8          S7               S Ahrensfelde Bhf  S Friedrichsfelde Ost (Berlin)
#> 9          S7               S Ahrensfelde Bhf          S Springpfuhl (Berlin)
#> 10         M8 Berlin, Ahrensfelde/Stadtgrenze          S Springpfuhl (Berlin)
#> 11         M8 Berlin, Ahrensfelde/Stadtgrenze     Berlin, Helene-Weigel-Platz
#>    arrival_time departure_time
#> 1      09:04:36       09:05:24
#> 2      09:06:54       09:07:24
#> 3      09:09:06       09:09:54
#> 4      09:11:36       09:12:12
#> 5      09:13:54       09:14:42
#> 6      09:16:12       09:16:42
#> 7      09:18:12       09:18:48
#> 8      09:20:42       09:21:12
#> 9      09:23:48       09:24:54
#> 10     09:30:00       09:30:00
#> 11     09:31:00       09:31:00

That route has only one transfer, and leaves at 09:04. In comparison, the route generated with earliest_arrival = FALSE (see #46) gives:

r2
#>    route_name                       trip_name                       stop_name
#> 1          S3                    S Erkner Bhf S+U Alexanderplatz Bhf (Berlin)
#> 2          S3                    S Erkner Bhf    S+U Jannowitzbrücke (Berlin)
#> 3          S3                    S Erkner Bhf           S Ostbahnhof (Berlin)
#> 4          S3                    S Erkner Bhf    S+U Warschauer Str. (Berlin)
#> 5          S3                    S Erkner Bhf         S Ostkreuz Bhf (Berlin)
#> 6          S7               S Ahrensfelde Bhf         S Nöldnerplatz (Berlin)
#> 7          S7               S Ahrensfelde Bhf    S+U Lichtenberg Bhf (Berlin)
#> 8          S7               S Ahrensfelde Bhf  S Friedrichsfelde Ost (Berlin)
#> 9          S7               S Ahrensfelde Bhf          S Springpfuhl (Berlin)
#> 10         M8 Berlin, Ahrensfelde/Stadtgrenze          S Springpfuhl (Berlin)
#> 11         M8 Berlin, Ahrensfelde/Stadtgrenze     Berlin, Helene-Weigel-Platz
#>    arrival_time departure_time
#> 1      09:01:36       09:02:24
#> 2      09:03:54       09:04:24
#> 3      09:06:06       09:07:24
#> 4      09:09:06       09:09:42
#> 5      09:11:24       09:12:12
#> 6      09:16:12       09:16:42
#> 7      09:18:12       09:18:48
#> 8      09:20:42       09:21:12
#> 9      09:23:48       09:24:54
#> 10     09:30:00       09:30:00
#> 11     09:31:00       09:31:00

Setting max_transfers = 1 should therefore yield the first of these routes, and yet it returns the second:

gtfs_route (gtfs, from = "Alexanderplatz", to = "Boschpoler Str",
            start_time = 9 * 3600,
            max_transfers = 1,
            earliest_arrival = FALSE)
#>    route_name                       trip_name                       stop_name
#> 1          S3                    S Erkner Bhf S+U Alexanderplatz Bhf (Berlin)
#> 2          S3                    S Erkner Bhf    S+U Jannowitzbrücke (Berlin)
#> 3          S3                    S Erkner Bhf           S Ostbahnhof (Berlin)
#> 4          S3                    S Erkner Bhf    S+U Warschauer Str. (Berlin)
#> 5          S3                    S Erkner Bhf         S Ostkreuz Bhf (Berlin)
#> 6          S7               S Ahrensfelde Bhf         S Nöldnerplatz (Berlin)
#> 7          S7               S Ahrensfelde Bhf    S+U Lichtenberg Bhf (Berlin)
#> 8          S7               S Ahrensfelde Bhf  S Friedrichsfelde Ost (Berlin)
#> 9          S7               S Ahrensfelde Bhf          S Springpfuhl (Berlin)
#> 10         M8 Berlin, Ahrensfelde/Stadtgrenze          S Springpfuhl (Berlin)
#> 11         M8 Berlin, Ahrensfelde/Stadtgrenze     Berlin, Helene-Weigel-Platz
#> 12         M8 Berlin, Ahrensfelde/Stadtgrenze         Berlin, Boschpoler Str.
#>    arrival_time departure_time
#> 1      09:01:36       09:02:24
#> 2      09:03:54       09:04:24
#> 3      09:06:06       09:07:24
#> 4      09:09:06       09:09:42
#> 5      09:11:24       09:12:12
#> 6      09:16:12       09:16:42
#> 7      09:18:12       09:18:48
#> 8      09:20:42       09:21:12
#> 9      09:23:48       09:24:54
#> 10     10:00:00       10:00:00
#> 11     10:01:00       10:01:00
#> 12     10:02:00       10:02:00

Created on 2020-10-12 by the reprex package (v0.3.0)

Fix that!