com.softtechdesign.ga
Class GAString

java.lang.Object
  |
  +--com.softtechdesign.ga.GA
        |
        +--com.softtechdesign.ga.GAString
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
GASequenceList

public abstract class GAString
extends GA

GAString models chromosomes as strings of characters

Author:
Jeff Smith jeff@SoftTechDesign.com

Field Summary
protected  int chromDecPts
          you can store floating point numbers in strings.
protected  java.lang.String possGeneValues
          legal gene (char) values.
 
Fields inherited from class com.softtechdesign.ga.GA
bestFitnessChromIndex, chromNextGen, chromosomeDim, chromosomes, computeStatistics, crossoverProb, crossoverType, genAvgDeviation, genAvgFitness, maxGenerations, maxPrelimGenerations, mutationProb, numPrelimRuns, populationDim, prelimChrom, randomSelectionChance, worstFitnessChromIndex
 
Constructor Summary
GAString(int chromosomeDim, int populationDim, double crossoverProb, int randomSelectionChance, int maxGenerations, int numPrelimRuns, int maxPrelimGenerations, double mutationProb, int chromDecPts, java.lang.String possGeneValues, int crossoverType, boolean computeStatistics)
          Initialize the GAString
 
Method Summary
protected  double chromStrToFloat(java.lang.String sChromosome, int iNumDecPts)
          Convert a chromosome string to it's double equivalent for example, if sChromosome = "01234" and iNumDecPts = 4, then return 0.1234
protected  void doOnePtCrossover(Chromosome Chrom1, Chromosome Chrom2)
          Genetically recombine the given chromosomes using a one point crossover technique.
protected  void doRandomMutation(int iChromIndex)
          randomly swap two genes in the chromosome identified by the given index (iChromIndex)
protected  void doTwoPtCrossover(Chromosome Chrom1, Chromosome Chrom2)
          Genetically recombine the given chromosomes using a two point crossover technique which combines two chromosomes at two random genes (loci), creating two new chromosomes.
protected  void doUniformCrossover(Chromosome Chrom1, Chromosome Chrom2)
          Genetically recombine the given chromosomes using a uniform crossover technique.
protected  ChromChars getChromosome(int index)
          returns the given chromosome casted as a ChromChars
protected  double getChromValAsDouble(java.lang.String sChromosome)
          convert a chromosome string to a double
protected  char getRandomGeneFromPossGenes()
          Randomly pick and return a possible gene value
protected  void initPopulation()
          create random chromosomes from the given gene space.
 
Methods inherited from class com.softtechdesign.ga.GA
addChromosomesToLog, binaryStrToInt, computeFitnessRankings, copyNextGenToThisGen, doGeneticMating, evolve, getAvgDeviation, getAvgDeviationAmongChroms, getAvgFitness, getAvgFitness, getChromosomeDim, getComputeStatistics, getCrossoverProb, getCrossoverType, getFitness, getFitnessRank, getFittestChromosome, getFittestChromosomesFitness, getMaxGenerations, getMaxPrelimGenerations, getMutationProb, getNumPrelimRuns, getPopulationDim, getRandom, getRandom, getRandomSelectionChance, run, selectTwoParents
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

chromDecPts

protected int chromDecPts
you can store floating point numbers in strings. For example a chromosome might look like "1234" and if chromDecPts = 2, then the number is 12.34

possGeneValues

protected java.lang.String possGeneValues
legal gene (char) values. For example, if the possGeneValues = "ABCD" then a gene could have the value "A", "B", "C", or "D"
Constructor Detail

GAString

public GAString(int chromosomeDim,
                int populationDim,
                double crossoverProb,
                int randomSelectionChance,
                int maxGenerations,
                int numPrelimRuns,
                int maxPrelimGenerations,
                double mutationProb,
                int chromDecPts,
                java.lang.String possGeneValues,
                int crossoverType,
                boolean computeStatistics)
         throws GAException
Initialize the GAString
Parameters:
chromosomeDim -  
populationDim -  
crossoverProb -  
randomSelectionChance -  
maxGenerations -  
numPrelimRuns -  
maxPrelimGenerations -  
mutationProb -  
chromDecPts -  
possGeneValues -  
crossoverType -  
computeStatistics -  
Throws:
GAException -  
Method Detail

getChromosome

protected ChromChars getChromosome(int index)
returns the given chromosome casted as a ChromChars
Parameters:
index -  
Returns:
ChromChars

chromStrToFloat

protected double chromStrToFloat(java.lang.String sChromosome,
                                 int iNumDecPts)
Convert a chromosome string to it's double equivalent for example, if sChromosome = "01234" and iNumDecPts = 4, then return 0.1234
Parameters:
sChromosome -  
iNumDecPts -  
Returns:
double

getChromValAsDouble

protected double getChromValAsDouble(java.lang.String sChromosome)
convert a chromosome string to a double
Parameters:
sChromosome -  
Returns:
double

getRandomGeneFromPossGenes

protected char getRandomGeneFromPossGenes()
Randomly pick and return a possible gene value
Returns:
char

doRandomMutation

protected void doRandomMutation(int iChromIndex)
randomly swap two genes in the chromosome identified by the given index (iChromIndex)
Overrides:
doRandomMutation in class GA
Parameters:
iChromIndex -  

initPopulation

protected void initPopulation()
create random chromosomes from the given gene space.
Overrides:
initPopulation in class GA

doOnePtCrossover

protected void doOnePtCrossover(Chromosome Chrom1,
                                Chromosome Chrom2)
Genetically recombine the given chromosomes using a one point crossover technique.
 For example, if we have:
   chromosome A = "ABCD"
   chromosome B = "EFGH"
 and we randomly choose the crossover point of 1, the new genes will be:
   new chromosome A = "A" + "FGH" = "AFGH"
   new chromosome B = "E" + "BCD" = "EBCD"
 
Overrides:
doOnePtCrossover in class GA
Parameters:
Chrom1 -  
Chrom2 -  

doTwoPtCrossover

protected void doTwoPtCrossover(Chromosome Chrom1,
                                Chromosome Chrom2)
Genetically recombine the given chromosomes using a two point crossover technique which combines two chromosomes at two random genes (loci), creating two new chromosomes.
 For example, if we have:
   chromosome A = "ABCDE"
   chromosome B = "FGHIJ"
 and we randomly choose the crossover points of 1 and 3, the new genes will be:
   new chromosome A = "A" + "GH" + "DE" = "AGHDE"
   new chromosome B = "F" + "BC" + "IJ" = "FBCIJ"
 
Overrides:
doTwoPtCrossover in class GA
Parameters:
Chrom1 -  
Chrom2 -  

doUniformCrossover

protected void doUniformCrossover(Chromosome Chrom1,
                                  Chromosome Chrom2)
Genetically recombine the given chromosomes using a uniform crossover technique. This technique randomly swaps genes from one chromosome to another.
 For example, if we have:
   chromosome A = "ABCD"
   chromosome B = "EFGH"
 our uniform (random) crossover might result in something like:
   new chromosome A = "EBCD"
   new chromosome B = "AFGH"
 if only the first gene in the chromosome was swapped.
 
Overrides:
doUniformCrossover in class GA
Parameters:
Chrom1 -  
Chrom2 -