Continuous replanning

VERSION 0.3.1106
PUBLIC PREVIEW

Navigation SDK for Android is only available upon request. Contact us to get started.

Route update mode

This mode specifies whether or not the system should try to periodically update the active route and look for better route proposals. There are two possible values:

  • ENABLED - The system periodically updates the active route and looks for better route proposals, based on replanRouteInterval. The way that better route proposals are handled is defined by ContinuousReplanningMode.
  • DISABLED - The system does not update the active route nor search for better route proposals.

By default, RouteUpdateMode is set to ENABLED. It is configured in the following way:

1val options = RouteReplanningEngineOptions(
2 routeUpdateMode = RouteUpdateMode.Enabled
3)
4val engine = RouteReplanningEngineFactory.create(routeReplanner, options)
5val navigationConfiguration = NavigationConfiguration(
6 context = context,
7 apiKey = apiKey,
8 locationProvider = locationProvider,
9 routeReplanner = routeReplanner,
10 routeReplanningEngine = engine
11)

Route refresh

Every trip takes time and the road situation is constantly changing. As a result, route data may become outdated during a trip. Route refresh provides users the most up-to-date route information such as:

  • Travel time and ETA (Estimated Time of Arrival)
  • Traffic information (delay and amount of traffic)
  • Updated legs and sections

Route refresh works only if RouteUpdateMode is set to ENABLED.

Route refresh might fail if the initial route planning was done with densely placed supporting points in comparison to route geometry. The replanning is made based on the geometry of the current route, where the density of coordinates may be lower.

Replanning response

The updated route will always be automatically applied and the reason will be set to RouteUpdateReason.Refresh.

Continuous Replanning - finding better alternatives

The Navigation module will then, based on this interval, periodically attempt to find a better alternative to the current route. This is what continuous replanning refers to. ContinuousReplanningMode defines how a better route proposal is handled.

The RouteReplanningEngine provides a default BetterRouteSelector implementation for selecting the best route. This can be configured by setting the following fields in RouteReplanningEngineOptions:

  • minTrafficDelay - Minimum traffic delay on the current route to trigger a search for a better alternative.
  • minTimeDifference - How much the alternative route has to be faster to be used as a replan proposal.

By default, minTrafficDelay is set to ten (10) minutes and minTimeDifference to five (5) minutes.

1val options = RouteReplanningEngineOptions(
2 minTrafficDelay = minTrafficDelay,
3 minTimeDifference = minTimeDifference
4)
5val engine = RouteReplanningEngineFactory.create(routeReplanner, options)
6val navigationConfiguration = NavigationConfiguration(
7 context = context,
8 apiKey = apiKey,
9 locationProvider = locationProvider,
10 routeReplanner = routeReplanner,
11 routeReplanningEngine = engine
12)

Providing a custom better router selector

If the default implementation of BetterRouteSelector does not do what you need it to do, you can provide your own when creating RouteReplanningEngine. Note that it’s up to the provider of the custom better route selector to make sure that a reachable proposal is chosen whenever the current route has a blockage.

1val engine =
2 RouteReplanningEngineFactory.create(routeReplanner, options, customBetterRouteSelector)
3val navigationConfiguration = NavigationConfiguration(
4 context = context,
5 apiKey = apiKey,
6 locationProvider = locationProvider,
7 routeReplanner = routeReplanner,
8 routeReplanningEngine = engine
9)

Replanning response

A better route proposal can be applied automatically or manually and the RouteUpdateReason will be set to:

  • BETTER_FOUND - A better alternative has been found for the current route.
  • UNREACHABLE - A better alternative has been found due to blockages on the current route.

Continuous replanning mode

There are three ways to handle a better route proposal:

Manual mode is set by default and can be changed by passing ContinuousReplanningMode to the NavigationConfiguration during the TomTomNavigation initialization.

1val navigationConfiguration = NavigationConfiguration(
2 context = context,
3 apiKey = apiKey,
4 locationProvider = locationProvider,
5 routeReplanner = routeReplanner,
6 continuousReplanningMode = ContinuousReplanningMode.Automatic
7)

The current ContinuousReplanningMode can also be checked and changed during runtime, even if the navigation is already started.

navigation.continuousReplanningMode
navigation.continuousReplanningMode = ContinuousReplanningMode.Automatic

Automatic handling

