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_ITERATIONS
data, keepGoing
maxIterations
DEFAULT_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, step
clone, getData, getKeepGoing, learn, setData, setKeepGoing, stop
getMaxIterations, isResultValid, setMaxIterations
addIterativeAlgorithmListener, fireAlgorithmEnded, fireAlgorithmStarted, fireStepEnded, fireStepStarted, getIteration, getListeners, removeIterativeAlgorithmListener, setIteration, setListeners
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
clone
learn
getMaxIterations, setMaxIterations
addIterativeAlgorithmListener, getIteration, removeIterativeAlgorithmListener
isResultValid
public 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 ParallelAlgorithm
public void setThreadPool(java.util.concurrent.ThreadPoolExecutor threadPool)
setThreadPool
in interface ParallelAlgorithm
threadPool
- Thread pool used to parallelize the computationpublic int getNumThreads()
getNumThreads
in interface ParallelAlgorithm
protected 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.