TreeChromosome (JEvolution)
Date: 2013-03-21

evSOLve.JEvolution.gp

## Class TreeChromosome

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

- All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

      public class TreeChromosome
      extends Chromosome

  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `FULL`
    `static int` | `GROW` Initial mode of creation of Chromosome.
    `static int` | `RAMPED`

    - ### Fields inherited from class evSOLve.JEvolution.chromosomes.Chromosome

      `BIASED, crossoverPoints, crossoverRate, LAPLACE, length, mutationRate, soupType`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TreeChromosome(Element c)` Creates a TreeChromosome via XML.
    `TreeChromosome(int depth, int resultType)` Constructs a TreeChromosome.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addNode(ProgramNode node)` Adds a program node to the node set.
    `TreeChromosome` | `clone()` A deep clone of this TreeChromosome.
    `void` | `doCrossover(Chromosome father)` Performs crossover by selecting a random node in each of the two parent trees and swapping the subtrees.
    `void` | `doMutation()` Performs tree and node mutation by iterating over the tree.
    `boolean` | `equals(java.lang.Object chrom)` Compares this program tree to another in 'chrom'.
    `void` | `fromString(java.lang.String b)` Creates a program tree from its string representation.
    `java.lang.Object` | `getBases()` Returns the genotype aka the program tree, which in this case is also the phenotype.
    `boolean` | `getNodeMutation()` Returns the flag for node mutation.
    `int` | `hashCode()` Returns a hash code for the program tree.
    `void` | `mixSoup()` Creates a random program tree in different manners.
    `void` | `setNodeMutation(boolean nodeMutation)` Sets the flag for node mutation.
    `java.lang.String` | `toString()` Returns the string representation of the program tree.
    `Element` | `toXml(Element parent)` Saves the current state to XML.

    - ### Methods inherited from class evSOLve.JEvolution.chromosomes.Chromosome

      `create, getCrossoverPoints, getCrossoverRate, getLength, getMutationRate, getSoupType, setCrossoverPoints, setCrossoverRate, setLength, setMutationRate, setSoupType`

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

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

- - ### Field Detail

    - #### GROW

          public static final int GROW

      Initial mode of creation of Chromosome.
      See Also:
        Constant Field Values

    - #### RAMPED

          public static final int RAMPED

      See Also:
        Constant Field Values

    - #### FULL

          public static final int FULL

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### TreeChromosome

          public TreeChromosome(int depth,
                        int resultType)

      Constructs a TreeChromosome.
      Parameters:
        `depth` - the maximal depth of the initial program tree
        `resultType` - the type of the result of the evolved function/program

    - #### TreeChromosome

          public TreeChromosome(Element c)

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

  - ### Method Detail

    - #### clone

          public TreeChromosome clone()

      A deep clone of this TreeChromosome.
      Overrides:
        `clone` in class `Chromosome`
      Returns:
        a deep clone

    - #### equals

          public boolean equals(java.lang.Object chrom)

      Compares this program tree to another in 'chrom'.
      Specified by:
        `equals` in class `Chromosome`
      Parameters:
        `chrom` - a TreeChromosome
      Returns:
        true, if the trees are equal

    - #### hashCode

          public int hashCode()

      Returns a hash code for the program tree.
      Specified by:
        `hashCode` in class `Chromosome`
      Returns:
        a hash code

    - #### getBases

          public java.lang.Object getBases()

      Returns the genotype aka the program tree, which in this case is also the phenotype.
      Specified by:
        `getBases` in class `Chromosome`
      Returns:
        the program tree

    - #### addNode

          public void addNode(ProgramNode node)

      Adds a program node to the node set.
      Parameters:
        `node` - a program node

    - #### getNodeMutation

          public boolean getNodeMutation()

      Returns the flag for node mutation.
      Returns:
        true, if node mutation is on

    - #### setNodeMutation

          public void setNodeMutation(boolean nodeMutation)

      Sets the flag for node mutation.
      Parameters:
        `nodeMutation` - true, if node mutation on

    - #### doMutation

          public void doMutation()

      Performs tree and node mutation by iterating over the tree. Either tree mutation or node mutation is performed depending on 'nodeMutation'.
      Specified by:
        `doMutation` in class `Chromosome`

    - #### doCrossover

          public void doCrossover(Chromosome father)

      Performs crossover by selecting a random node in each of the two parent trees and swapping the subtrees. If the result types of the two nodes do not match, the mother index (node) is fixed, and the father index is increased in order to find a matching subtree. If the father tree contains no matching node, the crossover does not take place. Note that we only check father indices greater than the random father node (we could also make the search complete by searching all tree nodes).
      Specified by:
        `doCrossover` in class `Chromosome`
      Parameters:
        `father` - the father chromosome

    - #### mixSoup

          public void mixSoup()

      Creates a random program tree in different manners. FULL always creates trees with the given 'lengt' (=depth), GROW may stop growing at any level with a probability of 0.5, and RAMPED is in the spirit of the original GP ramp, but is here a probabilistic ramping, so trees of any size may be generated. The limit size for all trees is 'length' (=depth).
      Specified by:
        `mixSoup` in class `Chromosome`

    - #### toString

          public java.lang.String toString()

      Returns the string representation of the program tree.
      Specified by:
        `toString` in class `Chromosome`
      Returns:
        the tree in string form

    - #### fromString

          public void fromString(java.lang.String b)

      Creates a program tree from its string representation. Does nothing here, as in the case of GP the program tree is not created from its string representation, but from the XML element 'Tree'. However, the string representation is still saved with the XML element 'Bases'.
      Specified by:
        `fromString` in class `Chromosome`
      Parameters:
        `b` - the program tree in string form

    - #### toXml

          public Element toXml(Element parent)

      Saves the current state to XML.
      Overrides:
        `toXml` in class `Chromosome`
      Parameters:
        `parent` - the JDOM parent element
      Returns:
        the Chromosome element with NodeSet and Tree