routeoptimization

package
v1.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2025 License: Apache-2.0 Imports: 27 Imported by: 2

Documentation

Overview

Package routeoptimization is an auto-generated package for the Route Optimization API.

The Route Optimization API assigns tasks and routes to a vehicle fleet, optimizing against the objectives and constraints that you supply for your transportation goals.

NOTE: This package is in beta. It is not stable, and may be subject to changes.

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.

// go get cloud.google.com/go/maps/routeoptimization/apiv1@latest
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 := routeoptimization.NewClient(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, mentioned above.

req := &routeoptimizationpb.BatchOptimizeToursRequest{
	// TODO: Fill request struct fields.
	// See https://pkg.go.dev/cloud.google.com/go/maps/routeoptimization/apiv1/routeoptimizationpb#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 NewClient 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.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultAuthScopes

func DefaultAuthScopes() []string

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

Types

type 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.

type CallOptions

type CallOptions struct {
	OptimizeTours            []gax.CallOption
	BatchOptimizeTours       []gax.CallOption
	OptimizeToursLongRunning []gax.CallOption
	OptimizeToursUri         []gax.CallOption
	GetOperation             []gax.CallOption
}

CallOptions contains the retry settings for each method of Client.

type Client

type Client struct {

	// The call options for this service.
	CallOptions *CallOptions

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

Client is a client for interacting with Route 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 NewClient

func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error)

NewClient creates a new route optimization 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"

	routeoptimization "cloud.google.com/go/maps/routeoptimization/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 := routeoptimization.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	// TODO: Use client.
	_ = c
}

func NewRESTClient

func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error)

NewRESTClient creates a new route optimization 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"

	routeoptimization "cloud.google.com/go/maps/routeoptimization/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 := routeoptimization.NewRESTClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	// TODO: Use client.
	_ = c
}

func (*Client) 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 from and written to Cloud Storage in user-specified format. Like the OptimizeTours method, each OptimizeToursRequest contains a ShipmentModel and returns an OptimizeToursResponse containing ShipmentRoute fields, which are a set of routes to be performed by vehicles minimizing the overall cost.

The user can poll operations.get to check the status of the LRO:

If the LRO done field is false, then at least one request is still being processed. Other requests may have completed successfully and their results are available in Cloud Storage.

If the LRO’s done field is true, then all requests have been processed. Any successfully processed requests will have their results available in Cloud Storage. Any requests that failed will not have their results available in Cloud Storage. If the LRO’s error field is set, then it contains the error from one of the failed requests.

Example
package main

import (
	"context"

	routeoptimization "cloud.google.com/go/maps/routeoptimization/apiv1"

	routeoptimizationpb "cloud.google.com/go/maps/routeoptimization/apiv1/routeoptimizationpb"
)

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 := routeoptimization.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &routeoptimizationpb.BatchOptimizeToursRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/maps/routeoptimization/apiv1/routeoptimizationpb#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 (*Client) BatchOptimizeToursOperation

func (c *Client) 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 (*Client) Close

func (c *Client) Close() error

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

func (*Client) Connection deprecated

func (c *Client) 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 (*Client) GetOperation

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

Example
package main

import (
	"context"

	longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
	routeoptimization "cloud.google.com/go/maps/routeoptimization/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 := routeoptimization.NewClient(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 (*Client) 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"

	routeoptimization "cloud.google.com/go/maps/routeoptimization/apiv1"

	routeoptimizationpb "cloud.google.com/go/maps/routeoptimization/apiv1/routeoptimizationpb"
)

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 := routeoptimization.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &routeoptimizationpb.OptimizeToursRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/maps/routeoptimization/apiv1/routeoptimizationpb#OptimizeToursRequest.
	}
	resp, err := c.OptimizeTours(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

func (*Client) OptimizeToursLongRunning added in v1.25.0

OptimizeToursLongRunning this is a variant of the OptimizeTours method designed for optimizations with large timeout values. It should be preferred over the OptimizeTours method for optimizations that take longer than a few minutes.

The returned [long-running operation][google.longrunning.Operation] (LRO) will have a name of the format <parent>/operations/<operation_id> and can be used to track progress of the computation. The metadata field type is OptimizeToursLongRunningMetadata. The response field type is OptimizeToursResponse, if successful.

Experimental: See https://developers.google.com/maps/tt/route-optimization/experimental/otlr/make-request (at https://developers.google.com/maps/tt/route-optimization/experimental/otlr/make-request) for more details.

Example
package main

import (
	"context"

	routeoptimization "cloud.google.com/go/maps/routeoptimization/apiv1"

	routeoptimizationpb "cloud.google.com/go/maps/routeoptimization/apiv1/routeoptimizationpb"
)

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 := routeoptimization.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &routeoptimizationpb.OptimizeToursRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/maps/routeoptimization/apiv1/routeoptimizationpb#OptimizeToursRequest.
	}
	op, err := c.OptimizeToursLongRunning(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}

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

