@ Override public SubsetValidation validate ( SubsetSolution solution ) { // check size boolean validSize = solution . getNumSelectedIDs ( ) >= getMinSubsetSize ( ) && solution . getNumSelectedIDs ( ) <= getMaxSubsetSize ( ) ; // combine with mandatory constraint validation if ( getMandatoryConstraints ( ) . isEmpty ( ) ) { // CASE 1: no mandatory constraints -- return constant validation object return validSize ? UNCONSTRAINED_VALID_SIZE : UNCONSTRAINED_INVALID_SIZE ; } else { // CASE 2: mandatory constraint(s) -- wrap constraints validation in subset validation Validation constraintVal = super . validate ( solution ) ; return new SubsetValidation ( validSize , constraintVal ) ; } }
Validate a subset solution . The returned validation object separately indicates whether the solution passed general mandatory constraint validation and whether it has a valid size .