UrbanAnalyst / gtfsrouter

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

for some stops still too many transfers #52

Closed AlexandraKapp closed 3 years ago

AlexandraKapp commented 3 years ago
## Example of too many transfers
# S Grunewald to Berlin, Koenigin-Luise-Str./Clayallee

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(gtfsrouter)

timetable <- readRDS("timetable_vbb.Rds")

# gtfs_route returns correct amount of transfers: 1
gtfs_route(timetable, start_time = 8*3600, "S Grunewald", "nigin-Luise-Str")
#>   route_name                trip_name                               stop_name
#> 1        186      S Lichterfelde Süd                    S Grunewald (Berlin)
#> 2        186      S Lichterfelde Süd                      Berlin, Hagenplatz
#> 3        186      S Lichterfelde Süd            Berlin, Richard-Strauss-Str.
#> 4        186      S Lichterfelde Süd              Berlin, Hubertusbader Str.
#> 5        186      S Lichterfelde Süd         Berlin, Roseneck/Teplitzer Str.
#> 6        X10 Teltow, Rammrath-Brücke         Berlin, Roseneck/Teplitzer Str.
#> 7        X10 Teltow, Rammrath-Brücke Berlin, Brücke-Museum/Kunsthaus Dahlem
#> 8        X10 Teltow, Rammrath-Brücke   Berlin, Königin-Luise-Str./Clayallee
#>   arrival_time departure_time
#> 1     08:10:00       08:10:00
#> 2     08:12:00       08:12:00
#> 3     08:14:00       08:14:00
#> 4     08:15:00       08:15:00
#> 5     08:15:30       08:15:30
#> 6     08:24:00       08:24:00
#> 7     08:27:00       08:27:00
#> 8     08:28:00       08:28:00

# with gtfs_isochrone 3 transfers are returned
iso <- gtfs_isochrone(timetable, "S Grunewald", start_time = 8 * 3600, end_time = 8 * 3600 + 30*60)
#> Loading required namespace: geodist
#> Loading required namespace: lwgeom
iso$end_points%>% filter(grepl("igin-Luise-Str", stop_name))
#> Simple feature collection with 0 features and 6 fields
#> bbox:           xmin: NA ymin: NA xmax: NA ymax: NA
#> geographic CRS: WGS 84
#> [1] stop_name stop_id   departure arrival   duration  transfers geometry 
#> <0 rows> (or 0-length row.names)
iso$mid_points%>% filter(grepl("igin-Luise-Str", stop_name))
#> Simple feature collection with 1 feature and 6 fields
#> geometry type:  POINT
#> dimension:      XY
#> bbox:           xmin: 13.27476 ymin: 52.46009 xmax: 13.27476 ymax: 52.46009
#> geographic CRS: WGS 84
#>                               stop_name      stop_id departure  arrival
#> 1 Berlin, Königin-Luise-Str./Clayallee 070101001743  08:06:00 08:28:00
#>   duration transfers                  geometry
#> 1 00:22:00         3 POINT (13.27476 52.46009)

# get isotrips: debug gtfs_isochrone and store isotrips in temp.Rds
isotrips <- readRDS("temp.Rds")

