Cloud Optimization API v1 - Package cloud.google.com/go/optimization/apiv1 (v1.7.7) Stay organized with collections Save and categorize content based on your preferences.
Package optimization is an auto-generated package for theCloud Optimization API.
Cloud Optimization API provides a portfolio of solvers to address commonoptimization use cases starting with optimal route planning for vehiclefleets.
General documentation
For information that is relevant for all client libraries please referencehttps://pkg.go.dev/cloud.google.com/go#pkg-overview. Some information on thispage includes:
- Authentication and Authorization
- Timeouts and Cancellation
- Testing against Client Libraries
- Debugging Client Libraries
- Inspecting errors
Example usage
To get started with this package, create a client.
// go get cloud.google.com/go/optimization/apiv1@latestctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=optimization.NewFleetRoutingClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()
The client will use your default application credentials. Clients should be reused instead of created as needed.The methods of Client are safe for concurrent use by multiple goroutines.The returned client must be Closed when it is done being used.
Using the Client
The following is an example of making an API call with the newly created client, mentioned above.
req:=&optimizationpb.BatchOptimizeToursRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/optimization/apiv1/optimizationpb#BatchOptimizeToursRequest.}op,err:=c.BatchOptimizeTours(ctx,req)iferr!=nil{// TODO: Handle error.}resp,err:=op.Wait(ctx)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp
Use of Context
The ctx passed to NewFleetRoutingClient is used for authentication requests andfor creating the underlying connection, but is not used for subsequent calls.Individual methods on the client use the ctx given to them.
To close the open connection, use the Close() method.
Functions
func DefaultAuthScopes
funcDefaultAuthScopes()[]stringDefaultAuthScopes reports the default set of authentication scopes to use with this package.
BatchOptimizeToursOperation
typeBatchOptimizeToursOperationstruct{// contains filtered or unexported fields}BatchOptimizeToursOperation manages a long-running operation from BatchOptimizeTours.
func (*BatchOptimizeToursOperation) Done
func(op*BatchOptimizeToursOperation)Done()boolDone reports whether the long-running operation has completed.
func (*BatchOptimizeToursOperation) Metadata
func(op*BatchOptimizeToursOperation)Metadata()(*optimizationpb.AsyncModelMetadata,error)Metadata returns metadata associated with the long-running operation.Metadata itself does not contact the server, but Poll does.To get the latest metadata, call this method after a successful call to Poll.If the metadata is not available, the returned metadata and error are both nil.
func (*BatchOptimizeToursOperation) Name
func(op*BatchOptimizeToursOperation)Name()stringName returns the name of the long-running operation.The name is assigned by the server and is unique within the service from which the operation is created.
func (*BatchOptimizeToursOperation) Poll
func(op*BatchOptimizeToursOperation)Poll(ctxcontext.Context,opts...gax.CallOption)(*optimizationpb.BatchOptimizeToursResponse,error)Poll fetches the latest state of the long-running operation.
Poll also fetches the latest metadata, which can be retrieved by Metadata.
If Poll fails, the error is returned and op is unmodified. If Poll succeeds andthe operation has completed with failure, the error is returned and op.Done will return true.If Poll succeeds and the operation has completed successfully,op.Done will return true, and the response of the operation is returned.If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (*BatchOptimizeToursOperation) Wait
func(op*BatchOptimizeToursOperation)Wait(ctxcontext.Context,opts...gax.CallOption)(*optimizationpb.BatchOptimizeToursResponse,error)Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
See documentation of Poll for error-handling information.
FleetRoutingCallOptions
typeFleetRoutingCallOptionsstruct{OptimizeTours[]gax.CallOptionBatchOptimizeTours[]gax.CallOptionGetOperation[]gax.CallOption}FleetRoutingCallOptions contains the retry settings for each method of FleetRoutingClient.
FleetRoutingClient
typeFleetRoutingClientstruct{// The call options for this service.CallOptions*FleetRoutingCallOptions// LROClient is used internally to handle long-running operations.// It is exposed so that its CallOptions can be modified if required.// Users should not Close this client.LROClient*lroauto.OperationsClient// contains filtered or unexported fields}FleetRoutingClient is a client for interacting with Cloud Optimization API.Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
A service for optimizing vehicle tours.
Validity of certain types of fields:
google.protobuf.Timestamp Times are in Unix time: seconds since 1970-01-01T00:00:00+00:00. seconds must be in [0, 253402300799], i.e. in [1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00]. nanos must be unset or set to 0.google.protobuf.Duration seconds must be in [0, 253402300799], i.e. in [1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00]. nanos must be unset or set to 0.google.type.LatLng latitude must be in [-90.0, 90.0]. longitude must be in [-180.0, 180.0]. at least one of latitude and longitude must be non-zero.func NewFleetRoutingClient
funcNewFleetRoutingClient(ctxcontext.Context,opts...option.ClientOption)(*FleetRoutingClient,error)NewFleetRoutingClient creates a new fleet routing client based on gRPC.The returned client must be Closed when it is done being used to clean up its underlying connections.
A service for optimizing vehicle tours.
Validity of certain types of fields:
google.protobuf.Timestamp Times are in Unix time: seconds since 1970-01-01T00:00:00+00:00. seconds must be in [0, 253402300799], i.e. in [1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00]. nanos must be unset or set to 0.google.protobuf.Duration seconds must be in [0, 253402300799], i.e. in [1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00]. nanos must be unset or set to 0.google.type.LatLng latitude must be in [-90.0, 90.0]. longitude must be in [-180.0, 180.0]. at least one of latitude and longitude must be non-zero.Example
packagemainimport("context"optimization"cloud.google.com/go/optimization/apiv1")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=optimization.NewFleetRoutingClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()// TODO: Use client._=c}func NewFleetRoutingRESTClient
funcNewFleetRoutingRESTClient(ctxcontext.Context,opts...option.ClientOption)(*FleetRoutingClient,error)NewFleetRoutingRESTClient creates a new fleet routing rest client.
A service for optimizing vehicle tours.
Validity of certain types of fields:
google.protobuf.Timestamp Times are in Unix time: seconds since 1970-01-01T00:00:00+00:00. seconds must be in [0, 253402300799], i.e. in [1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00]. nanos must be unset or set to 0.google.protobuf.Duration seconds must be in [0, 253402300799], i.e. in [1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00]. nanos must be unset or set to 0.google.type.LatLng latitude must be in [-90.0, 90.0]. longitude must be in [-180.0, 180.0]. at least one of latitude and longitude must be non-zero.Example
packagemainimport("context"optimization"cloud.google.com/go/optimization/apiv1")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=optimization.NewFleetRoutingRESTClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()// TODO: Use client._=c}func (*FleetRoutingClient) BatchOptimizeTours
func(c*FleetRoutingClient)BatchOptimizeTours(ctxcontext.Context,req*optimizationpb.BatchOptimizeToursRequest,opts...gax.CallOption)(*BatchOptimizeToursOperation,error)BatchOptimizeTours optimizes vehicle tours for one or more OptimizeToursRequestmessages as a batch.
This method is a Long Running Operation (LRO). The inputs for optimization(OptimizeToursRequest messages) and outputs (OptimizeToursResponsemessages) are read/written from/to Cloud Storage in user-specifiedformat. Like the OptimizeTours method, each OptimizeToursRequestcontains a ShipmentModel and returns an OptimizeToursResponsecontaining ShipmentRoutes, which are a set of routes to be performed byvehicles minimizing the overall cost.
Example
packagemainimport("context"optimization"cloud.google.com/go/optimization/apiv1"optimizationpb"cloud.google.com/go/optimization/apiv1/optimizationpb")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=optimization.NewFleetRoutingClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&optimizationpb.BatchOptimizeToursRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/optimization/apiv1/optimizationpb#BatchOptimizeToursRequest.}op,err:=c.BatchOptimizeTours(ctx,req)iferr!=nil{// TODO: Handle error.}resp,err:=op.Wait(ctx)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}func (*FleetRoutingClient) BatchOptimizeToursOperation
func(c*FleetRoutingClient)BatchOptimizeToursOperation(namestring)*BatchOptimizeToursOperationBatchOptimizeToursOperation returns a new BatchOptimizeToursOperation from a given name.The name must be that of a previously created BatchOptimizeToursOperation, possibly from a different process.
func (*FleetRoutingClient) Close
func(c*FleetRoutingClient)Close()errorClose closes the connection to the API service. The user should invoke this whenthe client is no longer required.
func (*FleetRoutingClient) Connection (deprecated)
func(c*FleetRoutingClient)Connection()*grpc.ClientConnConnection returns a connection to the API service.
Deprecated: Connections are now pooled so this method does not alwaysreturn the same resource.
func (*FleetRoutingClient) GetOperation
func(c*FleetRoutingClient)GetOperation(ctxcontext.Context,req*longrunningpb.GetOperationRequest,opts...gax.CallOption)(*longrunningpb.Operation,error)GetOperation is a utility method from google.longrunning.Operations.
Example
packagemainimport("context"longrunningpb"cloud.google.com/go/longrunning/autogen/longrunningpb"optimization"cloud.google.com/go/optimization/apiv1")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=optimization.NewFleetRoutingClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&longrunningpb.GetOperationRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest.}resp,err:=c.GetOperation(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}func (*FleetRoutingClient) OptimizeTours
func(c*FleetRoutingClient)OptimizeTours(ctxcontext.Context,req*optimizationpb.OptimizeToursRequest,opts...gax.CallOption)(*optimizationpb.OptimizeToursResponse,error)OptimizeTours sends an OptimizeToursRequest containing a ShipmentModel and returns anOptimizeToursResponse containing ShipmentRoutes, which are a set ofroutes to be performed by vehicles minimizing the overall cost.
A ShipmentModel model consists mainly of Shipments that need to becarried out and Vehicles that can be used to transport the Shipments.The ShipmentRoutes assign Shipments to Vehicles. More specifically,they assign a series of Visits to each vehicle, where a Visitcorresponds to a VisitRequest, which is a pickup or delivery for aShipment.
The goal is to provide an assignment of ShipmentRoutes to Vehicles thatminimizes the total cost where cost has many components defined in theShipmentModel.
Example
packagemainimport("context"optimization"cloud.google.com/go/optimization/apiv1"optimizationpb"cloud.google.com/go/optimization/apiv1/optimizationpb")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=optimization.NewFleetRoutingClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&optimizationpb.OptimizeToursRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/optimization/apiv1/optimizationpb#OptimizeToursRequest.}resp,err:=c.OptimizeTours(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-10-30 UTC.