SolutionType
- solution type of the problems that may be solved using this search, required to extend Solution
public abstract class LocalSearch<SolutionType extends Solution> extends Search<SolutionType>
setCurrentSolution(Solution)
before running the search, else,
a random initial solution is used. The current solution is retained across subsequent runs of a local search.
This means that upon restarting a local search, it will continue from where it had arrived in the previous run.Constructor and Description |
---|
LocalSearch(Problem<SolutionType> problem)
Create a new local search to solve the given problem, with default name "LocalSearch".
|
LocalSearch(String name,
Problem<SolutionType> problem)
Create a new local search to solve the given problem, with a custom name.
|
Modifier and Type | Method and Description |
---|---|
protected void |
generateRandomInitialSolution()
Generates a random initial solution.
|
SolutionType |
getCurrentSolution()
Get the current solution.
|
Evaluation |
getCurrentSolutionEvaluation()
Get the evaluation of the current solution.
|
Validation |
getCurrentSolutionValidation()
Get the validation of the current solution.
|
void |
init()
When the search is initialized, a random initial solution is generated if none has been specified
or generated before.
|
void |
setCurrentSolution(SolutionType solution)
Sets the current solution prior to execution or in between search runs.
|
void |
setCurrentSolution(SolutionType solution,
Evaluation evaluation,
Validation validation)
Sets the current solution given that it has already been evaluated and validated.
|
protected boolean |
updateCurrentAndBestSolution(SolutionType solution)
Update the current and best solution during search.
|
protected boolean |
updateCurrentAndBestSolution(SolutionType solution,
Evaluation evaluation,
Validation validation)
Update the current and best solution during search, given that the respective solution has already
been evaluated and validated.
|
protected void |
updateCurrentSolution(SolutionType solution)
Update the current solution during search.
|
protected void |
updateCurrentSolution(SolutionType solution,
Evaluation evaluation,
Validation validation)
Update the current solution during search, given that it has already been evaluated and validated.
|
addSearchListener, addStopCriterion, assertIdle, clearSearchListeners, clearStopCriteria, computeDelta, dispose, getBestSolution, getBestSolutionEvaluation, getBestSolutionValidation, getID, getMinDelta, getName, getProblem, getRandom, getRuntime, getSearchListeners, getStatus, getStatusLock, getSteps, getStepsWithoutImprovement, getTimeWithoutImprovement, removeSearchListener, removeStopCriterion, run, searchDisposed, searchStarted, searchStep, searchStopped, setRandom, setStopCriterionCheckPeriod, start, stop, toString, updateBestSolution, updateBestSolution
public LocalSearch(Problem<SolutionType> problem)
problem
- problem to solveNullPointerException
- if problem
is null
public LocalSearch(String name, Problem<SolutionType> problem)
name
is null
, the default name "LocalSearch" will be assigned.problem
- problem to solvename
- custom search nameNullPointerException
- if problem
is null
public void init()
init
in class Search<SolutionType extends Solution>
protected void generateRandomInitialSolution()
Search.searchStarted()
.SearchException
- if a current solution is already set when calling this methodpublic SolutionType getCurrentSolution()
null
if no current
solution has been set yet, for example when the search has just been created or is still initializing.null
otherwisepublic Evaluation getCurrentSolutionEvaluation()
null
if no current solution has been set yet, for example
when the search has just been created or is still initializing.null
otherwisepublic Validation getCurrentSolutionValidation()
null
if no current solution has been set yet, for example
when the search has just been created or is still initializing.null
otherwisepublic void setCurrentSolution(SolutionType solution)
solution
- current solution to be adoptedSearchException
- if the search is not idleNullPointerException
- if solution
is null
public void setCurrentSolution(SolutionType solution, Evaluation evaluation, Validation validation)
solution
- current solution to be adoptedevaluation
- current solution evaluationvalidation
- current solution validationSearchException
- if the search is not idleNullPointerException
- if any argument is null
protected void updateCurrentSolution(SolutionType solution)
solution
- new current solutionprotected void updateCurrentSolution(SolutionType solution, Evaluation evaluation, Validation validation)
solution
- new current solutionevaluation
- evaluation of new current solutionvalidation
- validation of new current solutionprotected boolean updateCurrentAndBestSolution(SolutionType solution)
solution
- new current solutiontrue
if the best solution has been updatedprotected boolean updateCurrentAndBestSolution(SolutionType solution, Evaluation evaluation, Validation validation)
solution
- new current solutionevaluation
- evaluation of new current solutionvalidation
- validation of new current solutiontrue
if the best solution has been updatedCopyright © 2016. All rights reserved.