Orbital library

orbital.algorithm.evolutionary
Class Genome

java.lang.Object
  extended by orbital.util.DelegateCollection
      extended by orbital.util.DelegateList
          extended by orbital.algorithm.evolutionary.Gene.List
              extended by orbital.algorithm.evolutionary.Genome
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable, java.util.Collection, java.util.List, Gene

public class Genome
extends Gene.List

The Genome data in a population represents a state. For bio informatics, genomes and chromosomes are treated as synonyms.

A Genome provides the following operators and functions:

Genomes provide fitness caching and clearing.

Author:
André Platzer
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface orbital.algorithm.evolutionary.Gene
Gene.BitSet, Gene.BoundedFloat, Gene.BoundedInteger, Gene.Fixed, Gene.Float, Gene.Integer, Gene.List, Gene.Number
 
Field Summary
static java.util.Comparator comparator
          Compare two Genomes according to their fitness, descending.
 
Constructor Summary
Genome()
           
Genome(Gene content)
          Construct a genome with a single gene.
 
Method Summary
 void add(int index, java.lang.Object o)
          Insert one gene.
 boolean add(java.lang.Object o)
          Add one gene.
 void clearFitness()
          Clears the fitness.
 java.lang.Object clone()
          Returns a deep copy of this exact type of gene.
 boolean equals(java.lang.Object o)
          Compares the specified object with this collection for equality.
 void evaluate(Population population, boolean redo)
          Evaluates the fitness of the Genomes, if necessary.
 java.lang.Object get()
          Use with care!! Will not clear fitness if the return-value is modified.
 java.lang.Object get(int i)
          Use with care! Will not clear fitness if the return-value is modified.
 double getFitness()
          Get the fitness calculated the least recently.
 boolean hasFitness()
          Whether genome has a fitness != Double.NaN.
 int hashCode()
          Returns the hash code value for this collection.
 Gene inverse()
          Get an inverted version of this Genome.
 Gene mutate(double probability)
          Get a mutated version of this Gene.
 Gene[] recombine(Gene[] parents, int childrenCount, double recombinationProbability)
          Genetically recombine gene data of parents to their children via reproduction..
 java.lang.Object set(int i, java.lang.Object g)
          Set one gene.
 void set(java.lang.Object list)
          Set the Genome data.
 void setFitness(double fitness)
          Set the fitness calculated.
 void setFitness(java.lang.Number fitness)
           
 
Methods inherited from class orbital.algorithm.evolutionary.Gene.List
distanceMeasure, elementwiseRecombine, toString, uniformRecombine
 
Methods inherited from class orbital.util.DelegateList
addAll, indexOf, lastIndexOf, listIterator, listIterator, remove, setDelegatee, setDelegatee, subList
 
Methods inherited from class orbital.util.DelegateCollection
addAll, clear, contains, containsAll, getDelegatee, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 

Field Detail

comparator

public static final java.util.Comparator comparator
Compare two Genomes according to their fitness, descending.

Constructor Detail

Genome

public Genome()

Genome

public Genome(Gene content)
Construct a genome with a single gene.

Parameters:
content - the initial member gene.
See Also:
add(Object)
Method Detail

clone

public java.lang.Object clone()
Description copied from class: Gene.List
Returns a deep copy of this exact type of gene.

Specified by:
clone in interface Gene
Overrides:
clone in class Gene.List

equals

public boolean equals(java.lang.Object o)
Description copied from class: DelegateCollection
Compares the specified object with this collection for equality.

While the Collection interface adds no stipulations to the general contract for the Object.equals, programmers who implement the Collection interface "directly" (in other words, create a class that is a Collection but is not a Set or a List) must exercise care if they choose to override the Object.equals. It is not necessary to do so, and the simplest course of action is to rely on Object's implementation, but the implementer may wish to implement a "value comparison" in place of the default "reference comparison." (The List and Set interfaces mandate such value comparisons.)

The general contract for the Object.equals method states that equals must be symmetric (in other words, a.equals(b) if and only if b.equals(a)). The contracts for List.equals and Set.equals state that lists are only equal to other lists, and sets to other sets. Thus, a custom equals method for a collection class that implements neither the List nor Set interface must return false when this collection is compared to any list or set. (By the same logic, it is not possible to write a class that correctly implements both the Set and List interfaces.)

Specified by:
equals in interface java.util.Collection
Specified by:
equals in interface java.util.List
Specified by:
equals in interface Gene
Overrides:
equals in class Gene.List
Parameters:
o - Object to be compared for equality with this collection.
Returns:
true if the specified object is equal to this collection
See Also:
Object.equals(Object), Set.equals(Object), List.equals(Object)

hashCode

