Time windows for vehicles

Hi, do you know how to apply time windows for vehicles? I need certain vehicles to work certain hours of the day. Thanks for the help you can give me :slight_smile:

You can use setEarliestStart and setLatestArrival on VehicleImpl.Builder to set the available time window for a vehicle. Also, you can specify a single break by setBreak within its time window. At the moment you can’t specify multiple time windows to a vehicle.

1 Like

Thanks for your help!

Can we add multiple breaks in one route?[quote=“Balage1551, post:2, topic:1915”]
setEarliestStart and setLatestArrival
[/quote]

This is a start time and end time of the vehicle. Am I right?
Thank you @Balage1551 you have helping nature.

As for now, you can’t add multiple breaks.

Yes, they are. Technically, they are the start and end of the “time window” of the vehicle.

1 Like

So Suppose I want to add multiple breaks in a single route.So How should I go about it?Can I get the little bit your help?

As far as I can figure it out, it wouldn’t be easy to do this.

The problem with breaks that it has no location. This is the main difference between breaks and jobs. It is taken at the location of the last activity before the break or on the route to the next activity. In short, it has no location, no movement, no travel cost. This is why it is handled specially and at the moment, there is only one break is available per vehicle.

If you have only single activity jobs (no shipments) and the break has a fix time, a rough approximation would be implemented by solving the problem in several steps. Let’s see an example:

There is a vehicle working from 8:00 till 16:00. It has 2 breaks: 10:00 - 10:30 and 14:00 - 14:30. Now you could split the problem into three. You define 3 vehicles instead of 1:

  • Vehicle #1 has a time window of 8:00 till 10:00
  • Vehicle #2 has a time window of 10:30 till 14:00
  • Vehicle #3 has a time window of 14:30 till 16:00

First you pick all the jobs with time window which has intersection with the time window of the first vehicle. (All jobs which has to done or may be done before the first break.) Run the optimalization on these subset of jobs using the first vehicle. You get a solution and possible some unassigned tasks. Now you take the jobs within the time window of Vehicle #2, add to them the unassigned jobs from the previous iteration, set the start location of the vehicle to the location of the last activity of the first solution and run the optimalization on this configuration. Now you have two solutions. Repeat this on the third vehicle similarly.
Finally, combine the three solutions.

This is not perfect, most probably it would left out some jobs (especially, when there are a lot of time windows overlaping the breaks), but I can’t think of a better solution as for now.

(PS: I am making a proposal for improvement to support jobs with no location. With this feature combined with the also upcomming mandatory job would offer a more flexible solution. But it would take some time and would be available no sooner than the new major version of the framework – meaning months from now.)

setEarliestStart(double earliest_startTime) . What would be earliest_startTime. For example if I want to set to 8AM for todays what would be the logic of earliest_startTime calculation

1 Like