graphhopper/jsprit

Inconsistent time units in activities response object

nilsnolde opened this issue · 3 comments

I just found a supposedly quick-to-fix inconsistency:
The arr_time field in the second activities object is in minutes or seconds, while all other arr_time fields are in UNIX epoch. It's only the first activities object which contains arr_time, hence only the second one in a list.

Maybe makes more sense, if you look at the JSON output of e.g. this one:

{
  "vehicle_types": [
    {
      "type_id": "lkw",
      "profile": "truck",
      "capacity": [
        8500
      ]
    },
  ],
  "objectives": [
    {
      "type": "min",
      "value": "vehicles"
    },
    {
      "type": "min",
      "value": "completion_time"
    }
  ],
  "vehicles": [
    {
      "vehicle_id": "lkw1",
      "start_address": {
        "location_id": "depot",
        "lon": 10.129495,
        "lat": 53.284878
      },
      "type_id": "lkw"
    },
    {
      "vehicle_id": "lkw2",
      "start_address": {
        "location_id": "depot",
        "lon": 10.129495,
        "lat": 53.284878
      },
      "type_id": "lkw"
    }
  ],
  "services": [
    {
      "id": "0",
      "address": {
        "location_id": "service-location-id_0",
        "lon": 9.583172,
        "lat": 54.6026
      },
      "duration": 1200,
      "size": [
        7536
      ],
      "time_windows": [
        {
          "earliest": 1576308600,
          "latest": 1576346400
        }
      ]
    },
    {
      "id": "1",
      "address": {
        "location_id": "service-location-id_1",
        "lon": 8.900615,
        "lat": 54.872602
      },
      "duration": 1200,
      "size": [
        6025
      ],
      "time_windows": [
        {
          "earliest": 1576308600,
          "latest": 1576346400
        }
      ]
    },
    {
      "id": "2",
      "address": {
        "location_id": "service-location-id_2",
        "lon": 10.148941,
        "lat": 53.290197
      },
      "duration": 1200,
      "size": [
        3050
      ],
      "time_windows": [
        {
          "earliest": 1576308600,
          "latest": 1576346400
        }
      ]
    },
    {
      "id": "3",
      "address": {
        "location_id": "service-location-id_3",
        "lon": 9.46429,
        "lat": 53.68274
      },
      "duration": 1200,
      "size": [
        2378
      ],
      "time_windows": [
        {
          "earliest": 1576308600,
          "latest": 1576346400
        }
      ]
    }
  ]
}

I am not sure what you mean and whether this is the right place for this issue. It seems that the example refers to GraphHopper's Optimization API and not jsprit. Is this correct? Furthermore, from the example you posted I cannot not see any inconsistencies. Would you mind to further explain what you mean?

Yes, correct, it's about GH Optimization API. I figured it's the direct output of jsprit?! If not, I'm happy to put this issue into GH itself. And I can see how this is confusing, sorry about that..

The above query is (partly) responding with the following response. Note, the difference in arr_time of the service with "id": "1" and "id": "0", i.e. second and third activity. While the second arr_time is described in seconds, the third arr_time is described in UNIX epoch (and so are all following arr_time).

Does it make more sense now?

...,
      "activities": [
        {
          "type": "start",
          "location_id": "depot",
          "address": {
            "location_id": "depot",
            "lat": 53.284878,
            "lon": 10.129495
          },
          "end_time": 0,
          "end_date_time": null,
          "distance": 0,
          "driving_time": 0,
          "preparation_time": 0,
          "waiting_time": 0,
          "load_after": [
            0
          ]
        },
        {
          "type": "service",
          "id": "1",
          "location_id": "service-location-id_1",
          "address": {
            "location_id": "service-location-id_1",
            "lat": 54.872602,
            "lon": 8.900615
          },
          "arr_time": 11902,
          "arr_date_time": null,
          "end_time": 1576309800,
          "end_date_time": null,
          "waiting_time": 1576296698,
          "distance": 231079,
          "driving_time": 11902,
          "preparation_time": 0,
          "load_before": [
            0
          ],
          "load_after": [
            6025
          ]
        },
        {
          "type": "service",
          "id": "0",
          "location_id": "service-location-id_0",
          "address": {
            "location_id": "service-location-id_0",
            "lat": 54.6026,
            "lon": 9.583172
          },
          "arr_time": 1576314090,
          "arr_date_time": null,
          "end_time": 1576315290,
          "end_date_time": null,
          "waiting_time": 0,
          "distance": 297714,
          "driving_time": 16192,
          "preparation_time": 0,
          "load_before": [
            6025
          ],
          "load_after": [
            13561
          ]
        },
...

Yes, it is still the wrong place. Now it is clearer, and actually it is neither inconsistent nor a bug. The departure time of the vehicle is 0 (i.e. 1.1.1970 in unix timestamp). It takes 11902 seconds ("driving_time": 11902) to the first activity, thus "arr_time": 11902. Since this activity has a time window, the vehicle needs to wait until the time window opens (here about 49 years), i.e. 1576308600. The activity itself takes 1200 seconds, therefore the end_time amounts to 1576309800.

If you dont want your vehicle to wait 49 years, you need to specify an appropriate "earliest_start". If you dont mind, I would like to close this here. If you want to further discuss this, please use: https://discuss.graphhopper.com/c/directions-api/optimization-api.