Package libai.genetics.chromosomes
Class BinaryChromosome
- java.lang.Object
-
- libai.genetics.chromosomes.Chromosome
-
- libai.genetics.chromosomes.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)
-
-
Constructor Summary
Constructors Modifier Constructor Description BinaryChromosome()protectedBinaryChromosome(int length, java.util.Random random)protectedBinaryChromosome(BinaryChromosome c)Initialize this chromosome with another one
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.longdecode()Convert this chromosome in a long value.doubledecode(double minValue, double maxValue)Convert this chromosome in a double value using the minValue and maxValue as reference.ChromosomegetCopy()Clone this chromosome.ChromosomegetInstance(int length, java.util.Random random)Creates a new chromosome with a length oflengthprotected ChromosomegetInstance(java.util.BitSet bs)Create a new instance of a Chromosome with this BitSet.Chromosomemutate(double pm)Flip a bit of the genes.java.lang.StringtoString()-
Methods inherited from class libai.genetics.chromosomes.Chromosome
getChance, getFitness, getFitnessReal, setChance, setFitness, setFitnessReal
-
-
-
-
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:
crossin classChromosome- Parameters:
b- chromosome to crossposition- 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 probabilitypm- Specified by:
mutatein classChromosome- 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-minValuemaxValue-maxValue- Returns:
- The double representation of the chromosome.
-
getCopy
public Chromosome getCopy()
Clone this chromosome.- Specified by:
getCopyin classChromosome- Returns:
- A identical chromosome of this.
-
getInstance
public Chromosome getInstance(int length, java.util.Random random)
Creates a new chromosome with a length oflength- Specified by:
getInstancein classChromosome- Parameters:
length- The length of the new chromosome.- Returns:
- A new instance of length
length
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-