func (*Client) OptimizeToursLongRunningOperation added in v1.25.0

func (c *Client) OptimizeToursLongRunningOperation(name string) *OptimizeToursLongRunningOperation

OptimizeToursLongRunningOperation returns a new OptimizeToursLongRunningOperation from a given name. The name must be that of a previously created OptimizeToursLongRunningOperation, possibly from a different process.

func (*Client) OptimizeToursUri added in v1.25.0

OptimizeToursUri this is a variant of the OptimizeToursLongRunning method designed for optimizations with large timeout values and large input/output sizes.

The client specifies the URI of the OptimizeToursRequest stored in Google Cloud Storage and the server writes the OptimizeToursResponse to a client-specified Google Cloud Storage URI.

This method should be preferred over the OptimizeTours method for optimizations that take longer than a few minutes and input/output sizes that are larger than 8MB, though it can be used for shorter and smaller optimizations as well.

The returned [long-running operation][google.longrunning.Operation] (LRO) will have a name of the format <parent>/operations/<operation_id> and can be used to track progress of the computation. The metadata field type is OptimizeToursLongRunningMetadata. The response field type is OptimizeToursUriResponse, if successful.

Experimental: See https://developers.google.com/maps/tt/route-optimization/experimental/otlr/make-request (at https://developers.google.com/maps/tt/route-optimization/experimental/otlr/make-request) for more details.

Example
package main

import (
	"context"

	routeoptimization "cloud.google.com/go/maps/routeoptimization/apiv1"

	routeoptimizationpb "cloud.google.com/go/maps/routeoptimization/apiv1/routeoptimizationpb"
)

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 := routeoptimization.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &routeoptimizationpb.OptimizeToursUriRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/maps/routeoptimization/apiv1/routeoptimizationpb#OptimizeToursUriRequest.
	}
	op, err := c.OptimizeToursUri(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}

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

func (*Client) OptimizeToursUriOperation added in v1.25.0

func (c *Client) OptimizeToursUriOperation(name string) *OptimizeToursUriOperation

OptimizeToursUriOperation returns a new OptimizeToursUriOperation from a given name. The name must be that of a previously created OptimizeToursUriOperation, possibly from a different process.

type OptimizeToursLongRunningOperation added in v1.25.0

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

OptimizeToursLongRunningOperation manages a long-running operation from OptimizeToursLongRunning.

func (*OptimizeToursLongRunningOperation) Done added in v1.25.0

Done reports whether the long-running operation has completed.

func (*OptimizeToursLongRunningOperation) Metadata added in v1.25.0

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 (*OptimizeToursLongRunningOperation) Name added in v1.25.0

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 (*OptimizeToursLongRunningOperation) Poll added in v1.25.0

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 (*OptimizeToursLongRunningOperation) Wait added in v1.25.0

Wait blocks until the long-running operation is completed, returning the response and any errors encountered.

See documentation of Poll for error-handling information.

type OptimizeToursUriOperation added in v1.25.0

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

OptimizeToursUriOperation manages a long-running operation from OptimizeToursUri.

func (*OptimizeToursUriOperation) Done added in v1.25.0

func (op *OptimizeToursUriOperation) Done() bool

Done reports whether the long-running operation has completed.

func (*OptimizeToursUriOperation) Metadata added in v1.25.0

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 (*OptimizeToursUriOperation) Name added in v1.25.0

func (op *OptimizeToursUriOperation) Name() string

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 (*OptimizeToursUriOperation) Poll added in v1.25.0

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 (*OptimizeToursUriOperation) Wait added in v1.25.0

Wait blocks until the long-running operation is completed, returning the response and any errors encountered.

See documentation of Poll for error-handling information.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL