r5r icon indicating copy to clipboard operation
r5r copied to clipboard

Redundant trip legs in detailed itineraries

Open FlxPo opened this issue 2 years ago • 1 comments

Hi,

detailed_itineraries sometimes returns options with multiple rows for the same trip leg. Here the bicycle and walk modes both start from the destination to get to a bus stop, for example : image

Could there be a problem when alternative paths from r5 are transformed in r5r ? Trip legs not well grouped by option ?

I could not reproduce the problem with the example dataset, so it might come from the osm and gtfs file I'm working with.

Here is a reproductible example (osm and gtfs data available at https://drive.google.com/file/d/1S61X5Rel0DLKWca4gNZYTf-t1fM8QQEv/view?usp=sharing) :

library(r5r)
library(sf)
library(data.table)
library(ggplot2)

data_path <- "D:/dev/r5r_test"

r5r_core <- setup_r5(data_path = data_path, verbose = TRUE)

transit_net <- transit_network_to_sf(r5r_core)

points <- transit_net$stops[c(1, 20), ]
points <- as.data.table(st_coordinates(points))
points$id <- c("origin", "destination")
setnames(points, c("lon", "lat", "id"))

modes <- c("WALK", "TRANSIT", "CAR", "BICYCLE")

departure_datetime <- as.POSIXct("15-01-2022 14:00:00",
                                 format = "%d-%m-%Y %H:%M:%S")


# calculate detailed itineraries
det <- detailed_itineraries(r5r_core = r5r_core,
                            origins = points[1],
                            destinations = points[2],
                            mode = modes,
                            shortest_path = FALSE,
                            departure_datetime = departure_datetime)

ggplot() +
  geom_sf(data = det[det$option == 3, ], aes(group = option, color = mode)) +
  geom_point(data = points, aes(x = lon, y = lat, shape = factor(id))) +
  theme_void()

stop_r5(r5r_core)
rJava::.jgc(R.gc = TRUE)

FlxPo avatar May 16 '22 16:05 FlxPo

Could there be a problem when alternative paths from r5 are transformed in r5r ? Trip legs not well grouped by option ?

Indeed, that seems to be the problem here. Thanks for pointing it out, we'll try to fix it for the next version of the package.

mvpsaraiva avatar May 18 '22 14:05 mvpsaraiva

Hi @FlxPo, could you please test if the dev version?

# or use the development version with latest features
  utils::remove.packages('r5r')
  devtools::install_github("ipeaGIT/r5r", subdir = "r-package")
  library(r5r)

rafapereirabr avatar Dec 02 '22 11:12 rafapereirabr

Hi, I just tested the dev version without any modification to the code I shared last year, but I get the following error for now : Error in assign_mode(mode, mode_egress) : Please use only 1 of {'WALK','CAR','BICYCLE'} when routing.

I have not used r5r in a while, so I might need to adjust the functions arguments to make it work.

FlxPo avatar Jan 23 '23 12:01 FlxPo

Hi @FlxPo . Thanks for the update.

The new version of r5r v1.0.0 will bring some changes that might break workflows built with previous versions. This is one of them. Fromv1.0.0 onwards, r5r throws an error if users simultaneously pass more than one of the following modes c('WALK','CAR','BICYCLE') to the transport_mode parameter. This is because these modes are understood as mutually exclusive.

We are documenting all breaking changes here.

rafapereirabr avatar Jan 23 '23 13:01 rafapereirabr

I tested different combination of modes with the dev version, and I could not reproduce the bug. Thank you !

FlxPo avatar Jan 23 '23 15:01 FlxPo

I'm glad to hear. Thanks for the feedback.

rafapereirabr avatar Jan 23 '23 17:01 rafapereirabr