UrbanAnalyst / gtfsrouter

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

allow vector with multiple times for parameter "end_time" in gtfs_isochrone #30

Closed AlexandraKapp closed 3 years ago

AlexandraKapp commented 4 years ago

Include the option to return isochrone with multiple "breaks", e.g. for 5, 10 and 15 min intervalls. This could be implemented by adding another column to the mid_points, indicating the max arrival time.

mpadge commented 4 years ago

This is how the current code works, stepping inside each function:

devtools::load_all (".", export_all = TRUE)
#> Loading gtfsrouter
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 not specified; extracting timetable for Monday
stn <- "Berlin, Rohrdammbrücke"
start_time <- 3600
end_time <- start_time + 600

#x <- gtfs_isochrone (gtfs, from = stn, start_time = start_time, end_time = end_time)
# code from gtfs_isochrone function:
from <- stn
from_is_id <- FALSE

gtfs_cp <- data.table::copy (gtfs)
start_time <- convert_time (start_time)
end_time <- convert_time (end_time)
gtfs_cp$timetable <- gtfs_cp$timetable [departure_time >= start_time, ]
start_stns <- station_name_to_ids (from, gtfs_cp, from_is_id)
start_stns
#> [1]   492 27286 28339

#isotrips <- get_isotrips (gtfs_cp, start_stns, start_time, end_time)
# code from get_isotrips function:
stns <- rcpp_csa_isochrone (gtfs$timetable, gtfs$transfers,
                            nrow (gtfs$stop_ids), nrow (gtfs$trip_ids),
                            start_stns, start_time, end_time)
stns
#> [[1]]
#> [1] 27286 27287 28819 27345 27346 27347 33326 33328 33330
#> 
#> [[2]]
#> [1] 25933 25933 25933 25933 25933 25933 50413 50413 50413
#> 
#> [[3]]
#> [1] 27286 27287 28819 27345 27346 27347 27348 27293 27294
#> 
#> [[4]]
#> [1] 25933 25933 25933 25933 25933 25933 25933 46653 46653
#> 
#> [[5]]
#> [1] 27286 27287 28819 27345 28559 29453 30470 28844 29376
#> 
#> [[6]]
#> [1] 25933 25933 25933 25933 45673 45673 45673 45673 45673
#> 
#> [[7]]
#> [1] 27286 27287 28819 27345 27346 27347 27348 27293 27319
#> 
#> [[8]]
#> [1] 25933 25933 25933 25933 25933 25933 25933 46653 25933
#> 
#> [[9]]
#> [1] 20820

Created on 2020-06-22 by the reprex package (v0.3.0)

So most of the work happens in the C++ function rcpp_csa_isochrone, which returns paired lists of vectors denoting (stations along each route, corresponding trip numbers). (There is an additional item, here [[9]], which records the start time in seconds.) This C++ code would thus need to be modified to add the arrival time at each of those sequences of stations. The stations are ultimately stored here: https://github.com/ATFutures/gtfs-router/blob/c7ba288609aaa28a4c826c2272544f73ee0bb6ff/src/csa-isochrone.cpp#L160-L161

With those values of prev_stn constructed here: https://github.com/ATFutures/gtfs-router/blob/c7ba288609aaa28a4c826c2272544f73ee0bb6ff/src/csa-isochrone.cpp#L122-L123 ... alongside equivalent values for prev_time. So all that we'd need to do would be to add an additional output vector for prev_time alongisde prev_stn, and then append that to the result as you suggest. Not sure how your C++ skills are @AlexandraKapp? Let me know if you feel up for the challenge, otherwise i'm happy to address it.

AlexandraKapp commented 4 years ago

Thanks for looking into it! I'm afraid I cannot really offer C++ skills - so that would probably take me a bit to get into that.

mpadge commented 4 years ago

No worries - I'll be happy to get on to it, after #14 is done.