for (i in 1:198) {
  r <- isotrips[[1]][[i]] %>% filter(grepl("igin-Luise-Str", stop_name))
  if (nrow(r) > 0){
    print (i)
    index <- i
  }
}
#> [1] 37
print(isotrips[[1]][index])
#> [[1]]
#>         stop_id                               stop_name parent_station stop_lon
#> 1  070101002370                    S Grunewald (Berlin)   900000048101 13.26194
#> 2  070101002920                  Berlin, Taubertstraße   900000048158 13.26798
#> 3  070101001409                      Berlin, Hagenplatz   900000048107 13.26591
#> 4  070101001410            Berlin, Richard-Strauss-Str.   900000048159 13.27158
#> 5  070101001411              Berlin, Hubertusbader Str.   900000048160 13.27560
#> 6  070101001248         Berlin, Roseneck/Teplitzer Str.   900000046354 13.28048
#> 7  070101002445         Berlin, Roseneck/Teplitzer Str.   900000046354 13.28048
#> 8  070101003809 Berlin, Brücke-Museum/Kunsthaus Dahlem   900000051259 13.27730
#> 9  070101001743   Berlin, Königin-Luise-Str./Clayallee   900000051204 13.27476
#> 10 070101000017                Berlin, Alliiertenmuseum   900000051255 13.27366
#> 11 070101000018                      Berlin, Hüttenweg   900000051256 13.27224
#>    stop_lat  route_id   trip_id            trip_headsign earliest_arrival
#> 1  52.48868 17445_700 141829991            U Mehringdamm            29160
#> 2  52.48460 17445_700 141829991            U Mehringdamm            29280
#> 3  52.48332 17341_700 141792572      S Lichterfelde Süd            29280
#> 4  52.47995 17341_700 141792572      S Lichterfelde Süd            29640
#> 5  52.47841 17341_700 141792572      S Lichterfelde Süd            29700
#> 6  52.47749 17341_700 141792572      S Lichterfelde Süd            29730
#> 7  52.47749 17529_700 141867473 Teltow, Rammrath-Brücke            29730
#> 8  52.46473 17529_700 141867473 Teltow, Rammrath-Brücke            30420
#> 9  52.46009 17529_700 141867473 Teltow, Rammrath-Brücke            30480
#> 10 52.45648 17299_700 141775970 Berlin, Neuruppiner Str.            30720
#> 11 52.45352 17299_700 141775970 Berlin, Neuruppiner Str.            30780

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

mpadge commented 3 years ago

Ah, thanks, that's the kind of result we need to debug this properly. Shall get on to that tomorrow

mpadge commented 3 years ago

The isochrone traces from Berlin Hbf to Potsdam Hbf leaving 08:00 Tues all have at least 1 transfer, whereas gtfs_route() selects the direct and fastest RE connection with no transfers. Those isochrone routes all select an initial connection on the S9 to "S Spandau Hbf", and change to the RE at Zoologischer Garten or Charlottenburg. That means they leave at 08:00:12, rather than the more direct RE which leaves at 08:11. That at least gives me a concrete example from which I can now use to work out why that happens and fix it. Thanks!

mpadge commented 3 years ago

@AlexandraKapp You okay with this being closed now? Just to confirm, the original query now gives these results:

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

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 <- "S Grunewald"
to <- "nigin-Luise-Str"
start_time <- 8 * 3600
gtfs_route(gtfs, from, to, start_time, max_transfers )
#>   route_name               trip_name                              stop_name
#> 1        186      S Lichterfelde Süd                   S Grunewald (Berlin)
#> 2        186      S Lichterfelde Süd                     Berlin, Hagenplatz
#> 3        186      S Lichterfelde Süd           Berlin, Richard-Strauss-Str.
#> 4        186      S Lichterfelde Süd             Berlin, Hubertusbader Str.
#> 5        186      S Lichterfelde Süd        Berlin, Roseneck/Teplitzer Str.
#> 6        X10 Teltow, Rammrath-Brücke        Berlin, Roseneck/Teplitzer Str.
#> 7        X10 Teltow, Rammrath-Brücke Berlin, Brücke-Museum/Kunsthaus Dahlem
#> 8        X10 Teltow, Rammrath-Brücke   Berlin, Königin-Luise-Str./Clayallee
#>   arrival_time departure_time
#> 1     08:10:00       08:10:00
#> 2     08:12:00       08:12:00
#> 3     08:14:00       08:14:00
#> 4     08:15:00       08:15:00
#> 5     08:15:30       08:15:30
#> 6     08:24:00       08:24:00
#> 7     08:27:00       08:27:00
#> 8     08:28:00       08:28:00
iso <- gtfs_traveltimes (gtfs, from = from, start_time = start_time)
iso [grep (to, iso$stop_name), ]
#>       duration ntransfers      stop_id                            stop_name
#> 26776 00:24:00          2 070101001259 Berlin, Königin-Luise-Str./Clayallee
#> 27213 00:22:00          1 070101001743 Berlin, Königin-Luise-Str./Clayallee
#> 27217 00:24:00          2 070101001747 Berlin, Königin-Luise-Str./Clayallee
#>       stop_lon stop_lat
#> 26776 13.27476 52.46009
#> 27213 13.27476 52.46009
#> 27217 13.27476 52.46009

Created on 2021-01-20 by the reprex package (v0.3.0)

AlexandraKapp commented 3 years ago

yes :)