conveyal / r5

Developed to power Conveyal's web-based interface for scenario planning and land-use/transport accessibility analysis, R5 is our routing engine for multimodal (transit/bike/walk/car) networks with a particular focus on public transit
https://conveyal.com/learn
MIT License
280 stars 73 forks source link

Monte Carlo draws in networks with no frequency routes #445

Open abyrd opened 6 years ago

abyrd commented 6 years ago

When debugging #290, I created a test project with only a single add-trip-pattern modification. It has a single timetable that has exact-times enabled. I can perform a single point analysis using this modification with no problem. But strangely the worker logs show:

INFO com.conveyal.r5.profile.FastRaptorWorker - Prefiltering patterns based on date active reduced 1020 patterns to 0 frequency and 763 scheduled patterns
INFO com.conveyal.r5.profile.FastRaptorWorker - Performing 120 scheduled iterations each with 9 Monte Carlo draws for a total of 1080 iterations

So the scenario includes no frequency patterns at all, yet the worker is performing Monte Carlo draws, presumably based on the presence of this modification (which should not add any frequency based trips). When exact-times is disabled, we see these messages:

INFO com.conveyal.r5.profile.FastRaptorWorker - Prefiltering patterns based on date active reduced 1020 patterns to 2 frequency and 761 scheduled patterns
INFO com.conveyal.r5.profile.FastRaptorWorker - Performing 120 scheduled iterations each with 2 Monte Carlo draws for a total of 240 iterations

So the frequency trip exists now but the behavior is the same, Monte Carlo simulation happens. Interestingly even with the modification completely removed I see:

INFO com.conveyal.r5.profile.FastRaptorWorker - Prefiltering patterns based on date active reduced 1018 patterns to 0 frequency and 761 scheduled patterns
INFO com.conveyal.r5.profile.FastRaptorWorker - Performing 120 scheduled iterations each with 9 Monte Carlo draws for a total of 1080 iterations

So it looks like the exact times check box works, creating non-frequency trips, but the worker still does MC draws even when there are no frequency trips in the network.

abyrd commented 6 years ago

First observation, on filtering. The log messages above come from the filtering performed around FastRaptorWorker L345. This pre-filtering does not work by changing the scenario-specific TransitNetwork, it creates arrays of subsets of patterns that are internal to the FastRaptorWorker. The TransitNetwork itself has two fields, hasFrequencies and hasSchedules, which the raptor search uses to decide whether to perform the schedule search and/or schedule randomization for frequency trips. Those fields are never updated, so if filtering removes all frequencies or schedules those fields give a false positive. This should not lead to incorrect results, but it causes a lot of unnecessary computation.

Second observation: even without this filtering the input data contains no frequencies. The TriMet GTFS doesn't even have a frequencies.txt. So somehow hasFrequencies is getting incorrectly set to "true". The fact that the MC draws are happening even with no modifications means that the fault cannot (solely) lie in the modification application code.

abyrd commented 6 years ago

I'm not able to determine how this is happening. TransitLayer.hasFrequencies is set in only a few places, will have to trace execution locally to see where it's going wrong.

Workaround: when you know for sure that the network has no frequencies, set number of MC draws to 1 in the UI.