Class IntegerChromosome

  • public class IntegerChromosome
    extends Chromosome
    Implementation of a permutation chromosome.
    • Field Detail

      • genes

        protected int[] genes
        The genetic charge
      • random

        protected java.util.Random random
    • Constructor Detail

      • IntegerChromosome

        public IntegerChromosome()
      • IntegerChromosome

        protected IntegerChromosome​(int length,
                                    java.util.Random random)
    • Method Detail

      • cross

        public Chromosome[] cross​(Chromosome b,
                                  int position)
        Cross the chromosomes, using a mask template. The position parameter is omitted. A random mask is generated. The first offspring takes the genes of this if the mask value is true. The second offspring takes the genes of the other parent if the mask value is false. Then for the empty positions, the first not contained genes of the other parent are taken until the chromosomes are completely fill.
        Specified by:
        cross in class Chromosome
        b - Chromosome to cross
        position - Omitted.
        A two position array with the new offsprings.
      • mutate

        public Chromosome mutate​(double pm)
        Swap two position of the genes. The positions are selected with probability pm
        Specified by:
        mutate in class Chromosome
        pm - Mutation probability.
        The new mutated chromosome.
      • getInstance

        protected Chromosome getInstance​(int[] genes,
                                         java.util.Random random)
        Create a new instance of a Chromosome with this int array.
        genes - The genetic charge to copy.
        A new chromosome with the same genetic charge.
      • 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
      • getGenes

        public int[] getGenes()
        The genetic charge of this chromosome.
      • toString

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