Objectives

Objectives are parameters that pre-define common optimization targets, such as shortest travel distance or duration, on time deliveries, balancing loads between drivers. It's meant to make it easier for developers to onboard to Route Optimization API before learning the sophications and full customization of cost parameters.

When set, the ShipmentModel.objectives overwrite the cost model completely, therefore they are incompatible with pre-existing costs. Each Objective maps to a number of predefined costs for vehicles, shipments or transition attributes.

When specifying the TRANSFORM_AND_RETURN_REQUEST solving mode, the request is not solved and it is only validated and filled with costs corresponding to the given objectives. The modified request is returned as OptimizeToursResponse.processed_request. All other solve modes will return the solved request.

The TRANSFORM_AND_RETURN_REQUEST solving mode is only valid for OptimizeTours requests and is not available for other Route Optimization API requests.

Example: Make a ShipmentModel.objectives request

Before making a request, complete the following steps:

  • 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 OptimizeToursRequest to the Route Optimization API which returns an OptimizeToursResponse.

    curl -X POST 'https://routeoptimization.googleapis.com/v1/projects/PROJECT_NUMBER_OR_ID:optimizeTours' \
    -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",
          }
        ],
        "objectives": [
          {
            "type": "MIN_TRAVEL_TIME"
          }
        ],
      }
    }
    EOM

Example: Make a TRANSFORM_AND_RETURN_REQUEST request

Before making a request, complete the following steps:

  • 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 OptimizeToursRequest to the Route Optimization API which returns an OptimizeToursResponse with the ProcessedRequest field set.

    curl -X POST 'https://routeoptimization.googleapis.com/v1/projects/PROJECT_NUMBER_OR_ID:optimizeTours' \
    -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",
          }
        ],
        "objectives": [
          {
            "type": "MIN_TRAVEL_TIME"
          }
        ]
      },
      "solvingMode": "TRANSFORM_AND_RETURN_REQUEST"
    }
    EOM
    The previous command will produce a similar response to the following.
    {
      "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"
      }
    }