This guide introduces the experimental launch of the OptimizeToursLongRunning
and OptimizeToursUri
API methods that allow users to make single
non-blocking optimization requests. In a non-blocking optimization, the user
quickly receives a Operation proto from the method that can be used
to reference the status of the optimization by calling GetOperation
.
See Long Running Operations
for more details.
These non-blocking methods provide the
reliability benefits over the blocking OptimizeTours
method since the
client does not need to maintain connection to the server while the optimization
is being executed. Also, these new methods make it easier to debug
failures compared to BatchOptimizeTours
since each optimization is
associated with a single Long-Running Operation (LRO).
Users who prefer to inline the optimization request can use the
OptimizeToursLongRunning
method while users who prefer to upload the
requests and the read response using Google Cloud Storage can use the
OptimizeToursUri
method.
OptimizeToursLongRunning
Example: Make an OptimizeToursLongRunning
request
Before making a request, replace the following parameters with values appropriate for your environment:
- Ensure you have Application Default Credentials configured as described in Use OAuth.
Set PROJECT_NUMBER_OR_ID to your Cloud project number or ID.
The following command sends an
OptimizeToursLongRunning
request to the Route Optimization API and receives an operation ID associated with it. TheGetOperation
method can be used to query the status of the operation. Once the operation completes, the metadata also contains the finalOptimizeToursResponse
.curl -X POST 'https://routeoptimization.googleapis.com/v1/projects/PROJECT_NUMBER_OR_ID:optimizeToursLongRunning' \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \ --data @- <<EOM { "model": { "shipments": [ { "pickups": [ { "arrivalLocation": { "latitude": 37.42506261000996, "longitude": -122.09535511930135 } } ], "deliveries": [ { "arrivalLocation": { "latitude": 37.42421503206021, "longitude": -122.09526063135228 } } ] } ], "vehicles": [ { "travelMode": "DRIVING", "costPerKilometer": 1.0 } ], } } EOM
OptimizeToursUri
Like BatchOptimizeTours
, you can use OptimizeToursUri
to continue
storing your optimization request and response on Google Cloud Storage.
Cloud Storage URIs must be specified in the OptimizeToursUri
request message.
The Operation
status returned is associated only with the single submitted
OptimizeToursRequest
.
Example: Make an OptimizeToursUri
request
Before making a request, replace the following parameters with values appropriate for your environment:
- Ensure you have Application Default Credentials configured as described in Use OAuth.
Set PROJECT_NUMBER_OR_ID to your Cloud project number or ID.
The following command sends an
OptimizeToursUri
request to the Route Optimization API and receives an operation ID associated with it. Use theGetOperation
method to query the status of the operation. Once the operation completes, theOptimizeToursResponse
is stored remotely on the output URI path provided in the request.curl -X POST 'https://routeoptimization.googleapis.com/v1/projects/PROJECT_NUMBER_OR_ID:optimizeToursUri' \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \ --data @- <<EOM { "input": { "uri": "gs://bucket/path/input/object.json" }, "output": { "uri": "gs://bucket/path/output/object.json" } } EOM