Top Description Fields Constructors Methods
org.apache.commons.math3.genetics

public abstract Class Chromosome

extends Object
implements Comparable<Chromosome>, Fitness
Class Inheritance
All Implemented Interfaces
org.apache.commons.math3.genetics.Fitness, java.lang.Comparable
Known Direct Subclasses
org.apache.commons.math3.genetics.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

Field Summary

Modifier and TypeField and Description
private double
fitness

Cached value of the fitness of this chromosome.

private static final double
NO_FITNESS

Value assigned when no fitness has been computed yet.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

  • -1 if another is better than this
  • 1 if another is worse than this
  • 0 if the two chromosomes have the same fitness
compareTo
(final Chromosome
another chromosome to compare
another
)

Implements java.lang.Comparable.compareTo.

Compares two chromosomes based on their fitness.

protected Chromosome

Returns:

Chromosome with the same representation, or null if no such chromosome exists.
findSameChromosome
(final Population
Population to search
population
)

Searches the population for another chromosome with the same representation.

public double

Returns:

the fitness
getFitness
()

Access the fitness of this chromosome.

protected boolean

Returns:

true if another is equivalent to this chromosome
isSame
(final Chromosome
chromosome to compare
another
)

Returns true iff another has the same representation and therefore the same fitness.

public void
searchForFitnessUpdate(final Population
Population to search
population
)

Searches the population for a chromosome representing the same solution, and if it finds one, updates the fitness to its value.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

fitnessback to summary
private double fitness

Cached value of the fitness of this chromosome.

NO_FITNESSback to summary
private static final double NO_FITNESS

Value assigned when no fitness has been computed yet.

Constructor Detail

Chromosomeback to summary
public Chromosome()

Method Detail

compareToback to summary
public int compareTo(final Chromosome another)

Implements java.lang.Comparable.compareTo.

Compares two chromosomes based on their fitness. The bigger the fitness, the better the chromosome.

Parameters
another:Chromosome

another chromosome to compare

Returns:int

  • -1 if another is better than this
  • 1 if another is worse than this
  • 0 if the two chromosomes have the same fitness
findSameChromosomeback to summary
protected Chromosome findSameChromosome(final Population population)

Searches the population for another chromosome with the same representation. If such chromosome is found, it is returned, if no such chromosome exists, returns null.

Parameters
population:Population

Population to search

Returns:Chromosome

Chromosome with the same representation, or null if no such chromosome exists.

getFitnessback to summary
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:double

the fitness

isSameback to summary
protected boolean isSame(final Chromosome another)

Returns 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.

Parameters
another:Chromosome

chromosome to compare

Returns:boolean

true if another is equivalent to this chromosome

searchForFitnessUpdateback to summary
public void searchForFitnessUpdate(final Population population)

Searches the population for a chromosome representing the same solution, and if it finds one, updates the fitness to its value.

Parameters
population:Population

Population to search