The Route Optimization API exposes two methods:
OptimizeTours
is 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 anOptimizeToursResponse
or error is returned.BatchOptimizeTours
is an asynchronous method that accepts URIs for one or moreOptimizeToursRequest
and correspondingOptimizeToursResponse
messages, returning the resource name of a Long Running Operation (LRO) (REST, gRPC) that is used to check for batch completion.OptimizeToursRequest
s are processed in the background, so clients maintain an open connections to the Route Optimization API only long enough to submit theBatchOptimizeToursRequest
or to callGetOperation
to check LRO status.BatchOptimizeTours
reads 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
BatchOptimizeToursRequest
to the Route Optimization API, which returns the resource name of an LRO. - Poll
GetOperation
with the returned LRO resource name until thedone
orerror
properties appear in the LRO response. - If
done
is true and no error is present, readOptimizeToursResponses
from the Google Cloud Storage URIs specified in theBatchOptimizeTours
request. Iferror
is present, inspect the error, update theOptimizeToursRequest
s 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.