Search code examples
here-apihere-tourplanning

HERE Tour Planning API Task on multiple day


I have a jobs that have to pickup some item on day 1 and have to deliver it on day 2. my fleet have two shift from from 9:00 to 18:00 from both job. if I insert only pickup, here return the response, but if i insert both pickup and delivery job or if i put both delivery and pickup on the same job i receive an error (Job cannot be served within vehicle time window)

I just tried with one pickup and one delivery, but the goal is optimize multiple job in different days

{
   "configuration":{
      "termination":{
         "maxTime":30,
         "stagnationTime":5
      }
   },
   "fleet":{
      "types":[
         {
            "id":"09c77738-1dba-42f1-b00e-eb63da7147d6",
            "profile":"normal_car",
            "costs":{
               "fixed":22.0,
               "distance":1.0E-4,
               "time":0.0048
            },
            "shifts":[
               {
                  "start":{
                     "time":"2021-01-05T09:00:00Z",
                     "location":{
                        "lat":44.492717,
                        "lng":11.346402
                     }
                  },
                  "end":{
                     "time":"2021-01-05T18:00:00Z",
                     "location":{
                        "lat":44.492717,
                        "lng":11.346402
                     }
                  },
                  "breaks":[
                     {
                        "times":[
                           [
                              "2021-01-05T11:00:00Z",
                              "2021-01-05T13:00:00Z"
                           ]
                        ],
                        "duration":1800
                     }
                  ]
               },
               {
                  "start":{
                     "time":"2021-01-06T09:00:00Z",
                     "location":{
                        "lat":44.492717,
                        "lng":11.346402
                     }
                  },
                  "end":{
                     "time":"2021-01-06T18:00:00Z",
                     "location":{
                        "lat":44.492717,
                        "lng":11.346402
                     }
                  },
                  "breaks":[
                     {
                        "times":[
                           [
                              "2021-01-06T11:00:00Z",
                              "2021-01-06T13:00:00Z"
                           ]
                        ],
                        "duration":1800
                     }
                  ]
               }
            ],
            "capacity":[
               100,
               5
            ],
            "skills":[
               "GRU"
            ],
            "limits":{
               "maxDistance":100000.0,
               "shiftTime":28800.0
            },
            "amount":1
         }
      ],
      "profiles":[
         {
            "type":"car",
            "name":"normal_car"
         }
      ],
      "traffic":"liveOrHistorical"
   },
   "plan":{
      "jobs":[
         {
            "id":"43ef69fd-98ee-4530-acbb-ec774a9d4769",
            "tasks":{
               "pickups":[
                  {
                     "places":[
                        {
                           "location":{
                              "lat":44.492717,
                              "lng":11.346402
                           },
                           "duration":180,
                           "times":[
                              [
                                 "2021-01-05T10:00:00Z",
                                 "2021-01-05T17:00:00Z"
                              ]
                           ]
                        }
                     ],
                     "demand":[
                        2
                     ]
                  }
               ]
            },
            "skills":[
               "GRU"
            ],
            "priority":2,
            "customerId":"012021010408302512_"
         },
         {
            "id":"ed3439b4-270f-488b-8323-5e0109e0d974",
            "tasks":{
               "deliveries":[
                  {
                     "places":[
                        {
                           "location":{
                              "lat":44.361081,
                              "lng":11.709962
                           },
                           "duration":180,
                           "times":[
                              [
                                 "2021-01-06T10:00:00Z",
                                 "2021-01-06T17:00:00Z"
                              ]
                           ]
                        }
                     ],
                     "demand":[
                        2
                     ]
                  }
               ]
            },
            "skills":[
               "GRU"
            ],
            "priority":2,
            "customerId":"012021010408302512_"
         }
      ],
      "relations":[
         {
            "type":"sequence",
            "jobs":[
               "departure",
               "43ef69fd-98ee-4530-acbb-ec774a9d4769",
               "ed3439b4-270f-488b-8323-5e0109e0d974",
               "arrival"
            ],
            "vehicleId":"09c77738-1dba-42f1-b00e-eb63da7147d6_1"
         }
      ],
      "clustering":{
         "serviceTimeStrategy":{
            "type":"fixedDurationStrategy",
            "duration":3600
         }
      }
   }
}

Solution

  • HERE Tour Planning API Task on multiple day Since you have added the jobs to the relation, the one relation object applies to one shift. That means you are asking to complete both jobs in the first shift of the vehicle. While one of the jobs is out of the vehicle’s first shift time window, the error is returned. In the relations, you can specify the shiftIndex property to guide in which shift the job has to be completed. Here is the modified 'relations' object for the problem with shiftIndex property. With this, the first job will be completed in the first shift (shiftIndex = 0) and the second will be done in the second shift (shiftIndex = 1).

    "relations":[ { "type":"sequence", "jobs":[ "departure", "43ef69fd-98ee-4530-acbb-ec774a9d4769", "arrival" ], "shiftIndex" : 0, "vehicleId":"09c77738-1dba-42f1-b00e-eb63da7147d6_1" }, { "type":"sequence", "jobs":[ "departure", "ed3439b4-270f-488b-8323-5e0109e0d974", "arrival" ], "shiftIndex" : 1, "vehicleId":"09c77738-1dba-42f1-b00e-eb63da7147d6_1" } ]