optaplannerdrools-planner

How to calculate return to depot time and make it hard constraint


I am using the TimeWindowed version of the vehicle routing and I added to the vehicle an endOfShift time. I want to calculate the time of return to depot and make it hard constraint. The returnToDepotTime is calculate in the ArrivalTimeUpdatingVariableListener, and I also changed the drl file I added

rule "returnToDepotBeforeEndOfShift"
when
    Vehicle(endOfShift < returnToDepotTime, $endOfShift : endOfShift, $returnToDepotTime : returnToDepotTime)
then
    scoreHolder.addHardConstraintMatch(kcontext, $endOfShift - $returnToDepotTime.intValue());  end

The problem is that OptaPlanner does not take returnToDepotTime into consideration and it is calculated but not taken by the hard constrains calculation. Any idea what to change?


Solution

  • Adjust the ArrivalTimeUpdatingVariableListener to also adjust the Vehicle's returnHomeTime for the Customer where getNextCustomer() is null.

    If the scoreDirector is properly notified (before/afterVarChanged methods) that the Vehicle's returnHomeTime changed, the rules will update accordingly.