public abstract class Chromosome extends java.lang.Object implements java.lang.Comparable<Chromosome>, Fitness
The chromosomes are IMMUTABLE, and so their fitness is also immutable and therefore it can be cached.
Modifier and Type | Field and Description |
---|---|
private double |
fitness
Cached value of the fitness of this chromosome.
|
private static double |
NO_FITNESS
Value assigned when no fitness has been computed yet.
|
Constructor and Description |
---|
Chromosome() |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Chromosome another)
Compares two chromosomes based on their fitness.
|
protected Chromosome |
findSameChromosome(Population population)
Searches the
population for another chromosome with the same representation. |
double |
getFitness()
Access the fitness of this chromosome.
|
protected boolean |
isSame(Chromosome another)
Returns
true iff another has the same representation and therefore the same fitness. |
void |
searchForFitnessUpdate(Population population)
Searches the population for a chromosome representing the same solution, and if it finds one,
updates the fitness to its value.
|
private static final double NO_FITNESS
private double fitness
public double getFitness()
Computation of fitness is usually very time-consuming task, therefore the fitness is cached.
public int compareTo(Chromosome another)
compareTo
in interface java.lang.Comparable<Chromosome>
another
- another chromosome to compareanother
is better than this
another
is worse than this
protected boolean isSame(Chromosome another)
true
iff another
has the same representation and therefore the same fitness. By
default, it returns false -- override it in your implementation if you need it.another
- chromosome to compareanother
is equivalent to this chromosomeprotected Chromosome findSameChromosome(Population population)
population
for another chromosome with the same representation. If such chromosome is
found, it is returned, if no such chromosome exists, returns null
.population
- Population to searchnull
if no such chromosome exists.public void searchForFitnessUpdate(Population population)
population
- Population to searchCopyright (c) 2003-2016 Apache Software Foundation