ガイドAPIリファレンス
ガイド

カスタムの時間距離マトリックスを実装する

ビジネスの特定の条件や要件を考慮したカスタムの時間距離マトリックスを実装することで、より正確で効率的な旅程計画を実現します。たとえば、特定のエリアに焦点を当てた配達サービスの場合、マトリックスは交通パターン、道路ネットワーク、地域別の配達優先度の観点から、そのエリアの実際の状況をより適切に反映できるため、運行管理全体に時間どおりの効率的なツアー計画を策定できます。

カスタムマトリックスは同期リクエストと非同期リクエストの両方に対応しているため、シンプルさと即時性を要求するものから、大型車両のルート検索問題を含む複雑なシナリオまで、幅広いビジネスユースケースで使用しやすくなっています。

📘

これはアルファ機能 (新規またはテスト段階であり、現在開発中) です。アルファ機能は、テストおよびフィードバックの目的で提供されています。これらは大幅に変更されたり、一般に入手できなくなったりする可能性があります。

詳細については、「テスト段階の機能の詳細」を参照してください。

カスタムマトリックスモデルを理解する

HERE Tour Planning APIの問題のJSONでは、非同期リクエストの場合はmatrixId値として、同期リクエストの場合はmatrixオブジェクトとして、カスタムマトリックスをfleet.profiles.matrixオブジェクト内にネストします。対応するユースケースについては、次のセクションを参照してください。

マトリックス例

次のスニペットは、matrixオブジェクトの例です。必須のoriginstravelTimesdistancesの配列と、任意のerrorCodes配列を含む必須の構造を示しています。

