Method: projects.locations.optimizeTours
发送包含 ShipmentModel
的 OptimizeToursRequest
,并返回包含 ShipmentRoute
的 OptimizeToursResponse
,这些 ShipmentRoute
是车辆执行的一组路线,可最大限度地降低总费用。
ShipmentModel
模型主要由需要执行的 Shipment
和可用于传输 Shipment
的 Vehicle
组成。ShipmentRoute
会将 Shipment
分配给 Vehicle
。更具体地说,它们会为每辆车分配一系列 Visit
,其中 Visit
对应于 VisitRequest
,即 Shipment
的接送点。
目标是为 ShipmentRoute
分配 Vehicle
,以最大限度地降低总费用,其中费用在 ShipmentModel
中定义了许多组成部分。
HTTP 请求
POST https://routeoptimization.googleapis.com/v1/{parent=projects/*/locations/*}:optimizeTours
网址采用 gRPC 转码语法。
路径参数
参数 |
parent |
string
必需。定位项目或位置以进行呼叫。 格式:* projects/{project-id} * projects/{project-id}/locations/{location-id} 如果未指定位置,则系统将自动选择区域。
|
请求正文
请求正文中包含结构如下的数据:
JSON 表示法 |
{
"timeout": string,
"model": {
object (ShipmentModel )
},
"solvingMode": enum (SolvingMode ),
"searchMode": enum (SearchMode ),
"injectedFirstSolutionRoutes": [
{
object (ShipmentRoute )
}
],
"injectedSolutionConstraint": {
object (InjectedSolutionConstraint )
},
"refreshDetailsRoutes": [
{
object (ShipmentRoute )
}
],
"interpretInjectedSolutionsUsingLabels": boolean,
"considerRoadTraffic": boolean,
"populatePolylines": boolean,
"populateTransitionPolylines": boolean,
"allowLargeDeadlineDespiteInterruptionRisk": boolean,
"useGeodesicDistances": boolean,
"label": string,
"geodesicMetersPerSecond": number,
"maxValidationErrors": integer
} |
字段 |
timeout |
string (Duration format)
如果设置此超时,服务器会在超时期限或同步请求的服务器截止时间(以较早者为准)到达之前返回响应。 对于异步请求,服务器会在超时之前生成解决方案(如果可能)。 该时长以秒为单位,最多包含九个小数位,以“s ”结尾。示例:"3.5s" 。
|
model |
object (ShipmentModel )
要解决的配送模型。
|
solvingMode |
enum (SolvingMode )
默认情况下,求解模式为 DEFAULT_SOLVE (0)。
|
searchMode |
enum (SearchMode )
用于解决请求的搜索模式。
|
injectedFirstSolutionRoutes[] |
object (ShipmentRoute )
引导优化算法找到与上一个解决方案类似的第一个解决方案。 在构建第一个解决方案时,模型会受到约束。在第一个解决方案中,系统会隐式跳过未在某个路线上执行的任何配送,但可能会在后续解决方案中执行这些配送。 该解决方案必须满足一些基本有效性假设:
- 对于所有路线,
vehicleIndex 必须在范围内且不得重复。
- 对于所有访问,
shipmentIndex 和 visitRequestIndex 都必须在范围内。
- 一个运输服务只能在一条路线中引用。
- 必须先取件,然后才能送货。
- 一笔发货只能执行一次自提替代方案或送货替代方案。
- 所有路线的时间都在增加(即
vehicleStartTime
<= visits[0].start_time <= visits[1].start_time ...
<= vehicleEndTime )。
- 只能使用允许的车辆进行运输。如果
Shipment.allowed_vehicle_indices 为空或其 vehicleIndex 包含在 Shipment.allowed_vehicle_indices 中,则允许相应车辆。
如果注入的解决方案不可行,则不一定会返回验证错误,而可能会返回指示不可行性的错误。
|
injectedSolutionConstraint |
object (InjectedSolutionConstraint )
限制优化算法,以找到与上一个解决方案类似的最终解决方案。例如,这可用于冻结已完成或将要完成但不得修改的路线的部分。 如果注入的解决方案不可行,则不一定会返回验证错误,而可能会返回指示不可行性的错误。
|
refreshDetailsRoutes[] |
object (ShipmentRoute )
如果不为空,系统会刷新给定路线,而不会更改其底层的访问顺序或行程时间:只有其他详细信息会更新。这并不能解决模型问题。 自 2020 年 11 月起,此方法仅填充非空路线的多段线,并且要求 populatePolylines 为 true。 传入路线的 routePolyline 字段可能与路线 transitions 不一致。 此字段不得与 injectedFirstSolutionRoutes 或 injectedSolutionConstraint 一起使用。 Shipment.ignore 和 Vehicle.ignore 对此行为没有影响。无论是否忽略相关运输或车辆,系统仍会在所有非空路线中的所有访问之间填充多段线。
|
interpretInjectedSolutionsUsingLabels |
boolean
如果为真:
此解释适用于 injectedFirstSolutionRoutes 、injectedSolutionConstraint 和 refreshDetailsRoutes 字段。如果请求中的运输或车辆编号自解决方案创建以来发生了变化(可能是因为运输或车辆已从请求中移除或添加到请求中),则可以使用此参数。 如果为 true,则以下类别中的标签在其类别中最多只能显示一次:
如果注入的解决方案中的 vehicleLabel 与请求车辆不符,相应的路线及其访问次数会从解决方案中移除。如果注入的解决方案中的 shipmentLabel 与请求发货不符,系统会从解决方案中移除相应的访问。如果注入的解决方案中的 SkippedShipment.label 与请求的运单不符,系统会从解决方案中移除 SkippedShipment 。 从注入的解决方案中移除路线访问或整个路线可能会影响隐含约束条件,从而导致解决方案发生变化、出现验证错误或不可行。 注意:调用方必须确保每个 Vehicle.label (resp. Shipment.label )用于唯一标识两个相关请求(即生成注入解决方案中所用 OptimizeToursResponse 的过往请求,以及包含注入解决方案的当前请求)中使用的车辆(或运输)实体。上述唯一性检查不足以保证这一要求。
|
considerRoadTraffic |
boolean
在计算 ShipmentRoute 字段 Transition.travel_duration 、Visit.start_time 和 vehicleEndTime ;设置 ShipmentRoute.has_traffic_infeasibilities 字段;以及计算 OptimizeToursResponse.total_cost 字段时,请考虑流量估算。
|
populatePolylines |
boolean
如果为 true,系统会在响应 ShipmentRoute 中填充多段线。
|
populateTransitionPolylines |
boolean
如果为 true,系统会在响应 ShipmentRoute.transitions 中填充多段线和路线令牌。
|
allowLargeDeadlineDespiteInterruptionRisk |
boolean
如果设置此值,则请求可以设置最长 60 分钟的截止期限(请参阅 https://grpc.io/blog/deadlines)。否则,最长期限只有 30 分钟。请注意,长时间运行的请求中断的风险要高得多(但仍然很小)。
|
useGeodesicDistances |
boolean
如果为 true,则将使用地面距离(而非 Google 地图距离)计算行程距离,并使用由 geodesicMetersPerSecond 定义的速度计算行程时间。
|
label |
string
可用于标识此请求的标签,会在 OptimizeToursResponse.request_label 中报告回来。
|
geodesicMetersPerSecond |
number
当 useGeodesicDistances 为 true 时,必须设置此字段,并定义用于计算行程时间的速度。其值必须至少为 1.0 米/秒。
|
maxValidationErrors |
integer
截断返回的验证错误数量。这些错误通常附加到 INVALID_ARGUMENT 错误载荷中,作为 BadRequest 错误详情 (https://cloud.google.com/apis/design/errors#error_details),除非 solvingMode=VALIDATE_ONLY:请参阅 OptimizeToursResponse.validation_errors 字段。此值的默认值为 100,上限为 10,000。
|
响应正文
如果成功,则响应正文包含一个 OptimizeToursResponse
实例。
授权范围
需要以下 OAuth 范围:
https://www.googleapis.com/auth/cloud-platform
IAM 权限
需要拥有 parent
资源的以下 IAM 权限:
routeoptimization.locations.use
如需了解详情,请参阅 IAM 文档。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-12-22。
[null,null,["最后更新时间 (UTC):2024-12-22。"],[[["Sends an `OptimizeToursRequest` and returns an `OptimizeToursResponse` containing optimized `ShipmentRoute`s for a given `ShipmentModel` and `Vehicle`s."],["The service aims to minimize the total cost of routes by assigning `Shipment`s to `Vehicle`s and optimizing their `Visit` sequences."],["Request body includes parameters to guide the optimization process such as timeout, model, solving mode, search mode, and constraints."],["The response contains the optimized routes, including details like polylines, travel durations, and total cost."],["Requires the `https://www.googleapis.com/auth/cloud-platform` OAuth scope and `routeoptimization.locations.use` IAM permission."]]],["This content describes the `OptimizeTours` API, which optimizes routes for shipments using vehicles. A `POST` request is sent to `https://routeoptimization.googleapis.com/v1/{parent=projects/*/locations/*}:optimizeTours`. The request body includes a `ShipmentModel` specifying shipments and vehicles. The API then generates an `OptimizeToursResponse` with `ShipmentRoute`s, assigning `Visit`s (pickups/deliveries) to each vehicle to minimize total cost. Optional parameters allow traffic consideration, polyline population, and injected solution constraints. Authorization requires cloud platform scope and IAM permissions.\n"]]