org.vizzini.ai.geneticprogramming
Class AbstractGeneticAlgorithmGP

java.lang.Object
  extended by org.vizzini.ai.geneticalgorithm.AbstractGeneticAlgorithm
      extended by org.vizzini.ai.geneticprogramming.AbstractGeneticAlgorithmGP
All Implemented Interfaces:
IGeneticAlgorithm, IGeneticAlgorithmGP
Direct Known Subclasses:
Ant, CartCentering, CharacterRecognition, SymbolicRegression, TicTacToeGeneticAlgorithmGP, XOR

public abstract class AbstractGeneticAlgorithmGP
extends AbstractGeneticAlgorithm
implements IGeneticAlgorithmGP

Provides base functionality for a genetic programming genetic algorithm.

Since:
v0.3
Version:
v0.3
Author:
Jeffrey M. Thompson

Field Summary
 
Fields inherited from class org.vizzini.ai.geneticalgorithm.AbstractGeneticAlgorithm
_crossoverFraction, _crossoverType, _elapsedTime, _generation
 
Constructor Summary
AbstractGeneticAlgorithmGP()
          Construct this object.
 
Method Summary
 void addFunction(IFunction function)
          Add a function exemplar to the function set.
 void addTerminal(ITerminal terminal)
          Add a terminal exemplar to the terminal set.
protected  IChromosome createChromosome()
          Create a new chromosome.
protected  void evaluateFitness()
          Evaluate the fitnesses of the chromosomes in the population.
protected abstract  int evaluateFitness(int index, IChromosomeGP chromosome, boolean isPrinting)
          Evaluate the fitness of the given chromosome for this problem.
protected  IContext getContext()
           
 int getFunctionCount()
          Return the function count.
protected  IFunctionGenerator getFunctionGenerator()
          Return the function generator.
protected  int getInitialMaxDepth()
           
protected abstract  Class getReturnType()
          Return the overall return type for the chromosomes.
 int getTerminalCount()
          Return the terminal count.
 boolean isSimpleBetter()
          Return true if simpler (smaller) functions are better.
protected  void onePointCrossover(IChromosome c0_0, IChromosome c1_0, IChromosome c2_0, IChromosome c3_0)
          Perform one point crossover using the first two given chromosomes into the third given chromosome.
protected  void penalizeComplexity(IChromosomeGP chromosome, int fitnessThreshold)
          Penalize the given chromosome for complexity.
protected  void setContext(IContext context)
           
protected  void setInitialMaxDepth(int initialMaxDepth)
           
 void setSimpleBetter(boolean isSimpleBetter)
           
 
Methods inherited from class org.vizzini.ai.geneticalgorithm.AbstractGeneticAlgorithm
averageCrossover, fillPopulation, generateNewPopulation, getAverageCrossoverFraction, getCrossoverFraction, getCrossoverType, getElapsedTime, getGeneration, getMostFit, getMutationFraction, getMutationMagnitude, getMutationRate, getPerfectFitness, getPopulation, getPopulationSize, getProcessingRate, isDuplicateAllowed, mutation, reproductionAndCrossover, reset, runGenerations, setAverageCrossoverFraction, setCrossoverFraction, setCrossoverType, setDuplicateAllowed, setMutationFraction, setMutationMagnitude, setMutationRate, setPopulation, setPopulationSize, sortPopulation, toString, uniformCrossover, writeReport, writeStats, writeStatsHeader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.vizzini.ai.geneticalgorithm.IGeneticAlgorithm
getCrossoverFraction, getCrossoverType, getElapsedTime, getGeneration, getMostFit, getMutationFraction, getMutationMagnitude, getMutationRate, getPopulationSize, getProcessingRate, reset, runGenerations, setAverageCrossoverFraction, setCrossoverFraction, setCrossoverType, setDuplicateAllowed, setMutationFraction, setMutationMagnitude, setMutationRate, setPopulationSize, writeReport
 

Constructor Detail

AbstractGeneticAlgorithmGP

public AbstractGeneticAlgorithmGP()
Construct this object.

Since:
v0.3
Method Detail

addFunction

public void addFunction(IFunction function)
Add a function exemplar to the function set.

Specified by:
addFunction in interface IGeneticAlgorithmGP
Parameters:
function - Function exemplar.
Since:
v0.3

addTerminal

public void addTerminal(ITerminal terminal)
Add a terminal exemplar to the terminal set.

Specified by:
addTerminal in interface IGeneticAlgorithmGP
Parameters:
terminal - Terminal exemplar.
Since:
v0.3

getFunctionCount

public int getFunctionCount()
Return the function count.

Specified by:
getFunctionCount in interface IGeneticAlgorithmGP
Since:
v0.3

getTerminalCount

public int getTerminalCount()
Return the terminal count.

Specified by:
getTerminalCount in interface IGeneticAlgorithmGP
Since:
v0.3

isSimpleBetter

public boolean isSimpleBetter()
Return true if simpler (smaller) functions are better.

Since:
v0.3

setSimpleBetter

public void setSimpleBetter(boolean isSimpleBetter)
Parameters:
isSimpleBetter - the isSimpleBetter to set

evaluateFitness

protected abstract int evaluateFitness(int index,
                                       IChromosomeGP chromosome,
                                       boolean isPrinting)
Evaluate the fitness of the given chromosome for this problem.

Parameters:
chromosome - Chromosome.
isPrinting - Flag indicating if the method should print.
Since:
v0.3

getReturnType

protected abstract Class getReturnType()
Return the overall return type for the chromosomes.

Since:
v0.3

createChromosome

protected IChromosome createChromosome()
Create a new chromosome.

Specified by:
createChromosome in class AbstractGeneticAlgorithm
Since:
v0.3

evaluateFitness

protected void evaluateFitness()
Evaluate the fitnesses of the chromosomes in the population.

Specified by:
evaluateFitness in class AbstractGeneticAlgorithm
Since:
v0.3

getContext

protected IContext getContext()
Returns:
Return context.
Since:
v0.3

getFunctionGenerator

protected IFunctionGenerator getFunctionGenerator()
Return the function generator.

Since:
v0.3

getInitialMaxDepth

protected int getInitialMaxDepth()
Returns:
Return initialMaxDepth.

onePointCrossover

protected void onePointCrossover(IChromosome c0_0,
                                 IChromosome c1_0,
                                 IChromosome c2_0,
                                 IChromosome c3_0)
Perform one point crossover using the first two given chromosomes into the third given chromosome.

Overrides:
onePointCrossover in class AbstractGeneticAlgorithm
Since:
v0.3

penalizeComplexity

protected void penalizeComplexity(IChromosomeGP chromosome,
                                  int fitnessThreshold)
Penalize the given chromosome for complexity.

Parameters:
chromosome - Chromosome to penalize.
fitnessThreshold - Fitness threshold which must be passed before a penalty is applied.
Since:
v0.3

setContext

protected void setContext(IContext context)
Parameters:
context - the context to set
Since:
v0.3

setInitialMaxDepth

protected void setInitialMaxDepth(int initialMaxDepth)
Parameters:
initialMaxDepth - the initialMaxDepth to set


Copyright 2007 Vizzini.org. All Rights Reserved. 2007.12.25.03.00.02