{
  "origins": [
    {"type": "id", "id": "location_1"},
    {"type": "id", "id": "location_2"},
    {"type": "id", "id": "location_3"},
    {"type": "id", "id": "location_4"},
    {"type": "id", "id": "location_5"},
    {"type": "id", "id": "location_6"}
  ],
  "travelTimes": [0, 200, 237, 475, 477, 325, 159, 0, 325, 563, 565, 382, 513, 495, 0, 238, 240, 516, 467, 449, 292, 0, 2, 455, 465, 447, 290, 2, 0, 453, 274, 256, 163, 401, 403, 0],
  "distances": [0, 1002, 1517, 3176, 3189, 1805, 881, 0, 2118, 3777, 3790, 2535, 3235, 3292, 0, 1659, 1672, 3322, 2903, 2960, 2029, 0, 13, 3062, 2890, 2947, 2016, 13, 0, 3049, 1465, 1522, 1367, 3026, 3039, 0],
  "errorCodes": [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
}

このマトリックス例には、origins配列のID文字列で参照される6つの場所が含まれています。さらに、マトリックスにはtravelTimesdistanceserrorCodesの配列が含まれており、origins配列内の場所間の最も効率的なルートを計算するのに役立ちます。

出発地

タイプオブジェクトの配列

この配列はマトリックスの場所の順序付けられたリストを表します。配列内の各オブジェクトには、次のプロパティが含まれます。

  • type:値は常にidです。
  • id:場所のIDを文字列で表したものです。

次のスニペットは、matrixオブジェクトの一部としてエンコードされた場所の例を示しています。

{
  "type": "id",
  "id": "location_1"
}
📘

カスタムマトリックスを使用する場合、HERE Tour Planning APIでは位置座標は不要になるため、プライバシーの法律や要件に準拠しやすくなります。ソリューションを受け取った後に、プログラムで位置IDをアプリケーション内の座標に関連付けて、ツアーを地図上にオーバーレイできます。

移動時間

タイプ整数のフラット配列

travelTimes配列は、origins配列の一部として指定された場所の、すべての2地点間の移動時間 (秒単位) を表します。

マトリックス構造と異なる場所間の関係をよりわかりやすく視覚化するために、次の表ではtravelTimes配列を1次元 (フラット) 構造から2次元構造に変換しています。次の2次元配列では、行は出発地を表し、列は目的地を表します。

出発地/Destinationlocation_1location_2location_3location_4location_5location_6
location_10200237475477325
location_21590325563565382
location_35134950238240516
location_446744929202455
location_546544729020453
location_62742561634014030

表で示されたとおり、たとえば、location_3からlocation_2への移動時間は495秒、location_2からlocation_4への移動時間は563秒です。また、同じIDを持つ場所間の移動時間は常に0秒です。

距離

タイプ整数のフラット配列

distances配列は、originsの場所の、すべての2地点間の距離 (メートル単位) を表します。

次の表では、前の例のdistances配列を1次元 (フラット) 構造から2次元構造に変換しています。

出発地/Destinationlocation_1location_2location_3location_4location_5location_6
location_1010021517317631891805
location_288102118377737902535
location_3323532920165916723322
location_42903296020290133062
location_52890294720161303049
location_6146515221367302630390

表で示されたとおり、たとえば、location_1からlocation_2までの距離は1002メートル、location_5からlocation_3までの距離は2016メートルです。また、同じIDを持つ場所間の距離は常に0メートルです。

任意:エラーコード

タイプ整数のフラット配列

このオプションの配列には、出発地と目的地の間のルートで発生した問題 (利用可能なルートの不足、違反など) のエラーコードが含まれます。次のエラーコード値が使用できます。

  • 0:エラーなし。ルートは利用可能です。
  • 1:出発地と目的地の間にルートが存在しません。
  • 2:出発地と目的地の間のルートには有効な開始地点または終了地点がありません。
  • 3:出発地と目的地の間のルートは存在しますが、使用できなくなる可能性のある違反が含まれています。
  • 4:出発地と目的地は、許容範囲のすぐ内側にあるか、完全に許容範囲外にあります。このため、出発地と目的地には有効なルートの開始地点または終了地点が存在しません。
  • 99:不明なエラー (デバッグおよび予期しない状況の処理用)。

詳細については、HERE Matrix RoutingのAPIリファレンスを参照してください。

次の表では、前の例のerrorCodes配列を1次元 (フラット) 構造から2次元構造に変換しています。

出発地/Destinationlocation_1location_2location_3location_4location_5location_6
location_1001000
location_2000000
location_3100000
location_4000000
location_5000000
location_6000000

errorCodes配列を2次元表示したこの表では、location_3からlocation_1へのルートとlocation_1からlocation_3へのルートが利用できないため、それぞれにエラーコード1が返されます。

フラットマトリックスのインデックス計算

distancestravelTimeserrorCodeの配列はフラットです。つまり1次元しかありません。シンプルで、パフォーマンスの点でもメリットのあるフラット配列は、操作しやすく、アクセスも高速です。

カスタムマトリックスでは、インデックス位置を計算することで、対応するフラット配列から任意の出発地と目的地の2地点間の距離、移動時間、エラーコードをすばやく取得できます。特定の距離、移動時間、エラーコード値のインデックス (k) を計算するには、次の式を使用します。

k = num_destinations × i + j

説明

  • num_destinationsoriginsの場所の数
  • iは行インデックス (出発地または開始地点)
  • jは列インデックス (目的地または終了地点)
  • kはフラット化された配列の1次元インデックス

この式は、出発地と目的地の2地点の行と列に基づいて、フラット配列内の正しい位置を見つけるのに役立ちます。たとえば、前に示したtravelTimes配列の例からlocation_4location_2間の移動時間を取得するには、次の式を使用します。

  • num_destinations=6 (origins配列には合計6つの場所があります)
  • i=3 (出発地location_4の0から始まる行インデックス)
  • j=1 (目的地location_2の0から始まる列インデックス)

したがって、次のようになります: k = 6 × 3 + 1 = 18 + 1 = 19

travelTimes配列のインデックス19に割り当てられる値は449秒で、これはlocation_4location_2の間の移動時間に対応します。

同期リクエストでカスタムマトリックスを実装する

同期リクエストでカスタムマトリックスを使用するには、matrixオブジェクトを対象の車両プロファイル内にネストします。カスタムマトリックスを特定の車両プロファイルに適用することで、その車両タイプ固有の特性に基づいて距離と移動時間を調整できます。

📘

同期リクエストには、次のカスタムマトリックス制限が適用されます。

  • 同期リクエストではmatrixIdを使用しないため、問題のJSONに完全なmatrixオブジェクトを含めて送信する必要があります。
  • 1回のリクエストにつき、送信できるカスタムマトリックスは1つのみです。

次のスニペットは、問題のJSONの例を示しています。この問題ではカスタムマトリックスを使用しているため、対応する位置idの値とともに指定する位置座標は任意パラメーターとなります。ジョブの位置座標は、たとえば、地域や会社のプライバシーポリシーに準拠するために省略できます。

Click to expand/collapse the sample JSON
{
  "fleet": {
    "types": [
      {
        "id": "car_1",
        "profile": "delivery_car",
        "costs": {
          "fixed": 10,
          "distance": 0.004,
          "time": 0.009
        },
        "shifts": [
          {
            "start": {
              "time": "2024-09-20T08:30:00Z",
              "location": {
                "id": "location_6"
              }
            },
            "end": {
              "time": "2024-09-20T16:30:00Z",
              "location": {
                "id": "location_6"
              }
            }
          }
        ],
        "capacity": [
          175
        ],
        "amount": 1
      }
    ],
    "profiles": [
      {
        "type": "car",
        "name": "delivery_car",
        "matrix": {
          "origins": [
            {
              "type": "id",
              "id": "location_1"
            },
            {
              "type": "id",
              "id": "location_2"
            },
            {
              "type": "id",
              "id": "location_3"
            },
            {
              "type": "id",
              "id": "location_4"
            },
            {
              "type": "id",
              "id": "location_5"
            },
            {
              "type": "id",
              "id": "location_6"
            }
          ],
          "travelTimes": [
            0,
            200,
            237,
            475,
            477,
            325,
            159,
            0,
            325,
            563,
            565,
            382,
            513,
            495,
            0,
            238,
            240,
            516,
            467,
            449,
            292,
            0,
            2,
            455,
            465,
            447,
            290,
            2,
            0,
            453,
            274,
            256,
            163,
            401,
            403,
            0
          ],
          "distances": [
            0,
            1002,
            1517,
            3176,
            3189,
            1805,
            881,
            0,
            2118,
            3777,
            3790,
            2535,
            3235,
            3292,
            0,
            1659,
            1672,
            3322,
            2903,
            2960,
            2029,
            0,
            13,
            3062,
            2890,
            2947,
            2016,
            13,
            0,
            3049,
            1465,
            1522,
            1367,
            3026,
            3039,
            0
          ]
        }
      }
    ]
  },
  "plan": {
    "jobs": [
      {
        "id": "job_1",
        "tasks": {
          "deliveries": [
            {
              "places": [
                {
                  "location": {
                    "id": "location_1"
                  },
                  "duration": 180
                }
              ],
              "demand": [
                16
              ]
            }
          ]
        }
      },
      {
        "id": "job_2",
        "tasks": {
          "deliveries": [
            {
              "places": [
                {
                  "location": {
                    "id": "location_2"
                  },
                  "duration": 600
                }
              ],
              "demand": [
                12
              ]
            }
          ]
        }
      },
      {
        "id": "job_3",
        "tasks": {
          "deliveries": [
            {
              "places": [
                {
                  "location": {
                    "id": "location_3"
                  },
                  "duration": 300
                }
              ],
              "demand": [
                6
              ]
            }
          ]
        }
      },
      {
        "id": "job_4",
        "tasks": {
          "deliveries": [
            {
              "places": [
                {
                  "location": {
                    "id": "location_4"
                  },
                  "duration": 720
                }
              ],
              "demand": [
                18
              ]
            }
          ]
        }
      },
      {
        "id": "job_5",
        "tasks": {
          "deliveries": [
            {
              "places": [
                {
                  "location": {
                    "id": "location_5"
                  },
                  "duration": 600
                }
              ],
              "demand": [
                12
              ]
            }
          ]
        }
      }
    ]
  }
}

リクエストに応じて、APIは次の例に示すようにソリューションを返します。

Click to expand/collapse the sample JSON
{
  "statistic": {
    "cost": 78.269,
    "distance": 8641,
    "duration": 3745,
    "times": {
      "driving": 1345,
      "serving": 2400,
      "waiting": 0,
      "stopping": 0,
      "break": 0
    }
  },
  "tours": [
    {
      "vehicleId": "car_1_1",
      "typeId": "car_1",
      "stops": [
        {
          "time": {
            "arrival": "2024-09-20T08:30:00Z",
            "departure": "2024-09-20T08:30:00Z"
          },
          "load": [
            64
          ],
          "activities": [
            {
              "jobId": "departure",
              "type": "departure",
              "location": {
                "id": "location_6"
              },
              "time": {
                "start": "2024-09-20T08:30:00Z",
                "end": "2024-09-20T08:30:00Z"
              }
            }
          ],
          "location": {
            "id": "location_6"
          },
          "distance": 0
        },
        {
          "time": {
            "arrival": "2024-09-20T08:34:16Z",
            "departure": "2024-09-20T08:44:16Z"
          },
          "load": [
            52
          ],
          "activities": [
            {
              "jobId": "job_2",
              "type": "delivery",
              "location": {
                "id": "location_2"
              },
              "time": {
                "start": "2024-09-20T08:34:16Z",
                "end": "2024-09-20T08:44:16Z"
              }
            }
          ],
          "location": {
            "id": "location_2"
          },
          "distance": 1522
        },
        {
          "time": {
            "arrival": "2024-09-20T08:46:55Z",
            "departure": "2024-09-20T08:49:55Z"
          },
          "load": [
            36
          ],
          "activities": [
            {
              "jobId": "job_1",
              "type": "delivery",
              "location": {
                "id": "location_1"
              },
              "time": {
                "start": "2024-09-20T08:46:55Z",
                "end": "2024-09-20T08:49:55Z"
              }
            }
          ],
          "location": {
            "id": "location_1"
          },
          "distance": 2403
        },
        {
          "time": {
            "arrival": "2024-09-20T08:53:52Z",
            "departure": "2024-09-20T08:58:52Z"
          },
          "load": [
            30
          ],
          "activities": [
            {
              "jobId": "job_3",
              "type": "delivery",
              "location": {
                "id": "location_3"
              },
              "time": {
                "start": "2024-09-20T08:53:52Z",
                "end": "2024-09-20T08:58:52Z"
              }
            }
          ],
          "location": {
            "id": "location_3"
          },
          "distance": 3920
        },
        {
          "time": {
            "arrival": "2024-09-20T09:02:50Z",
            "departure": "2024-09-20T09:14:50Z"
          },
          "load": [
            12
          ],
          "activities": [
            {
              "jobId": "job_4",
              "type": "delivery",
              "location": {
                "id": "location_4"
              },
              "time": {
                "start": "2024-09-20T09:02:50Z",
                "end": "2024-09-20T09:14:50Z"
              }
            }
          ],
          "location": {
            "id": "location_4"
          },
          "distance": 5579
        },
        {
          "time": {
            "arrival": "2024-09-20T09:14:52Z",
            "departure": "2024-09-20T09:24:52Z"
          },
          "load": [
            0
          ],
          "activities": [
            {
              "jobId": "job_5",
              "type": "delivery",
              "location": {
                "id": "location_5"
              },
              "time": {
                "start": "2024-09-20T09:14:52Z",
                "end": "2024-09-20T09:24:52Z"
              }
            }
          ],
          "location": {
            "id": "location_5"
          },
          "distance": 5592
        },
        {
          "time": {
            "arrival": "2024-09-20T09:32:25Z",
            "departure": "2024-09-20T09:32:25Z"
          },
          "load": [
            0
          ],
          "activities": [
            {
              "jobId": "arrival",
              "type": "arrival",
              "location": {
                "id": "location_6"
              },
              "time": {
                "start": "2024-09-20T09:32:25Z",
                "end": "2024-09-20T09:32:25Z"
              }
            }
          ],
          "location": {
            "id": "location_6"
          },
          "distance": 8641
        }
      ],
      "statistic": {
        "cost": 78.269,
        "distance": 8641,
        "duration": 3745,
        "times": {
          "driving": 1345,
          "serving": 2400,
          "waiting": 0,
          "stopping": 0,
          "break": 0
        }
      },
      "shiftIndex": 0
    }
  ]
}

問題に位置座標が指定されていない場合 (上の例のように)、地図上にツアーを重ねるには、システム内の対応する座標に位置IDを一致させる必要があります。

非同期リクエストでカスタムマトリックスを実装する

非同期リクエストの一部としてカスタムマトリックスを実装するには、同期リクエストとは異なるアプローチが必要です。まず、マトリックスオブジェクトを専用の/matricesエンドポイントに送信する必要があります。その後、取得したmatrixIdを問題の対象車両プロファイル内に埋め込みます。以下の手順では、非同期リクエストプロセスの一部としてカスタムマトリックスを実装する方法を説明します。

📘

非同期リクエストには、次のカスタムマトリックス制限が適用されます。

  • 1つの問題内で参照できるmatrixId値は最大2つです。これにより、最大2つの車両プロファイルで専用のカスタムマトリックスを使用できます。
  • 送信後、マトリックスIDの使用時間は最大24時間です。この期間が経過すると、マトリックスを/matricesエンドポイントに再送信し、新しいmatrixIdを取得する必要があります。

1.マトリックスを送信してmatrixIdを取得する

POSTメソッドを使用して、カスタムマトリックスをHERE Tour Planning APIの/matricesエンドポイントにアップロードします。

次のスニペットは、curlコマンドを使用して、前のセクションで示したマトリックス例を送信するリクエスト例を示しています。

curl --location 'https://tourplanning.hereapi.com/v3/matrices?apikey=<YOUR_HERE_API_KEY>' \
--header 'Content-Type: application/json' \
--data '{
    "origins": [
        {
            "type": "id",
            "id": "location_1"
        },
        {
            "type": "id",
            "id": "location_2"
        },
        {
            "type": "id",
            "id": "location_3"
        },
        {
            "type": "id",
            "id": "location_4"
        },
        {
            "type": "id",
            "id": "location_5"
        },
        {
            "type": "id",
            "id": "location_6"
        }
    ],
    "travelTimes": [
        0,
        200,
        237,
        475,
        477,
        325,
        159,
        0,
        325,
        563,
        565,
        382,
        513,
        495,
        0,
        238,
        240,
        516,
        467,
        449,
        292,
        0,
        2,
        455,
        465,
        447,
        290,
        2,
        0,
        453,
        274,
        256,
        163,
        401,
        403,
        0
    ],
    "distances": [
        0,
        1002,
        1517,
        3176,
        3189,
        1805,
        881,
        0,
        2118,
        3777,
        3790,
        2535,
        3235,
        3292,
        0,
        1659,
        1672,
        3322,
        2903,
        2960,
        2029,
        0,
        13,
        3062,
        2890,
        2947,
        2016,
        13,
        0,
        3049,
        1465,
        1522,
        1367,
        3026,
        3039,
        0
    ]
}'

