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
        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
        b - chromosome to cross
        position - Position to split the chromosomes.
        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
        pm - Mutation probability.
        The new mutated chromosome.
      • getInstance

        protected Chromosome getInstance​(java.util.BitSet bs)
        Create a new instance of a Chromosome with this BitSet.
        bs - The genetic charge to copy.
        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.
        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.
        minValue - minValue
        maxValue - maxValue
        The double representation of the chromosome.
      • getCopy

        public Chromosome getCopy()
        Clone this chromosome.
        Specified by:
        getCopy in class Chromosome
        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
        length - The length of the new chromosome.
        A new instance of length length
      • toString

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