リクエスト メッセージを作成する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
ルート最適化の概要で簡単に説明したように、基本的なリクエストは、必要なエンティティとして モデル、配送、車両で構成されます。
- モデルは、
Shipments
と Vehicles
の両方を含む、リクエスト全体の制約と設定をキャプチャします。
- Shipments は、集荷と配送の
VisitRequest
を含むタスクまたは実際の配送を表します。配送にはローカル設定と制約があります。
- 車両は、車両、運転手、人員を表します。車両にはローカル設定と制約もあります。
各エンティティのプロパティは、特定の粒度レベルで最適化問題の一部を記述します。モデル全体の制約はすべての配送と車両に適用されますが、配送または車両で指定された制約とプロパティは、単一の配送または車両に固有のものです。
各メッセージ タイプの完全なドキュメントについては、ShipmentModel
(REST、gRPC)、Shipment
(REST、gRPC)、Vehicle
(REST、gRPC)メッセージのリファレンス ドキュメントをご覧ください。
OptimizeToursRequest
件の宿泊施設
最上位の OptimizeToursRequest
メッセージ(REST、gRPC)でよく使用されるプロパティには、次のものがあります。
searchMode
は、指定された制約を満たす最初の解決策を返すか、設定された期限内に可能な限り最適な解決策を見つけるかを示します。
considerRoadTraffic
は、ルート検索と到着予定時刻の推定にリアルタイムの交通情報を使用するかどうかを決定します。
populateTransitionPolylines
は、レスポンスでルートのポリラインとルートトークンが返されるかどうかを決定します。
モデル プロパティ
ShipmentModel
メッセージ(REST、gRPC)で一般的に使用されるプロパティは次のとおりです。
globalStartTime
は、すべての車両と配送のルートの最も早い開始時刻を表します。この時間より前に、車両の最初の移行と出荷を開始することはできません。
globalEndTime
は、すべての車両と配送のルートの最新の終了時刻を表します。割り当てられたすべての配送と移行は、この時間までに完了している必要があります。
配送プロパティ
Shipment
メッセージ(REST、gRPC)で一般的に使用されるプロパティは次のとおりです。
pickups[]
と deliveries[]
は、荷物の受け取りまたは配達場所を表します。pickups[]
プロパティと deliveries[]
プロパティはどちらも VisitRequest
メッセージ(REST、gRPC)を使用します。
loadDemands
は、車両が配送を完了するために必要な積載量を示します。車両の対応する load_limits
(REST、gRPC)プロパティは、車両が一度に収容できる負荷の量を示します。負荷の詳細については、負荷の需要と上限をご覧ください。
penalty_cost
は、配送をスキップした場合に発生する費用を表します。費用の詳細については、費用モデルのパラメータをご覧ください。
車両プロパティ
Vehicle
メッセージ(REST、gRPC)で一般的に使用されるプロパティは次のとおりです。
startLocation
は、車両がルートを開始する必要がある場所を表します。このプロパティは省略可能です。指定しない場合、車両のルートは最初に割り当てられた荷物の場所から開始されます。
endLocation
は、車両がルートを終了する必要がある場所を表します。このプロパティは省略可能です。指定しない場合、車両のルートは最後に割り当てられた荷物の場所で終了します。
startTimeWindows[]
は、車両がルートを開始できる時刻を表します。このプロパティは省略可能です。
endTimeWindows[]
は、車両がルートを開始および終了できる時刻を表します。どちらのプロパティも省略可能です。
loadLimits
は、荷物の積載需要を満たすために利用可能な車両の容量を表します。負荷の需要と上限については、負荷の需要と上限をご覧ください。
JSON 形式の完全なリクエストの例は次のようになります。
{
"model": {
"shipments": [
{
"pickups": [
{
"arrivalLocation": {
"latitude": 37.73881799999999,
"longitude": -122.4161
}
}
],
"deliveries": [
{
"arrivalLocation": {
"latitude": 37.79581,
"longitude": -122.4218856
}
}
]
}
],
"vehicles": [
{
"startLocation": {
"latitude": 37.73881799999999,
"longitude": -122.4161
},
"endLocation": {
"latitude": 37.73881799999999,
"longitude": -122.4161
},
"costPerKilometer": 1.0
}
],
"globalStartTime": "2024-02-13T00:00:00.000Z",
"globalEndTime": "2024-02-14T06:00:00.000Z"
}
}
OptimizeTours
と BatchOptimizeTours
はどちらも上記の例のようなリクエスト メッセージを消費しますが、その方法は異なります。ルート最適化リクエストを行う前に、次の 2 つの方法の違いを理解しておくことが重要です。
OptimizeTours と BatchOptimizeTours の比較
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-09-04 UTC。
[null,null,["最終更新日 2025-09-04 UTC。"],[[["\u003cp\u003eRoute Optimization requests require defining a \u003ccode\u003eModel\u003c/code\u003e with \u003ccode\u003eShipments\u003c/code\u003e and \u003ccode\u003eVehicles\u003c/code\u003e to represent the optimization problem.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eModel\u003c/code\u003e sets global parameters, while \u003ccode\u003eShipments\u003c/code\u003e and \u003ccode\u003eVehicles\u003c/code\u003e have individual properties and constraints for pickups, deliveries, loads, and time windows.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eOptimizeToursRequest\u003c/code\u003e allows controlling the search mode, traffic considerations, and response details.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eOptimizeTours\u003c/code\u003e and \u003ccode\u003eBatchOptimizeTours\u003c/code\u003e offer synchronous and asynchronous request processing, respectively, with key differences in handling large or complex scenarios.\u003c/p\u003e\n"],["\u003cp\u003eYou can specify global start and end times for all vehicles and shipments within the \u003ccode\u003eShipmentModel\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Construct a request message\n\n**European Economic Area (EEA) developers** If your billing address is in the European Economic Area, effective on 8 July 2025, the [Google Maps Platform EEA Terms of Service](https://cloud.google.com/terms/maps-platform/eea) will apply to your use of the Services. Functionality varies by region. [Learn more](/maps/comms/eea/faq).\n\nAs briefly described in [Route Optimization Overview](/maps/documentation/route-optimization/overview), a basic request\nconsists of **Model** , **Shipments** , and **Vehicles** as required entities:\n\n- **Model** captures settings and constraints for the entire request, inclusive of both `Shipments` and `Vehicles`.\n- **Shipments** represent tasks or actual shipments that include pickup and delivery `VisitRequest`s. Shipments have local settings and constraints.\n- **Vehicles** represent vehicles, drivers, or personnel. Vehicles also have local settings and constraints.\n\nEach entity's properties describe part of an optimization problem at a\nparticular level of granularity. Model-wide constraints are applied to all\nshipments and vehicles, while constraints and properties specified on shipments\nor vehicles are specific to a single shipment or vehicle.\n\nFor complete documentation on each message type, see the reference documentation\nfor `ShipmentModel` ([REST](/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel), [gRPC](/maps/documentation/route-optimization/reference/rpc/google.maps.routeoptimization.v1#google.maps.routeoptimization.v1.ShipmentModel)), `Shipment` ([REST](/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel#Shipment), [gRPC](/maps/documentation/route-optimization/reference/rpc/google.maps.routeoptimization.v1#google.maps.routeoptimization.v1.Shipment)),\nand `Vehicle` ([REST](/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel#Vehicle), [gRPC](/maps/documentation/route-optimization/reference/rpc/google.maps.routeoptimization.v1#google.maps.routeoptimization.v1.Vehicle)) messages.\n\n`OptimizeToursRequest` properties\n---------------------------------\n\nSome commonly used properties of the top-level `OptimizeToursRequest` message\n([REST](/maps/documentation/route-optimization/reference/rest/v1/projects/optimizeTours), [gRPC](/maps/documentation/route-optimization/reference/rpc/google.maps.routeoptimization.v1#google.maps.routeoptimization.v1.OptimizeToursRequest)) include the following:\n\n- `searchMode` indicates whether to return the first solution that satisfies specified constraints or find the best possible solution within a set deadline.\n- `considerRoadTraffic` determines whether or not live traffic is used for routing and ETA estimation.\n- `populateTransitionPolylines` determines whether or not route polylines and route tokens are returned in the response.\n\nModel properties\n----------------\n\nSome commonly used properties of the `ShipmentModel` message ([REST](/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel),\n[gRPC](/maps/documentation/route-optimization/reference/rpc/google.maps.routeoptimization.v1#google.maps.routeoptimization.v1.ShipmentModel)) include:\n\n- `globalStartTime` represents the earliest start time of routes across all vehicles and shipments. No vehicle may start its first transitions and shipments before this time.\n- `globalEndTime` represents the latest end time of routes across all vehicles and shipments. All assigned shipments and transitions must be complete before this time.\n\nShipment properties\n-------------------\n\nSome commonly used properties of the `Shipment` message ([REST](/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel#Shipment), [gRPC](/maps/documentation/route-optimization/reference/rpc/google.maps.routeoptimization.v1#google.maps.routeoptimization.v1.Shipment))\ninclude:\n\n- `pickups[]` and `deliveries[]` represent where a shipment can be picked up or dropped off. `pickups[]` and `deliveries[]` properties both use the `VisitRequest` message ([REST](/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel#VisitRequest), [gRPC](/maps/documentation/route-optimization/reference/rpc/google.maps.routeoptimization.v1#google.maps.routeoptimization.v1.Shipment.VisitRequest)).\n- `loadDemands` represent the load required for a vehicle to complete a shipment. Vehicles' corresponding `load_limits` ([REST](/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel#Vehicle.FIELDS.load_limits), [gRPC](/maps/documentation/route-optimization/reference/rpc/google.maps.routeoptimization.v1#google.maps.routeoptimization.v1.Vehicle.FIELDS.repeated.google.maps.routeoptimization.v1.Vehicle.LoadLimitsEntry.google.maps.routeoptimization.v1.Vehicle.load_limits)) property represents how much load a vehicle can accommodate at one time. Read more about load in [Load Demands and Limits](/maps/documentation/route-optimization/load-demands-limits).\n- `penalty_cost` represents the cost incurred if a shipment is skipped. Read more on costs in [Cost Model Parameters](/maps/documentation/route-optimization/cost-model).\n\nVehicle properties\n------------------\n\nSome commonly used properties of the `Vehicle` message ([REST](/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel#Vehicle), [gRPC](/maps/documentation/route-optimization/reference/rpc/google.maps.routeoptimization.v1#google.maps.routeoptimization.v1.Vehicle))\ninclude:\n\n- `startLocation` represents where a vehicle must start its route. This property is optional. If not specified, the vehicle's route starts at the location of its first assigned shipment.\n- `endLocation` represents where a vehicle must end its route. This property is optional. If not specified, the vehicle's route ends at the location of its last assigned shipment.\n- `startTimeWindows[]` represents when a vehicle can start its route. This property is optional.\n- `endTimeWindows[]` represents when a vehicle can start and end its route. Both properties are optional.\n- `loadLimits` represent the vehicle's capacity available to meet shipments' load demands. Read more about load demands and limits in [Load Demands and\n Limits](/maps/documentation/route-optimization/load-demands-limits).\n\nA complete example request in JSON format looks like: \n\n {\n \"model\": {\n \"shipments\": [\n {\n \"pickups\": [\n {\n \"arrivalLocation\": {\n \"latitude\": 37.73881799999999,\n \"longitude\": -122.4161\n }\n }\n ],\n \"deliveries\": [\n {\n \"arrivalLocation\": {\n \"latitude\": 37.79581,\n \"longitude\": -122.4218856\n }\n }\n ]\n }\n ],\n \"vehicles\": [\n {\n \"startLocation\": {\n \"latitude\": 37.73881799999999,\n \"longitude\": -122.4161\n },\n \"endLocation\": {\n \"latitude\": 37.73881799999999,\n \"longitude\": -122.4161\n },\n \"costPerKilometer\": 1.0\n }\n ],\n \"globalStartTime\": \"2024-02-13T00:00:00.000Z\",\n \"globalEndTime\": \"2024-02-14T06:00:00.000Z\"\n }\n }\n\n`OptimizeTours` and `BatchOptimizeTours` both consume request messages like the\nexample above, but in different ways. Before making a Route Optimization\nrequest, it's important to understand the difference between the two methods:\n\n[Comparing OptimizeTours and BatchOptimizeTours](/maps/documentation/route-optimization/sync-vs-async)"]]