結果:次の例に示すように、APIはマトリックスIDオブジェクトを含むレスポンスを返します。

{
  "matrixId": "3d6be06e-2609-4229-bc7f-509ba646aa29"
}

2.非同期リクエストを送信する

前の手順で取得したmatrixId値を問題のJSON本文内に埋め込み、そのリクエストを/problems/asyncエンドポイントに送信します。

次のスニペットは、非同期リクエスト用に調整された問題のJSONの例を示しており、matrixIdプロパティの形式で1つのカスタムマトリックスを使用しています。

Click to expand/collapse the sample JSON
{
  "fleet": {
    "types": [
      {
        "id": "car_1",
        "profile": "delivery_car",
        "costs": {
          "fixed": 10,
          "distance": 0.004,
          "time": 0.009
        },
        "shifts": [
          {
            "start": {
              "time": "2024-09-20T08:30:00Z",
              "location": {
                "id": "location_6"
              }
            },
            "end": {
              "time": "2024-09-20T16:30:00Z",
              "location": {
                "id": "location_6"
              }
            }
          }
        ],
        "capacity": [
          175
        ],
        "amount": 1
      }
    ],
    "profiles": [
      {
        "type": "car",
        "name": "delivery_car",
        "matrixId": "3d6be06e-2609-4229-bc7f-509ba646aa29"
      }
    ]
  },
  "plan": {
    "jobs": [
      {
        "id": "job_1",
        "tasks": {
          "deliveries": [
            {
              "places": [
                {
                  "location": {
                    "id": "location_1"
                  },
                  "duration": 180
                }
              ],
              "demand": [
                16
              ]
            }
          ]
        }
      },
      {
        "id": "job_2",
        "tasks": {
          "deliveries": [
            {
              "places": [
                {
                  "location": {
                    "id": "location_2"
                  },
                  "duration": 600
                }
              ],
              "demand": [
                12
              ]
            }
          ]
        }
      },
      {
        "id": "job_3",
        "tasks": {
          "deliveries": [
            {
              "places": [
                {
                  "location": {
                    "id": "location_3"
                  },
                  "duration": 300
                }
              ],
              "demand": [
                6
              ]
            }
          ]
        }
      },
      {
        "id": "job_4",
        "tasks": {
          "deliveries": [
            {
              "places": [
                {
                  "location": {
                    "id": "location_4"
                  },
                  "duration": 720
                }
              ],
              "demand": [
                18
              ]
            }
          ]
        }
      },
      {
        "id": "job_5",
        "tasks": {
          "deliveries": [
            {
              "places": [
                {
                  "location": {
                    "id": "location_5"
                  },
                  "duration": 600
                }
              ],
              "demand": [
                12
              ]
            }
          ]
        }
      }
    ]
  }
}

