Skip to content

Conversation

@hakoncarlsen
Copy link

@hakoncarlsen hakoncarlsen commented Jan 15, 2026

Summary

A carpool trip has a maximum deviation time budget, which for now is set to a constant 15 minutes as a temporary value. This is how much longer the driver accepts that the trip will take with extra passengers, compared to how long it would take if the driver did the trip alone.

To check whether the deviation budget was exceeded, the following calculation was used:

additional duration = total duration - baseline duration.

The problem is that the baseline duration is calculated using all stops in the trip, including stops for any previously inserted passengers. This means that the deviation budget could be exceeded for carpooling trips with multiple passengers. This PR fixes this issue.

Unit tests

A test findOptimalInsertion_onDeviationBudgetExceeded_returnsNull is added, in which the deviation budget of a carpooling trip with another passenger is exceeded only after this fix.

A few other tests of InsertionEvaluatorTest are also refractored into using a deterministic routing function, since the previous design using a function which depended on the order in which it was called caused problems. Some of the tests also had to have their durations changed for the tests to pass.

@hakoncarlsen hakoncarlsen requested a review from a team as a code owner January 15, 2026 09:05
@hakoncarlsen hakoncarlsen marked this pull request as draft January 15, 2026 09:05
/**
* Calculates the additional duration caused by inserting this passenger.
* Calculates the difference between the total duration when inserting this passenger,
* and the duration when driving straight from the start to the start of the trip.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/from the start to the start of the trip./from the start to the end

Copy link
Author

@hakoncarlsen hakoncarlsen Jan 15, 2026

Choose a reason for hiding this comment

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

fixed

int dropoffPosition,
List<GraphPath<State, Edge, Vertex>> routeSegments,
Duration baselineDuration,
Duration durationBetweenStartAndStop,
Copy link
Contributor

Choose a reason for hiding this comment

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

Stop is ambiguous here since the intermediate locations the trip will visit are also termed stops. Maybe durationBetweenStartAndEnd or durationBetweenOriginAndDestination?

Copy link
Author

@hakoncarlsen hakoncarlsen Jan 15, 2026

Choose a reason for hiding this comment

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

I changed to durationBetweenOriginAndDestination

*
* @return route from coordinate from to coordinate to, or null if routing function fails
*/
private GraphPath<State, Edge, Vertex> routeFromStartToStop(
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, Stop is ambiguous in this context. Maybe the singular routeSegment to differentiate from the other one that computes multiple segments?

Copy link
Author

@hakoncarlsen hakoncarlsen Jan 15, 2026

Choose a reason for hiding this comment

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

I changed to routeSegment

return null;
}

Duration durationBetweenStartAndStop = calculateDuration(pathBetweenStartAndStop);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here about stop being ambiguous.

Copy link
Author

Choose a reason for hiding this comment

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

fixed

@leonardehrenfried leonardehrenfried added +Sandbox This will be implemented as a Sandbox feature +Skip Changelog This is not a relevant change for a product owner since last release. labels Jan 15, 2026
@codecov
Copy link

codecov bot commented Jan 15, 2026

Codecov Report

❌ Patch coverage is 85.71429% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.08%. Comparing base (5d7363c) to head (b5061df).

Files with missing lines Patch % Lines
...ner/ext/carpooling/routing/InsertionEvaluator.java 81.25% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #7206      +/-   ##
=============================================
+ Coverage      72.07%   72.08%   +0.01%     
- Complexity     20907    20914       +7     
=============================================
  Files           2282     2282              
  Lines          84459    84469      +10     
  Branches        8433     8434       +1     
=============================================
+ Hits           60873    60890      +17     
+ Misses         20617    20613       -4     
+ Partials        2969     2966       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…eturn the same value given the same paramters
@hakoncarlsen hakoncarlsen force-pushed the baselineDuration_of_carpool_trip_fix branch from 4dea270 to a08e236 Compare January 15, 2026 11:02
@hakoncarlsen hakoncarlsen force-pushed the baselineDuration_of_carpool_trip_fix branch from a08e236 to b5061df Compare January 15, 2026 11:09
@hakoncarlsen hakoncarlsen marked this pull request as ready for review January 15, 2026 11:10
@t2gran t2gran added the !Bug Apply to issues describing a bug and PRs witch fixes it. label Jan 15, 2026
@leonardehrenfried leonardehrenfried added this to the 2.9 (next release) milestone Jan 15, 2026
}

/**
* Routes from start to stop
Copy link
Contributor

Choose a reason for hiding this comment

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

Start to stop here too. Please avoid this.


Duration[] cumulativeDurations = calculateCumulativeDurations(baselineSegments);

GraphPath<State, Edge, Vertex> pathBetweenStartAndStop = routeSegment(
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, avoid start and stop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

!Bug Apply to issues describing a bug and PRs witch fixes it. +Sandbox This will be implemented as a Sandbox feature +Skip Changelog This is not a relevant change for a product owner since last release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants