- [HTTP request](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/projects.locations/optimizeToursLongRunning#body.HTTP_TEMPLATE)
- [Path parameters](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/projects.locations/optimizeToursLongRunning#body.PATH_PARAMETERS)
- [Request body](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/projects.locations/optimizeToursLongRunning#body.request_body)
  - [JSON representation](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/projects.locations/optimizeToursLongRunning#body.request_body.SCHEMA_REPRESENTATION)
- [Response body](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/projects.locations/optimizeToursLongRunning#body.response_body)
- [Authorization scopes](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/projects.locations/optimizeToursLongRunning#body.aspect)
- [IAM Permissions](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/projects.locations/optimizeToursLongRunning#body.aspect_1)

This is a variant of the `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/projects.locations/optimizeTours#google.maps.routeoptimization.v1.RouteOptimization.OptimizeTours` method designed for optimizations with large timeout values. It should be preferred over the `locations.optimizeTours` method for optimizations that take longer than a few minutes.

The returned `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/projects.locations.operations#Operation` (LRO) will have a name of the format `<parent>/operations/<operation_id>` and can be used to track progress of the computation. The `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/projects.locations.operations#Operation.FIELDS.metadata` field type is `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/OptimizeToursLongRunningMetadata`. The `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/projects.locations.operations#Operation.FIELDS.response` field type is `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/OptimizeToursResponse`, if successful.

### HTTP request

`POST https://routeoptimization.googleapis.com/v1/{parent=projects/*/locations/*}:optimizeToursLongRunning`

The URL uses [gRPC Transcoding](https://google.aip.dev/127) syntax.

### Path parameters

| Parameters ||
|---|---|
| `parent` | `string` Required. Target project or location to make a call. Format: - `projects/{project-id}` - `projects/{project-id}/locations/-` Regional `{location-id}` values are not supported. |

### Request body

The request body contains data with the following structure:

| JSON representation |
|---|
| ``` { "timeout": string, "model": { object (`https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel`) }, "solvingMode": enum (`https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/SolvingMode`), "searchMode": enum (`https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/SearchMode`), "injectedFirstSolutionRoutes": [ { object (`https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentRoute`) } ], "injectedSolutionConstraint": { object (`https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/InjectedSolutionConstraint`) }, "refreshDetailsRoutes": [ { object (`https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentRoute`) } ], "interpretInjectedSolutionsUsingLabels": boolean, "considerRoadTraffic": boolean, "populatePolylines": boolean, "populateTransitionPolylines": boolean, "allowLargeDeadlineDespiteInterruptionRisk": boolean, "useGeodesicDistances": boolean, "label": string, "geodesicMetersPerSecond": number, "maxValidationErrors": integer } ``` |

| Fields ||
|---|---|
| `timeout` | ``string (`https://protobuf.dev/reference/protobuf/google.protobuf#duration` format)`` If this timeout is set, the server returns a response before the timeout period has elapsed or the server deadline for synchronous requests is reached, whichever is sooner. For asynchronous requests, the server will generate a solution (if possible) before the timeout has elapsed. |
| `model` | ``object (`https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel`)`` Shipment model to solve. |
| `solvingMode` | ``enum (`https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/SolvingMode`)`` By default, the solving mode is `DEFAULT_SOLVE` (0). |
| `searchMode` | ``enum (`https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/SearchMode`)`` Search mode used to solve the request. |
| `injectedFirstSolutionRoutes[]` | ``object (`https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentRoute`)`` Guide the optimization algorithm in finding a first solution that is similar to a previous solution. The model is constrained when the first solution is built. Any shipments not performed on a route are implicitly skipped in the first solution, but they may be performed in successive solutions. The solution must satisfy some basic validity assumptions: - for all routes, `vehicleIndex` must be in range and not be duplicated. - for all visits, `shipmentIndex` and `visitRequestIndex` must be in range. - a shipment may only be referenced on one route. - the pickup of a pickup-delivery shipment must be performed before the delivery. - no more than one pickup alternative or delivery alternative of a shipment may be performed. - for all routes, times are increasing (i.e., `vehicleStartTime <= visits[0].start_time <= visits[1].start_time ... <= vehicleEndTime`). - a shipment may only be performed on a vehicle that is allowed. A vehicle is allowed if `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel#Shipment.FIELDS.allowed_vehicle_indices` is empty or its `vehicleIndex` is included in `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel#Shipment.FIELDS.allowed_vehicle_indices`. If the injected solution is not feasible, a validation error is not necessarily returned and an error indicating infeasibility may be returned instead. |
| `injectedSolutionConstraint` | ``object (`https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/InjectedSolutionConstraint`)`` Constrain the optimization algorithm to find a final solution that is similar to a previous solution. For example, this may be used to freeze portions of routes which have already been completed or which are to be completed but must not be modified. If the injected solution is not feasible, a validation error is not necessarily returned and an error indicating infeasibility may be returned instead. |
| `refreshDetailsRoutes[]` | ``object (`https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentRoute`)`` If non-empty, the given routes will be refreshed, without modifying their underlying sequence of visits or travel times: only other details will be updated. This does not solve the model. As of 2020/11, this only populates the polylines of non-empty routes and requires that `populatePolylines` is true. The `routePolyline` fields of the passed-in routes may be inconsistent with route `transitions`. This field must not be used together with `injectedFirstSolutionRoutes` or `injectedSolutionConstraint`. `Shipment.ignore` and `Vehicle.ignore` have no effect on the behavior. Polylines are still populated between all visits in all non-empty routes regardless of whether the related shipments or vehicles are ignored. |
| `interpretInjectedSolutionsUsingLabels` | `boolean` If true: - uses `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentRoute#FIELDS.vehicle_label` instead of `vehicleIndex` to match routes in an injected solution with vehicles in the request; reuses the mapping of original `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentRoute#FIELDS.vehicle_index` to new `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentRoute#FIELDS.vehicle_index` to update `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/InjectedSolutionConstraint#ConstraintRelaxation.FIELDS.vehicle_indices` if non-empty, but the mapping must be unambiguous (i.e., multiple `ShipmentRoute`s must not share the same original `vehicleIndex`). - uses `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentRoute#Visit.FIELDS.shipment_label` instead of `shipmentIndex` to match visits in an injected solution with shipments in the request; - uses `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/SkippedShipment#FIELDS.label` instead of `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/SkippedShipment#FIELDS.index` to match skipped shipments in the injected solution with request shipments. This interpretation applies to the `injectedFirstSolutionRoutes`, `injectedSolutionConstraint`, and `refreshDetailsRoutes` fields. It can be used when shipment or vehicle indices in the request have changed since the solution was created, perhaps because shipments or vehicles have been removed from or added to the request. If true, labels in the following categories must appear at most once in their category: - `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel#Vehicle.FIELDS.label` in the request; - `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel#Shipment.FIELDS.label` in the request; - `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentRoute#FIELDS.vehicle_label` in the injected solution; - `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/SkippedShipment#FIELDS.label` and `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentRoute#Visit.FIELDS.shipment_label` in the injected solution (except pickup/delivery visit pairs, whose `shipmentLabel` must appear twice). If a `vehicleLabel` in the injected solution does not correspond to a request vehicle, the corresponding route is removed from the solution along with its visits. If a `shipmentLabel` in the injected solution does not correspond to a request shipment, the corresponding visit is removed from the solution. If a `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/SkippedShipment#FIELDS.label` in the injected solution does not correspond to a request shipment, the `SkippedShipment` is removed from the solution. Removing route visits or entire routes from an injected solution may have an effect on the implied constraints, which may lead to change in solution, validation errors, or infeasibility. NOTE: The caller must ensure that each `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel#Vehicle.FIELDS.label` (resp. `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel#Shipment.FIELDS.label`) uniquely identifies a vehicle (resp. shipment) entity used across the two relevant requests: the past request that produced the `OptimizeToursResponse` used in the injected solution and the current request that includes the injected solution. The uniqueness checks described above are not enough to guarantee this requirement. |
| `considerRoadTraffic` | `boolean` Consider traffic estimation in calculating `ShipmentRoute` fields `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentRoute#Transition.FIELDS.travel_duration`, `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentRoute#Visit.FIELDS.start_time`, and `vehicleEndTime`; in setting the `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentRoute#FIELDS.has_traffic_infeasibilities` field, and in calculating the `OptimizeToursResponse.total_cost` field. |
| `populatePolylines` | `boolean` If true, polylines will be populated in response `ShipmentRoute`s. |
| `populateTransitionPolylines` | `boolean` If true, polylines and route tokens will be populated in response `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentRoute#FIELDS.transitions`. |
| `allowLargeDeadlineDespiteInterruptionRisk` | `boolean` If this is set, then the request can have a deadline (see <https://grpc.io/blog/deadlines>) of up to 60 minutes. Otherwise, the maximum deadline is only 30 minutes. Note that long-lived requests have a significantly larger (but still small) risk of interruption. |
| `useGeodesicDistances` | `boolean` If true, travel distances will be computed using geodesic distances instead of Google Maps distances, and travel times will be computed using geodesic distances with a speed defined by `geodesicMetersPerSecond`. |
| `label` | `string` Label that may be used to identify this request, reported back in the `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/OptimizeToursResponse#FIELDS.request_label`. |
| `geodesicMetersPerSecond` | `number` When `useGeodesicDistances` is true, this field must be set and defines the speed applied to compute travel times. Its value must be at least 1.0 meters/seconds. |
| `maxValidationErrors` | `integer` Truncates the number of validation errors returned. These errors are typically attached to an INVALID_ARGUMENT error payload as a BadRequest error detail (<https://cloud.google.com/apis/design/errors#error_details)>, unless solvingMode=VALIDATE_ONLY: see the `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/OptimizeToursResponse#FIELDS.validation_errors` field. This defaults to 100 and is capped at 10,000. |

### Response body

If successful, the response body contains an instance of `https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/projects.locations.operations#Operation`.

### Authorization scopes

Requires the following OAuth scope:

- `https://www.googleapis.com/auth/cloud-platform`

### IAM Permissions

Requires the following [IAM](https://cloud.google.com/iam/docs) permission on the `parent` resource:

- `routeoptimization.operations.create`

For more information, see the [IAM documentation](https://cloud.google.com/iam/docs).