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

Compare routes using step names #3301

Merged
merged 1 commit into from Jul 15, 2020
Merged

Conversation

kmadsen
Copy link
Contributor

@kmadsen kmadsen commented Jul 8, 2020

Description

Resolves #3144

Midway through a route we request a new route, and we're looking to see if it's faster. This is working as design. The problem is the route we're checking, can be the current route.

This is the 3rd approach considered for this.

Going to test this in a few regions

  • I have added any issue links
  • I have added all related labels (bug, feature, new API(s), SEMVER, etc.)
  • I have added the appropriate milestone and project boards

Screenshots

output

Testing

Please describe the manual tests that you ran to verify your changes

  • I have tested locally (including SNAPSHOT upstream dependencies if needed) through testapp/demo app and run all activities to avoid regressions
  • I have tested via a test drive, or a simulation/mock location app
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have updated the CHANGELOG including this PR
  • We might need to update / push api/current.txt files after running $> make 1.0-core-update-api (Core) / $> make 1.0-ui-update-api (UI) if there are changes / errors we're 🆗 with (e.g. AddedMethod changes are marked as errors but don't break SemVer) 🚀 If there are SemVer breaking changes add the SEMVER label. See Metalava docs

@kmadsen kmadsen mentioned this pull request Jul 8, 2020
11 tasks
@Guardiola31337
Copy link
Contributor

How is @mapbox/navigation-ios approach to tackle this issue? Do you know @1ec5?

@kmadsen kmadsen force-pushed the km-compare-routes-with-step-names branch 8 times, most recently from 3f4cee6 to a65947d Compare July 8, 2020 18:43
@kmadsen kmadsen marked this pull request as ready for review July 8, 2020 18:46
}
every { directionsSession.routes } returns listOf(currentRoute)
every { tripSession.getEnhancedLocation() } returns mockk {
every { latitude } returns -33.874308
every { longitude } returns 151.206087
}
every { tripSession.getRouteProgress() } returns mockk {
every { durationRemaining } returns 601.334
Copy link
Contributor Author

@kmadsen kmadsen Jul 8, 2020

Choose a reason for hiding this comment

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

These test values are covered in FasterRouteDetectorTest

@codecov-commenter
Copy link

codecov-commenter commented Jul 8, 2020

Codecov Report

Merging #3301 into master will increase coverage by 0.00%.
The diff coverage is 39.28%.

@@            Coverage Diff            @@
##             master    #3301   +/-   ##
=========================================
  Coverage     39.30%   39.31%           
- Complexity     2312     2314    +2     
=========================================
  Files           547      548    +1     
  Lines         20019    20043   +24     
  Branches       1901     1913   +12     
=========================================
+ Hits           7869     7880   +11     
- Misses        11228    11229    +1     
- Partials        922      934   +12     

@kmadsen
Copy link
Contributor Author

kmadsen commented Jul 8, 2020

Follow up issue from this, there is a race condition.

In the event of a faster route, the current step index can change while requesting. This will cause the requested route to include an extra step.

For example,
t0 = current route includes steps "A", "B", "C", "D"
t1 = request faster route
t2 = current route becomes "B", "C", "D"
t3 = faster route response is "A", "B", "C", "D"

The route will be considered different

@kmadsen kmadsen force-pushed the km-compare-routes-with-step-names branch from a65947d to b53d874 Compare July 8, 2020 19:44
@Guardiola31337
Copy link
Contributor

Guardiola31337 commented Jul 9, 2020

@kmadsen

Resolves #3116

As mentioned in #3262 (review)

Which BTW was used for the Off-route scenario as re-routes are handled by us by default i.e. we try to respect the original route if possible so we might need it either way.

we used Damerau Levenshtein algorithm in the legacy for off-routes and this PR is addressing Faster route only. Should we add same Compare routes using step names logic suggested for Off-route to try to stick to the original route when getting re-routed? Maybe we can follow up in a separate PR, but was wondering if we've considered it.

@1ec5
Copy link
Contributor

1ec5 commented Jul 9, 2020

This approach seems OK to me: #3116 (comment).

How is @mapbox/navigation-ios approach to tackle this issue?
Should we add same Compare routes using step names logic suggested for Off-route to try to stick to the original route when getting re-routed? Maybe we can follow up in a separate PR, but was wondering if we've considered it.

The iOS navigation SDK ranks the routes by edit distance over the summary string, the same approach @kmadsen investigated in #3116. The comparison happens in a bottlenecked part of the code that handles rerouting due to both going off-route and finding a faster route.

I think either approach is sufficient for this use case, because a sufficiently different route will rank lower by either measure (leg summary or step names). It’s possible that the step name comparison will be slightly more reliable in cases where the alternative routes differ in a way that isn’t significant enough to result in a difference to the summary, but I’d assume that getting such cases right would be a marginal improvement. (The summary consists of the two most common street names by length along the leg.) If you have a concrete example of where it yields a practical improvement, I’d love to consider it.

Note that the iOS navigation SDK only uses the edit distance algorithm to choose from among multiple alternative routes. It doesn’t use the algorithm to decide whether to replace the preexisting route. That determination is based on a much simpler heuristic: whether the new route is at least 10% faster and the user isn’t near the destination.

@kmadsen kmadsen force-pushed the km-compare-routes-with-step-names branch from b53d874 to 6667ce6 Compare July 9, 2020 19:45
@kmadsen
Copy link
Contributor Author

kmadsen commented Jul 9, 2020

That determination is based on a much simpler heuristic: whether the new route is at least 10% faster and the user isn’t near the destination.

@1ec5 this is what is being addressed in this pull request. it turns out, the "new route that is 10% faster" is not new. It's more often than not, the same route

Note that I agree with everything else though, maybe comparing steps is better than route summaries when the origin and destination are the same. The issue with faster route, is that it has been partially completed and the route summary is no longer a working description for faster route. Also agreeing with performance considerations, there may 10-1000 route steps to compare. This is worth testing

@kmadsen kmadsen force-pushed the km-compare-routes-with-step-names branch from 6667ce6 to 2844b2c Compare July 13, 2020 16:08
@kmadsen
Copy link
Contributor Author

kmadsen commented Jul 13, 2020

In the question for performance. Tested creating a route from SF to NYC and this was the result:

faster_route_debug time to compare 46 steps 0.053s 

considering this operation is run once every 5 minutes, there's little concern here. but it should be executed on a background thread.

@kmadsen kmadsen force-pushed the km-compare-routes-with-step-names branch from 2844b2c to 1263ce6 Compare July 13, 2020 17:40
@@ -37,7 +56,7 @@ class FasterRouteDetectorTest {
}

@Test
fun shouldDefaultToFalseWhenDurationIsNull() {
fun shouldDefaultToFalseWhenDurationIsNull() = runBlocking {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The answer is in, runBlocking is better than runBlockingTest

Kotlin/kotlinx.coroutines#1222 (comment)

Copy link
Contributor

@Guardiola31337 Guardiola31337 left a comment

Choose a reason for hiding this comment

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

A couple of minor comments.

@kmadsen kmadsen force-pushed the km-compare-routes-with-step-names branch from 1263ce6 to cb565a6 Compare July 15, 2020 14:39
Copy link
Contributor

@Guardiola31337 Guardiola31337 left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the feedback @kmadsen 🚢

@kmadsen kmadsen merged commit f89d299 into master Jul 15, 2020
@kmadsen kmadsen deleted the km-compare-routes-with-step-names branch August 21, 2020 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Faster route does not guarantee new route is different
4 participants