Package io.jenetics

Interface Chromosome<G extends Gene<?,G>>

All Superinterfaces:
BaseSeq<G>, Factory<Chromosome<G>>, Iterable<G>, RandomAccess, Verifiable
All Known Subinterfaces:
BoundedChromosome<A,G>, NumericChromosome<N,G>, TreeChromosome<A,G>
All Known Implementing Classes:
AbstractChromosome, AbstractTreeChromosome, AnyChromosome, BigIntegerChromosome, BitChromosome, CharacterChromosome, DoubleChromosome, IntegerChromosome, LongChromosome, PermutationChromosome, ProgramChromosome

public interface Chromosome<G extends Gene<?,G>> extends BaseSeq<G>, Factory<Chromosome<G>>, Verifiable
A chromosome consists of one or more genes. It also provides a factory method for creating new, random chromosome instances of the same type and the same constraint.
Since:
1.0
Version:
6.0
See Also:
Implementation Requirements:
Implementations of the Chromosome interface must be immutable and guarantee efficient random access (O(1)) to the genes. A Chromosome must contains at least one Gene.
  • Method Details

    • gene

      default G gene()
      Return the first gene of this chromosome. Each chromosome must contain at least one gene.
      Returns:
      the first gene of this chromosome.
      Since:
      5.2
    • isValid

      default boolean isValid()
      Description copied from interface: Verifiable
      Check if this object is valid.
      Specified by:
      isValid in interface Verifiable
      Returns:
      true if this object is valid, false otherwise.
    • newInstance

      A factory method which creates a new Chromosome of specific type and the given genes.
      Parameters:
      genes - the genes of the new chromosome. The given genes array is not copied.
      Returns:
      A new Chromosome of the same type with the given genes.
      Throws:
      NullPointerException - if the given genes are null.
      IllegalArgumentException - if the length of the given gene sequence is smaller than one.
    • as

      default <C extends Chromosome<G>> C as(Class<C> type)
      Casts this Chromosome to an instance of type C. This is a convenient method for an ordinary cast and allows seamless method-chaining. Instead of
      final Genotype<BitGene> gt = ... final int count = ((BitChromosome)gt.chromosome()).bitCount()
      you can write
      final Genotype<BitGene> gt = ... final int count = gt.chromosome() .as(BitChromosome.class) .bitCount()
      This may lead to a more elegant programming style in some cases.
      Type Parameters:
      C - the target chromosome type
      Parameters:
      type - the target type class
      Returns:
      this chromosome cast as C
      Throws:
      NullPointerException - if the target type class is null
      ClassCastException - if this chromosome can't be cast to a chromosome of type C
      Since:
      3.7