|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.vizzini.ai.geneticalgorithm.AbstractGeneticAlgorithm
public abstract class AbstractGeneticAlgorithm
Provides base functionality for genetic algorithms.
Field Summary | |
---|---|
protected double |
_crossoverFraction
Number of chromosomes to form from crossover of the retained ones as a fraction of the population size. |
protected CrossoverType |
_crossoverType
Crossover type. |
protected long |
_elapsedTime
Elapsed time (milliseconds). |
protected int |
_generation
Current generation. |
Constructor Summary | |
---|---|
AbstractGeneticAlgorithm()
|
Method Summary | |
---|---|
protected void |
averageCrossover(IChromosome c0,
IChromosome c1,
IChromosome c2,
IChromosome c3)
Perform uniform crossover using the first two given chromosomes into the third given chromosome. |
protected abstract IChromosome |
createChromosome()
Create a new chromosome. |
protected abstract void |
evaluateFitness()
Evaluate the fitness of all chromosomes in the population. |
protected void |
fillPopulation()
Fill the population with chromosomes. |
protected void |
generateNewPopulation()
Create the new population of chromosomes from the current population. |
double |
getAverageCrossoverFraction()
|
double |
getCrossoverFraction()
Return the crossover fraction. |
CrossoverType |
getCrossoverType()
Return the crossover type. |
long |
getElapsedTime()
Return the elapsed time. |
int |
getGeneration()
Return the number of generations run. |
IChromosome |
getMostFit()
Return the most fit chromosome. |
double |
getMutationFraction()
|
double |
getMutationMagnitude()
Return the mutation magnitude. |
double |
getMutationRate()
Return the mutation rate. |
protected int |
getPerfectFitness()
Return the perfect fitness. |
protected IPopulation |
getPopulation()
Return the population. |
int |
getPopulationSize()
Return the population size. |
double |
getProcessingRate()
Return the processing rate. |
boolean |
isDuplicateAllowed()
Return true if duplicate chromosomes are allowed. |
protected void |
mutation(IPopulation oldPopulation,
IPopulation newPopulation)
Perform the mutation operation to fill the given new population from the given old population. |
protected void |
onePointCrossover(IChromosome c0,
IChromosome c1,
IChromosome c2,
IChromosome c3)
Perform one point crossover using the first two given chromosomes into the third given chromosome. |
protected void |
reproductionAndCrossover(IPopulation oldPopulation,
IPopulation newPopulation)
Perform the reproduction and crossover operations to fill the given new population from the given old population. |
void |
reset()
Reset. |
int |
runGenerations(int numGenerations,
int printFrequency)
Run for the given number of generations. |
void |
setAverageCrossoverFraction(double averageCrossoverFraction)
|
void |
setCrossoverFraction(double crossoverFraction)
Set the crossover fraction. |
void |
setCrossoverType(CrossoverType crossoverType)
Set the crossover type. |
void |
setDuplicateAllowed(boolean isDuplicateAllowed)
Set the flag indicating whether duplicate chromosomes are allowed. |
void |
setMutationFraction(double mutationFraction)
|
void |
setMutationMagnitude(double mutationMagnitude)
Set the mutation magnitude. |
void |
setMutationRate(double mutationRate)
Set the mutation rate. |
protected void |
setPopulation(IPopulation population)
Set the population. |
void |
setPopulationSize(int size)
Set the population size. |
protected void |
sortPopulation()
Sort the chromosomes by fitness. |
String |
toString()
Return a string representation of this object. |
protected void |
uniformCrossover(IChromosome c0,
IChromosome c1,
IChromosome c2,
IChromosome c3)
Perform uniform crossover using the first two given chromosomes into the third given chromosome. |
void |
writeReport()
Write a report. |
protected void |
writeStats(Writer writer,
int localGens)
Write statistics using the given parameters. |
protected void |
writeStatsHeader(Writer writer)
Write a header for the statistics. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected double _crossoverFraction
protected CrossoverType _crossoverType
protected long _elapsedTime
protected int _generation
Constructor Detail |
---|
public AbstractGeneticAlgorithm()
Method Detail |
---|
public double getAverageCrossoverFraction()
public double getCrossoverFraction()
getCrossoverFraction
in interface IGeneticAlgorithm
public CrossoverType getCrossoverType()
getCrossoverType
in interface IGeneticAlgorithm
public long getElapsedTime()
getElapsedTime
in interface IGeneticAlgorithm
public int getGeneration()
getGeneration
in interface IGeneticAlgorithm
public IChromosome getMostFit()
getMostFit
in interface IGeneticAlgorithm
public double getMutationFraction()
getMutationFraction
in interface IGeneticAlgorithm
public double getMutationMagnitude()
getMutationMagnitude
in interface IGeneticAlgorithm
public double getMutationRate()
getMutationRate
in interface IGeneticAlgorithm
public int getPopulationSize()
getPopulationSize
in interface IGeneticAlgorithm
public double getProcessingRate()
getProcessingRate
in interface IGeneticAlgorithm
public boolean isDuplicateAllowed()
public void reset()
reset
in interface IGeneticAlgorithm
public int runGenerations(int numGenerations, int printFrequency)
runGenerations
in interface IGeneticAlgorithm
numGenerations
- Number of generations to run.printFrequency
- Print frequency.public void setAverageCrossoverFraction(double averageCrossoverFraction)
setAverageCrossoverFraction
in interface IGeneticAlgorithm
averageCrossoverFraction
- The averageCrossoverFraction to set.public void setCrossoverFraction(double crossoverFraction)
setCrossoverFraction
in interface IGeneticAlgorithm
crossoverFraction
- Number of chromosomes to form from crossover
of the retained ones as a fraction of the
population size.public void setCrossoverType(CrossoverType crossoverType)
setCrossoverType
in interface IGeneticAlgorithm
public void setDuplicateAllowed(boolean isDuplicateAllowed)
setDuplicateAllowed
in interface IGeneticAlgorithm
public void setMutationFraction(double mutationFraction)
setMutationFraction
in interface IGeneticAlgorithm
mutationFraction
- the mutationFraction to setpublic void setMutationMagnitude(double mutationMagnitude)
setMutationMagnitude
in interface IGeneticAlgorithm
mutationMagnitude
- The maximum allowed magnitude of the mutation.public void setMutationRate(double mutationRate)
setMutationRate
in interface IGeneticAlgorithm
mutationRate
- Probability of a gene being mutated.public void setPopulationSize(int size)
setPopulationSize
in interface IGeneticAlgorithm
public String toString()
toString
in class Object
public void writeReport()
writeReport
in interface IGeneticAlgorithm
protected abstract IChromosome createChromosome()
protected abstract void evaluateFitness()
protected void averageCrossover(IChromosome c0, IChromosome c1, IChromosome c2, IChromosome c3)
protected void fillPopulation()
protected void generateNewPopulation()
protected int getPerfectFitness()
protected IPopulation getPopulation()
protected void mutation(IPopulation oldPopulation, IPopulation newPopulation)
oldPopulation
- newPopulation
- protected void onePointCrossover(IChromosome c0, IChromosome c1, IChromosome c2, IChromosome c3)
protected void reproductionAndCrossover(IPopulation oldPopulation, IPopulation newPopulation)
oldPopulation
- newPopulation
- protected void setPopulation(IPopulation population)
protected void sortPopulation()
protected void uniformCrossover(IChromosome c0, IChromosome c1, IChromosome c2, IChromosome c3)
protected void writeStats(Writer writer, int localGens)
writer
- Writer.localGens
- Current generation.protected void writeStatsHeader(Writer writer)
writer
- Writer.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2007 Vizzini.org. All Rights Reserved. | 2007.12.25.03.00.02 |