org.jamesframework.core.problems

## Interface Problem<SolutionType extends Solution>

• Type Parameters:
SolutionType - the solution type that corresponds to this problem, required to extend Solution
All Known Implementing Classes:
GenericProblem, SubsetProblem

public interface Problem<SolutionType extends Solution>
Interface of a problem with a generic solution type. Contains methods to evaluate or validate a solution or move and to create a random solution. Also indicates whether evaluations are to be maximized or minimized.
Author:
Herman De Beukelaer
• ### Method Summary

All Methods
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.
• ### Method Detail

• #### evaluate

Evaluation evaluate(SolutionType solution)
Evaluates a given solution. Returns an object of type Evaluation. The corresponding double value can be obtained by calling Evaluation.getValue() on the evaluation object.
Parameters:
solution - the solution to evaluate
Returns:
evaluation of the given solution
• #### evaluate

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). 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.

Parameters:
move - move to evaluate
curSolution - current solution
curEvaluation - evaluation of current solution
Returns:
evaluation of modified solution obtained when applying the move to the current solution
Throws:
IncompatibleDeltaEvaluationException - if the provided delta evaluation is not compatible with the received move type
• #### validate

Validation validate(SolutionType solution)
Validates a solution. Returns an object of type 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.
Parameters:
solution - solution to validate
Returns:
a validation object that indicates wether the solution passed validation
• #### validate

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). 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.

Parameters:
move - move to validate
curSolution - current solution
curValidation - validation of current solution
Returns:
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
• #### isMinimizing

boolean isMinimizing()
Indicates whether scores are being minimized or maximized.
Returns:
true if scores are being minimized
• #### createRandomSolution

SolutionType createRandomSolution(Random rnd)
Creates a random solution using the given source of randomness. Such random solutions are for example be used as default initial solution in most neighbourhood searches.
Parameters:
rnd - source of randomness used to generate a random solution
Returns:
a random solution
• #### createRandomSolution

default SolutionType createRandomSolution()
Creates a random solution, using a default source of randomness. The default implementation delegates to createRandomSolution(ThreadLocalRandom.current()) where a thread local random generator is used to avoid overhead and contention for parallel calls.
Returns:
a random solution