org.jamesframework.core.problems.constraints

## Interface PenalizingConstraint<SolutionType extends Solution,DataType>

• Type Parameters:
SolutionType - solution type to which the constraint is applied, required to extend Solution
DataType - underlying data type used for validation
All Superinterfaces:
Constraint<SolutionType,DataType>

public interface PenalizingConstraint<SolutionType extends Solution,DataType>
extends Constraint<SolutionType,DataType>

Interface of a penalizing constraint that assigns a penalty to a solution's evaluation if it does not satisfy the constraint. This penalty is taken into account when evaluating the corresponding solution: in case evaluations are maximized the penalty is subtracted from the solution's evaluation, in case of minimization the penalty is added to the evaluation. When a solution satisfies the constraint, no penalty (zero) should be assigned.

It is required to provide a full validation by implementing validate(Solution, Object). If desired, an efficient delta validation can also be provided by overriding the default behaviour of validate(Move, Solution, Validation, Object) which (1) applies the move, (2) performs a full validation and (3) undoes the move.

Author:
Herman De Beukelaer
• ### Method Summary

All Methods
Modifier and Type Method and Description
default <ActualSolutionType extends SolutionType>PenalizingValidation validate(Move<? super ActualSolutionType> move, ActualSolutionType curSolution, Validation curValidation, DataType data)
Validates a move that will be applied to the current solution of a local search (delta validation).
PenalizingValidation validate(SolutionType solution, DataType data)
Validates a solution given the underlying data.
• ### Method Detail

• #### validate

PenalizingValidation validate(SolutionType solution,
DataType data)
Validates a solution given the underlying data. Returns an object of type PenalizingValidation. The assigned penalty can be retrieved by calling PenalizingValidation.getPenalty() on this object.
Specified by:
validate in interface Constraint<SolutionType extends Solution,DataType>
Parameters:
solution - solution to validate
data - underlying data used for validation
Returns:
penalizing validation that indicates the assigned penalty
• #### validate

default <ActualSolutionType extends SolutionType> PenalizingValidation validate(Move<? super ActualSolutionType> move,
ActualSolutionType curSolution,
Validation curValidation,
DataType data)

Validates a move that will be applied to the current solution of a local search (delta validation). The result corresponds to the validation of the modified solution that would be obtained by applying the given move to the current solution. A default implementation is provided that (1) applies the move, (2) performs a full validation by calling validate(Solution, Object) and (3) undoes the applied move.

It is often possible to provide a custom, much more efficient delta validation based on the current validation and the changes that will be made when applying the move to the current solution. This can be done by overriding this method. It is usually required to cast the received move to a specific type so that this constraint can only be used in combination with neighbourhoods that generate moves of this type (or a subtype). If an incompatible move type is received, an IncompatibleDeltaValidationException may be thrown.

Given that both this method and the full validation (validate(Solution, Object)) return validations of the same type, it is guaranteed that curValidation will also be of this specific type and it is safe to perform a cast, if required.

Specified by:
validate in interface Constraint<SolutionType extends Solution,DataType>
Type Parameters:
ActualSolutionType - the actual solution type of the problem that is being solved; a subtype of the solution types of both the constraint and the applied move
Parameters:
move - move to validate
curSolution - current solution
curValidation - validation of current solution
data - underlying data used for validation
Returns:
penalizing validation of modified solution obtained when applying the move to the current solution
Throws:
IncompatibleDeltaValidationException - if the provided delta validation is not compatible with the received move type