|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jscience.computing.ai.evolutionary.geneticalgorithms.BinaryCodedGA
public abstract class BinaryCodedGA
Implementation of binary-coded genetic algorithm.
If you don't want to use default implementation of any method. You should extend this class and override that method.
| Field Summary | |
|---|---|
protected double |
avgFitness
Average fitness in the current population |
protected int |
bestChromosomeNo
Index of the best chromosome in the current generation |
protected int |
chromosomeLength
Size of the chromosomes for individuals |
protected double |
crossoverProbability
Probability of crossover operation |
protected boolean[][] |
currentPopulation
Individuals in the current generation |
protected double[] |
currentPopulationFitness
Fitnesses of the individuals in the current generation |
protected int |
generationNo
Current generation number |
protected double[] |
historyAvgFitness
Average fitnesses over all generations |
protected int |
historyLength
Maxiumum hist�ry length for historyMaxFitness, historyMinFitness and historyAvgFitness variables |
protected double[] |
historyMaxFitness
Maximum fitnesses over all generations |
protected double[] |
historyMinFitness
Minimum fitnesses over all generations |
protected double |
maxFitness
Maximum fitness in the current population |
protected double |
minFitness
Minimum fitness in the current population |
protected double |
mutationProbability
Probability of mutation operation |
protected boolean[][] |
nextPopulation
Individuals in the next generation |
protected int |
populationSize
Size of the population |
protected double |
tmpSumOfFitnesses
TODO: Remove this vriable in the future relases. |
protected double |
tmpSumx
TODO: Remove this vriable in the future relases. |
| Constructor Summary | |
|---|---|
BinaryCodedGA()
Creates a binary-coded genetic algorithm with default parameters. |
|
BinaryCodedGA(int populationSize,
int chromosomeLength,
double crossoverProbability,
double mutationProbability)
Creates a binary-coded genetic algorithm with given parameters. |
|
BinaryCodedGA(int populationSize,
int chromosomeLength,
double crossoverProbability,
double mutationProbability,
int maxHistory)
Creates a binary-coded genetic algorithm with given parameters. |
|
| Method Summary | |
|---|---|
protected void |
crossoverChromosomes(boolean[] chromosome1,
boolean[] chromosome2)
Applies crossover operator to given chromosomes. |
static boolean[] |
deSerializeIndividual(java.lang.String fileName,
boolean isBinary)
Deserializes given individual from disk with the given file name. |
double |
evaluateIndividual(int chromosomeNo,
boolean[] chromosome)
Evaluates an individual in the population. |
void |
evolve()
Evolves the population. |
double |
getAvgFitness()
Returns average fitness in the current generation |
double[] |
getAvgHistory()
Returns the history of the average fitnesses |
int |
getChromosomeLength()
Returns the length of chromosomes. |
double |
getCrossoverProbability()
Returns probability of the crossover operation |
double[] |
getCurrentPopulationFitness()
Returns fitnesses of the individuals in the current generation |
boolean[] |
getFittestChromosome()
Returns the best individual in the current generation |
double |
getMaxFitness()
Returns maximum fitness in the current generation |
double[] |
getMaxHistory()
Returns the fitness history of best individuals over all generations. |
double |
getMinFitness()
Returns minimum fitness in the current generation |
double[] |
getMinHistory()
Returns the fitness history of worst individuals over all generations. |
double |
getMutationProbability()
Returns probability of the mutation operation |
boolean[][] |
getPopulation()
Returns individuals of the current generation |
int |
getPopulationSize()
Returns population size |
void |
initializePopulation()
Intitializes the population. |
protected boolean |
mutateChromosome(boolean bit)
Mutates a given bit in a chromosome randomly. |
void |
printIndividual(boolean[] chromosome)
Prints given individual |
protected int |
selectChromosome()
Selects a chromosome using roulette-selection. |
static void |
serializeIndividual(boolean[] chromosome,
java.lang.String fileName,
boolean isBinary)
Serializes given individual to disk with the given file name. |
void |
setChromosomeFitness(int chromosomeNo,
double newFitness)
Changes fitness of the given chromosome |
void |
setCrossoverProbability(double newProbability)
Changes probability of the crossover operation |
void |
setMutationProbability(double newProbability)
Changes probability of the mutation operation |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected int populationSize
protected int chromosomeLength
protected double crossoverProbability
protected double mutationProbability
protected boolean[][] currentPopulation
protected boolean[][] nextPopulation
protected double[] currentPopulationFitness
protected int generationNo
protected int bestChromosomeNo
protected double maxFitness
protected double minFitness
protected double avgFitness
protected double[] historyMaxFitness
protected double[] historyMinFitness
protected double[] historyAvgFitness
protected int historyLength
protected double tmpSumx
protected double tmpSumOfFitnesses
| Constructor Detail |
|---|
public BinaryCodedGA()
public BinaryCodedGA(int populationSize,
int chromosomeLength,
double crossoverProbability,
double mutationProbability)
populationSize - size of the populationchromosomeLength - size of the chromosomes for individualscrossoverProbability - probability of crossover operationmutationProbability - probability of mutation operation
public BinaryCodedGA(int populationSize,
int chromosomeLength,
double crossoverProbability,
double mutationProbability,
int maxHistory)
populationSize - size of the populationchromosomeLength - size of the chromosomes for individualscrossoverProbability - probability of crossover operationmutationProbability - probability of mutation operationmaxHistory - maxiumum hist�ry length for historyMaxFitness, historyMinFitness
and historyAvgFitness variables| Method Detail |
|---|
public void initializePopulation()
throws InvalidFitnessValueException
InvalidFitnessValueException - if the fitness value of any individual is lower than zero.
public double evaluateIndividual(int chromosomeNo,
boolean[] chromosome)
chromosomeNo - index of the chromosome in the current population to be evaluated.chromosome - chromosome of the individual to be evaluated.
public void evolve()
throws InvalidFitnessValueException
InvalidFitnessValueException - if the fitness value of any individual is lower than zero.protected int selectChromosome()
protected boolean mutateChromosome(boolean bit)
bit - bit to mutate
mutationProbability
protected void crossoverChromosomes(boolean[] chromosome1,
boolean[] chromosome2)
chromosome1 - first parent chromosomechromosome2 - second parent chromosome
public void setChromosomeFitness(int chromosomeNo,
double newFitness)
throws InvalidFitnessValueException
chromosomeNo - index of the chromosome in the current populationnewFitness - new fitness of the individual
InvalidFitnessValueException - if a fitness value lower than zero is tried to be used.public double getMaxFitness()
public double getMinFitness()
public double getAvgFitness()
public double[] getCurrentPopulationFitness()
public boolean[][] getPopulation()
public boolean[] getFittestChromosome()
public double[] getMaxHistory()
public double[] getMinHistory()
public double[] getAvgHistory()
public double getCrossoverProbability()
public double getMutationProbability()
public void setCrossoverProbability(double newProbability)
newProbability - new crossover probabilitypublic void setMutationProbability(double newProbability)
newProbability - new mutation probabilitypublic int getPopulationSize()
public int getChromosomeLength()
public void printIndividual(boolean[] chromosome)
chromosome - individual to print
public static void serializeIndividual(boolean[] chromosome,
java.lang.String fileName,
boolean isBinary)
throws java.io.IOException
chromosome - individual to serializefileName - name of the file where the serialized individual will be writtenisBinary - specifies whether the serialization done with Java's own
serialization method or with a simple text representation.
If set to true, then Java serialization will be used.
java.io.IOException - if serialization fails
public static boolean[] deSerializeIndividual(java.lang.String fileName,
boolean isBinary)
throws java.io.IOException,
java.lang.ClassNotFoundException
fileName - name of the file where the serialized individual will be writtenisBinary - specifies whether the serialization done with Java's own
serialization method or with a simple text representation.
If set to true, then Java serialization will be used.
java.lang.ClassNotFoundException - if deserialization fails
java.io.IOException - if deserialization fails
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||