Class AbstractListChromosome<T>

java.lang.Object
org.apache.commons.math.genetics.Chromosome
org.apache.commons.math.genetics.AbstractListChromosome<T>
Type Parameters:
T - type of the representation list
All Implemented Interfaces:
Comparable<Chromosome>, Fitness
Direct Known Subclasses:
BinaryChromosome, RandomKey

public abstract class AbstractListChromosome<T> extends Chromosome
Chromosome represented by an immutable list of a fixed length.
Since:
2.0
Version:
$Revision: 811685 $ $Date: 2009-09-05 19:36:48 +0200 (sam. 05 sept. 2009) $
  • Constructor Details

    • AbstractListChromosome

      public AbstractListChromosome(List<T> representation)
      Constructor.
      Parameters:
      representation - inner representation of the chromosome
    • AbstractListChromosome

      public AbstractListChromosome(T[] representation)
      Constructor.
      Parameters:
      representation - inner representation of the chromosome
  • Method Details

    • checkValidity

      protected abstract void checkValidity(List<T> chromosomeRepresentation) throws InvalidRepresentationException
      Asserts that representation can represent a valid chromosome.
      Parameters:
      chromosomeRepresentation - representation of the chromosome
      Throws:
      InvalidRepresentationException - iff the representation can not represent a valid chromosome
    • getRepresentation

      protected List<T> getRepresentation()
      Returns the (immutable) inner representation of the chromosome.
      Returns:
      the representation of the chromosome
    • getLength

      public int getLength()
      Returns the length of the chromosome.
      Returns:
      the length of the chromosome
    • newFixedLengthChromosome

      public abstract AbstractListChromosome<T> newFixedLengthChromosome(List<T> chromosomeRepresentation)
      Creates a new instance of the same class as this is, with a given arrayRepresentation. This is needed in crossover and mutation operators, where we need a new instance of the same class, but with different array representation. Usually, this method just calls a constructor of the class.
      Parameters:
      chromosomeRepresentation - the inner array representation of the new chromosome.
      Returns:
      new instance extended from FixedLengthChromosome with the given arrayRepresentation
    • toString

      public String toString()
      Overrides:
      toString in class Object