I am reading through the vehicle routing example (v 7.25.0) and have stumbled on some confusion regarding what is a problem fact vs planning entity.
The documentation in section 4.3.5.4 states:
A planning variable that is chained either:
- Directly points to a problem fact (or planning entity), which is called an anchor.
- Points to another planning entity with the same planning variable, which recursively points to an anchor.
And then right below it also states:
Every chain always has exactly one anchor. The anchor is a problem fact, never a planning entity.
This conflicting information leads to my confusion #1: is an anchor always a problem fact, or can it be a planning entity?
The reason I ask is because Vehicle (the anchor) implements Standstill which is defined in the vehicleRoutingSolverConfig.xml as:
<entityClass>org.optaplanner.examples.vehiclerouting.domain.Standstill</entityClass>
which leads me to believe that the Vehicle would "inherit" the planning entity property.
But then, I tried creating a drools rule that sets a hard constraint on the max # of customers associated to a vehicle using an instance method on Vehicle that returns the count by walking nextCustomer shadow variable until null, like:
when
Vehicle(totalCustomers > 5, $totalCustomers : totalCustomers)
then
scoreHolder.addHardConstraintMatch(kcontext, 5 - $totalCustomers)
and it doesn't seem to work: the hard constraints are violated and the hard score stays 0 (there are no other hard constraints, this was just a test -- also, I had the planner run for a very long time using CH + local search and breakpoints showed this method returning > 5 at various points in time including the final solution, so it wasn't just a configuration issue).
What am I missing?