SolutionType
- the solution type that corresponds to this problem, required to extend Solution
public interface Problem<SolutionType extends Solution>
Modifier and Type | Method and Description |
---|---|
default SolutionType |
createRandomSolution()
Creates a random solution, using a default source of randomness.
|
SolutionType |
createRandomSolution(Random rnd)
Creates a random solution using the given source of randomness.
|
default Evaluation |
evaluate(Move<? super SolutionType> move,
SolutionType curSolution,
Evaluation curEvaluation)
Evaluates a move that will be applied to the current solution of a local search (delta evaluation).
|
Evaluation |
evaluate(SolutionType solution)
Evaluates a given solution.
|
boolean |
isMinimizing()
Indicates whether scores are being minimized or maximized.
|
default Validation |
validate(Move<? super SolutionType> move,
SolutionType curSolution,
Validation curValidation)
Validates a move that will be applied to the current solution of a local search (delta validation).
|
Validation |
validate(SolutionType solution)
Validates a solution.
|
Evaluation evaluate(SolutionType solution)
Evaluation
. The corresponding
double value can be obtained by calling Evaluation.getValue()
on the evaluation object.solution
- the solution to evaluatedefault Evaluation evaluate(Move<? super SolutionType> move, SolutionType curSolution, Evaluation curEvaluation)
Evaluates a move that will be applied to the current solution of a local search (delta evaluation).
The result corresponds to the evaluation 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) computes a full evaluation by calling evaluate(Solution)
and (3) undoes the applied move.
It is often possible to provide a custom, much more efficient delta evaluation that computes
the modified evaluation based on the current evaluation 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 problem
requires application of neighbourhoods that generate moves of this type (or a subtype).
If an incompatible move type is received, an IncompatibleDeltaEvaluationException
may be thrown.
Given that both this method and the full evaluation (evaluate(Solution)
) return
evaluations of the same type, it is guaranteed that curEvaluation
will also be of
this specific type and it is safe to perform a cast, if required.
move
- move to evaluatecurSolution
- current solutioncurEvaluation
- evaluation of current solutionIncompatibleDeltaEvaluationException
- if the provided delta evaluation is not compatible
with the received move typeValidation validate(SolutionType solution)
Validation
. It can be checked wether the
solution passed validation by calling Validation.passed()
on this validation object. When
a solution does not pass validation it is discarded by any search so that the best found solution
is guaranteed to be valid.solution
- solution to validatedefault Validation validate(Move<? super SolutionType> move, SolutionType curSolution, Validation curValidation)
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)
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)
) 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.
move
- move to validatecurSolution
- current solutioncurValidation
- validation of current solutionIncompatibleDeltaValidationException
- if the provided delta validation is not compatible
with the received move typeboolean isMinimizing()
SolutionType createRandomSolution(Random rnd)
rnd
- source of randomness used to generate a random solutiondefault SolutionType createRandomSolution()
createRandomSolution(ThreadLocalRandom.current())
where a thread
local random generator is used to avoid overhead and contention for parallel calls.Copyright © 2016. All rights reserved.