Search code examples
optaplanner

Modeling lunch breaks and additional depot returns in Optaplanner


we are using optaplanner to try to improve our current vehicle routes with time windows. We have a few smaller issues which we are not sure how to overcome:

  • Our drivers need to have to have a 30 minutes lunch break, somewhere between 3rd and 5th hour of their shift (from the start of their drive), and if the drive is shorter than 5 hours - no break is required.
  • We have to make sure that some packages (but not all) get back to the depot by a certain time. For example, some customer would have a pick-up time from 8:00 to 8:30 but their package / parcel has to be returned to depot by 12:00.

Our current idea for the second problem is to create two new classes:

public class ReturningCustomer extends TimeWindowedCustomer {

   protected int returningId;

and

public class ReturnToDepot extends TimeWindowedCustomer {

   protected int returningId;

where the first one models the customer with special packages, which are to be returned. The second one is the “fake” customer that represents the driver’s return to the depot. ReturnToDepot would have the same location as the depot itself. Comparing their ids in Drools will assure that they are on the same vehicle’s path. Treating the ReturnToDepot as another customer would hopefully assure that the planner finds an optimal way to put it into a route.

However, for the lunch break modeling, we are not quite sure what to do.

Is there a better way to model this? What would be the best way to model the lunch breaks? Are there any samples which could point us to the right direction?

Thanks.


Solution

  • Starting from the TimeWindowed VRP examples, you can do those 2 reqs like this:

    • Lunch breaks: adjust the arrivalTime calculation in the VariableListener so that any arrival after the 3th hour will add another 30 minutes to the arrivalTime. Depending on your business needs - for example they can only take a break between locations not at locations - optionally add a hard constraint to assure there's an arrival between the 3th and 5th hour.

    • Get back in time to depot: add a shadow variable on Vehicle called arrivalBackToDepotTime and use variableListenerRef to reuse the ArrivalTimeUpdateVariableListener which then also needs to update that field. Add a hard constraint to check for each Customer that the Vehicle's arrivalBackToDepotTime is less than the Customer's required time to get to the depot.