SolutionType
- solution type of the problems that may be solved using this search,
required to extend Solution
public class BasicParallelSearch<SolutionType extends Solution> extends Search<SolutionType>
A basic parallel search runs several (heterogeneous) searches in parallel and keeps track of the best solution found by any of these searches. The parallel search consists of a single step in which (1) all subsearches are executed concurrently using a cached thread pool, (2) the main search waits until termination of all subsearches and (3) the main search itself terminates.
When a parallel search is requested to stop (see Search.stop()
) it will propagate this request
to its subsearches and will wait for their termination. Similarly, when a parallel search is disposed
(see Search.dispose()
) all subsearches are also disposed.
Because searches are executed in separate threads, it is important to ensure that any shared objects (problem, objective, constraints, neighbourhood, ...) are thread-safe.
Constructor and Description |
---|
BasicParallelSearch(Problem<SolutionType> problem)
Creates a new basic parallel search, specifying the problem to solve.
|
BasicParallelSearch(String name,
Problem<SolutionType> problem)
Creates a new basic parallel search, specifying the problem to solve and a custom search name.
|
Modifier and Type | Method and Description |
---|---|
void |
addSearch(Search<SolutionType> search)
Add the given search, to be executed in parallel with the other searches.
|
List<Search<SolutionType>> |
getSearches()
Get an unmodifiable view of the list of all searches that
have been added to this parallel search for concurrent execution.
|
void |
init()
When the search is initialized, it is verified whether at least one subsearch
has been added and all subsearches are initialized as well (in parallel).
|
boolean |
removeSearch(Search<SolutionType> search)
Remove the given search.
|
protected void |
searchDisposed()
When disposing a basic parallel search, each of the searches that have been added to the parallel
algorithm are disposed and the thread pool used for concurrent search execution is released.
|
protected void |
searchStep()
This algorithm consists of a single search step only, in which (1) the contained subsearches are executed in
parallel, (2) the main search waits until they terminate and (3) the main search stops.
|
void |
stop()
When requesting to stop a basic parallel search, this request is propagated to each contained search.
|
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, searchStarted, searchStopped, setRandom, setStopCriterionCheckPeriod, start, toString, updateBestSolution, updateBestSolution
public BasicParallelSearch(Problem<SolutionType> problem)
null
.
The default search name "BasicParallelSearch" is assigned to this search.problem
- problem to solveNullPointerException
- if problem
is null
public BasicParallelSearch(String name, Problem<SolutionType> problem)
null
. The search name can be null
in which case the default name
"BasicParallelSearch" is assigned.problem
- problem to solvename
- custom search nameNullPointerException
- if problem
is null
public void addSearch(Search<SolutionType> search)
Add the given search, to be executed in parallel with the other searches. Only searches that solve the same problem as the one specified when creating the parallel search can be added. An exception will be thrown when attempting to add a search that solves a different problem. Note that this method may only be called when the search is idle.
Because searches are executed in separate threads, it is important to ensure that any shared objects (problem, objective, constraints, neighbourhood, ...) are thread-safe.
search
- search to add for parallel executionSearchException
- if the parallel search is not idle, or if the given search does not solve
the same problem as the parallel searchpublic boolean removeSearch(Search<SolutionType> search)
false
is returned.
Note that this method may only be called when the search is idle.search
- search to be removed from parallel algorithmtrue
if search is successfully removedSearchException
- if the search is not idlepublic List<Search<SolutionType>> getSearches()
public void init()
init
in class Search<SolutionType extends Solution>
SearchException
- if no searches have been addedpublic void stop()
stop
in class Search<SolutionType extends Solution>
protected void searchDisposed()
searchDisposed
in class Search<SolutionType extends Solution>
protected void searchStep()
searchStep
in class Search<SolutionType extends Solution>
Copyright © 2016. All rights reserved.