<br />

> [!WARNING]
> This product or feature is Experimental (pre-GA). Pre-GA products and features might have limited support, and changes to pre-GA products and features might not be compatible with other pre-GA versions. Pre-GA Offerings are covered by the [Google
> Maps Platform Service Specific Terms](https://cloud.google.com/maps-platform/terms/maps-service-terms). For more information, see the [launch stage descriptions](https://developers.google.com/maps/launch-stages.md.txt).

<br />

![Objective properties include `objectives` in `ShipmentModel` and `type` and `weight` in `objectives`](https://developers.google.com/static/maps/tt/route-optimization/experimental/objectives/objectives.svg "Objectives data diagram")

Objectives are parameters you can use to specify high-level optimization goals
instead of providing specific cost parameters from the [cost model](https://developers.google.com/maps/documentation/route-optimization/concepts/costs.md.txt).

You can use **multiple objectives** in a single request, and give each objective
a relative weight to control how strongly it influences the overall
optimization. Objectives affect your **entire request** , influencing all your
vehicles and shipments. Lastly, you can also use objectives to start the
development of your own cost model as described in [Generate a cost model](https://developers.google.com/maps/tt/route-optimization/experimental/objectives/make-request.md.txt#cost_model).

You can use objectives to control the following impacts on your route plan:

- Total travel time or distance of your routes.
- Total working time across all vehicles.
- Total number of vehicles used.

## Properties

The [`objectives`](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel.md.txt#FIELDS.objectives) property is an array of [`Objective`](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel.md.txt#Objective) message
types within [`ShipmentModel`](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel.md.txt). Each [`Objective`](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel.md.txt#Objective) defines a
specific optimization goal and contains the fields listed in the following
table:

| Field | Type | Description |
|---|---|---|
| [`type`](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel.md.txt#Objective.FIELDS.type) | Enum | Specifies the predefined optimization target. The accepted values are the following: - **`DEFAULT`** : Uses a default set of costs to ensure a baseline solution, meaning it prevents the solution from using extreme values to accomplish an objective. `DEFAULT` is added automatically to requests that contain an objective, and it's added with a [`weight`](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel.md.txt#Objective.FIELDS.weight) of `1.0`. If you actively include this objective in your request, the solution uses the `weight` you specify. - **`MIN_DISTANCE`**: Minimizes the total distance traveled. - **`MIN_WORKING_TIME`**: Minimizes the total working time, summed over all vehicles. - **`MIN_TRAVEL_TIME`**: Minimizes the total travel time, summed over all vehicles. - **`MIN_NUM_VEHICLES`**: Minimizes the number of vehicles used. |
| [`weight`](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel.md.txt#Objective.FIELDS.weight) | Double | Defines the relative importance of this objective. When using multiple objectives, the [`weight`](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel.md.txt#Objective.FIELDS.weight) value controls how strongly this specific objective influences the overall route optimization compared to the others. This can be any non-negative number and doesn't need to sum to 1. The default value is `1.0`. |

> [!IMPORTANT]
> **Important:** The `objectives` array is incompatible with manually defined cost parameters. **Don't set custom cost parameters through other properties if
> you use objectives**. If your request includes both objectives and cost parameters, the API sends back a validation error.

## Examples

This section covers two types of examples:

- A code sample that illustrates the structure of the [`objectives`](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel.md.txt#FIELDS.objectives) array.
- A request example that includes the [`objectives`](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel.md.txt#FIELDS.objectives) array.

### Code samples

The following example shows the structure of [`objectives`](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel.md.txt#FIELDS.objectives):

```json
"objectives": [
  {
    "type": "OBJECTIVE_TYPE",
    "weight": WEIGHT
  }
]
```

### Request example

The following example shows the structure of a basic [`optimizeTours`](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/projects/optimizeTours.md.txt)
request incorporating multiple objectives, where `MIN_TRAVEL_TIME` is 3 times as
important as `MIN_WORKING_TIME`.

```
{
  "model": {
    "shipments": [
      {
        "pickups": [
          {
            "arrivalLocation": {
              "latitude": 37.42506261000996,
              "longitude": -122.09535511930135
            }
          }
        ],
        "deliveries": [
          {
            "arrivalLocation": {
              "latitude": 37.42421503206021,
              "longitude": -122.09526063135228
            }
          }
        ]
      }
    ],
    "vehicles": [
      {
        "travelMode": "DRIVING"
      }
    ],
    "objectives": [
      {
        "type": "MIN_TRAVEL_TIME",
        "weight": 3.0
      },
      {
        "type": "MIN_WORKING_TIME"
      }
    ]
  }
}
```

## Generate a cost model

Objectives are a quick way to set optimization targets, but in some cases, they
alone might not be specific enough. To achieve your exact routing goals, you may
need the granular control only available through cost model parameters.

You can start the development of your own cost model by adding objectives to
your request, then **converting the objectives** in your request to **cost model
parameters** using the [`TRANSFORM_AND_RETURN_REQUEST`](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/SolvingMode.md.txt#ENUM_VALUES.TRANSFORM_AND_RETURN_REQUEST) solving
mode.

When you send a request using this solving mode, the following happens:

- The API converts your objectives into **cost model parameters** and returns them in a [`processedRequest`](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/OptimizeToursResponse.md.txt#FIELDS.processed_request). You can then adjust the cost model parameters as needed to fine-tune your route plan.
- When using multiple objectives, the API **combines the costs** of all your objectives and scales them by their respective **weights**.
- You are **not billed** for this request, since the API doesn't provide you with an optimized route, it only converts the objectives to cost model parameters.

> [!NOTE]
> **Note:** The [`TRANSFORM_AND_RETURN_REQUEST`](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/SolvingMode.md.txt#ENUM_VALUES.TRANSFORM_AND_RETURN_REQUEST) solving mode is only valid for [`OptimizeTours`](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/projects/optimizeTours.md.txt) requests.

### Example request

The following example shows a request using the `MIN_TRAVEL_TIME` objective and
the [`TRANSFORM_AND_RETURN_REQUEST`](https://developers.google.com/maps/documentation/route-optimization/reference/rest/v1/SolvingMode.md.txt#ENUM_VALUES.TRANSFORM_AND_RETURN_REQUEST) solving mode:

```
{
  "model": {
    "shipments": [
      {
        "pickups": [
          {
            "arrivalLocation": {
              "latitude": 37.42506261000996,
              "longitude": -122.09535511930135
            }
          }
        ],
        "deliveries": [
          {
            "arrivalLocation": {
              "latitude": 37.42421503206021,
              "longitude": -122.09526063135228
            }
          }
        ]
      }
    ],
    "vehicles": [
      {
        "travelMode": "DRIVING"
      }
    ],
    "objectives": [
      {
        "type": "MIN_TRAVEL_TIME"
      }
    ]
  },
  "solvingMode": "TRANSFORM_AND_RETURN_REQUEST"
}
```

### Example response

The following is the response corresponding to the previous request. This
response includes both the generated cost model parameters and the original
objective for reference.

```
{
  "processedRequest": {
    "model": {
      "shipments": [
        {
          "pickups": [
            {
              "arrivalLocation": {
                "latitude": 37.425062610009959,
                "longitude": -122.09535511930135
              }
            }
          ],
          "deliveries": [
            {
              "arrivalLocation": {
                "latitude": 37.424215032060211,
                "longitude": -122.09526063135228
              }
            }
          ]
        }
      ],
      "vehicles": [
        {
          "travelMode": "DRIVING",
          "costPerHour": 30,
          "costPerTraveledHour": 330,
          "costPerKilometer": 0.2
        }
      ],
      "objectives": [
        {
          "type": "MIN_TRAVEL_TIME"
        }
      ]
    },
    "solvingMode": "TRANSFORM_AND_RETURN_REQUEST"
  }
}
```