Cloud Optimization API v1 - Package cloud.google.com/go/optimization/apiv1 (v1.7.2)

Package optimization is an auto-generated package for the Cloud Optimization API.

Cloud Optimization API provides a portfolio of solvers to address common optimization use cases starting with optimal route planning for vehicle fleets.

General documentation

For information that is relevant for all client libraries please reference https://pkg.go.dev/cloud.google.com/go#pkg-overview. Some information on this page includes:

Example usage

To get started with this package, create a client.

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_Options
c, err := optimization.NewFleetRoutingClient(ctx)
if err != nil {
    // TODO: Handle error.
}
defer c.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.

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_Options
c, err := optimization.NewFleetRoutingClient(ctx)
if err != nil {
    // TODO: Handle error.
}
defer c.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)
if err != nil {
    // TODO: Handle error.
}

resp, err := op.Wait(ctx)
if err != nil {
    // TODO: Handle error.
}
// TODO: Use resp.
_ = resp

Use of Context

The ctx passed to NewFleetRoutingClient is used for authentication requests and for 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

func DefaultAuthScopes() []string

DefaultAuthScopes reports the default set of authentication scopes to use with this package.

BatchOptimizeToursOperation

type BatchOptimizeToursOperation struct {
	// contains filtered or unexported fields
}

BatchOptimizeToursOperation manages a long-running operation from BatchOptimizeTours.

func (*BatchOptimizeToursOperation) Done

func (op *BatchOptimizeToursOperation) Done() bool

Done reports whether the long-running operation has completed.

func (*BatchOptimizeToursOperation) Metadata

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

Name 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

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 and the 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

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

type FleetRoutingCallOptions struct {
	OptimizeTours      []gax.CallOption
	BatchOptimizeTours []gax.CallOption
	GetOperation       []gax.CallOption
}

FleetRoutingCallOptions contains the retry settings for each method of FleetRoutingClient.

FleetRoutingClient

type FleetRoutingClient struct {

	// 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

func NewFleetRoutingClient(ctx context.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

package main

import (
	"context"

	optimization "cloud.google.com/go/optimization/apiv1"
)

func main() {
	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_Options
	c, err := optimization.NewFleetRoutingClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	// TODO: Use client.
	_ = c
}

func NewFleetRoutingRESTClient

func NewFleetRoutingRESTClient(ctx context.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

package main

import (
	"context"

	optimization "cloud.google.com/go/optimization/apiv1"
)

func main() {
	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_Options
	c, err := optimization.NewFleetRoutingRESTClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	// TODO: Use client.
	_ = c
}

func (*FleetRoutingClient) BatchOptimizeTours

BatchOptimizeTours optimizes vehicle tours for one or more OptimizeToursRequest messages as a batch.

This method is a Long Running Operation (LRO). The inputs for optimization (OptimizeToursRequest messages) and outputs (OptimizeToursResponse messages) are read/written from/to Cloud Storage in user-specified format. Like the OptimizeTours method, each OptimizeToursRequest contains a ShipmentModel and returns an OptimizeToursResponse containing ShipmentRoutes, which are a set of routes to be performed by vehicles minimizing the overall cost.

Example

package main

import (
	"context"

	optimization "cloud.google.com/go/optimization/apiv1"

	optimizationpb "cloud.google.com/go/optimization/apiv1/optimizationpb"
)

func main() {
	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_Options
	c, err := optimization.NewFleetRoutingClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.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)
	if err != nil {
		// TODO: Handle error.
	}

	resp, err := op.Wait(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

func (*FleetRoutingClient) BatchOptimizeToursOperation

func (c *FleetRoutingClient) BatchOptimizeToursOperation(name string) *BatchOptimizeToursOperation

BatchOptimizeToursOperation 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() error

Close closes the connection to the API service. The user should invoke this when the client is no longer required.

func (*FleetRoutingClient) Connection (deprecated)

func (c *FleetRoutingClient) Connection() *grpc.ClientConn

Connection returns a connection to the API service.

Deprecated: Connections are now pooled so this method does not always return the same resource.

func (*FleetRoutingClient) GetOperation

GetOperation is a utility method from google.longrunning.Operations.

Example

package main

import (
	"context"

	longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
	optimization "cloud.google.com/go/optimization/apiv1"
)

func main() {
	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_Options
	c, err := optimization.NewFleetRoutingClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.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)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

func (*FleetRoutingClient) OptimizeTours

OptimizeTours sends an OptimizeToursRequest containing a ShipmentModel and returns an OptimizeToursResponse containing ShipmentRoutes, which are a set of routes to be performed by vehicles minimizing the overall cost.

A ShipmentModel model consists mainly of Shipments that need to be carried 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 Visit corresponds to a VisitRequest, which is a pickup or delivery for a Shipment.

The goal is to provide an assignment of ShipmentRoutes to Vehicles that minimizes the total cost where cost has many components defined in the ShipmentModel.

Example

package main

import (
	"context"

	optimization "cloud.google.com/go/optimization/apiv1"

	optimizationpb "cloud.google.com/go/optimization/apiv1/optimizationpb"
)

func main() {
	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_Options
	c, err := optimization.NewFleetRoutingClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.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)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}