

# Learn how to use OptimizeWaypoints
<a name="optimize-waypoints-how-to"></a>

Learn how to use `OptimizeWaypoints` to find the best routes for minimizing travel time or distance.

**Topics**
+ [How to optimize waypoints for a route](optimize-waypoints.md)
+ [How to optimize waypoints for a route with traffic awareness](optimize-waypoints-traffic-awareness.md)
+ [How to optimize waypoints for a route with access hours awareness](optimize-waypoints-access-hours.md)

# How to optimize waypoints for a route
<a name="optimize-waypoints"></a>

The OptimizeWaypoints API calculates the most efficient route between a series of waypoints, minimizing either travel time or total distance. This API solves the Traveling Salesman Problem by considering road networks and traffic conditions to determine the optimal path.

## Potential use cases
<a name="optimize-waypoints-potential-use"></a>
+ **Analyze service area patterns:** Use waypoint optimization to make informed decisions about business service areas and improve logistics efficiency.

## Examples
<a name="optimize-waypoints-examples"></a>

### Optimize waypoints using Car TravelMode
<a name="optimize-waypoints-car"></a>

------
#### [ Sample Request ]

```
{
    "Origin": [
        -123.095740,
        49.274426
    ],
    "Waypoints": [
        {
            "Position": [
                -123.115193,
                49.280596
            ]
        },
        {
            "Position": [
                -123.089557,
                49.271774
            ]
        }
    ],
    "DepartureTime": "2024-10-25T18:13:42Z",
    "Destination": [
        -123.095185,
        49.263728
    ],
    "TravelMode": "Car"
}
```

------
#### [ Sample Response ]

```
{
    "Connections": [
        {
            "Distance": 1989,
            "From": "Origin",
            "RestDuration": 0,
            "To": "Waypoint0",
            "TravelDuration": 258,
            "WaitDuration": 0
        },
        {
            "Distance": 3010,
            "From": "Waypoint0",
            "RestDuration": 0,
            "To": "Waypoint1",
            "TravelDuration": 298,
            "WaitDuration": 0
        },
        {
            "Distance": 2371,
            "From": "Waypoint1",
            "RestDuration": 0,
            "To": "Destination",
            "TravelDuration": 311,
            "WaitDuration": 0
        }
    ],
    "Distance": 7370,
    "Duration": 867,
    "ImpedingWaypoints": [],
    "OptimizedWaypoints": [
        {
            "DepartureTime": "2024-10-25T18:13:42Z",
            "Id": "Origin",
            "Position": [
                -123.09574,
                49.274426
            ]
        },
        {
            "DepartureTime": "2024-10-25T18:18:00Z",
            "Id": "Waypoint0",
            "Position": [
                -123.115193,
                49.280596
            ]
        },
        {
            "DepartureTime": "2024-10-25T18:22:58Z",
            "Id": "Waypoint1",
            "Position": [
                -123.089557,
                49.271774
            ]
        },
        {
            "ArrivalTime": "2024-10-25T18:28:09Z",
            "Id": "Destination",
            "Position": [
                -123.095185,
                49.263728
            ]
        }
    ],
    "TimeBreakdown": {
        "RestDuration": 0,
        "ServiceDuration": 0,
        "TravelDuration": 867,
        "WaitDuration": 0
    }
}
```

------
#### [ cURL ]

```
curl --request POST \
  --url 'https://routes.geo.eu-central-1.amazonaws.com/v2/optimize-waypoints?key=Your_key' \
  --header 'Content-Type: application/json' \
  --data '{
    "Origin": [
        -123.095740,
        49.274426
    ],
    "Waypoints": [
        {
            "Position": [
                -123.115193,
                49.280596
            ]
        },
        {
            "Position": [
                -123.089557,
                49.271774
            ]
        }
    ],
    "DepartureTime": "2024-10-25T18:13:42Z",
    "Destination": [
        -123.095185,
        49.263728
    ],
    "TravelMode": "Car"
}'
```

------
#### [ AWS CLI ]

```
aws geo-routes optimize-waypoints --key ${YourKey} \
--origin -123.095740 49.274426 \
--waypoints '[{"Position": [-123.115193 , 49.280596]}, {"Position": [-123.089557 , 49.271774]}]' \
--destination -123.095185 49.263728 \
--departure-time "2024-10-25T18:13:42Z" \
--travel-mode "Car"
```

------

# How to optimize waypoints for a route with traffic awareness
<a name="optimize-waypoints-traffic-awareness"></a>

The OptimizeWaypoints API calculates the optimal route between multiple waypoints to minimize travel time or total distance. It utilizes advanced algorithms to solve the Traveling Salesman Problem, determining the most efficient path while accounting for factors such as road networks and real-time traffic conditions.

## Potential use cases
<a name="optimize-waypoints-potential-use"></a>
+ **Optimize multi-stop routes for delivery efficiency:** Improve delivery operations by calculating the shortest or fastest route among several stops. This is useful for reducing operational costs, fuel consumption, and travel time in logistics and delivery services.

## Examples
<a name="optimize-waypoints-examples"></a>

### Optimize waypoints with traffic awareness using car TravelMode
<a name="optimize-waypoints-traffic-car"></a>

------
#### [ Sample request ]

```
{
    "Origin": [
        -123.095740,
        49.274426
    ],
    "Waypoints": [
        {
            "Position": [
                -123.115193,
                49.280596
            ]
        },
        {
            "Position": [
                -123.089557,
                49.271774
            ]
        }
    ],
    "DepartureTime": "2024-10-25T18:13:42Z",
    "Destination": [
        -123.095185,
        49.263728
    ],
    "TravelMode": "Car",
    "Traffic": {
        "Usage": "UseTrafficData"
    }
}
```

------
#### [ Sample response ]

```
{
    "Connections": [
        {
            "Distance": 1989,
            "From": "Origin",
            "RestDuration": 0,
            "To": "Waypoint0",
            "TravelDuration": 324,
            "WaitDuration": 0
        },
        {
            "Distance": 2692,
            "From": "Waypoint0",
            "RestDuration": 0,
            "To": "Waypoint1",
            "TravelDuration": 338,
            "WaitDuration": 0
        },
        {
            "Distance": 2371,
            "From": "Waypoint1",
            "RestDuration": 0,
            "To": "Destination",
            "TravelDuration": 395,
            "WaitDuration": 0
        }
    ],
    "Distance": 7052,
    "Duration": 1057,
    "ImpedingWaypoints": [],
    "OptimizedWaypoints": [
        {
            "DepartureTime": "2024-10-25T18:13:42Z",
            "Id": "Origin",
            "Position": [
                -123.09574,
                49.274426
            ]
        },
        {
            "ArrivalTime": "2024-10-25T18:19:06Z",
            "DepartureTime": "2024-10-25T18:19:06Z",
            "Id": "Waypoint0",
            "Position": [
                -123.115193,
                49.280596
            ]
        },
        {
            "ArrivalTime": "2024-10-25T18:24:44Z",
            "DepartureTime": "2024-10-25T18:24:44Z",
            "Id": "Waypoint1",
            "Position": [
                -123.089557,
                49.271774
            ]
        },
        {
            "ArrivalTime": "2024-10-25T18:31:19Z",
            "Id": "Destination",
            "Position": [
                -123.095185,
                49.263728
            ]
        }
    ],
    "TimeBreakdown": {
        "RestDuration": 0,
        "ServiceDuration": 0,
        "TravelDuration": 1057,
        "WaitDuration": 0
    }
}
```

------
#### [ cURL ]

```
curl --request POST \
  --url 'https://routes.geo.eu-central-1.amazonaws.com/v2/optimize-waypoints?key=Your_key' \
  --header 'Content-Type: application/json' \
  --data '{
    "Origin": [
        -123.095740,
        49.274426
    ],
    "Waypoints": [
        {
            "Position": [
                -123.115193,
                49.280596
            ]
        },
        {
            "Position": [
                -123.089557,
                49.271774
            ]
        }
    ],
    "DepartureTime": "2024-10-25T18:13:42Z",
    "Destination": [
        -123.095185,
        49.263728
    ],
    "TravelMode": "Car",
    "Traffic": {
        "Usage": "UseTrafficData"
    }
}'
```

------
#### [ AWS CLI ]

```
aws geo-routes optimize-waypoints --key ${YourKey} \
--origin -123.095740 49.274426 \
--waypoints '[{"Position": [-123.115193 , 49.280596]}, {"Position": [-123.089557 , 49.271774]}]' \
--destination -123.095185 49.263728 \
--departure-time "2024-10-25T18:13:42Z" \
--travel-mode "Car" \
--traffic '{"Usage": "UseTrafficData"}'
```

------

# How to optimize waypoints for a route with access hours awareness
<a name="optimize-waypoints-access-hours"></a>

The OptimizeWaypoints API also calculates the optimal route between a set of waypoints, with the goal of minimizing either the travel time or the total distance covered. It solves the Traveling Salesman Problem of determining the most efficient path, taking into account factors such as the road network and traffic conditions.

## Potential use cases
<a name="optimize-waypoints-access-hours-potential-use"></a>
+ **Analyze customer access hours:** Plan for efficiency around your customer’s access hours.

## Examples
<a name="optimize-waypoints-examples"></a>

### Optimize waypoints with access hours awareness using Car TravelMode
<a name="optimize-waypoints-car"></a>

------
#### [ Sample Request ]

