I am trying to solve VRP with OptaPlanner. I have multiple customers that have different time windows. Here are my constraint providers
protected Constraint arrivalAfterDueTime(ConstraintFactory factory) {
return factory.from(TimeWindowedCustomer.class)
.filter(customer -> customer.getArrivalTime() >= customer.getDueTime())
.penalizeLong("arrivalAfterDueTime",
HardSoftLongScore.ONE_HARD,
customer -> customer.getArrivalTime() - customer.getDueTime());
}
protected Constraint arrivalBeforeReadyTime(ConstraintFactory factory) {
return factory.from(TimeWindowedCustomer.class)
.filter(customer -> customer.getArrivalTime() > customer.getReadyTime()
&& customer.getArrivalTime() < customer.getDueTime() )
.penalizeLong("arrivalBeforeReadyTime",
HardSoftLongScore.ONE_HARD,
customer -> customer.getReadyTime() - customer.getArrivalTime());
}
But in the solution I get arrival times that are < ready time. How can I fix this? Thank you in advance.
There are generally three approaches when arriving too early:
In any case, use ConstraintVerifier
to unit test your constraints!