GenomeType - Type of genome used to represent a single element in
the genetic population. For example, a Vector.CostParametersType - Type of parameters that the cost function
takes. For example, Collection<InputOutputPairs>.public class ParallelizedGeneticAlgorithm<CostParametersType,GenomeType> extends GeneticAlgorithm<CostParametersType,GenomeType> implements ParallelAlgorithm
| Modifier and Type | Class and Description |
|---|---|
protected class |
ParallelizedGeneticAlgorithm.EvaluateGenome
Callable task for the evaluate() method.
|
DEFAULT_MAX_ITERATIONSdata, keepGoingmaxIterationsDEFAULT_ITERATION, iteration| Constructor and Description |
|---|
ParallelizedGeneticAlgorithm()
Default constructor
|
ParallelizedGeneticAlgorithm(java.util.Collection<GenomeType> initialPopulation,
Reproducer<GenomeType> reproducer,
CostFunction<? super GenomeType,? super CostParametersType> cost,
java.util.concurrent.ThreadPoolExecutor threadPool) |
ParallelizedGeneticAlgorithm(java.util.Collection<GenomeType> initialPopulation,
Reproducer<GenomeType> reproducer,
CostFunction<? super GenomeType,? super CostParametersType> cost,
java.util.concurrent.ThreadPoolExecutor threadPool,
int maxIterations,
int maxIterationsWithoutImprovement) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
createEvaluationTasks(java.util.Collection<GenomeType> population)
Creates the evaluation tasks to execute in parallel.
|
protected java.util.ArrayList<EvaluatedGenome<GenomeType>> |
evaluatePopulation(java.util.Collection<GenomeType> population)
Converts a population of genomes into evaluated genomes.
|
int |
getNumThreads()
Getter for #threads
|
java.util.concurrent.ThreadPoolExecutor |
getThreadPool()
Getter for threadPool
|
void |
setThreadPool(java.util.concurrent.ThreadPoolExecutor threadPool)
Setter for threadPool
|
cleanupAlgorithm, getBestSoFar, getCostFunction, getInitialPopulation, getIterationsWithoutImprovement, getMaxIterationsWithoutImprovement, getPerformance, getPopulation, getReproducer, getResult, initializeAlgorithm, searchForBetter, setBestSoFar, setCostFunction, setInitialPopulation, setIterationsWithoutImprovement, setMaxIterationsWithoutImprovement, setPopulation, setReproducer, stepclone, getData, getKeepGoing, learn, setData, setKeepGoing, stopgetMaxIterations, isResultValid, setMaxIterationsaddIterativeAlgorithmListener, fireAlgorithmEnded, fireAlgorithmStarted, fireStepEnded, fireStepStarted, getIteration, getListeners, removeIterativeAlgorithmListener, setIteration, setListenersequals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitclonelearngetMaxIterations, setMaxIterationsaddIterativeAlgorithmListener, getIteration, removeIterativeAlgorithmListenerisResultValidpublic ParallelizedGeneticAlgorithm()
public ParallelizedGeneticAlgorithm(java.util.Collection<GenomeType> initialPopulation, Reproducer<GenomeType> reproducer, CostFunction<? super GenomeType,? super CostParametersType> cost, java.util.concurrent.ThreadPoolExecutor threadPool)
initialPopulation - The initial population to start the algorithmreproducer - The reproduction method to use.cost - The cost function for genomes.threadPool - Thread pool to use for parallelizationpublic ParallelizedGeneticAlgorithm(java.util.Collection<GenomeType> initialPopulation, Reproducer<GenomeType> reproducer, CostFunction<? super GenomeType,? super CostParametersType> cost, java.util.concurrent.ThreadPoolExecutor threadPool, int maxIterations, int maxIterationsWithoutImprovement)
initialPopulation - The initial population to start the algorithmreproducer - The reproduction method to use.cost - The cost function for genomes.threadPool - Thread pool to use for parallelizationmaxIterations - The maximum number of iterations to run.maxIterationsWithoutImprovement - The maximum number of iterations
to go without improvement before stopping.public java.util.concurrent.ThreadPoolExecutor getThreadPool()
getThreadPool in interface ParallelAlgorithmpublic void setThreadPool(java.util.concurrent.ThreadPoolExecutor threadPool)
setThreadPool in interface ParallelAlgorithmthreadPool - Thread pool used to parallelize the computationpublic int getNumThreads()
getNumThreads in interface ParallelAlgorithmprotected void createEvaluationTasks(java.util.Collection<GenomeType> population)
population - The population to create tasks for.protected java.util.ArrayList<EvaluatedGenome<GenomeType>> evaluatePopulation(java.util.Collection<GenomeType> population)
evaluatePopulation in class GeneticAlgorithm<CostParametersType,GenomeType>population - The population of genomes to evaluate.