Method: projects.optimizeTours
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
发送包含 ShipmentModel
的 OptimizeToursRequest
,并返回包含 ShipmentRoute
的 OptimizeToursResponse
,这些 ShipmentRoute
是车辆执行的一组路线,可最大限度地降低总费用。
ShipmentModel
模型主要由需要执行的 Shipment
和可用于传输 Shipment
的 Vehicle
组成。ShipmentRoute
会将 Shipment
分配给 Vehicle
。更具体地说,它们为每辆车分配了一系列 Visit
,其中 Visit
对应于 VisitRequest
,即 Shipment
的取货或送货服务。
目标是为 Vehicle
分配 ShipmentRoute
,从而最大限度地降低总费用,因为 ShipmentModel
中定义了许多组件。
HTTP 请求
POST https://routeoptimization.googleapis.com/v1/{parent=projects/*}: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 中,则允许车辆通行。
- 如果将
avoidUTurns 设置为 true,则必须针对相关访问设置 injectedSolutionLocationToken
如果注入的解决方案不可行,则不一定会返回验证错误,而可能会返回指示不可行性的错误。
|
injectedSolutionConstraint |
object (InjectedSolutionConstraint )
限制优化算法以找到与先前解决方案类似的最终解决方案。例如,这可用于冻结已完成或即将完成但不得修改的路线部分。 如果注入的解决方案不可行,则不一定会返回验证错误,而可能会返回指示不可行性的错误。
|
refreshDetailsRoutes[] |
object (ShipmentRoute )
如果不为空,则将刷新给定路线,而不修改其基本访问顺序或行程时间:仅更新其他详细信息。这并不能解决模型问题。 自 2020 年 11 月起,此方法仅会填充非空路线的多段线,并要求 populatePolylines 为 true。 传入路由的 routePolyline 字段可能与路由 transitions 不一致。 此字段不得与 injectedFirstSolutionRoutes 或 injectedSolutionConstraint 一起使用。 Shipment.ignore 和 Vehicle.ignore 对此行为没有影响。无论相关货运或车辆是否被忽略,所有非空路线中的所有访问之间仍会填充多段线。
|
interpretInjectedSolutionsUsingLabels |
boolean
如果为 true:
这种解释适用于 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):2025-08-29。
[null,null,["最后更新时间 (UTC):2025-08-29。"],[[["\u003cp\u003eThis API optimizes delivery routes by sending an \u003ccode\u003eOptimizeToursRequest\u003c/code\u003e with a \u003ccode\u003eShipmentModel\u003c/code\u003e, and it returns an \u003ccode\u003eOptimizeToursResponse\u003c/code\u003e that includes \u003ccode\u003eShipmentRoute\u003c/code\u003es, which outline the routes for vehicles to minimize cost.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eShipmentModel\u003c/code\u003e includes \u003ccode\u003eShipment\u003c/code\u003es that require transport and \u003ccode\u003eVehicle\u003c/code\u003es available for use, with the goal being to assign \u003ccode\u003eShipmentRoute\u003c/code\u003es to \u003ccode\u003eVehicle\u003c/code\u003es efficiently to reduce overall cost.\u003c/p\u003e\n"],["\u003cp\u003eThe HTTP request uses a \u003ccode\u003ePOST\u003c/code\u003e method to the \u003ccode\u003ehttps://routeoptimization.googleapis.com/v1/{parent=projects/*}:optimizeTours\u003c/code\u003e endpoint, utilizing gRPC Transcoding syntax, and requiring the \u003ccode\u003eparent\u003c/code\u003e parameter to specify the project or location.\u003c/p\u003e\n"],["\u003cp\u003eThe request body includes fields such as \u003ccode\u003etimeout\u003c/code\u003e, \u003ccode\u003emodel\u003c/code\u003e, \u003ccode\u003esolvingMode\u003c/code\u003e, and \u003ccode\u003esearchMode\u003c/code\u003e, allowing for customization of the optimization process, and other parameters related to route details, and injected solutions.\u003c/p\u003e\n"],["\u003cp\u003eThe API requires the \u003ccode\u003ehttps://www.googleapis.com/auth/cloud-platform\u003c/code\u003e OAuth scope and the \u003ccode\u003erouteoptimization.locations.use\u003c/code\u003e IAM permission on the parent resource for authorization.\u003c/p\u003e\n"]]],[],null,[]]