Optaplanner vehicle starting and ending time - schedule

This Optaplanner is really very useful.
I do have a few questions, though.
I am doing a time-windowed problem, and can't find exact information about the route start and end. The Depot.readyTime and dueTime are taken into account, but just as a constraint. Is there any point where I could find the route start time directly, or do I need to get the ArrivalTime to first customer and subtract the travel time from depot (analogously for the last one)?
Very connected to this is the question if I can limit the working time of the vehicle?
And the last one from this batch is - is it possible to schedule lunch breaks for the drivers (and how)?
Thank you!

Limiting the working time of the vehicle is a matter of having the VariableListener set the back to depot arrivalTime on each vehicle and then adding a constraint (score rule) to check if it's not too late.
Scheduling lunch breaks is usually best done by adjusting the VariableListener to when it calculates the arrivalTime for the next visit, automatically add an hour if the previous visit crossed the "noon" time.

Related

Conditional Time Window based on the type of crew

We are building a solution that will optimize flight crew transportation (vehicle capacited problem with time window) . The problem is bus must be at the correct time when picking up arrival crew and when dropping off departure crew. Can we set time window for pickup time of arrival crew and another time window for dropoff time of departure crew? Also i cannot split optimization into runs since both types of crew are using the same buses?
This is a VRP with pickup and delivery and time windows. The OptaPlanner Examples don't include a pickup and delivery example yet, but many users have implemented it before. There are several ways to do pickup and delivery (see discussions on mailing list etc).
If you have the easiest pickup and delivery use case, for which you can't mix crews in the same bus at the same time, it's easy: simply split Customer.location into Customer.pickupLocation and Customer.deliveryLocation. Similarly, split up the readyTime and dueTime into pickupReadyTime, pickupDueTime, deliveryReadyTime and deliveryDuetime. Then split up the shadow var arrivalTime into pickupArrivalTime and maybe deliveryArrivalTime if needed. Adjust the variable listener that updates those 2 arrivalTimes accordingly. Have that listener still make sure that if the pickupReadyTime is after the pickupArrivalTime, it delays the pickupArrivalTime to the pickupReadyTime.

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.
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.

tour start as an additional planning variable in Optaplanner VRPTW - a good idea?

Hi and happy new year to all Optaplanner users,
we have a requirement to plan tours. These tours contain chained and time-windowed activities (deliveries) executed by a weekly changing number of trucks.
The start time of a single tour can vary and is dependent on several conditions (i.e. the goods to be delivered must be produced, before the tour can start; only a limited number of trucks can be served at the plants gates at the same time; truck must be back before starting a new tour). Means: also the order of tours can vary and time gaps between the tours of a truck can occur.
My design plan is, to annotate TourStartTime as a second planning variable in Optaplanners VRPTW-example and to assign TourStartTime to 2-hours time grains (planning horizon is 1 week and tours normally do not start during night times; so the mentioned time grains reflect a simplified calendar for possible tour starts).
The number of available trucks (from external logistic companies) can vary from week to week. Regarding this I wanted to plan with a 'unlimited' number of trucks. But the number of trucks per logistic company, that can be actually assigned with deliveries, should be controlled by a constraint (i.e. 'trucks_to_be_used_in_parallel').
Can anybody tell me, if this is a feasable design approach, or where do I have to avoid traps (ca. 1000 deliveries/week, 40-80 trucks per day) ?
Thank you
Michael
A second planning variable is possible (and might be even the best design depending on your requirements), but it will blow up the search space and maybe even custom course grained moves might become needed to get great results.
Instead, I 'd first investigate if the Truck's TourStartTime can be made a shadow variable. For example, give all trucks a unique priority number. Then make a Truck's TourStartTime a shadow variable: the soonest time a truck can leave. If there are only 3 lanes and 4 trucks want to leave, the 3 trucks with the highest priority number leave first (so get the original TourStartTime, the 4th truck gets a later one).

Optaplanner - availability of Vehicles

I am working on a VRPTW problem where vehicles have availablity constraints. This means that they might not be available the entire period of a day - basically a time windows for vehicles. Is there a way to build this in optaplanner?
Thank you and Brgds,
Paul
This following should work:
add 2 fields (start and end) on (TimeWindowed)Vehicle
in ArrivalTimeUpdatingVariableListener use at least the vehicle's start time before it leaves a depot
add a hard constraint that the vehicle should be back at the depot by it's end time. Make sure to penalize not just -1, but instead, minus the amount of time it's overdue (to avoid a score trap, see docs).

how to model (mvc) an abstract time period for employe shift management

I've started thinking about an employee shift management application to handle the shifts (who works when, trading, etc) at my current workplace (that uses pen and paper and hasn't got anyway for us employees to communicate about changes without going through the boss and be on site).
Currently the shifts are modeled loosely as:
There is a recurring 4 week period (from Monday week 1 to Sunday week 4)
There is a template for placing employees in this 4 week period
Every 4 months (ie 3 times a year) the 4 week template is projected over the next 4 month period
The shifts have been the same for a long time and it seems many employees would prefer to have them changed (I can say this by the requests for change that come in every time a new 4 month is set).
What I'm aiming at are the models:
Shift_group_tpl (the 4 week period above)
Shift_tpl (a single shift in the 4 week period, including info on who defaults to work this shift)
Shift_group (a set period of time whit actual shifts)
Shift (a set shift whit a real time period and an employee - and the possibility to be changed both in start_time, end_time and employee)
I've thought of a way to do this with recurring iCalendar events: Creating RRULE's (without an endtime) and then calculate (using temporary start and end times) if that specific Shift_group_tpl could be used within a real Shift_group. (The problem with this approach is that I can't figure out how to trim the Shift_group_tpl's to fit into the start or end of a Shift_group.)
What I'm looking for are some other perspectives or ways of doing it or even just a pat on the shoulder letting me know that I'm on the right track (and then giving advice on the trimming problem).
/iole1
What I'm aiming at are the models:
Shift_group_tpl (the 4 week period above)
Shift_tpl (a single shift in the 4 week period, including info on who defaults to work this shift)
Shift_group (a set period of time whit actual shifts)
Shift (a set shift whit a real time period and an employee - and the possibility to be changed both in start_time, end_time and employee)
You have "sql" as a tag for this post? So im guessing you want these as SQL tables?
By the sounds, the problem is that your considering the data you have, rather than the abstract concepts you need to store that data. Which is what you'd need to do to create an application. (Most likely a "Shifts" table, rather than the four tables above).
There is little information here to help, Consider refining your thoughts and ask another question.