Time windows and opening hours

Vehicles often can’t just show up at a visit when they feel like it. Some visits have a time window: a time period in which the visit must be performed. When a technician vehicle visits a customer, the customer might only be available in the morning, or in the afternoon. Often this was decided earlier, when the customer booked the visit.

For example, visit A must occur between 13:00 (1:00 AM) and 17:00 (5:00 PM). So, the input sets the minimum start time (also known as ready time) to 13:00 and the maximum end time (also known as due time) to 17:00. The estimated duration of the visit is 1.5 hours.

visit time windows

The solver assigns visit A as Carl’s 3rd visit that day. He arrives there at 14:00 to start working. That start (14:00) is after the minStartTime (13:00), so it’s fine.

The end is the start plus the duration, so Carl ends at 15:30. That end (15:30) is before the maxEndTime (17:00), so it’s ok too.

1. Too early

What happens if Carl arrives too early?

For example, Carl arrives at 12:00, before the minStartTime of 13:00.

visit time windows too early

This doesn’t break hard constraints. Instead, Carl needs to wait an hour to start working, until 13:00 when someone is there to open the door. It also means that the end time is pushed back by an hour too.

Despite the lost waiting time, this can be the most productive solution:

visit time windows the wait time paradox

Of course, waiting time automatically incentives the solver to fill up the waiting time with other visits, due to soft constraints that minimize travel time and maximize productivity. So it’s unlikely that Carl gets to wait for a long time.

2. Too late

When Carl arrives too late, it’s worse: he can’t finish the job in time. The job ends at 14:00, which is after the maxEndTime of 13:00. This is an infeasible schedule.

visit time windows too late

In this case, the model penalizes the amount of time that Carl finishes the job too late as a hard constraint: one hour. This automatically incentivises the solver to assign that visit earlier, or leave it unassigned.

3. Multiple time windows (opening hours)

Sometimes, there are multiple options when to schedule a visit. For example, Visit A must occur either on:

  • Monday 1-feb between 8:30 and 11:30

  • Monday 1-feb between 13:30 and 17:00

  • Tuesday 2-feb between 09:30 and 12:30

The solver assigns that visit to a vehicle shift during one of those time windows, for instance Carl on his Monday shift:

visit multiple time windows

Define three time windows for Visit A as follows:

{
  "visits": [
    {
      "id": "Visit A",
      "timeWindows": [
        {
          "minStartTime": "2027-02-01T08:30:00",
          "maxEndTime": "2027-02-01T11:30:00"
        },
        {
          "minStartTime": "2027-02-01T13:30:00",
          "maxEndTime": "2027-02-01T17:00:00"
        },
        {
          "minStartTime": "2027-02-02T09:30:00",
          "maxEndTime": "2027-02-02T12:30:00"
        }
      ],
      ...
    }
  ...
}