AI-generated Key Takeaways
-
The Route Optimization API offers two methods:
OptimizeToursfor synchronous processing of smaller, simpler requests andBatchOptimizeToursfor asynchronous handling of larger, more complex requests. -
OptimizeToursrequires an open connection until a response is received, whileBatchOptimizeToursutilizes Google Cloud Storage for requests and responses, enabling background processing. -
BatchOptimizeToursrelies on Long Running Operations (LROs) to track batch progress, which can be monitored via theGetOperationmethod. -
When using
BatchOptimizeTours, users should submit the request, poll for completion using the LRO, and retrieve results or address errors as indicated by the LRO status.
The Route Optimization API exposes two methods:
OptimizeToursis a synchronous method that returns an optimized route in response to anOptimizeToursRequest. Clients must maintain an open connection to the Route Optimization API until the request is processed and anOptimizeToursResponseor error is returned.BatchOptimizeToursis an asynchronous method that accepts URIs for one or moreOptimizeToursRequestand correspondingOptimizeToursResponsemessages, returning the resource name of a Long Running Operation (LRO) (REST, gRPC) that is used to check for batch completion.OptimizeToursRequests are processed in the background, so clients maintain an open connections to the Route Optimization API only long enough to submit theBatchOptimizeToursRequestor to callGetOperationto check LRO status.BatchOptimizeToursreads requests from and writes responses to Google Cloud Storage.
Use cases
OptimizeTours is convenient for solving small and simple requests, or for
requests with solving times of a few minutes or less. Maintaining long-lived
connections to the Route Optimization API increases risk of interruption before
a solution can be returned.
BatchOptimizeTours can handle larger requests and requests with longer solving
time because it does not require a long-lived connection to the Route
Optimization API.
Long running operations
LROs are read from the Route Optimization API using the GetOperation method to
check the completion status of a batch. LROs include a done property that
indicates whether processing of the entire batch is complete and an error
field that reports errors encountered during processing. If done is true and
no error is present, the batch completed successfully. The presence of an
error indicates that some or all of the batch failed processing.
The typical lifecycle of a BatchOptimizeTours request is as follows:
- Submit a
BatchOptimizeToursRequestto the Route Optimization API, which returns the resource name of an LRO. - Poll
GetOperationwith the returned LRO resource name until thedoneorerrorproperties appear in the LRO response. - If
doneis true and no error is present, readOptimizeToursResponsesfrom the Google Cloud Storage URIs specified in theBatchOptimizeToursrequest. Iferroris present, inspect the error, update theOptimizeToursRequests accordingly in Google Cloud Storage, and retry as appropriate depending on the observed error.
You can send OptimizeTours and BatchOptimizeTours requests in a variety of
ways, either from the command line or using a client library.