Class BinaryChromosome


  • public class BinaryChromosome
    extends Chromosome
    The binary form of the chromosome. This chromosome contains a sequence of bits. The mutation operation are supported by flipping a bit. And the cross by masking the bits:
    offspring1: (this & mask) | (otherparent & ~mask)
    offspring2: (otherparent & mask) | (this & ~mask)
    • Field Detail

      • genes

        protected java.util.BitSet genes
        The genetic charge
      • length

        protected int length
      • random

        protected java.util.Random random
    • Constructor Detail

      • BinaryChromosome

        public BinaryChromosome()
      • BinaryChromosome

        protected BinaryChromosome​(int length,
                                   java.util.Random random)
      • BinaryChromosome

        protected BinaryChromosome​(BinaryChromosome c)
        Initialize this chromosome with another one
        Parameters:
        c - The chromosome to copy.
    • Method Detail

      • cross

        public Chromosome[] cross​(Chromosome b,
                                  int position)
        Split the genes by position and swap lower portion of this with the lower portion of b and vice versa to return 2 offsprings.
        Specified by:
        cross in class Chromosome
        Parameters:
        b - chromosome to cross
        position - Position to split the chromosomes.
        Returns:
        A two position array with the new offsprings.
      • mutate

        public Chromosome mutate​(double pm)
        Flip a bit of the genes. The bits are selected with probability pm
        Specified by:
        mutate in class Chromosome
        Parameters:
        pm - Mutation probability.
        Returns:
        The new mutated chromosome.
      • getInstance

        protected Chromosome getInstance​(java.util.BitSet bs)
        Create a new instance of a Chromosome with this BitSet.
        Parameters:
        bs - The genetic charge to copy.
        Returns:
        A new chromosome with the same genetic charge.
      • decode

        public long decode()
        Convert this chromosome in a long value. If the chromosome is too large this value can be overflowed.
        Returns:
        The integral representation of the chromosome.
      • decode

        public double decode​(double minValue,
                             double maxValue)
        Convert this chromosome in a double value using the minValue and maxValue as reference. If the chromosome is too large this value can be overflowed.
        Parameters:
        minValue - minValue
        maxValue - maxValue
        Returns:
        The double representation of the chromosome.
      • getCopy

        public Chromosome getCopy()
        Clone this chromosome.
        Specified by:
        getCopy in class Chromosome
        Returns:
        A identical chromosome of this.
      • getInstance

        public Chromosome getInstance​(int length,
                                      java.util.Random random)
        Creates a new chromosome with a length of length
        Specified by:
        getInstance in class Chromosome
        Parameters:
        length - The length of the new chromosome.
        Returns:
        A new instance of length length
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object