len
len

Reputation: 807

Optaplanner - timewindow is not fulfilled

I am using OptaPlanner for a business related optimization.

Concerning 6.1.0. Final version: When I modify the optimization problem, so that a vehicle has to arrive inside of a time window (with earliest possible and latest possible arrival time, punished by hardscores when too early or too late) and when I take only 1 vehicle with two customers, whereby timewindow 1 is much earlier than timewindow 2 (end of timewindow 1 + travelling time to customer 2 < start of timewindow 2) then the vehicle meets the timewindow 1 exactly at earliest time, but the arrival at customer 2 is too early.

example

The vehicle (2363) starts from depot 270 first to customer 13 (time window is 8:50-10:50) and arrives exactly at 8:50. The working duration there is 75 min. The departure is at 10:05 and the vehicle arrives at 10:12 at customer 16 (time window is 15:45-17:45). In some business cases it is better to wait instead to arrive too early.

How can I force the vehicle to WAIT, so that it arrives at the location of next customer in time?

PS: The circles show the time window of possible arrival time (inner circle: 0-12h, outer circle: 12-24h). Times and distances between locations are determined from GraphHopper

Upvotes: 1

Views: 363

Answers (1)

Geoffrey De Smet
Geoffrey De Smet

Reputation: 27312

So you want to wait at the previous standstill (= the previous customer or the depot), instead of at the current customer?

In the OptaPlanner VRP example, departureTime = arrivalTime + duration. So arrivalTime is a shadow variable (based on previousStandstill) and departureTime is just a calculation on top of that (so departureTime itself is not shadow variable, because it isn't even a field (or put differently because it's not a java variable it's cannot be a planning variable (genuine or shadow)).

In your variant, make departureTime a shadow variable too, defined as follows: departureTime = Math.max((arrivalTime + duration), nextCustomer.readyTime - drivingTime). That new shadow variable (and therefor it's VariableListener) depends on the planning variables arrivalTime and nextCustomer. So a shadow var depending on shadow vars. Notice how there's NO cycle in this proposal: nextCustomer.readyTime is used, but readyTime is a problem fact.

You might need to upgrade to 6.2.0.CR2 or higher for this, because 6.1 might not yet support shadow variables that depend on shadow variables (I don't recall any more). I also fear that optaplanner doesn't automatically reorder variable listener triggering yet to follow the hierarchy (feel free to make a jira about that), so that means you'll have to declare the getters with variable listeners as follows: previousStandstill, nextCustomer, arrivalTime, departureTime.

VariableListener triggering order will be formalized more in future versions.

Upvotes: 1

Related Questions