gov.sandia.cognition.learning.algorithm.genetic
Class ParallelizedGeneticAlgorithm<CostParametersType,GenomeType>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.algorithm.AbstractIterativeAlgorithm
          extended by gov.sandia.cognition.algorithm.AbstractAnytimeAlgorithm<ResultType>
              extended by gov.sandia.cognition.learning.algorithm.AbstractAnytimeBatchLearner<CostParametersType,GenomeType>
                  extended by gov.sandia.cognition.learning.algorithm.genetic.GeneticAlgorithm<CostParametersType,GenomeType>
                      extended by gov.sandia.cognition.learning.algorithm.genetic.ParallelizedGeneticAlgorithm<CostParametersType,GenomeType>
Type Parameters:
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>.
All Implemented Interfaces:
AnytimeAlgorithm<GenomeType>, IterativeAlgorithm, MeasurablePerformanceAlgorithm, ParallelAlgorithm, StoppableAlgorithm, AnytimeBatchLearner<CostParametersType,GenomeType>, BatchCostMinimizationLearner<CostParametersType,GenomeType>, BatchLearner<CostParametersType,GenomeType>, CloneableSerializable, Serializable, Cloneable

public class ParallelizedGeneticAlgorithm<CostParametersType,GenomeType>
extends GeneticAlgorithm<CostParametersType,GenomeType>
implements ParallelAlgorithm

This is a parallel implementation of the genetic algorithm. The default is to use n-1 available cores/hyperthreads on a machine and spread the cost function evaluations across these computational units.

Author:
cewarr
See Also:
Serialized Form

Nested Class Summary
protected  class ParallelizedGeneticAlgorithm.EvaluateGenome
          Callable task for the evaluate() method.
 
Field Summary
 
Fields inherited from class gov.sandia.cognition.learning.algorithm.genetic.GeneticAlgorithm
DEFAULT_MAX_ITERATIONS
 
Fields inherited from class gov.sandia.cognition.learning.algorithm.AbstractAnytimeBatchLearner
data, keepGoing
 
Fields inherited from class gov.sandia.cognition.algorithm.AbstractAnytimeAlgorithm
maxIterations
 
Fields inherited from class gov.sandia.cognition.algorithm.AbstractIterativeAlgorithm
DEFAULT_ITERATION, iteration
 
Constructor Summary
ParallelizedGeneticAlgorithm()
          Default constructor
ParallelizedGeneticAlgorithm(Collection<GenomeType> initialPopulation, Reproducer<GenomeType> reproducer, CostFunction<? super GenomeType,? super CostParametersType> cost, ThreadPoolExecutor threadPool)
           
ParallelizedGeneticAlgorithm(Collection<GenomeType> initialPopulation, Reproducer<GenomeType> reproducer, CostFunction<? super GenomeType,? super CostParametersType> cost, ThreadPoolExecutor threadPool, int maxIterations, int maxIterationsWithoutImprovement)
           
 
Method Summary
protected  void createEvaluationTasks(Collection<GenomeType> population)
          Creates the evaluation tasks to execute in parallel.
protected  ArrayList<EvaluatedGenome<GenomeType>> evaluatePopulation(Collection<GenomeType> population)
          Converts a population of genomes into evaluated genomes.
 int getNumThreads()
          Getter for #threads
 ThreadPoolExecutor getThreadPool()
          Getter for threadPool
 void setThreadPool(ThreadPoolExecutor threadPool)
          Setter for threadPool
 
Methods inherited from class gov.sandia.cognition.learning.algorithm.genetic.GeneticAlgorithm
cleanupAlgorithm, getBestSoFar, getCostFunction, getInitialPopulation, getIterationsWithoutImprovement, getMaxIterationsWithoutImprovement, getPerformance, getPopulation, getReproducer, getResult, initializeAlgorithm, searchForBetter, setBestSoFar, setCostFunction, setInitialPopulation, setIterationsWithoutImprovement, setMaxIterationsWithoutImprovement, setPopulation, setReproducer, step
 
