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 中,则允许车辆通行。
如果注入的解决方案不可行,则不一定会返回验证错误,而可能会返回指示不可行性的错误。
|
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
如果设置此属性,则请求的截止时间(请参阅 https://grpc.io/blog/deadlines)最长为 60 分钟。否则,最长期限只有 30 分钟。请注意,长时间运行的请求中断的风险要高得多(但仍然很小)。
|
useGeodesicDistances |
boolean
如果为 true,系统将使用测地距离(而非 Google 地图距离)计算行程距离,并使用由 geodesicMetersPerSecond 定义的速度的测地距离计算行程时间。
|
label |
string
可用于识别此请求的标签,会在 OptimizeToursResponse.request_label 中报告。
|
geodesicMetersPerSecond |
number
当 useGeodesicDistances 为 true 时,必须设置此字段并定义用于计算行程时间的速度。其值必须至少为 1.0 米/秒。
|
maxValidationErrors |
integer
截断返回的验证错误数。这些错误通常作为 BadRequest 错误详情 (https://cloud.google.com/apis/design/errors#error_details) 附加到 INVALID_ARGUMENT 错误负载,除非 SolveMode=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-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThe Route Optimization API minimizes the total cost of routes by assigning \u003ccode\u003eShipmentRoute\u003c/code\u003es to \u003ccode\u003eVehicle\u003c/code\u003es.\u003c/p\u003e\n"],["\u003cp\u003eThe API takes an \u003ccode\u003eOptimizeToursRequest\u003c/code\u003e with a \u003ccode\u003eShipmentModel\u003c/code\u003e and returns an \u003ccode\u003eOptimizeToursResponse\u003c/code\u003e with \u003ccode\u003eShipmentRoute\u003c/code\u003es.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eShipmentModel\u003c/code\u003e defines the \u003ccode\u003eShipment\u003c/code\u003es to be transported, the \u003ccode\u003eVehicle\u003c/code\u003es available, and the cost components.\u003c/p\u003e\n"],["\u003cp\u003eThe API considers various factors, including traffic, time windows, and vehicle capacities, to optimize the routes.\u003c/p\u003e\n"],["\u003cp\u003eAuthorization is required using OAuth scope \u003ccode\u003ehttps://www.googleapis.com/auth/cloud-platform\u003c/code\u003e and IAM permission \u003ccode\u003erouteoptimization.locations.use\u003c/code\u003e.\u003c/p\u003e\n"]]],["This content details the `OptimizeTours` API, which optimizes routes for shipments using vehicles. The core action involves sending a `POST` request to `https://routeoptimization.googleapis.com/v1/{parent=projects/*}:optimizeTours`, specifying a `ShipmentModel` within the request body. This model defines shipments, vehicles, and cost parameters. The API returns an `OptimizeToursResponse` that details `ShipmentRoute`s, assigning visits to each vehicle to minimize costs. The request body allows for parameters like `timeout`, `solvingMode`, and `injectedSolutionConstraint` to further fine-tune the route optimization process.\n"],null,[]]