次のスニペットは、curlコマンドを使用して、前の問題のJSONをリクエストの本文として埋め込んだ例です。

Click to expand/collapse the sample JSON
curl --location 'https://tourplanning.hereapi.com/v3/problems/async?apikey=<YOUR_HERE_API_KEY>' \
--header 'Content-Type: application/json' \
--data '{
  "fleet": {
    "types": [
      {
        "id": "car_1",
        "profile": "delivery_car",
        "costs": {
          "fixed": 10,
          "distance": 0.004,
          "time": 0.009
        },
        "shifts": [
          {
            "start": {
              "time": "2024-09-20T08:30:00Z",
              "location": {
                "id": "location_6"
              }
            },
            "end": {
              "time": "2024-09-20T16:30:00Z",
              "location": {
                "id": "location_6"
              }
            }
          }
        ],
        "capacity": [
          175
        ],
        "amount": 1
      }
    ],
    "profiles": [
      {
        "type": "car",
        "name": "delivery_car",
        "matrixId": "3d6be06e-2609-4229-bc7f-509ba646aa29"
      }
    ]
  },
  "plan": {
    "jobs": [
      {
        "id": "job_1",
        "tasks": {
          "deliveries": [
            {
              "places": [
                {
                  "location": {
                    "id": "location_1"
                  },
                  "duration": 180
                }
              ],
              "demand": [
                16
              ]
            }
          ]
        }
      },
      {
        "id": "job_2",
        "tasks": {
          "deliveries": [
            {
              "places": [
                {
                  "location": {
                    "id": "location_2"
                  },
                  "duration": 600
                }
              ],
              "demand": [
                12
              ]
            }
          ]
        }
      },
      {
        "id": "job_3",
        "tasks": {
          "deliveries": [
            {
              "places": [
                {
                  "location": {
                    "id": "location_3"
                  },
                  "duration": 300
                }
              ],
              "demand": [
                6
              ]
            }
          ]
        }
      },
      {
        "id": "job_4",
        "tasks": {
          "deliveries": [
            {
              "places": [
                {
                  "location": {
                    "id": "location_4"
                  },
                  "duration": 720
                }
              ],
              "demand": [
                18
              ]
            }
          ]
        }
      },
      {
        "id": "job_5",
        "tasks": {
          "deliveries": [
            {
              "places": [
                {
                  "location": {
                    "id": "location_5"
                  },
                  "duration": 600
                }
              ],
              "demand": [
                12
              ]
            }
          ]
        }
      }
    ]
  }
}'

結果:次の例に示すように、APIはリクエストステータスIDとステータスURLを含むレスポンスを返します。

{
  "statusId": "1298a8bc-bc91-4ff6-a664-f62a58e1d147",
  "href": "https://tourplanning.hereapi.com/v3/status/1298a8bc-bc91-4ff6-a664-f62a58e1d147"
}

3.ソリューションURLを取得する

次の例に示すように、ステータスURLを使用して、/statusエンドポイントに定期的にポーリングし、ソリューションURLを取得します。

https://tourplanning.hereapi.com/v3/status/<statusId>?apikey=<YOUR_HERE_API_KEY>

結果:ソリューションのステータスがpendingからsuccessに変わると、APIはソリューションURLを返し、ユーザーはそのURLを使用してソリューションを取得できます。

{
  "status": "success",
  "resource": {
    "resourceId": "1298a8bc-bc91-4ff6-a664-f62a58e1d147",
    "href": "https://tourplanning.hereapi.com/v3/problems/1298a8bc-bc91-4ff6-a664-f62a58e1d147/solution"
  }
}

4.ソリューションを取得する

次の例に示すように、前の手順で取得したリソースIDを使用してソリューションをダウンロードします。

https://tourplanning.hereapi.com/v3/problems/<resourceId>/solution?apikey=<YOUR_HERE_API_KEY>

