-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Implement GTFS Flex safe duration spec draft #5796
Implement GTFS Flex safe duration spec draft #5796
Conversation
9ae0f00
to
0b95370
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev-2.x #5796 +/- ##
=============================================
+ Coverage 67.90% 67.94% +0.03%
- Complexity 16556 16575 +19
=============================================
Files 1910 1911 +1
Lines 72436 72455 +19
Branches 7447 7448 +1
=============================================
+ Hits 49190 49231 +41
+ Misses 20725 20700 -25
- Partials 2521 2524 +3 ☔ View full report in Codecov by Sentry. |
0b95370
to
0c1a651
Compare
Can the safe or mean offset/factor be one that decreases the travel time? I quickly took a look at the spec and didn't notice a mention about it. |
Yes, it can also lower the time, although this is not explicitly stated in the spec. |
At least in this current implementation, I'm not preventing it from happening. |
0c1a651
to
991406e
Compare
if (UnscheduledTrip.isUnscheduledTrip(stopTimes)) { | ||
var modifier = builder.getFlexDurationFactors().getOrDefault(trip, TimePenalty.ZERO); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we stick to call to calling them modifiers instead of factors? Or is there some difference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sorry, I did several renames of this field and made a mess. Lets discuss in the dev meeting what this field should be called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets use timePenalty here - modifier is too wide. Factor is not correct, it is more than a factor.
|
||
public DurationModifierCalculator(FlexPathCalculator delegate, TimePenalty penalty) { | ||
this.delegate = delegate; | ||
this.factors = penalty; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
src/ext/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTrip.java
Outdated
Show resolved
Hide resolved
7e15260
to
a4dc25b
Compare
Thanks for that implementation! Something that was discussed in the past but never decided was the relationship between that penalty and traffic. Do we agree that here you are applying the penalty after applying traffic? (Assuming traffic is at least y = ax, the order of application has an impact since we have an offset.) |
@LeoFrachet Not sure if you're aware but OTP doesn't have any real-time road traffic information. |
@LeoFrachet To answer your question, I would apply the penalty BEFORE traffic to make the behaviour simpler and more deterministic. You could argue that there is often a correlation between traffic and delays and the wanted penalty, but I think this is not always true and implisitt. I good principle for designing models like this is to keep each factor independent - so traffic should not depend on penalty and vis versa. It become very difficult to tune system where features propagate. Since OTP does not have support for traffic, this only apply to where in the code we put this. So the question for us is: If traffic is added, will this feature still work as intended? If not, should we consider another implementation? This is about designing with the ability to adopt change. |
From this user's perspective, I agree this should be separate from any consideration of traffic, which I think is accounted for in the spec: "The MeanTravelDuration may be calculated for the time and the day of the trip to take into account traffic; in other words the consumer is expected to know that DrivingDuration is dynamic." I'm not sure that before/after necessarily matters, and the spec implies this is "after" in the sense that the consumer's independent MeanTravelDuration calculation is assumed to already account for traffic (if the consumer is able to account for traffic). But regardless, it should be additive to traffic if traffic is considered. |
* Does this penalty actually modify a duration or would it be returned unchanged? | ||
*/ | ||
public boolean modifies() { | ||
return !constant().isZero() && coefficient() != 1.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comparison reliable or should we use an epsilon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, if it's not exactly 1.0 then I would argue that it does modify and therefore should return true.
Summary
It implements the proposed fields
flex_safe_duration_factor
andflex_safe_duration_offset
which are currently undergoing specification and discussion at MobilityData/gtfs-flex#79These fields give data producers some influence over how travel times are computed for flex trips. The implementation in this PR limits itself to what the OTP flex implementation calls
UnscheduledTrip
but the name "demand-responsive" is used more commonly. Here the duration modifier can add (or even subtract) travel time to what OTP's A* algorithm thinks it will take to go from origin to destination.These fields are experimental as of now so I expect a few future changes.
Unit tests
Lots added.
Documentation
Lots of Javadoc.
Bumping the serialization version id
✔️
cc @tsherlockcraig @westontrillium