public int hashCode()
Description copied from class: DelegateCollection
Returns the hash code value for this collection. While the Collection interface adds no stipulations to the general contract for the Object.hashCode method, programmers should take note that any class that overrides the Object.equals method must also override the Object.hashCode method in order to satisfy the general contract for the Object.hashCodemethod. In particular, c1.equals(c2) implies that c1.hashCode()==c2.hashCode().

Specified by:
hashCode in interface java.util.Collection
Specified by:
hashCode in interface java.util.List
Specified by:
hashCode in interface Gene
Overrides:
hashCode in class Gene.List
Returns:
the hash code value for this collection
See Also:
Object.hashCode(), Object.equals(Object)

getFitness

public double getFitness()
Get the fitness calculated the least recently.

See Also:
evaluate(Population, boolean), setFitness(double)

hasFitness

public boolean hasFitness()
Whether genome has a fitness != Double.NaN.

Returns:
!Double.isNaN(getFitness()).
See Also:
getFitness()

setFitness

public void setFitness(double fitness)
Set the fitness calculated.


setFitness

public void setFitness(java.lang.Number fitness)

clearFitness

public void clearFitness()
Clears the fitness. Called to say that the fitness has changed and must be re-evaluated. Sets the fitness to Double.NaN.

See Also:
setFitness(double)

get

public java.lang.Object get(int i)
Use with care! Will not clear fitness if the return-value is modified. This constraint does apply to all parts of the gene returned, as well, if they are modified, the fitness must be cleared and re-evaluated.

Specified by:
get in interface java.util.List
Overrides:
get in class DelegateList

set

public java.lang.Object set(int i,
                            java.lang.Object g)
Set one gene. Will clear fitness.

Specified by:
set in interface java.util.List
Overrides:
set in class DelegateList

add

public boolean add(java.lang.Object o)
Add one gene. Will clear fitness.

Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.List
Overrides:
add in class DelegateCollection
Parameters:
o - element whose presence in this collection is to be ensured.
Returns:
true if this collection changed as a result of the call

add

public void add(int index,
                java.lang.Object o)
Insert one gene. Will clear fitness.

Specified by:
add in interface java.util.List
Overrides:
add in class DelegateList

get

public java.lang.Object get()
Use with care!! Will not clear fitness if the return-value is modified.

Specified by:
get in interface Gene
Overrides:
get in class Gene.List
Returns:
the Object represented by this gene. Interprets gene by decoding its data.
See Also:
get(int)

set

public void set(java.lang.Object list)
Set the Genome data. Will clear fitness.

Specified by:
set in interface Gene
Overrides:
set in class Gene.List
Parameters:
list - the Object this gene should represent. Encodes the value such that this gene represents the given object.

mutate

public Gene mutate(double probability)
Description copied from class: Gene.List
Get a mutated version of this Gene.

Implemented as Element-wise mutation.

Specified by:
mutate in interface Gene
Overrides:
mutate in class Gene.List
Parameters:
probability - the probability rating of mutation level. f.ex. probability with that each bit of the Gene mutates.
Returns:
a new gene that is a mutation of this one.

recombine

public Gene[] recombine(Gene[] parents,
                        int childrenCount,
                        double recombinationProbability)
Description copied from class: Gene.List
Genetically recombine gene data of parents to their children via reproduction.
 a       a  = direct ancestors to be used
 n * --- ;    n  = number of children to be produced
 p       p  = probability for each part of parent's Gene to be inherited
 a/p = elongation of Gene length
 n/a = growth of population size
 if n/a < 1 the population is contracting.
 if n/a = 1 the population size is fixed.
 if n/a > 1 the population is growing.
 
Usually it is p=n/a..

Specified by:
recombine in interface Gene
Overrides:
recombine in class Gene.List
Parameters:
parents - the Genes to be used as parents for the children. a is the number of parents (direct ancestors). parents are readonly.
childrenCount - the number of Gene children to produce and return. n is the number of children to be produced.
recombinationProbability - the probability with that parts of the inherited gene data is recombined. This does not necessarily imply an exchange of data, Genes might as well realign or repair at random. But it makes a data recombination possible.
Returns:
the new childrenCount children produced.
See Also:
Gene.List.elementwiseRecombine(Gene[],int,double)

inverse

public Gene inverse()
Get an inverted version of this Genome.

Specified by:
inverse in interface Gene
Overrides:
inverse in class Gene.List
Returns:
inverted Genome where all data booleans are negated.

evaluate

public void evaluate(Population population,
                     boolean redo)
Evaluates the fitness of the Genomes, if necessary.

Default implementation will consider GeneticAlgorithm.getEvaluation().

Parameters:
redo - force whole evaluation again, even for cached fitness values. Should usually be false for efficiency reasons.
population - the population containing this genome. (Redundant information but required for better performance).
See Also:
getFitness()

Orbital library
1.3.0: 11 Apr 2009

Copyright © 1996-2009 André Platzer
All Rights Reserved.