r5r icon indicating copy to clipboard operation
r5r copied to clipboard

fare calculator not working with Sao Paulo example

Open rafapereirabr opened this issue 3 years ago • 1 comments

rafapereirabr avatar Jun 21 '22 17:06 rafapereirabr

The test below works with all functions but with pareto_frontier(). The main difference between this function and the others is that pareto_frontier() has to consider fares in consideration, thus uses McRaptor. The function output a "pareto frontier" that only considers walking, ignoring transit altogether (although the other functions consider transit alright).

https://github.com/ipeaGIT/r5r/blob/99a0e34962d845b5c3ec94cc44994da3634a45a1/r-package/tests/testthat/test-set_monte_carlo_draws.R#L227-L250

dhersz avatar Jun 21 '22 17:06 dhersz

Testing the pareto_frontier() function with the draws_per_minute parameter under different settings:

Problem 1:

  • the functions works with the example of Porto Alegre (which has NO frequencies.txt table)
  • BUT, using the draws_per_minute parameter affects the result. This is in conflict with the current draws_per_minute documentation, which says that "This parameter only affects the results when the GTFS feeds contain a frequencies.txt table."

This is the current test. So either the documentation OR this test below needs to be fixed.

test_that("draws_per_minute arg works in pareto_frontier() - poa", {
  basic_expr <- call(
    "pareto_frontier",
    r5r_core = r5r_core,
    origins = points[1:10],
    destinations = points[1:10],
    mode = c("TRANSIT", "WALK"),
    departure_datetime = departure_datetime,
    max_trip_duration = 60,
    time_window = 30,
    percentiles = c(1, 50, 99),
    fare_structure = fare_structure,
    fare_cutoffs = c(0, 5, 10)
  )

  small_draws_expr <- big_draws_expr <- basic_expr
  small_draws_expr$draws_per_minute <- 1
  big_draws_expr$draws_per_minute <- 5

  small_draws <- eval(small_draws_expr)
  big_draws <- eval(big_draws_expr)
  expect_false(identical(small_draws, big_draws))
})

Problem 2:

  • the functions works with the example of São Paulo (which frequencies.txt table)
  • BUT, using the draws_per_minute parameter DOES NOT affect the results.
# this test is currently failing
test_that("draws_per_minute arg works in pareto_frontier() - spo", {
  basic_expr <- call(
    "pareto_frontier",
    r5r_core = spo_core,
    origins = spo_points[51:80],
    destinations = spo_points[51:80],
    mode = c("TRANSIT", "WALK"),
    departure_datetime = departure_datetime,
    max_trip_duration = 60,
    time_window = 30,
    percentiles = c(1, 50, 99),
    fare_structure = spo_fare_struc,
    fare_cutoffs = c(0, 5, 10, 15, Inf)
  )

  small_draws_expr <- big_draws_expr <- basic_expr
  small_draws_expr$draws_per_minute <- 1
  big_draws_expr$draws_per_minute <- 5

  small_draws <- eval(small_draws_expr)
  big_draws <- eval(big_draws_expr)
  expect_false(identical(small_draws, big_draws))
})

rafapereirabr avatar Dec 02 '22 14:12 rafapereirabr

Proposed solutions

Problem 1 Since the pareto frontier function only works with stop_times GTFS feeds AND the monte calo simulation does not work stop_times GTFS feeds, then the pareto frontier function should not event have a draw per minute parameter.

  • Remove the draw per minute parameter

Problem 2 Since the pareto frontier function only works with stop_times GTFS, the function should throw an error when using frequency-based GTFS feeds.

  • throw an error when frequency-based GTFS feed is detected

rafapereirabr avatar Jan 20 '23 12:01 rafapereirabr