-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New detailed_itineraries()
#265
Comments
If you need lots of path alternatives, the new The plot below shows that you can get up to 134 different alternatives between the same origin/destination pair when Obviously, those routes are far from the best alternatives and sometimes have very large detours: The following table shows all the itineraries mapped above:
|
Now you can also use # load packages
library("r5r")
library("dplyr")
library("ggplot2")
# build transport network
data_path <- system.file("extdata/poa", package = "r5r")
r5r_core <- setup_r5(data_path)
# load origin/destination points
points <- read.csv(file.path(data_path, "poa_points_of_interest.csv"))
# load fare structure object
fare_structure_path <- system.file(
"extdata/poa/fares/fares_poa.zip",
package = "r5r"
)
fare_structure <- read_fare_structure(fare_structure_path)
# inputs
departure_datetime <- as.POSIXct("13-05-2019 14:00:00",
format = "%d-%m-%Y %H:%M:%S")
# plan itineraries
dit <- detailed_itineraries(r5r_core,
origins = points[10,],
destinations = points[12,],
mode = c("WALK", "TRANSIT"),
departure_datetime = departure_datetime,
max_trip_duration = 140,
fare_structure = fare_structure,
max_fare = 9,
shortest_path = FALSE,
drop_geometry = TRUE)
# build Pareto frontiers
pareto_df <- dit |>
group_by(option) |>
summarise(travel_time = max(total_duration),
fare = max(total_fare),
mode = paste(if_else(mode == "WALK", "", mode), collapse = " ")) |>
mutate(mode = if_else(mode == "", "WALK", mode))
# plot Pareto frontiers
ggplot(pareto_df , aes(x=fare, y=travel_time)) +
geom_step() +
geom_point() +
geom_text(aes(label=mode), hjust = -0.1, vjust=-0.5) +
geom_text(aes(label=paste("BRL", scales::comma(fare, accuracy = 0.01))),
hjust = 0.3, vjust=1.5) +
scale_y_continuous(breaks = seq(0, 140, 20), limits = c(0, 140)) +
scale_x_continuous(breaks = 0:10, limits = c(0, 10),
labels = scales::comma_format(accuracy = 0.01)) +
theme_light() +
labs(x = "fare (BRL)", y = "travel time (minutes)",
subtitle = "Travel time and monetary cost of trips between\nFarrapos Station and Praia de Belas Shopping Mall") |
Finally, if you don't care about a lot of path alternatives or monetary costs, but you need the detailed shortest itinerary between two points (with geometries, travel distances, routes and so on...), the new See below the processing times for up to 40,000 queries: the new version is 4 to 5 times faster, on average! It's also much more memory efficient: it uses 5GB of RAM to compute 40,000 queries, while before it used 20GB of RAM to do the same. I think that's a wrap for it :) |
A final note before closing this issue: even though |
Marcus, just checking the performance comparison between CRAN version and dev version. In this simple reprex below, I get that the currenct version of the funcion on CRAN is faster then the dev version. Am I missing something here?
|
You're using the same points for origins and destinations, which is a scenario that I didn't test. Perhaps there's some optimisation to do there. I've made a small change to your code and got some better results: system.time(
det <- detailed_itineraries(
r5r_core,
origins = points[1:1227,],
destinations = points[1227:1,],
mode = "TRANSIT",
departure_datetime = departure_datetime,
max_trip_duration = 60 ,
shortest_path = T,
drop_geometry = T
)
)
|
ah! indeed. Here are the results that I got.
thanks again, Marcus! |
I have rebuilt the
detailed_itineraries()
function to make it faster, more reliable, and add some cool new features. It's on thedev
branch now, and I think we can move it to themaster
branch after we update the tests and documentation.Some of the new features:
time_window
parameter;suboptimal_minutes
parameter, which extends the search space and returns a larger number of trips beyond the fastest ones;max_fare
parameter;Reproducible example:
Map:
Data:
The text was updated successfully, but these errors were encountered: