Skip to content

optimize_waypoints

optimize_waypoints(
    origin: Position,
    *,
    config_overrides: Optional[GeoRoutesClientConfig] = None,
    avoid: Optional[WaypointOptimizationAvoidanceOptions] = None,
    clustering: Optional[WaypointOptimizationClusteringOptions] = None,
    departure_time: Optional[TimestampWithTimezoneOffset] = None,
    destination: Optional[Position] = None,
    destination_options: Optional[WaypointOptimizationDestinationOptions] = None,
    driver: Optional[WaypointOptimizationDriverOptions] = None,
    exclude: Optional[WaypointOptimizationExclusionOptions] = None,
    key: Optional[ApiKey] = None,
    optimize_sequencing_for: Optional[WaypointOptimizationSequencingObjective] = None,
    origin_options: Optional[WaypointOptimizationOriginOptions] = None,
    traffic: Optional[WaypointOptimizationTrafficOptions] = None,
    travel_mode: Optional[WaypointOptimizationTravelMode] = None,
    travel_mode_options: Optional[WaypointOptimizationTravelModeOptions] = None,
    waypoints: Optional[WaypointOptimizationWaypointList] = None,
) -> OptimizeWaypointsResponse

OptimizeWaypoints calculates the optimal order to travel between a set of waypoints to minimize either the travel time or the distance travelled during the journey, based on road network restrictions and the traffic pattern data.

For more information, see Optimize waypoints in the Amazon Location Service Developer Guide.

Parameters:

Raises:

Source code in docs_src/capo_geo_routes/_services/geo_routes.py
def optimize_waypoints(
    self,
    origin: "capo_geo_routes.types.position.Position",
    *,
    config_overrides: Optional[GeoRoutesClientConfig] = None,
    avoid: Optional[
        "capo_geo_routes.types.waypoint_optimization_avoidance_options.WaypointOptimizationAvoidanceOptions"
    ] = None,
    clustering: Optional[
        "capo_geo_routes.types.waypoint_optimization_clustering_options.WaypointOptimizationClusteringOptions"
    ] = None,
    departure_time: Optional[
        "capo_geo_routes.types.timestamp_with_timezone_offset.TimestampWithTimezoneOffset"
    ] = None,
    destination: Optional["capo_geo_routes.types.position.Position"] = None,
    destination_options: Optional[
        "capo_geo_routes.types.waypoint_optimization_destination_options.WaypointOptimizationDestinationOptions"
    ] = None,
    driver: Optional[
        "capo_geo_routes.types.waypoint_optimization_driver_options.WaypointOptimizationDriverOptions"
    ] = None,
    exclude: Optional[
        "capo_geo_routes.types.waypoint_optimization_exclusion_options.WaypointOptimizationExclusionOptions"
    ] = None,
    key: Optional["capo_geo_routes.types.api_key.ApiKey"] = None,
    optimize_sequencing_for: Optional[
        "capo_geo_routes.types.waypoint_optimization_sequencing_objective.WaypointOptimizationSequencingObjective"
    ] = None,
    origin_options: Optional[
        "capo_geo_routes.types.waypoint_optimization_origin_options.WaypointOptimizationOriginOptions"
    ] = None,
    traffic: Optional[
        "capo_geo_routes.types.waypoint_optimization_traffic_options.WaypointOptimizationTrafficOptions"
    ] = None,
    travel_mode: Optional[
        "capo_geo_routes.types.waypoint_optimization_travel_mode.WaypointOptimizationTravelMode"
    ] = None,
    travel_mode_options: Optional[
        "capo_geo_routes.types.waypoint_optimization_travel_mode_options.WaypointOptimizationTravelModeOptions"
    ] = None,
    waypoints: Optional[
        "capo_geo_routes.types.waypoint_optimization_waypoint_list.WaypointOptimizationWaypointList"
    ] = None,
) -> "capo_geo_routes.types.optimize_waypoints_response.OptimizeWaypointsResponse":
    """<p> <code>OptimizeWaypoints</code> calculates the optimal order to travel between a set of waypoints to minimize either the travel time or the distance travelled during the journey, based on road network restrictions and the traffic pattern data.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/location/latest/developerguide/actions-optimize-waypoints.html">Optimize waypoints</a> in the <i>Amazon Location Service Developer Guide</i>.</p>

    Args:
        avoid: <p>Features that are avoided. Avoidance is on a best-case basis. If an avoidance can't be satisfied for a particular case, this setting is ignored.</p>
        clustering: <p>Clustering allows you to specify how nearby waypoints can be clustered to improve the optimized sequence.</p>
        departure_time: <p>Departure time from the waypoint.</p> <p>Time format:<code>YYYY-MM-DDThh:mm:ss.sssZ | YYYY-MM-DDThh:mm:ss.sss+hh:mm</code> </p> <p>Examples:</p> <p> <code>2020-04-22T17:57:24Z</code> </p> <p> <code>2020-04-22T17:57:24+02:00</code> </p>
        destination: <p>The final position for the route in the World Geodetic System (WGS 84) format: <code>[longitude, latitude]</code>.</p>
        destination_options: <p>Destination related options.</p>
        driver: <p>Driver related options.</p>
        exclude: <p>Features to be strictly excluded while calculating the route.</p>
        key: <p>Optional: The API key to be used for authorization. Either an API key or valid SigV4 signature must be provided when making a request. </p>
        optimize_sequencing_for: <p>Specifies the optimization criteria for the calculated sequence.</p> <p>Default value: <code>FastestRoute</code>.</p>
        origin: <p>The start position for the route in World Geodetic System (WGS 84) format: [longitude, latitude].</p>
        origin_options: <p>Origin related options.</p>
        traffic: <p>Traffic-related options.</p>
        travel_mode: <p>Specifies the mode of transport when calculating a route. Used in estimating the speed of travel and road compatibility.</p> <p>Default value: <code>Car</code> </p>
        travel_mode_options: <p>Travel mode related options for the provided travel mode.</p>
        waypoints: <p>List of waypoints between the <code>Origin</code> and <code>Destination</code>, in World Geodetic System (WGS 84) format: [longitude, latitude].</p> <p>The maximum number of waypoints allowed per request:</p> <ul> <li> <p>Maximum 50 waypoints per request</p> </li> <li> <p>Maximum 20 waypoints when using constraints (<code>AccessHours</code>, <code>AppointmentTime</code>, <code>ServiceDuration</code>, <code>Heading</code>, <code>SideOfStreet</code>, <code>Before</code>)</p> </li> </ul>

    Raises:
        capo_geo_routes.errors.access_denied_exception.AccessDeniedException: <p>You don't have sufficient access to perform this action.</p>
        capo_geo_routes.errors.internal_server_exception.InternalServerException: <p>The request processing has failed because of an unknown error, exception or failure.</p>
        capo_geo_routes.errors.throttling_exception.ThrottlingException: <p>The request was denied due to request throttling.</p>
        capo_geo_routes.errors.validation_exception.ValidationException: <p>The input fails to satisfy the constraints specified by an AWS service.</p>
        capo_geo_routes.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_geo_routes.types.optimize_waypoints_request.OptimizeWaypointsRequest]",
    ) -> OperationResponse[
        "capo_geo_routes.types.optimize_waypoints_response.OptimizeWaypointsResponse"
    ]:
        import capo_geo_routes._operations.routes_service.optimize_waypoints

        output, http_response = (
            capo_geo_routes._operations.routes_service.optimize_waypoints.optimize_waypoints(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_geo_routes.types.optimize_waypoints_request.OptimizeWaypointsRequest",
    ) -> dict[str, Any]:
        import capo_geo_routes.types.optimize_waypoints_request

        return capo_geo_routes.types.optimize_waypoints_request.redact_sensitive(
            input_
        )

    def _redact_output(
        output: "capo_geo_routes.types.optimize_waypoints_response.OptimizeWaypointsResponse",
    ) -> dict[str, Any]:
        import capo_geo_routes.types.optimize_waypoints_response

        return capo_geo_routes.types.optimize_waypoints_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "OptimizeWaypoints",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_geo_routes.types.optimize_waypoints_request.OptimizeWaypointsRequest = {
        "origin": origin
    }
    if avoid is not None:
        input_["avoid"] = avoid
    if clustering is not None:
        input_["clustering"] = clustering
    if departure_time is not None:
        input_["departure_time"] = departure_time
    if destination is not None:
        input_["destination"] = destination
    if destination_options is not None:
        input_["destination_options"] = destination_options
    if driver is not None:
        input_["driver"] = driver
    if exclude is not None:
        input_["exclude"] = exclude
    if key is not None:
        input_["key"] = key
    if optimize_sequencing_for is not None:
        input_["optimize_sequencing_for"] = optimize_sequencing_for
    if origin_options is not None:
        input_["origin_options"] = origin_options
    if traffic is not None:
        input_["traffic"] = traffic
    if travel_mode is not None:
        input_["travel_mode"] = travel_mode
    if travel_mode_options is not None:
        input_["travel_mode_options"] = travel_mode_options
    if waypoints is not None:
        input_["waypoints"] = waypoints

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output