The main goal of Route Optimization API is to find routes with the lowest cost. As such, the cost model is the main driver for route optimization.
The cost model is a set of properties that specify global, vehicle, and shipment costs.
Cost model properties support the following kinds of optimization objectives:
- Efficient vehicle assignments and routes
- Cost-effective pickup and delivery times
- Prioritization of critical shipments
Structure
As shown in the diagram, cost model properties are structured as follows:
Shipment
contains thepenaltyCost
property.Vehicle
contains the following properties:
This document only highlights essential cost model parameters. See the reference documentation for the complete set of cost parameters.
Essentials checklist
The following checklist describes essential knowledge that prevents potential cost-related mistakes. This list can help you validate your request and troubleshoot your response.
Properties
The following table lists and describes the cost model properties.
Parent | Property name | Property type | Cost per | Property description |
---|---|---|---|---|
Shipment |
penaltyCost |
number | Skipped shipment | The cost incurred by skipping the shipment. The API skips a shipment when the cost to complete it exceeds its penalty cost.
|
Vehicle |
fixedCost |
number | Shipment | Fixed cost applied if this vehicle is used to handle a shipment. |
costPerHour |
number | Hour | The cost of operating a vehicle per hour inclusive of transit, wait, visit, and break times. As this cost increases, the optimizer attempts to find faster routes that may not be the shortest routes. This property can be an effective standalone cost per vehicle due to its simplicity and completeness. |
|
costPerKilometer |
number | Kilometer | The cost per kilometer traveled by the vehicle, such as fuel costs and amortized vehicle maintenance costs. | |
costPerTraveledHour |
number | Hour | The cost of operating a vehicle per hour only while in transit, excluding wait, visit, and break times. This prioritizes faster travel routes over shorter routes. |
Examples
This section covers three types of examples:
- Code samples that illustrate the structure of cost model properties.
- An example scenario that shows one way to use cost model properties to achieve a business objective.
- A request example that includes the values set in the example scenario.
Code samples
The following code sample shows the structure of the cost model properties in
Shipment
:
{ "model": { "shipments": [ ... { "penaltyCost": PENALTY_COST } ], "vehicles": [ ... ] } }
The following code sample shows the structure of the cost model properties in
Vehicle
:
{ "model": { "shipments": [ ... ], "vehicles": [ ... { "fixedCost": FIXED_COST, "costPerKilometer": KILOMETER_COST, "costPerHour": HOUR_COST, "costPerTraveledHour": TRAVELED_HOUR_COST } ] } }
Example scenario
This section describes a scenario where you have a doggy daycare business. You are optimizing a route for the truck you use to pick up the dogs from their homes. In this scenario, you want the optimizer to take in account costs related to picking up the dogs and vehicle operations when providing a route.
For this example, one cost unit represents 1 dollar. This means the cost model property values in your request are the following:
Property | Value | Scenario |
---|---|---|
penaltyCost |
10 | Represents the penalty you offer to your customers for not picking up their dog on a scheduled day. Whenever you don't pickup the dog on a scheduled day, the customer gets 40 dollars discounted from their service total. |
fixedCost |
30 | Represents the daily cost of your vehicle loan payments, which is 30 dollars per day. |
costPerKilometer |
0.08 | Represents how much gasoline the truck spends per kilometer. Your truck needs 0.04 gallons per kilometer to move, and the cost per gallon in your region is 2 dollars. |
costPerHour |
27.7 | Represents how much you have to pay a driver for driving the truck and you pay the truck driver 27.7 dollars per hour. |
costPerTraveledHour |
2.5 | Represents how much you have to pay for truck air conditioning per hour for the dogs while on the road. Whenever the truck is not moving, the driver can open the doors at the back and turn off the air conditioning. |
Based on costs parameters, the optimizer could make trade-offs that are not obvious to the user, but can be found through optimization.
The following diagram illustrates an example where the optimizer could choose a longer but faster route through the green dashed line to avoid traffic on the dotted red line.
In this scenario, the cost balance of the two routes are the following:
The green dashed line has a low
costPerHour
andcostPerTraveledHour
since it's a fast route avoiding traffic, which is more cost-effective even when thecostPerKilometer
is high.The red dotted line has a low
costPerKilometer
since it's a direct route, but thecostPerHour
andcostPerTraveledHour
are too high due to the wait-times in traffic, making it the most expensive route.
In addition to providing cost-effective routes, the optimizer also provides a summation of the total costs of the delivery routes in the response properties.
Request example
The following example shows the structure of a basic optimizeTours
request incorporating the values set in the example scenario:
{ "model": { "shipments": [ { "pickups": [ { "arrivalLocation": { "latitude": 37.8024, "longitude": -122.4058 } } ], "deliveries": [ { "arrivalLocation": { "latitude": 37.759773, "longitude": -122.427063 } } ] "penaltyCost": 40 } ], "vehicles": [ { "startLocation": { "latitude": 37.759773, "longitude": -122.427063 }, "endLocation": { "latitude": 37.759773, "longitude": -122.427063 }, "fixedCost": 30, "costPerKilometer": 0.08, "costPerHour": 27.7, "costPerTraveledHour": 2.5 } ] } }
Response properties
The OptimizeToursResponse
message has cost properties
that describe the costs incurred in the process of completing a route:
metrics.costs
: The total cost across all routes broken down by cost-related request fields.metrics.totalCost
: The total cost across all routes summed up.