Alekz
Alekz

Reputation: 1

Day switch in VRP with Time Windows in OptaPlanner (Business Resource Planner)

I basically want to create a rule that helps me solve VRP in a certain way (I'm optimizing for distance):

I want it to have Time Windows, these rules work OK:

// TIME WINDOW &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
rule "arrivalAfterDueTime"  
salience -1  
when  
    $customer: TimeWindowedCustomer(dueTime < arrivalTime,
                                    $dueTime : dueTime,
                                    $arrivalTime : arrivalTime)  
then  
    scoreHolder.addHardConstraintMatch(kcontext, 
              (int)(10*($dueTime - $arrivalTime.intValue())) );  
end  
// ******************  

rule "Delivery in time window"  
salience -2  
when   
    $customer:TimeWindowedCustomer(nextCustomer != null,
                                   $arrivalTimeCustomer: arrivalTime)  

    $actual: TimeWindowedCustomer( previousStandstill == $customer,
           $arrivalTimeCustomer>arrivalTime,
           $arrival:arrivalTime )  
then
    scoreHolder.addHardConstraintMatch(kcontext,
             (int)(10*($arrival-$arrivalTimeCustomer)) );  
end  

But I want the vehicles to choose to deliver on more than one option of a day. Example: Time window is 8:00 am to 2:00 pm Monday through Thursday, so if a solution comes up that delivers on 3:00 pm on Monday, I want to have the rule consider Tuesday at 8:00 am instead if it's a better choice, and switch route order accordingly between days and vehicles without going off the time windows, but still making sequenced deliveries efficient (let OP 'choose' the best way to deliver while optimizing distance).

I hope I explained myself well, I don't know if the question is addressed correctly, if not please let me know so I can fix it.

Thank you very much!

Upvotes: 0

Views: 155

Answers (1)

laune
laune

Reputation: 31290

Your rules reward punctual (early) delivery and delivery in the set sequence. I don't see any reference to the 8am-2pm interval or from where the day of the week might come.

If you have to deliver everything between 8am and 2pm: Would it be possible to look at the problem disregarding the 8am-2pm interval as if the absolute time of the day wouldn't matter at all? This should construct one big route which will then simple be "cut" into the 6 hour intervals. Of course, you are disregarding the distances from home base to the 1st customer of the day and from the last one back to base.

It might be possible to do the "cut" in a second optimization provided there is a little leeway, e.g., continue a little longer than 2pm or even stop a little earlier.

Upvotes: 0

Related Questions