Chromosome (JEvolution)
Date: 2013-03-21

evSOLve.JEvolution.chromosomes

## Class Chromosome

- java.lang.Object
- - evSOLve.JEvolution.chromosomes.Chromosome

- All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable
  Direct Known Subclasses:
    BitChromosome, IntChromosome, RealChromosome, TreeChromosome

      public abstract class Chromosome
      extends java.lang.Object
      implements java.lang.Cloneable, java.io.Serializable

  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `BIASED`
    `protected int` | `crossoverPoints` The number of crossover sites (default = 2).
    `protected double` | `crossoverRate` The crossover rate (default = 0.6).
    `static int` | `LAPLACE` Initial mode of creation of Chromosome.
    `protected int` | `length` The default length of the Chromosome.
    `protected double` | `mutationRate` The mutation rate (default = 0.1).
    `protected int` | `soupType` Method of generation of start population (default = LAPLACE).

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `Chromosome(Element c)` Creates a Chromosome via XML.
    `protected` | `Chromosome(int length)` Constructs a chromosome of given length.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.Object` | `clone()` The Chromosome's clone, which has to be done properly, i.e., all objects representing the chromosome should be replicated exactly.
    `static Chromosome` | `create(Element element)` Creates the chromosome designated by an XML element by calling the XML constructor.
    `abstract void` | `doCrossover(Chromosome mate)` Crossover.
    `abstract void` | `doMutation()` Mutation of Chromosome.
    `abstract boolean` | `equals(java.lang.Object o)` This is very important for usage of the fitness repository.
    `abstract void` | `fromString(java.lang.String representation)` Constructs the Chromosome from its string representation.
    `abstract java.lang.Object` | `getBases()` Returns the genetic information carrier of the Chromosome.
    `int` | `getCrossoverPoints()` Access crossover points.
    `double` | `getCrossoverRate()` Access crossover rate.
    `int` | `getLength()` Return length of the Chromosome.
    `double` | `getMutationRate()` Access mutation rate.
    `int` | `getSoupType()` Access soup type.
    `abstract int` | `hashCode()` The Chromosome's hash code.
    `abstract void` | `mixSoup()` Generate initial chromosomes.
    `void` | `setCrossoverPoints(int crossoverPoints)` Change crossover points.
    `void` | `setCrossoverRate(double crossoverRate)` Change crossover rate.
    `void` | `setLength(int length)` Change Chromosome length.
    `void` | `setMutationRate(double mutationRate)` Change mutation rate.
    `void` | `setSoupType(int soupType)` Change soup type.
    `abstract java.lang.String` | `toString()` Returns bases of the Chromosome as String.
    `Element` | `toXml(Element parent)` Saves the current state to XML.

    - ### Methods inherited from class java.lang.Object

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### length

          protected int length

      The default length of the Chromosome.

    - #### mutationRate

          protected double mutationRate

      The mutation rate (default = 0.1).

    - #### crossoverRate

          protected double crossoverRate

      The crossover rate (default = 0.6).

    - #### crossoverPoints

          protected int crossoverPoints

      The number of crossover sites (default = 2).

    - #### LAPLACE

          public static final int LAPLACE

      Initial mode of creation of Chromosome. With LAPLACE all 1s (and 0s) have a probability of 0.5. With BIASED for each chromosome a random probability is drawn, which determines the probability of a 1.
      See Also:
        Constant Field Values

    - #### BIASED

          public static final int BIASED

      See Also:
        Constant Field Values

    - #### soupType

          protected int soupType

      Method of generation of start population (default = LAPLACE).

  - ### Constructor Detail

    - #### Chromosome

          protected Chromosome(int length)

      Constructs a chromosome of given length.
      Parameters:
        `length` - the number of bases

    - #### Chromosome

          protected Chromosome(Element c)

      Creates a Chromosome via XML.
      Parameters:
        `c` - an XML Chromosome element

  - ### Method Detail

    - #### clone

          public java.lang.Object clone()

      The Chromosome's clone, which has to be done properly, i.e., all objects representing the chromosome should be replicated exactly. Specifically, the bases of the Chromosome must be cloned.
      Overrides:
        `clone` in class `java.lang.Object`

    - #### equals

          public abstract boolean equals(java.lang.Object o)

      This is very important for usage of the fitness repository. This method of a specific Chromosome should be as efficient as possible, e.g., if the bases of the Chromosome are implemented as BitSet, then the corresponding equals() method of BitSet should be called. For other Chromosomes it might be beneficial, if a specific, efficient equals() is implemented. Of course, you could also use the inherited equals(), but it will affect performance of the fitness repository, maybe even to the point that it is not used at all.
      Overrides:
        `equals` in class `java.lang.Object`

    - #### hashCode

          public abstract int hashCode()

      The Chromosome's hash code. This is explicitely listed here, as the hashCode() method of a specific Chromosome should be as efficient as possible, e.g., if the bases of the Chromosome are implemented as BitSet, then the corresponding hashCode() method of BitSet should be called. For other Chromosomes it might be beneficial, if a specific, efficient hashCode() is implemented. Of course, you could also use the inherited hashCode(), but it will affect performance of the fitness repository, maybe even to the point that it is not used at all.
      Overrides:
        `hashCode` in class `java.lang.Object`

    - #### doMutation

          public abstract void doMutation()

      Mutation of Chromosome. Candidate for customizable plug-in.

    - #### doCrossover

          public abstract void doCrossover(Chromosome mate)

      Crossover. Candidate for customizable plug-in.

    - #### mixSoup

          public abstract void mixSoup()

      Generate initial chromosomes.

    - #### getBases

          public abstract java.lang.Object getBases()

      Returns the genetic information carrier of the Chromosome.
      Returns:
        the bases of the Chromosome

    - #### toString

          public abstract java.lang.String toString()

      Returns bases of the Chromosome as String.
      Overrides:
        `toString` in class `java.lang.Object`

    - #### fromString

          public abstract void fromString(java.lang.String representation)

      Constructs the Chromosome from its string representation.

    - #### getLength

          public int getLength()

      Return length of the Chromosome.
      Returns:
        length The number of bases.

    - #### setLength

          public void setLength(int length)
                         throws JEvolutionException

      Change Chromosome length.
      Parameters:
        `length` - The number of bases.
      Throws:
        `JEvolutionException` - The chromosome has no length.

    - #### getMutationRate

          public double getMutationRate()

      Access mutation rate.
      Returns:
        mutationRate The mutation probability.

    - #### setMutationRate

          public void setMutationRate(double mutationRate)
                               throws JEvolutionException

      Change mutation rate.
      Parameters:
        `mutationRate` - The mutation probability.
      Throws:
        `JEvolutionException` - No probability value.

    - #### getCrossoverRate

          public double getCrossoverRate()

      Access crossover rate.
      Returns:
        crossoverRate The crossover probability.

    - #### setCrossoverRate

          public void setCrossoverRate(double crossoverRate)
                                throws JEvolutionException

      Change crossover rate.
      Parameters:
        `crossoverRate` - The crossover probability.
      Throws:
        `JEvolutionException` - No probability value.

    - #### getCrossoverPoints

          public int getCrossoverPoints()

      Access crossover points.
      Returns:
        crossoverPoints The number of crossover sites.

    - #### setCrossoverPoints

          public void setCrossoverPoints(int crossoverPoints)
                                  throws JEvolutionException

      Change crossover points.
      Parameters:
        `crossoverPoints` - The number of crossover sites.
      Throws:
        `JEvolutionException` - Invalid number.

    - #### getSoupType

          public int getSoupType()

      Access soup type.
      Returns:
        soupType How to generate initial Genotype.

    - #### setSoupType

          public void setSoupType(int soupType)

      Change soup type.
      Parameters:
        `soupType` - How to generate initial Genotype.

    - #### toXml

          public Element toXml(Element parent)

      Saves the current state to XML.
      Parameters:
        `parent` - the JDOM parent element
      Returns:
        the Chromosome element

    - #### create

          public static Chromosome create(Element element)

      Creates the chromosome designated by an XML element by calling the XML constructor.
      Parameters:
        `element` - an XML element
      Returns:
        a new Chromosome (null, if problems)