```
{
    "Origin": [
        -123.095740,
        49.274426
    ],
    "Waypoints": [
        {
            "Position": [
                -123.115193,
                49.280596
            ],
            "SideOfStreet": {
                "Position": [
                    -123.089557,
                    49.271774
                ],
                "UseWith": "AnyStreet"
            },
            "AccessHours": {
                "From": {
                    "DayOfWeek": "Saturday",
                    "TimeOfDay": "00:02:42Z"
                },
                "To": {
                    "DayOfWeek": "Friday",
                    "TimeOfDay": "1:33:36+02:50"
                }
            },
            "Heading": "250",
            "ServiceDuration": "200"
        },
        {
            "Position": [
                -123.089557,
                49.271774
            ],
            "AccessHours": {
                "From": {
                    "DayOfWeek": "Monday",
                    "TimeOfDay": "00:02:42Z"
                },
                "To": {
                    "DayOfWeek": "Tuesday",
                    "TimeOfDay": "1:33:36+02:50"
                }
            },
            "ServiceDuration": "200"
        }
    ],
    "DepartureTime": "2024-10-25T18:13:42Z",
    "Destination": [
        -123.095185,
        49.263728
    ],
    "TravelMode": "Car"
}
```

------
#### [ Sample Response ]

```
{
    "Connections": [
        {
            "Distance": 1989,
            "From": "Origin",
            "RestDuration": 0,
            "To": "Waypoint0",
            "TravelDuration": 258,
            "WaitDuration": 20682
        },
        {
            "Distance": 3360,
            "From": "Waypoint0",
            "RestDuration": 0,
            "To": "Waypoint1",
            "TravelDuration": 378,
            "WaitDuration": 172222
        },
        {
            "Distance": 2371,
            "From": "Waypoint1",
            "RestDuration": 0,
            "To": "Destination",
            "TravelDuration": 311,
            "WaitDuration": 0
        }
    ],
    "Distance": 7720,
    "Duration": 194251,
    "ImpedingWaypoints": [],
    "OptimizedWaypoints": [
        {
            "DepartureTime": "2024-10-25T18:13:42Z",
            "Id": "Origin",
            "Position": [
                -123.09574,
                49.274426
            ]
        },
        {
            "ArrivalTime": "2024-10-25T18:18:00Z",
            "DepartureTime": "2024-10-26T00:06:02Z",
            "Id": "Waypoint0",
            "Position": [
                -123.115193,
                49.280596
            ]
        },
        {
            "ArrivalTime": "2024-10-26T00:12:20Z",
            "DepartureTime": "2024-10-28T00:06:02Z",
            "Id": "Waypoint1",
            "Position": [
                -123.089557,
                49.271774
            ]
        },
        {
            "ArrivalTime": "2024-10-28T00:11:13Z",
            "Id": "Destination",
            "Position": [
                -123.095185,
                49.263728
            ]
        }
    ],
    "TimeBreakdown": {
        "RestDuration": 0,
        "ServiceDuration": 400,
        "TravelDuration": 947,
        "WaitDuration": 192904
    }
}
```

------
#### [ cURL ]

```
curl --request POST \
  --url 'https://routes.geo.eu-central-1.amazonaws.com/v2/optimize-waypoints?key=Your_key' \
  --header 'Content-Type: application/json' \
  --data '{
    "Origin": [
        -123.095740,
        49.274426
    ],
    "Waypoints": [
        {
            "Position": [
                -123.115193,
                49.280596
            ],
            "SideOfStreet": {
                "Position": [
                    -123.089557,
                    49.271774
                ],
                "UseWith": "AnyStreet"
            },
            "AccessHours": {
                "From": {
                    "DayOfWeek": "Saturday",
                    "TimeOfDay": "00:02:42Z"
                },
                "To": {
                    "DayOfWeek": "Friday",
                    "TimeOfDay": "1:33:36+02:50"
                }
            },
            "Heading": "250",
            "ServiceDuration": "200"
        },
        {
            "Position": [
                -123.089557,
                49.271774
            ],
            "AccessHours": {
                "From": {
                    "DayOfWeek": "Monday",
                    "TimeOfDay": "00:02:42Z"
                },
                "To": {
                    "DayOfWeek": "Tuesday",
                    "TimeOfDay": "1:33:36+02:50"
                }
            },
            "ServiceDuration": "200"
        }
    ],
    "DepartureTime": "2024-10-25T18:13:42Z",
    "Destination": [
        -123.095185,
        49.263728
    ],
    "TravelMode": "Car"
}'
```

------
#### [ AWS CLI ]

```
aws geo-routes optimize-waypoints --key ${YourKey} \
--origin -123.095740 49.274426 \
--waypoints '[{"Position": [-123.115193 , 49.280596], "SideOfStreet": {"Position": [-123.089557, 49.271774], "UseWith": "AnyStreet"}, "AccessHours": {"From": {"DayOfWeek": "Saturday", "TimeOfDay": "00:02:42Z"}, "To": {"DayOfWeek": "Friday", "TimeOfDay": "1:33:36+02:50"}}, "Heading": 250, "ServiceDuration": 200}, {"Position": [-123.089557, 49.271774], "AccessHours": {"From": {"DayOfWeek": "Monday", "TimeOfDay": "00:02:42Z"}, "To": {"DayOfWeek": "Tuesday", "TimeOfDay": "1:33:36+02:50"}}, "ServiceDuration": 200}]' \
--destination -123.095185 49.263728 \
--departure-time "2024-10-25T18:13:42Z" \
--travel-mode "Car"
```

------