Class Chromosome
java.lang.Object
org.apache.commons.math3.genetics.Chromosome
- All Implemented Interfaces:
Comparable<Chromosome>,Fitness
- Direct Known Subclasses:
AbstractListChromosome
Individual in a population. Chromosomes are compared based on their fitness.
The chromosomes are IMMUTABLE, and so their fitness is also immutable and therefore it can be cached.
- Since:
- 2.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(Chromosome another) Compares two chromosomes based on their fitness.protected ChromosomefindSameChromosome(Population population) Searches thepopulationfor another chromosome with the same representation.doubleAccess the fitness of this chromosome.protected booleanisSame(Chromosome another) Returnstrueiffanotherhas the same representation and therefore the same fitness.voidsearchForFitnessUpdate(Population population) Searches the population for a chromosome representing the same solution, and if it finds one, updates the fitness to its value.
-
Constructor Details
-
Chromosome
public Chromosome()
-
-
Method Details
-
getFitness
public double getFitness()Access the fitness of this chromosome. The bigger the fitness, the better the chromosome.Computation of fitness is usually very time-consuming task, therefore the fitness is cached.
- Returns:
- the fitness
-
compareTo
Compares two chromosomes based on their fitness. The bigger the fitness, the better the chromosome.- Specified by:
compareToin interfaceComparable<Chromosome>- Parameters:
another- another chromosome to compare- Returns:
- -1 if
anotheris better thanthis - 1 if
anotheris worse thanthis - 0 if the two chromosomes have the same fitness
- -1 if
-
isSame
Returnstrueiffanotherhas the same representation and therefore the same fitness. By default, it returns false -- override it in your implementation if you need it.- Parameters:
another- chromosome to compare- Returns:
- true if
anotheris equivalent to this chromosome
-
findSameChromosome
Searches thepopulationfor another chromosome with the same representation. If such chromosome is found, it is returned, if no such chromosome exists, returnsnull.- Parameters:
population- Population to search- Returns:
- Chromosome with the same representation, or
nullif no such chromosome exists.
-
searchForFitnessUpdate
Searches the population for a chromosome representing the same solution, and if it finds one, updates the fitness to its value.- Parameters:
population- Population to search
-