Methods inherited from class gov.sandia.cognition.learning.algorithm.AbstractAnytimeBatchLearner
clone, getData, getKeepGoing, learn, setData, setKeepGoing, stop
 
Methods inherited from class gov.sandia.cognition.algorithm.AbstractAnytimeAlgorithm
getMaxIterations, isResultValid, setMaxIterations
 
Methods inherited from class gov.sandia.cognition.algorithm.AbstractIterativeAlgorithm
addIterativeAlgorithmListener, fireAlgorithmEnded, fireAlgorithmStarted, fireStepEnded, fireStepStarted, getIteration, getListeners, removeIterativeAlgorithmListener, setIteration, setListeners
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.util.CloneableSerializable
clone
 
Methods inherited from interface gov.sandia.cognition.learning.algorithm.BatchCostMinimizationLearner
learn
 
Methods inherited from interface gov.sandia.cognition.algorithm.AnytimeAlgorithm
getMaxIterations, setMaxIterations
 
Methods inherited from interface gov.sandia.cognition.algorithm.IterativeAlgorithm
addIterativeAlgorithmListener, getIteration, removeIterativeAlgorithmListener
 
Methods inherited from interface gov.sandia.cognition.algorithm.StoppableAlgorithm
isResultValid
 

Constructor Detail

ParallelizedGeneticAlgorithm

public ParallelizedGeneticAlgorithm()
Default constructor


ParallelizedGeneticAlgorithm

public ParallelizedGeneticAlgorithm(Collection<GenomeType> initialPopulation,
                                    Reproducer<GenomeType> reproducer,
                                    CostFunction<? super GenomeType,? super CostParametersType> cost,
                                    ThreadPoolExecutor threadPool)
Parameters:
initialPopulation - The initial population to start the algorithm
reproducer - The reproduction method to use.
cost - The cost function for genomes.
threadPool - Thread pool to use for parallelization

ParallelizedGeneticAlgorithm

public ParallelizedGeneticAlgorithm(Collection<GenomeType> initialPopulation,
                                    Reproducer<GenomeType> reproducer,
                                    CostFunction<? super GenomeType,? super CostParametersType> cost,
                                    ThreadPoolExecutor threadPool,
                                    int maxIterations,
                                    int maxIterationsWithoutImprovement)
Parameters:
initialPopulation - The initial population to start the algorithm
reproducer - The reproduction method to use.
cost - The cost function for genomes.
threadPool - Thread pool to use for parallelization
maxIterations - The maximum number of iterations to run.
maxIterationsWithoutImprovement - The maximum number of iterations to go without improvement before stopping.
Method Detail

getThreadPool

public ThreadPoolExecutor getThreadPool()
Getter for threadPool

Specified by:
getThreadPool in interface ParallelAlgorithm
Returns:
Thread pool used to parallelize the computation

setThreadPool

public void setThreadPool(ThreadPoolExecutor threadPool)
Setter for threadPool

Specified by:
setThreadPool in interface ParallelAlgorithm
Parameters:
threadPool - Thread pool used to parallelize the computation

getNumThreads

public int getNumThreads()
Getter for #threads

Specified by:
getNumThreads in interface ParallelAlgorithm
Returns:
#threads

createEvaluationTasks

protected void createEvaluationTasks(Collection<GenomeType> population)
Creates the evaluation tasks to execute in parallel.

Parameters:
population - The population to create tasks for.

evaluatePopulation

protected ArrayList<EvaluatedGenome<GenomeType>> evaluatePopulation(Collection<GenomeType> population)
Converts a population of genomes into evaluated genomes.

Overrides:
evaluatePopulation in class GeneticAlgorithm<CostParametersType,GenomeType>
Parameters:
population - The population of genomes to evaluate.
Returns:
A population of evaluated genomes.