SolutionType
- solution type to which the constraint is applied, required to extend Solution
DataType
- underlying data type used for validationpublic 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.
Modifier and Type | Method and Description |
---|---|
default <ActualSolutionType extends SolutionType> |
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.
|
PenalizingValidation validate(SolutionType solution, DataType data)
PenalizingValidation
.
The assigned penalty can be retrieved by calling PenalizingValidation.getPenalty()
on this object.validate
in interface Constraint<SolutionType extends Solution,DataType>
solution
- solution to validatedata
- underlying data used for validationdefault <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.
validate
in interface Constraint<SolutionType extends Solution,DataType>
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 movemove
- move to validatecurSolution
- current solutioncurValidation
- validation of current solutiondata
- underlying data used for validationIncompatibleDeltaValidationException
- if the provided delta validation is not compatible
with the received move typeCopyright © 2016. All rights reserved.