Package libai.genetics.chromosomes
Class IntegerChromosome
- java.lang.Object
-
- libai.genetics.chromosomes.Chromosome
-
- libai.genetics.chromosomes.IntegerChromosome
-
public class IntegerChromosome extends Chromosome
Implementation of a permutation chromosome.
-
-
Constructor Summary
Constructors Modifier Constructor Description IntegerChromosome()
protected
IntegerChromosome(int length, java.util.Random random)
protected
IntegerChromosome(IntegerChromosome b)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Chromosome[]
cross(Chromosome b, int position)
Cross the chromosomes, using a mask template.Chromosome
getCopy()
Clone this chromosome.int[]
getGenes()
protected Chromosome
getInstance(int[] genes, java.util.Random random)
Create a new instance of a Chromosome with this int array.Chromosome
getInstance(int length, java.util.Random random)
Creates a new chromosome with a length oflength
Chromosome
mutate(double pm)
Swap two position of the genes.java.lang.String
toString()
-
Methods inherited from class libai.genetics.chromosomes.Chromosome
getChance, getFitness, getFitnessReal, setChance, setFitness, setFitnessReal
-
-
-
-
Constructor Detail
-
IntegerChromosome
public IntegerChromosome()
-
IntegerChromosome
protected IntegerChromosome(int length, java.util.Random random)
-
IntegerChromosome
protected IntegerChromosome(IntegerChromosome b)
-
-
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 classChromosome
- Parameters:
b
- Chromosome to crossposition
- Omitted.- Returns:
- 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 probabilitypm
- Specified by:
mutate
in classChromosome
- Parameters:
pm
- Mutation probability.- Returns:
- 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.- Parameters:
genes
- The genetic charge to copy.- Returns:
- A new chromosome with the same genetic charge.
-
getCopy
public Chromosome getCopy()
Clone this chromosome.- Specified by:
getCopy
in 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:
getInstance
in classChromosome
- Parameters:
length
- The length of the new chromosome.- Returns:
- A new instance of length
length
-
getGenes
public int[] getGenes()
- Returns:
- The genetic charge of this chromosome.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-