Skip to content
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

Calculating speed via detailed_itineraries() leg info results in different value than the one set in walk_speed #277

Open
dhersz opened this issue Jun 9, 2022 · 2 comments

Comments

@dhersz
Copy link
Collaborator

dhersz commented Jun 9, 2022

Code:

data_path <- system.file("extdata/poa", package = "r5r")
r5r_core <- setup_r5(data_path, verbose = FALSE)
pois <- data.table::fread(file.path(data_path, "poa_points_of_interest.csv"))
departure_datetime <- as.POSIXct(
  "13-05-2019 14:00:00",
  format = "%d-%m-%Y %H:%M:%S"
)
calculate_speed <- function(distance, time) distance / 1000 / (time / 60)

dit <- detailed_itineraries(
  r5r_core,
  pois,
  pois[15:1],
  mode = "WALK",
  drop_geometry = TRUE,
  walk_speed = 2
)
dit[, speed := calculate_speed(distance, segment_duration)]

dit[, .(from_id, to_id, segment_duration, distance, speed)]
#>                           from_id                          to_id
#> 1:            bus_central_station                          ufrgs
#> 2:            santa_casa_hospital praia_de_belas_shopping_center
#> 3:         metropolitan_cathedral      moinhos_de_vento_hospital
#> 4:               farroupilha_park               farroupilha_park
#> 5:      moinhos_de_vento_hospital         metropolitan_cathedral
#> 6: praia_de_belas_shopping_center            santa_casa_hospital
#> 7:                          ufrgs            bus_central_station
#>    segment_duration distance    speed
#> 1:             47.4     1400 1.772152
#> 2:             83.7     2490 1.784946
#> 3:             92.4     2668 1.732468
#> 4:              0.6       42 4.200000
#> 5:             93.7     2721 1.742369
#> 6:             84.0     2490 1.778571
#> 7:             47.7     1400 1.761006

Created on 2022-06-09 by the reprex package (v2.0.1)

Expected speed: 2km/h

Got: Usually 1.7~, but a big 4.2 as well

Some things might explain the difference. First, R5 uses a fixed "off-road" speed (from the specified point to the snapped location) of 1.3 m/s, which we cannot change in r5r: https://github.com/conveyal/r5/blob/ccc302f391968852b13477c01045e8b182dcf95b/src/main/java/com/conveyal/r5/streets/LinkedPointSet.java#L46

Also, there seems to be a significant difference between the distance calculated from the legs geometries (which is the distance returned in the output) vs. the one provided by R5 output. For example, the route from farroupilha_park to itself, which in the example above is 42 meters long, in the R5 output is 33 meters long.

Had we traveled a 33 meters trip at 1.3 m/s (4.68 km/h), we would be finished in 25 seconds, which is around 0.4 minutes (which is exactly the result we have when we run detailed_itineraries() with walk_speed = 4.68 km/h):

dit[
  from_id == "farroupilha_park",
  .(from_id, to_id, segment_duration, distance, speed)
]
#>             from_id            to_id segment_duration distance speed
#> 1: farroupilha_park farroupilha_park              0.4       42   6.3

So things to take away from this issue:

  • The duration calculated in detailed_itineraries() is correct.
  • Calculating the distance from the shapes result in different distances estimates, when compared to the "original" R5 distances. Why? How does R5 calculates distances?
  • As far as I understand, we would be able to change the "off-road" speed to the one we want it to be if the variable wasn't final, but we currently can't.
  • The trip from farroupilha_park to itself apart, all the other speeds are lower than the one specified. Since the off-road speed is much higher than the one specified, if that was the only thing affecting the speed, our speeds would be on average higher than the one specified. So either we are regularly underestimating distances, or there are even more things affecting the calculated speed here.

PS: The network was calculated with no elevation info, so that's not the problem here.

@rafapereirabr
Copy link
Member

rafapereirabr commented Jun 10, 2022

Perhaps some of this differences could be a result of how R5 accounts for elevation, as Marcus mentioned in #273

@rafapereirabr
Copy link
Member

related to #357

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants