Find out the Travel time


#1

Hi,
we are currently using the tour API with business license.
We have the need to find out the travel time that the driver spends moving between waypoints.

We are stuck with a problem. When we add restrictions to the tour that we want to optimize the arrival time in the response is correctly influenced by the time restrictions. In this cases calculating the differences between arrival times doesn’t always indicate the travel time. How we can always find out the travel time that the driver spends moving between each waypoint?

Example:

Request

[
  {
    "address": "-1",
    "lat": "39.0323",
    "lng": "8.994979"
  },
  {
    "address": "17525500",
    "lat": "39.0654",
    "lng": "9.007817",
    "servicetime": 28,
    "restrictions": {
      "ready": 0,
      "due": 208
    }
  },
  {
    "address": "17420359",
    "lat": "39.03619",
    "lng": "8.999581",
    "servicetime": 47,
    "restrictions": {
      "ready": 148,
      "due": 242
    }
  },
  {
    "address": "17400609",
    "lat": "39.03562",
    "lng": "9.001219",
    "servicetime": 48,
    "restrictions": {
      "ready": 180,
      "due": 408
    }
  },
  {
    "address": "17400733",
    "lat": "39.01208",
    "lng": "8.998238",
    "servicetime": 28,
    "restrictions": {
      "ready": 180,
      "due": 388
    }
  },
  {
    "address": "17463650",
    "lat": "39.0008",
    "lng": "9.000796",
    "servicetime": 20,
    "restrictions": {
      "ready": 180,
      "due": 380
    }
  },
  {
    "address": "18644946",
    "lat": "39.01253",
    "lng": "8.997813",
    "servicetime": 19,
    "restrictions": {
      "ready": 180,
      "due": 379
    }
  },
  {
    "address": "17400574",
    "lat": "39.00759",
    "lng": "8.998443",
    "servicetime": 24,
    "restrictions": {
      "ready": 360,
      "due": 624
    }
  },
  {
    "address": "17400588",
    "lat": "39.01194",
    "lng": "9.00275",
    "servicetime": 32,
    "restrictions": {
      "ready": 360,
      "due": 632
    }
  },
  {
    "address": "17400597",
    "lat": "39.01112",
    "lng": "8.997948",
    "servicetime": 18,
    "restrictions": {
      "ready": 360,
      "due": 618
    }
  },
  {
    "address": "17400610",
    "lat": "39.03562",
    "lng": "9.001219",
    "servicetime": 23,
    "restrictions": {
      "ready": 600,
      "due": 863
    }
  },
  {
    "address": "17400734",
    "lat": "39.01208",
    "lng": "8.998238",
    "servicetime": 20,
    "restrictions": {
      "ready": 600,
      "due": 860
    }
  },
  {
    "address": "17525505",
    "lat": "39.0654",
    "lng": "9.007817",
    "servicetime": 21,
    "restrictions": {
      "ready": 600,
      "due": 861
    }
  }
]

Response

{
  "id": "59sMWo1L",
  "count": 13,
  "feasible": true,
  "route": {
    "0": {
      "name": "-1",
      "arrival": 0,
      "distance": 0
    },
    "1": {
      "name": "17525500",
      "arrival": 5,
      "distance": 4.9
    },
    "2": {
      "name": "17420359",
      "arrival": 38,
      "distance": 9.2
    },
    "3": {
      "name": "17400609",
      "arrival": 196,
      "distance": 9.6
    },
    "4": {
      "name": "18644946",
      "arrival": 247,
      "distance": 12.5
    },
    "5": {
      "name": "17400733",
      "arrival": 267,
      "distance": 12.7
    },
    "6": {
      "name": "17463650",
      "arrival": 297,
      "distance": 14.2
    },
    "7": {
      "name": "17400588",
      "arrival": 319,
      "distance": 15.7
    },
    "8": {
      "name": "17400574",
      "arrival": 394,
      "distance": 16.8
    },
    "9": {
      "name": "17400597",
      "arrival": 418,
      "distance": 17.4
    },
    "10": {
      "name": "17400734",
      "arrival": 437,
      "distance": 17.7
    },
    "11": {
      "name": "17400610",
      "arrival": 624,
      "distance": 20.7
    },
    "12": {
      "name": "17525505",
      "arrival": 652,
      "distance": 25.1
    }
  }
}

We want to know how much time the driver spends driving between the waypoint 17420359 and 17400609.
If we calculate the difference of arrival times:

Travel time = Arrival time - (Previuos arrival time + Service time)
111 = 196 - (38 + 47)

But in this case the Travel time is not correctly calculated, we assume due to the “ready” restriction.
How we can find out the exact amout time that the driver spends driving for the distance returned (in this case for only 0.4 km)?

Thanks in advance.


#2

You’re missing the waiting time, which is not explicit in the output. Waiting time is added when arriving too early at a stop.

Waypoint 17420359 has a ready time of 148 and a service time of 47. The earliest moment of departure is 148 + 47 = 195. Travel time to 17400609 is 196 - 195 = 1. Your formula could be adapted to something like this:

Travel time = Arrival time - ( Max( Previous arrival time, Previous Ready time) + Service time )