com.softtechdesign.ga
Class ChromStrings

java.lang.Object
  |
  +--com.softtechdesign.ga.Chromosome
        |
        +--com.softtechdesign.ga.ChromStrings

public class ChromStrings
extends Chromosome

Chromosome class where genes are stored as an array of strings

Author:
Jeff Smith jeff@SoftTechDesign.com

Field Summary
private  java.lang.String[] genes
          array of genes which comprise this Chromosome
 
Fields inherited from class com.softtechdesign.ga.Chromosome
fitness, fitnessRank
 
Constructor Summary
ChromStrings(int iGenesDim)
          Creates new string array of genes
 
Method Summary
 void copyChromGenes(Chromosome chromosome)
          Copy the genes from the given chromosome over the existing genes
 java.lang.String getGene(int iGene)
          return the gene indexed by iGene as a char
 java.lang.String[] getGenes()
          Get a reference to the genes array
 java.lang.String getGenesAsStr()
          return the array of genes as a string
 int getNumGenesInCommon(Chromosome chromosome)
          Calculates how many genes are the same between this chromosome and the given chromosome
 void setGene(java.lang.String gene, int geneIndex)
          sets the gene value
 java.lang.String toString()
          Returns the array of genes as a string
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

genes

private java.lang.String[] genes
array of genes which comprise this Chromosome
Constructor Detail

ChromStrings

public ChromStrings(int iGenesDim)
Creates new string array of genes
Parameters:
iGenesDim - the size of the array of genes
Method Detail

toString

public java.lang.String toString()
Returns the array of genes as a string
Overrides:
toString in class java.lang.Object
Returns:
String

setGene

public void setGene(java.lang.String gene,
                    int geneIndex)
sets the gene value
Parameters:
gene - value to set
geneIndex - index of gene

getNumGenesInCommon

public int getNumGenesInCommon(Chromosome chromosome)
Calculates how many genes are the same between this chromosome and the given chromosome
Overrides:
getNumGenesInCommon in class Chromosome
Parameters:
chromosome - chromosome to compare
Returns:
int

getGenes

public java.lang.String[] getGenes()
Get a reference to the genes array
Returns:
String[]

getGenesAsStr

public java.lang.String getGenesAsStr()
return the array of genes as a string
Overrides:
getGenesAsStr in class Chromosome
Returns:
String

getGene

public java.lang.String getGene(int iGene)
return the gene indexed by iGene as a char
Parameters:
iGene -  
Returns:
String

copyChromGenes

public void copyChromGenes(Chromosome chromosome)
Copy the genes from the given chromosome over the existing genes
Overrides:
copyChromGenes in class Chromosome
Parameters:
chromosome -