The Encog Project

org.encog.solve.genetic
Class GeneticAlgorithm<GENE_TYPE>

java.lang.Object
  extended by org.encog.solve.genetic.GeneticAlgorithm<GENE_TYPE>
Direct Known Subclasses:
NeuralGeneticAlgorithm

public abstract class GeneticAlgorithm<GENE_TYPE>
extends java.lang.Object

GeneticAlgorithm: Implements a genetic algorithm. This is an abstract class. Other classes are provided in this book that use this base class to train neural networks or provide an answer to the traveling salesman problem. The genetic algorithm is also capable of using a thread pool to speed execution.


Field Summary
static int TIMEOUT
          Threadpool timeout.
 
Constructor Summary
GeneticAlgorithm()
           
 
Method Summary
 Chromosome<GENE_TYPE> getChromosome(int i)
          Get a specific chromosome.
 Chromosome<GENE_TYPE>[] getChromosomes()
          Return the entire population.
 int getCutLength()
          Get the cut length.
 double getMatingPopulation()
          Get the mating population.
 double getMutationPercent()
          Get the mutation percent.
 double getPercentToMate()
          Get the percent to mate.
 java.util.concurrent.ExecutorService getPool()
          Get the optional threadpool.
 int getPopulationSize()
          Get the population size.
 boolean isPreventRepeat()
          Should repeating genes be prevented.
 void iteration()
          Modify the weight matrix and thresholds based on the last call to calcError.
 void setChromosome(int i, Chromosome<GENE_TYPE> value)
          Set the specified chromosome.
 void setChromosomes(Chromosome<GENE_TYPE>[] chromosomes)
          Set the entire population.
 void setCutLength(int cutLength)
          Set the cut length.
 void setMatingPopulation(double matingPopulation)
          Set the mating population percent.
 void setMutationPercent(double mutationPercent)
          Set the mutation percent.
 void setPercentToMate(double percentToMate)
          Set the percent to mate.
 void setPool(java.util.concurrent.ExecutorService pool)
          Set the optional thread pool.
 void setPopulationSize(int populationSize)
          Set the population size.
 void setPreventRepeat(boolean preventRepeat)
          Set the gene.
 void sortChromosomes()
          Sort the chromosomes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIMEOUT

public static final int TIMEOUT
Threadpool timeout.

See Also:
Constant Field Values
Constructor Detail

GeneticAlgorithm

public GeneticAlgorithm()
Method Detail

getChromosome

public Chromosome<GENE_TYPE> getChromosome(int i)
Get a specific chromosome.

Parameters:
i - The chromosome to return, 0 for the first one.
Returns:
A chromosome.

getChromosomes

public Chromosome<GENE_TYPE>[] getChromosomes()
Return the entire population.

Returns:
the chromosomes

getCutLength

public int getCutLength()
Get the cut length.

Returns:
The cut length.

getMatingPopulation

public double getMatingPopulation()
Get the mating population.

Returns:
The mating population percent.

getMutationPercent

public double getMutationPercent()
Get the mutation percent.

Returns:
The mutation percent.

getPercentToMate

public double getPercentToMate()
Get the percent to mate.

Returns:
The percent to mate.

getPool

public java.util.concurrent.ExecutorService getPool()
Get the optional threadpool.

Returns:
the pool

getPopulationSize

public int getPopulationSize()
Get the population size.

Returns:
The population size.

isPreventRepeat

public boolean isPreventRepeat()
Should repeating genes be prevented.

Returns:
True if repeating genes should be prevented.

iteration

public void iteration()
Modify the weight matrix and thresholds based on the last call to calcError.

Throws:
NeuralNetworkException

setChromosome

public void setChromosome(int i,
                          Chromosome<GENE_TYPE> value)
Set the specified chromosome.

Parameters:
i - The chromosome to set.
value - The value for the specified chromosome.

setChromosomes

public void setChromosomes(Chromosome<GENE_TYPE>[] chromosomes)
Set the entire population.

Parameters:
chromosomes - the chromosomes to set

setCutLength

public void setCutLength(int cutLength)
Set the cut length.

Parameters:
cutLength - The cut length.

setMatingPopulation

public void setMatingPopulation(double matingPopulation)
Set the mating population percent.

Parameters:
matingPopulation - The mating population percent.

setMutationPercent

public void setMutationPercent(double mutationPercent)
Set the mutation percent.

Parameters:
mutationPercent - The percent to mutate.

setPercentToMate

public void setPercentToMate(double percentToMate)
Set the percent to mate.

Parameters:
percentToMate - The percent to mate.

setPool

public void setPool(java.util.concurrent.ExecutorService pool)
Set the optional thread pool.

Parameters:
pool - the pool to set

setPopulationSize

public void setPopulationSize(int populationSize)
Set the population size.

Parameters:
populationSize - The population size.

setPreventRepeat

public void setPreventRepeat(boolean preventRepeat)
Set the gene.

Parameters:
preventRepeat - Should repeats be prevented.

sortChromosomes

public void sortChromosomes()
Sort the chromosomes.


The Encog Project