timefold-solver
timefold-solver copied to clipboard
Feat: Support testing of node sharing between constraints
Assume two constraints sharing the same UniConstraintStream:
@Override
public Constraint[] defineConstraints(ConstraintFactory factory) {
UniConstraintStream<VehicleShift> nonVirtualVehicles = factory.forEach(VehicleShift.class)
.filter(vehicleShift -> !vehicleShift.isVirtual());
return new Constraint[] {
// hard
endLocationMaxArrivalTimeHardLimit(nonVirtualVehicles),
lastVisitMaxDepartureTimeHardLimit(nonVirtualVehicles)
};
}
These constraints cannot be unit-tested using the ConstraintVerifier as the constraintVerifier.verifyThat() expects a method reference with a single parameter, the ConstraintFactory .
Out of curiosity: Does node sharing like this improve performance or is it solely done to avoid code duplication?
This improves performance. If your constraint streams share parts, those parts will only be executed once, regardless of how many constraints they're part of.
The Enterprise Edition takes care of this automatically, no need to think about it, or to restructure your code for it.