org.apache.commons.math3.genetics

## Class Chromosome

- java.lang.Object
- - org.apache.commons.math3.genetics.Chromosome

- All Implemented Interfaces:
    java.lang.Comparable<Chromosome>, Fitness
  Direct Known Subclasses:
    AbstractListChromosome

      public abstract class Chromosome
      extends java.lang.Object
      implements java.lang.Comparable<Chromosome>, Fitness

  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
  Version:
    $Id: Chromosome.java 1416643 2012-12-03 19:37:14Z tn $

- - ### Field Summary

    Fields
    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 Summary

    Constructors
    Constructor and Description
    `Chromosome()`

  - ### Method Summary

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

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.apache.commons.math3.genetics.Fitness

      `fitness`

- - ### Field Detail

    - #### NO_FITNESS

          private static final double NO_FITNESS

      Value assigned when no fitness has been computed yet.
      See Also:
        Constant Field Values

    - #### fitness

          private double fitness

      Cached value of the fitness of this chromosome.

  - ### Constructor Detail

    - #### Chromosome

          public Chromosome()

  - ### Method Detail

    - #### 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

          public int compareTo(Chromosome another)

      Compares two chromosomes based on their fitness. The bigger the fitness, the better the chromosome.
      Specified by:
        `compareTo` in interface `java.lang.Comparable<Chromosome>`
      Parameters:
        `another` - another chromosome to compare
      Returns:
        - -1 if `another` is better than `this`
        - 1 if `another` is worse than `this`
        - 0 if the two chromosomes have the same fitness

    - #### isSame

          protected boolean isSame(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 to compare
      Returns:
        true if `another` is equivalent to this chromosome

    - #### findSameChromosome

          protected Chromosome findSameChromosome(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 to search
      Returns:
        Chromosome with the same representation, or `null` if no such chromosome exists.

    - #### searchForFitnessUpdate

          public 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.
      Parameters:
        `population` - Population to search

Copyright (c) 2003-2013 Apache Software Foundation