結果:APIは、次のような完全なソリューションのJSONを含むレスポンスを返します。

Click to expand/collapse the sample JSON
{
  "statistic": {
    "cost": 78.269,
    "distance": 8641,
    "duration": 3745,
    "times": {
      "driving": 1345,
      "serving": 2400,
      "waiting": 0,
      "stopping": 0,
      "break": 0
    }
  },
  "tours": [
    {
      "vehicleId": "car_1_1",
      "typeId": "car_1",
      "stops": [
        {
          "time": {
            "arrival": "2024-09-20T08:30:00Z",
            "departure": "2024-09-20T08:30:00Z"
          },
          "load": [64],
          "activities": [
            {
              "jobId": "departure",
              "type": "departure",
              "location": {
                "id": "location_6"
              },
              "time": {
                "start": "2024-09-20T08:30:00Z",
                "end": "2024-09-20T08:30:00Z"
              }
            }
          ],
          "location": {
            "id": "location_6"
          },
          "distance": 0
        },
        {
          "time": {
            "arrival": "2024-09-20T08:34:16Z",
            "departure": "2024-09-20T08:44:16Z"
          },
          "load": [52],
          "activities": [
            {
              "jobId": "job_2",
              "type": "delivery",
              "location": {
                "id": "location_2"
              },
              "time": {
                "start": "2024-09-20T08:34:16Z",
                "end": "2024-09-20T08:44:16Z"
              }
            }
          ],
          "location": {
            "id": "location_2"
          },
          "distance": 1522
        },
        {
          "time": {
            "arrival": "2024-09-20T08:46:55Z",
            "departure": "2024-09-20T08:49:55Z"
          },
          "load": [36],
          "activities": [
            {
              "jobId": "job_1",
              "type": "delivery",
              "location": {
                "id": "location_1"
              },
              "time": {
                "start": "2024-09-20T08:46:55Z",
                "end": "2024-09-20T08:49:55Z"
              }
            }
          ],
          "location": {
            "id": "location_1"
          },
          "distance": 2403
        },
        {
          "time": {
            "arrival": "2024-09-20T08:53:52Z",
            "departure": "2024-09-20T08:58:52Z"
          },
          "load": [30],
          "activities": [
            {
              "jobId": "job_3",
              "type": "delivery",
              "location": {
                "id": "location_3"
              },
              "time": {
                "start": "2024-09-20T08:53:52Z",
                "end": "2024-09-20T08:58:52Z"
              }
            }
          ],
          "location": {
            "id": "location_3"
          },
          "distance": 3920
        },
        {
          "time": {
            "arrival": "2024-09-20T09:02:50Z",
            "departure": "2024-09-20T09:14:50Z"
          },
          "load": [12],
          "activities": [
            {
              "jobId": "job_4",
              "type": "delivery",
              "location": {
                "id": "location_4"
              },
              "time": {
                "start": "2024-09-20T09:02:50Z",
                "end": "2024-09-20T09:14:50Z"
              }
            }
          ],
          "location": {
            "id": "location_4"
          },
          "distance": 5579
        },
        {
          "time": {
            "arrival": "2024-09-20T09:14:52Z",
            "departure": "2024-09-20T09:24:52Z"
          },
          "load": [0],
          "activities": [
            {
              "jobId": "job_5",
              "type": "delivery",
              "location": {
                "id": "location_5"
              },
              "time": {
                "start": "2024-09-20T09:14:52Z",
                "end": "2024-09-20T09:24:52Z"
              }
            }
          ],
          "location": {
            "id": "location_5"
          },
          "distance": 5592
        },
        {
          "time": {
            "arrival": "2024-09-20T09:32:25Z",
            "departure": "2024-09-20T09:32:25Z"
          },
          "load": [0],
          "activities": [
            {
              "jobId": "arrival",
              "type": "arrival",
              "location": {
                "id": "location_6"
              },
              "time": {
                "start": "2024-09-20T09:32:25Z",
                "end": "2024-09-20T09:32:25Z"
              }
            }
          ],
          "location": {
            "id": "location_6"
          },
          "distance": 8641
        }
      ],
      "statistic": {
        "cost": 78.269,
        "distance": 8641,
        "duration": 3745,
        "times": {
          "driving": 1345,
          "serving": 2400,
          "waiting": 0,
          "stopping": 0,
          "break": 0
        }
      },
      "shiftIndex": 0
    }
  ]
}

次のステップ

  • HERE Tour Planning APIで問題を作成する方法の詳細については、「問題」を参照してください。
  • HERE Tour Planning APIのメソッド、エンドポイント、パラメーターの詳細については、「APIリファレンス」を参照してください。