com.softtechdesign.ga
Class GAStringsSeq

java.lang.Object
  |
  +--com.softtechdesign.ga.GA
        |
        +--com.softtechdesign.ga.GAStringsSeq
All Implemented Interfaces:
java.lang.Runnable

public abstract class GAStringsSeq
extends GA

  GAStringsSeq models chromosomes as arrays of strings.

  Chromosome strings store chromosomeDim genes. Unlike GAString (where each gene is a
  single char), with GAStringsSeq each gene itself is a string. For example, one might look
  like:
  "dw|l80|nop|dn2" --4 genes, each separated by a pipe char (nop = special no operation gene)

  This type of GA could be used for:
    determining a sequence for navigating a maze
    discovering a useful image processing algorithm (seq) for highlighting an image feature
    modeling any system where genes are naturally modeled as Strings
 

Author:
Jeff Smith jeff@SoftTechDesign.com

Field Summary
protected  int numPossGeneValues
          the number of possible gene values
protected  java.lang.String[] possGeneValues
          the building material or pool "allowed" or "possible" gene 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
GAStringsSeq(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 GAStringSeq
 
Method Summary
protected  void doOnePtCrossover(Chromosome Chrom1, Chromosome Chrom2)
          Genetically recombine the given chromosomes using a one point crossover technique.
protected  void doRandomMutation(int iChromIndex)
          Randomly reassign a gene in the chromosome identified by the given index (iChromIndex) to one of the possible gene values
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  ChromStrings getChromosome(int index)
          Returns the chromosome given by index casted as a ChromStrings object
protected  java.lang.String getRandomGeneFromPossGenes()
          Randomly pick and return a gene value
protected  void initPopulation()
          Create random chromosomes from the given gene space.
private  void setGeneValue(int iChromIndex, int geneIndex, java.lang.String gene)
          Sets the value of a gene for the given chromosome at the given geneIndex
 
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

possGeneValues

protected java.lang.String[] possGeneValues
the building material or pool "allowed" or "possible" gene values

numPossGeneValues

protected int numPossGeneValues
the number of possible gene values
Constructor Detail

GAStringsSeq

public GAStringsSeq(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 GAStringSeq
Parameters:
chromosomeDim -  
populationDim -  
crossoverProb -  
randomSelectionChance -  
maxGenerations -  
numPrelimRuns -  
maxPrelimGenerations -  
mutationProb -  
chromDecPts -  
possGeneValues -  
crossoverType -  
computeStatistics -  
Throws:
GAException -  
Method Detail

getChromosome

protected ChromStrings getChromosome(int index)
Returns the chromosome given by index casted as a ChromStrings object
Parameters:
index -  
Returns:
 

getRandomGeneFromPossGenes

protected java.lang.String getRandomGeneFromPossGenes()
Randomly pick and return a gene value
Returns:
String

doRandomMutation

protected void doRandomMutation(int iChromIndex)
Randomly reassign a gene in the chromosome identified by the given index (iChromIndex) to one of the possible gene values
Overrides:
doRandomMutation in class GA
Parameters:
iChromIndex -  

setGeneValue

private void setGeneValue(int iChromIndex,
                          int geneIndex,
                          java.lang.String gene)
Sets the value of a gene for the given chromosome at the given geneIndex
Parameters:
iChromIndex -  
geneIndex -  
gene -  

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 = { "x1", "x2", "x3", "x4" }
   chromosome B = { "y1", "y2", "y3", "y4" }
 and we randomly choose the crossover point of 1, the new genes will be:
   new chromosome A = { "y1", "x2", "x3", "x4" }
   new chromosome B = { "x1", "y2", "y3", "y4" }
 
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 = { "x1", "x2", "x3", "x4", "x5" }
   chromosome B = { "y1", "y2", "y3", "y4", "y5" }
 and we randomly choose the crossover points of 1 and 3, the new genes will be:
   new chromosome A = { "y1", "x2", "y3", "x4", "x5" }
   new chromosome B = { "x1", "y2", "x3", "y4", "y5" }
 
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 = { "x1", "x2", "x3", "x4", "x5" }
   chromosome B = { "y1", "y2", "y3", "y4", "y5" }
 our uniform (random) crossover might result in something like:
   chromosome A = { "y1", "x2", "x3", "x4", "x5" }
   chromosome B = { "x1", "y2", "y3", "y4", "y5" }
 if only the first gene in the chromosome was swapped.
 
Overrides:
doUniformCrossover in class GA
Parameters:
Chrom1 -  
Chrom2 -