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

Implement GTFS Flex safe duration spec draft #5796

Merged

Conversation

leonardehrenfried
Copy link
Member

Summary

It implements the proposed fields flex_safe_duration_factor and flex_safe_duration_offset which are currently undergoing specification and discussion at MobilityData/gtfs-flex#79

These 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

@leonardehrenfried leonardehrenfried added New Feature Sandbox bump serialization id Add this label if you want the serialization id automatically bumped after merging the PR labels Apr 9, 2024
@leonardehrenfried leonardehrenfried requested a review from a team as a code owner April 9, 2024 12:59
Copy link

codecov bot commented Apr 9, 2024

Codecov Report

Attention: Patch coverage is 94.33962% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 67.94%. Comparing base (8823782) to head (695161a).
Report is 35 commits behind head on dev-2.x.

Files Patch % Lines
...a/org/opentripplanner/gtfs/mapping/TripMapper.java 88.88% 0 Missing and 1 partial ⚠️
.../main/java/org/opentripplanner/model/StopTime.java 0.00% 0 Missing and 1 partial ⚠️
...ner/routing/api/request/framework/TimePenalty.java 50.00% 0 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

@leonardehrenfried
Copy link
Member Author

@LeoFrachet @FinnLidbetter

@optionsome
Copy link
Member

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.

@leonardehrenfried
Copy link
Member Author

Yes, it can also lower the time, although this is not explicitly stated in the spec.

@leonardehrenfried
Copy link
Member Author

At least in this current implementation, I'm not preventing it from happening.

doc-templates/Flex.md Show resolved Hide resolved
if (UnscheduledTrip.isUnscheduledTrip(stopTimes)) {
var modifier = builder.getFlexDurationFactors().getOrDefault(trip, TimePenalty.ZERO);
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@leonardehrenfried leonardehrenfried force-pushed the flex-duration-factors branch from 7e15260 to a4dc25b Compare May 6, 2024 15:54
@t2gran t2gran added this to the 2.6 (next release) milestone May 7, 2024
@LeoFrachet
Copy link
Contributor

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.)

@leonardehrenfried
Copy link
Member Author

@LeoFrachet Not sure if you're aware but OTP doesn't have any real-time road traffic information.

@leonardehrenfried leonardehrenfried changed the title Implement GTFS Flex safe durations spec draft Implement GTFS Flex safe duration spec draft May 14, 2024
@t2gran
Copy link
Member

t2gran commented May 14, 2024

@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.

@tsherlockcraig
Copy link
Contributor

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;
Copy link
Member

@optionsome optionsome May 17, 2024

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?

Copy link
Member Author

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.

@leonardehrenfried leonardehrenfried merged commit ef0d16b into opentripplanner:dev-2.x May 17, 2024
5 checks passed
@leonardehrenfried leonardehrenfried deleted the flex-duration-factors branch May 17, 2024 10:47
t2gran pushed a commit that referenced this pull request May 17, 2024
t2gran pushed a commit that referenced this pull request May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump serialization id Add this label if you want the serialization id automatically bumped after merging the PR New Feature Sandbox
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants