-
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
Use millisecond precision in A* traversal #6436
base: dev-2.x
Are you sure you want to change the base?
Use millisecond precision in A* traversal #6436
Conversation
… backwards are always the same length, to the millisecond, and also when rounded to seconds
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev-2.x #6436 +/- ##
=============================================
+ Coverage 69.84% 70.31% +0.47%
- Complexity 18124 18165 +41
=============================================
Files 2069 2058 -11
Lines 77268 76952 -316
Branches 7855 7772 -83
=============================================
+ Hits 53965 54107 +142
+ Misses 20546 20091 -455
+ Partials 2757 2754 -3 ☔ View full report in Codecov by Sentry. |
application/src/ext/java/org/opentripplanner/ext/flex/edgetype/FlexTripEdge.java
Outdated
Show resolved
Hide resolved
...cation/src/main/java/org/opentripplanner/service/vehiclerental/street/VehicleRentalEdge.java
Show resolved
Hide resolved
@@ -1169,7 +1169,7 @@ private StateEditor doTraverse(State s0, TraverseMode traverseMode, boolean walk | |||
default -> otherTraversalCosts(preferences, traverseMode, walkingBike, speed); | |||
}; | |||
|
|||
int time = (int) Math.ceil(traversalCosts.time()); | |||
long time_ms = (long) Math.ceil(1000.0 * traversalCosts.time()); |
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.
Snake case is only allowed in static values.
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.
Let's discuss this in relation to StreetEdge.length_mm in the dev meeting. I can see at least three different ways of writing a unit in our code base.
@@ -111,19 +111,19 @@ public State[] traverse(State s0) { | |||
RoutingPreferences preferences = s0.getPreferences(); | |||
|
|||
/* TODO: Consider mode, so that passing through multiple fare gates is not possible */ | |||
int time = traversalTime; | |||
long time_ms = 1000L * traversalTime; |
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.
No snake case.
// the current time at this state, in seconds since UNIX epoch | ||
protected long time; | ||
// the current time at this state, in milliseconds since UNIX epoch | ||
protected long time_ms; |
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 here.
@@ -49,7 +49,7 @@ public State[] traverse(State s0) { | |||
var streetPreferences = s0.getPreferences().street(); | |||
|
|||
s1.incrementWeight(streetPreferences.elevator().boardCost()); | |||
s1.incrementTimeInSeconds(streetPreferences.elevator().boardTime()); | |||
s1.incrementTimeInMilliseconds(1000L * streetPreferences.elevator().boardTime()); |
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.
Use the seconds method here.
int seconds = this.travelTime > 0 | ||
? this.travelTime | ||
: (int) (preferences.street().elevator().hopTime() * this.levels); | ||
s1.incrementTimeInMilliseconds(1000L * seconds); |
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.
Use the seconds method here.
I think this PR will be a bit easier to review if you use the |
Summary
The existing State handling code in searches updates the time (integer, seconds) by calculating the time used by each step, rounding it up to the nearest integer, and then updating the total. In well-mapped indoor areas, the steps are small, and there are many of them. In our example problem spot, there are 42 edges in 284 metres. This ends up making the total 35 seconds too long. Our transfers try to be well designed, and we have a 7 minute window for that transfer. It takes 287 seconds to walk that distance, and a 90 second transferSlack. We cannot afford inaccuracies of the order of half a minute.
This PR changes the unit of calculation to milliseconds in the actual traversal, and still uses whole numbers. The granularity of time elsewhere in OTP still mostly stays as one second, to avoid a massive change.
The symmetry of backward and forward changes is preserved. When the same trip is searched backward and forward, the duration is exactly the same both in milliseconds and when rounded to seconds. When a forward search is made, the rounded end time is taken as a start time of a reverse search, the rounded end time of the reverse search is the same as the start time of the forward search, given that that had a millisecond part of zero.
Unit tests
In a large number of tests trip durations have become slightly shorter. This accounts for the large amount of changes to tests.
Changelog
This will be a significant change, because the durations have been incorrect for a long time, and people will notice.
Bumping the serialization version id
Unnecessary.