org.jgap.impl
Class NumberGene

java.lang.Object
  extended byorg.jgap.impl.NumberGene
All Implemented Interfaces:
java.lang.Comparable, Gene, java.io.Serializable
Direct Known Subclasses:
DoubleGene, IntegerGene

public abstract class NumberGene
extends java.lang.Object
implements Gene

Base class for all Genes based on numbers. Known implementations: IntegerGene, DoubleGene

Since:
1.1 (most code moved and adapted from IntegerGene)
Author:
Klaus Meffert
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.jgap.Gene
PERSISTENT_FIELD_DELIMITER
 
Constructor Summary
NumberGene()
           
 
Method Summary
abstract  void applyMutation(int index, double a_percentage)
          Applies a mutation of a given intensity (percentage) onto the atomic element at given index (NumberGenes only have one atomic element)
 void cleanup()
          Executed by the genetic engine when this Gene instance is no longer needed and should perform any necessary resource cleanup.
 int compareTo(java.lang.Object other)
          Compares this IntegerGene with the specified object (which must also be an IntegerGene) for order, which is determined by the integer value of this Gene compared to the one provided for comparison.
 boolean equals(java.lang.Object other)
          Compares this IntegerGene with the given object and returns true if the other object is a IntegerGene and has the same value (allele) as this IntegerGene.
 java.lang.Object getAllele()
          Retrieves the value (allele) represented by this Gene.
 IGeneConstraintChecker getConstraintChecker()
           
 int hashCode()
          Retrieves the hash code value for this IntegerGene.
 void setAllele(java.lang.Object a_newValue)
          Sets the value (allele) of this Gene to the new given value.
 void setConstraintChecker(IGeneConstraintChecker a_constraintChecker)
          Sets the constraint checker to be used for this gene whenever method setAllele(Object a_newValue) is called
 int size()
           
 java.lang.String toString()
          Retrieves a string representation of this IntegerGene's value that may be useful for display purposes.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jgap.Gene
getPersistentRepresentation, newGene, setToRandomValue, setValueFromPersistentRepresentation
 

Constructor Detail

NumberGene

public NumberGene()
Method Detail

cleanup

public void cleanup()
Executed by the genetic engine when this Gene instance is no longer needed and should perform any necessary resource cleanup.

Specified by:
cleanup in interface Gene
Since:
1.1

equals

public boolean equals(java.lang.Object other)
Compares this IntegerGene with the given object and returns true if the other object is a IntegerGene and has the same value (allele) as this IntegerGene. Otherwise it returns false.

Parameters:
other - the object to compare to this IntegerGene for equality.
Returns:
true if this Gene is equal to the given object, false otherwise.
Since:
1.1

hashCode

public int hashCode()
Retrieves the hash code value for this IntegerGene.

Returns:
this IntegerGene's hash code.
Since:
1.1

compareTo

public int compareTo(java.lang.Object other)
Compares this IntegerGene with the specified object (which must also be an IntegerGene) for order, which is determined by the integer value of this Gene compared to the one provided for comparison.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
other - the IntegerGene to be compared to this IntegerGene.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the object provided for comparison.
Throws:
java.lang.ClassCastException - if the specified object's type prevents it from being compared to this IntegerGene.
Since:
1.1

toString

public java.lang.String toString()
Retrieves a string representation of this IntegerGene's value that may be useful for display purposes.

Specified by:
toString in interface Gene
Returns:
a string representation of this IntegerGene's value.
Since:
1.1

setAllele

public void setAllele(java.lang.Object a_newValue)
Sets the value (allele) of this Gene to the new given value. This class expects the value to be an instance of current type (e.g. Integer). If the value is above or below the upper or lower bounds, it will be mappped to within the allowable range.

Specified by:
setAllele in interface Gene
Parameters:
a_newValue - the new value of this Gene instance.
Since:
1.1

setConstraintChecker

public void setConstraintChecker(IGeneConstraintChecker a_constraintChecker)
Sets the constraint checker to be used for this gene whenever method setAllele(Object a_newValue) is called

Parameters:
a_constraintChecker - the constraint checker to be set
Since:
2.0

getConstraintChecker

public IGeneConstraintChecker getConstraintChecker()
Returns:
IGeneConstraintChecker the constraint checker to be used whenever method setAllele(Object a_newValue) is called
Since:
2.0

getAllele

public java.lang.Object getAllele()
Retrieves the value (allele) represented by this Gene. All values returned by this class will be Integer instances.

Specified by:
getAllele in interface Gene
Returns:
the Integer value of this Gene.
Since:
1.1

size

public int size()
Specified by:
size in interface Gene
Returns:
the size of the gene, i.e the number of atomic elements. Always 1 for numbers
Since:
1.1

applyMutation

public abstract void applyMutation(int index,
                                   double a_percentage)
Applies a mutation of a given intensity (percentage) onto the atomic element at given index (NumberGenes only have one atomic element)

Specified by:
applyMutation in interface Gene
Parameters:
index - index of atomic element, between 0 and size()-1
a_percentage - percentage of mutation (greater than -1 and smaller than 1).
Since:
1.1