Replan proposals are applied automatically. The user will be notified on OnRouteUpdatedListener, which will return both a Route and RouteUpdateReason as the reason for the change:

  • BETTER_FOUND - A better alternative has been found for the current route.
  • UNREACHABLE - A better alternative has been found due to blockages on the current route.
1navigation.addOnRouteUpdatedListener(object : OnRouteUpdatedListener {
2 override fun onRouteUpdated(route: Route, updateReason: RouteUpdateReason) {
3 if (updateReason == RouteUpdateReason.BetterFound) {
4 /* Your code goes here */
5 }
6 }
7})

Unreachable_only handling

Replan proposals are applied automatically only if there is a blockage on the current route. In that case, the user is notified on OnRouteUpdatedListener. Otherwise, better route proposals are offered using OnReplannedRouteProposedListener.

Manual handling

Obtained routes are proposed using OnReplannedRouteProposedListener. You decide whether the proposed route should be applied with update() or ignored.

1navigation.addOnReplannedRouteProposedListener(object : OnReplannedRouteProposedListener {
2 override fun onReplannedRouteProposed(replannedRoute: ReplannedRoute) {
3 /* Your code goes here */
4 navigation.update(RoutePlan(replannedRoute.route, routePlanningOptions))
5 }
6})

Specifying replanning intervals

By default, the intervals between route updates are set to three (3) minutes. The minimum remaining travel time is set to ten (10) minutes. After this point, route refresh and continuous replanning are automatically disabled.

These parameters can be set in RouteReplanningEngineOptions.

1val options = RouteReplanningEngineOptions(
2 replanRouteInterval = replanRouteInterval,
3 validRemainingRouteDuration = validRemainingRouteDuration
4)
5val engine = RouteReplanningEngineFactory.create(routeReplanner, options)
6val navigationConfiguration = NavigationConfiguration(
7 context = context,
8 apiKey = apiKey,
9 locationProvider = locationProvider,
10 routeReplanner = routeReplanner,
11 routeReplanningEngine = engine
12)

Replanning on deviation

If a user has deviated from the current route, the navigation informs them of it. The navigation module may do one of the following things:

  • Automatically plan a new route.
  • Wait for the user to manually provide a new route.

Automatic handling

The default is to automatically plan a new route. To turn off automatic route planning, configure TomTomNavigation:

1val navigationConfiguration = NavigationConfiguration(
2 context = context,
3 apiKey = apiKey,
4 locationProvider = locationProvider,
5 routeReplanner = routeReplanner,
6 deviationReplanningMode = DeviationReplanningMode.None
7)

This means the user doesn’t need to take any action, because the new route is automatically applied. The user is then be notified on OnRouteUpdatedListener, which returns RouteUpdateReason.Deviation as the reason for the change as well as the Route itself.

Manual handling

This is the default route deviation handling strategy. Manual handling means that once a user is informed about a deviation from the route, navigation is stopped. Navigation only starts again once a new route has been planned and started.

A manual route update is made by calling TomTomNavigation.update(RoutePlan). The RoutePlan parameter is built with a Route for the user to follow and the RoutePlanningOptions used for planning that route.

val routePlan = RoutePlan(route = route, routePlanningOptions = routePlanningOptions)
tomTomNavigation.update(routePlan)

Replan retry policy

If the replanning is successful, the Navigation module uses the returned route to replace the current one. Otherwise the Navigation module tries to replan the route again. The number of replan attempts and the delay between retries are defined by the ReplanningRetryPolicy interface.

Policy configuration

The default implementation of ReplanningRetryPolicy (see TomTomReplanningRetryPolicy) periodically retries the operation with increasing delays between calls. The default maximum delay time is ten (10) seconds.

The default parameters can also be overridden as follows:

1val replanningRetryPolicy = TomTomReplanningRetryPolicy(
2 maxRetryDelay = maxRetryDelay
3)

Once the policy is configured, it must be provided during initialization of the Navigation module:

1val navigationConfiguration = NavigationConfiguration(
2 context = context,
3 apiKey = apiKey,
4 locationProvider = locationProvider,
5 routeReplanner = routeReplanner,
6 replanningRetryPolicy = replanningRetryPolicy
7)

Providing a custom replan retry policy

You can also provide your own implementation instead of using the default policy. To do this, implement the ReplanningRetryPolicy interface and pass it during the Navigation module initialization.

Next steps

Since you have learned about route replanning, here are recommendations for the next steps: