U-turn avoidance

  • Vehicles typically arrive and depart from locations in any direction, potentially requiring u-turns.

  • The avoid_u_turns setting prevents vehicles from changing direction at a pickup or delivery location, ensuring arrival and departure with the same heading.

  • The side_of_road setting ensures vehicles arrive and leave on the side of the road closest to the waypoint, also avoiding changes in heading.

  • avoid_u_turns and side_of_road can be used together to prevent u-turns while also maintaining the vehicle's position on the correct side of the road.

  • U-turn avoidance is not supported in all travel modes, such as WALKING mode, and is also not supported when the arrival and departure locations for a delivery or pickup differ.

U-turn avoidance is present in `ShipmentModel.Shipment` in the pickups and deliveries objects.

U-turn avoidance is a route optimization feature that prevents vehicles from turning around at the specific pickup or delivery location of a visit. By setting u-turn avoidance, you specify that the vehicle should face the same direction when it arrives and when it leaves a visit location.

U-turn avoidance works in the following way:

  1. You set the u-turn avoidance property on a specific visit.
  2. The API considers both directions of travel on two-way roads and chooses the most optimal path.
  3. The API generates a route where the vehicle arrives and leaves without making a u-turn at the visit location. The driver may need to cross the road to reach this location.

This property is ideal for situations where making a u-turn is difficult or impossible due to vehicle size, traffic signs, or usual traffic conditions.

Properties

The u-turn avoidance property is defined within the VisitRequest object. This object is used inside the pickups and deliveries arrays of a shipment.

Property Type Description
boolean When set to true , the API prevents the vehicle from making a u-turn at this visit location. The vehicle will arrive and leave facing the same direction.

Examples

This section covers two types of examples:

  • Code samples that illustrate the structure of u-turn avoidance.
  • A request example that includes the feature.

Code samples

The following example shows the structure of avoidUTurns within a pickup and a delivery:

 "pickups" 
 :[ 
  
 { 
  
 "arrivalLocation" 
 : 
  
 { 
  
 "latitude" 
 : 
  
 37.42506261000996 
 , 
  
 "longitude" 
 : 
  
 -122.09535511930135 
  
 }, 
  
 "avoidUTurns" 
 : 
  
  true 
 
  
 } 
 ], 
 "deliveries" 
 :[ 
  
 { 
  
 "arrivalLocation" 
 : 
  
 { 
  
 "latitude" 
 : 
  
 37.42421503206021 
 , 
  
 "longitude" 
 : 
  
 -122.09526063135228 
  
 }, 
  
 "avoidUTurns" 
 : 
  
  true 
 
  
 } 
 ] 

Request example

The following example shows a basic optimizeTours request that incorporates u-turn avoidance. This request includes the following elements:

  • A shipment with a pickup and a delivery inside the model object.
  • The avoidUTurns property set to true on both the pickup and delivery locations to prevent the vehicle from changing direction at those stops.
  
 { 
  
 "model" 
 : 
  
 { 
  
 "shipments" 
 :[ 
  
 { 
  
 "pickups" 
 :[ 
  
 { 
  
 "arrivalLocation" 
 : 
  
 { 
  
 "latitude" 
 : 
  
 37.42506261000996 
 , 
  
 "longitude" 
 : 
  
 -122.09535511930135 
  
 }, 
  
  "avoidUTurns" 
 : 
  
 true 
 
  
 } 
  
 ], 
  
 "deliveries" 
 :[ 
  
 { 
  
 "arrivalLocation" 
 : 
  
 { 
  
 "latitude" 
 : 
  
 37.42421503206021 
 , 
  
 "longitude" 
 : 
  
 -122.09526063135228 
  
 }, 
  
  "avoidUTurns" 
 : 
  
 true 
 
  
 } 
  
 ] 
  
 } 
  
 ], 
  
 "vehicles" 
 :[ 
  
 { 
  
 "travelMode" 
 : 
  
 "DRIVING" 
 , 
  
 "costPerKilometer" 
 : 
  
 1.0 
  
 } 
  
 ] 
  
 } 
  
 } 

Avoid u-turns with sideOfRoad

While sideOfRoad is a separate feature, it is closely related to u-turn avoidance because it prevents many u-turns by routing the vehicle to the side of the road closest to the destination. This forces the vehicle to approach a visit location from a specific direction, which eliminates the need to do a u-turn.

In practice, you should use u-turn avoidance when it is safe to cross the road on foot to get to the visit location. If crossing the road is discouraged or not possible, consider setting sideOfRoad to true instead.

The sideOfRoad property is defined within a Waypoint object.

Interaction with other features

U-turn avoidance interacts with other routing features in the following ways:

  • Side of road:Setting both avoidUTurns and sideOfRoad to true slightly increases the chances of avoiding a u-turn while routing the vehicle to the side of the road closest to the visit location. However, doing so introduces extra complexities related to the restrictions of u-turn avoidance. For most visit locations, setting only one of these properties is enough to avoid u-turns.
  • Injected solutions:When you use u-turn avoidance, the API response includes an injectedSolutionLocationToken inside the generated ShipmentRoute.Visit to record which side of the road it selected. If you ever reuse this visit as an injected solution in a future request, you must pass this token back to the API.

Limitations

U-turn avoidance is a best-effort feature. The API might still include u-turns in a generated route under the following conditions:

  • The travel mode is set to a mode other than DRIVING .
  • The arrival and departure locations for a specific visit location are different. In this case, the API returns an error.
  • The visit is located on a dead-end road, requiring a u-turn to exit.
  • The u-turn occurs along the route, rather than at the actual visit location.
  • The maneuver is a very sharp turn onto a different road, which the API does not classify as a u-turn.
Design a Mobile Site
View Site in Mobile | Classic
Share by: