SolutionType
- solution type of the problems that may be solved using this search, required to extend Solution
public class TabuSearch<SolutionType extends Solution> extends SingleNeighbourhoodSearch<SolutionType>
If all valid neighbours of the current solution are tabu, the search stops. Note that this may never happen so that a stop criterion should preferably be set to ensure termination.
Constructor and Description |
---|
TabuSearch(Problem<SolutionType> problem,
Neighbourhood<? super SolutionType> neighbourhood,
TabuMemory<SolutionType> tabuMemory)
Creates a new tabu search, specifying the problem to solve, the neighbourhood used to modify the current
solution and the applied tabu memory.
|
TabuSearch(String name,
Problem<SolutionType> problem,
Neighbourhood<? super SolutionType> neighbourhood,
TabuMemory<SolutionType> tabuMemory)
Creates a new tabu search, specifying the problem to solve, the neighbourhood used to modify the current
solution, the applied tabu memory and a custom search name.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
accept(Move<? super SolutionType> move)
Overrides acceptance of a move to update the tabu memory by registering the newly visited solution.
|
void |
clearTabuMemory()
Clear the tabu memory.
|
protected void |
generateRandomInitialSolution()
Updates the tabu memory if a random initial solution is generated.
|
TabuMemory<SolutionType> |
getTabuMemory()
Get the tabu memory.
|
protected void |
searchStep()
In every step, all neighbours of the current solution are inspected and the best valid, non tabu neighbour is
adopted as the new current solution, if any.
|
void |
setCurrentSolution(SolutionType solution)
Updates the tabu memory when a custom current/initial solution is set.
|
void |
setTabuMemory(TabuMemory<SolutionType> tabuMemory)
Set the tabu memory.
|
getNeighbourhood, setNeighbourhood
evaluate, getBestMove, getNumAcceptedMoves, getNumRejectedMoves, incNumAcceptedMoves, incNumRejectedMoves, init, isImprovement, reject, setEvaluatedMoveCache, updateCurrentSolution, validate
getCurrentSolution, getCurrentSolutionEvaluation, getCurrentSolutionValidation, setCurrentSolution, updateCurrentAndBestSolution, updateCurrentAndBestSolution, updateCurrentSolution
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, searchStopped, setRandom, setStopCriterionCheckPeriod, start, stop, toString, updateBestSolution, updateBestSolution
public TabuSearch(Problem<SolutionType> problem, Neighbourhood<? super SolutionType> neighbourhood, TabuMemory<SolutionType> tabuMemory)
null
. The search name defaults
to "TabuSearch".
Note that the applied neighbourhood and tabu memory should be compatible in terms of generated and accepted move
types, respectively, else an IncompatibleTabuMemoryException
might be thrown during search.
problem
- problem to solveneighbourhood
- neighbourhood used to create neighbouring solutionstabuMemory
- applied tabu memoryNullPointerException
- if problem
, neighbourhood
or tabuMemory
are null
public TabuSearch(String name, Problem<SolutionType> problem, Neighbourhood<? super SolutionType> neighbourhood, TabuMemory<SolutionType> tabuMemory)
null
. The search name can be null
in which case the default name "TabuSearch"
is assigned.
Note that the applied neighbourhood and tabu memory should be compatible in terms of generated and accepted move
types, respectively, else an IncompatibleTabuMemoryException
might be thrown during search.
name
- custom search nameproblem
- problem to solveneighbourhood
- neighbourhood used to create neighbouring solutionstabuMemory
- applied tabu memoryNullPointerException
- if problem
, neighbourhood
or tabyMemory
are null
public void clearTabuMemory()
public TabuMemory<SolutionType> getTabuMemory()
public void setTabuMemory(TabuMemory<SolutionType> tabuMemory)
null
.tabuMemory
- new tabu memoryNullPointerException
- if tabuMemory
is null
protected boolean accept(Move<? super SolutionType> move)
accept
in class NeighbourhoodSearch<SolutionType extends Solution>
move
- move to be acceptedtrue
if the update was successful, false
if the move is invalidpublic void setCurrentSolution(SolutionType solution)
setCurrentSolution
in class LocalSearch<SolutionType extends Solution>
solution
- manually specified current solutionSearchException
- if the search is not idleNullPointerException
- if solution
is null
protected void generateRandomInitialSolution()
generateRandomInitialSolution
in class LocalSearch<SolutionType extends Solution>
SearchException
- if a current solution is already set when calling this methodprotected void searchStep()
searchStep
in class Search<SolutionType extends Solution>
IncompatibleTabuMemoryException
- if the applied tabu memory is not compatible with the type of moves
generated by the applied neighbourhoodJamesRuntimeException
- if depending on malfunctioning components (problem, neighbourhood, ...)Copyright © 2016. All rights reserved.