Package libai.genetics.chromosomes
Class Chromosome
- java.lang.Object
-
- libai.genetics.chromosomes.Chromosome
-
- Direct Known Subclasses:
BinaryChromosome
,IntegerChromosome
public abstract class Chromosome extends java.lang.Object
The chromosome abstraction. Keeps the fitness and the chance to be selected by the roulette. Also has the methods to mutate and cross with another chromosome in an specific point.
-
-
Constructor Summary
Constructors Constructor Description Chromosome()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract Chromosome[]
cross(Chromosome b, int position)
Split the genes byposition
and swap lower portion of this with the lower portion ofb
and return the new individualdouble
getChance()
abstract Chromosome
getCopy()
Copy constructordouble
getFitness()
double
getFitnessReal()
abstract Chromosome
getInstance(int length, java.util.Random random)
Generic constructorabstract Chromosome
mutate(double pm)
Change one gene of the chromosomevoid
setChance(double chance)
void
setFitness(double fitness)
void
setFitnessReal(double fitnessReal)
-
-
-
Method Detail
-
cross
public abstract Chromosome[] cross(Chromosome b, int position)
Split the genes byposition
and swap lower portion of this with the lower portion ofb
and return the new individual- Parameters:
b
-b
position
-position
- Returns:
- new individual
-
mutate
public abstract Chromosome mutate(double pm)
Change one gene of the chromosome- Parameters:
pm
-pm
- Returns:
- mutated
Chromosome
-
getCopy
public abstract Chromosome getCopy()
Copy constructor- Returns:
- copy of this Chromosome
-
getInstance
public abstract Chromosome getInstance(int length, java.util.Random random)
Generic constructor- Parameters:
length
-length
- Returns:
Chromosome
instance
-
getFitness
public double getFitness()
- Returns:
- the fitness
-
setFitness
public void setFitness(double fitness)
- Parameters:
fitness
- The new fitness
-
getChance
public double getChance()
- Returns:
- the chance to be selected
-
setChance
public void setChance(double chance)
- Parameters:
chance
- The new chance.
-
getFitnessReal
public double getFitnessReal()
- Returns:
- the fitnessReal
-
setFitnessReal
public void setFitnessReal(double fitnessReal)
- Parameters:
fitnessReal
- The new fitnessReal.
-
-