org.jgap.impl
Class NumberGene
java.lang.Object
org.jgap.BaseGene
org.jgap.impl.NumberGene
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Comparable, Gene, IBusinessKey, IUniqueKey
- Direct Known Subclasses:
- DoubleGene, IntegerGene, MutipleIntegerGene
public abstract class NumberGene
- extends BaseGene
Base class for all Genes based on numbers.
- Since:
- 1.1 (most code moved and adapted from IntegerGene)
- See Also:
- Serialized Form
|
Method Summary |
int |
compareTo(java.lang.Object a_other)
Compares this NumberGene with the specified object (which must also
be a NumberGene) for order, which is determined by the number value of
this Gene compared to the one provided for comparison. |
protected abstract int |
compareToNative(java.lang.Object a_o1,
java.lang.Object a_o2)
Compares to objects by first casting them into their expected type
(e.g. |
protected java.lang.Object |
getInternalValue()
Each Gene implementation holds its own m_value object keeping the allele
value. |
protected abstract void |
mapValueToWithinBounds()
Maps the value of this NumberGene to within the bounds specified by
the m_upperBounds and m_lowerBounds instance variables. |
void |
setAllele(java.lang.Object a_newValue)
Sets the value (allele) of this Gene to the new given value. |
| Methods inherited from class org.jgap.BaseGene |
cleanup, compareApplicationData, decode, encode, equals, getAllele, getApplicationData, getBusinessKey, getConfiguration, getConstraintChecker, getEnergy, getUniqueID, getUniqueIDTemplate, hashCode, isCompareApplicationData, newGene, newGeneInternal, setApplicationData, setCompareApplicationData, setConstraintChecker, setEnergy, setUniqueIDTemplate, size, toString |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
NumberGene
public NumberGene(Configuration a_config)
throws InvalidConfigurationException
- Throws:
InvalidConfigurationException
compareTo
public int compareTo(java.lang.Object a_other)
- Compares this NumberGene with the specified object (which must also
be a NumberGene) for order, which is determined by the number value of
this Gene compared to the one provided for comparison.
- Parameters:
a_other - the NumberGene to be compared to this NumberGene
- 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 NumberGene- Since:
- 1.1
compareToNative
protected abstract int compareToNative(java.lang.Object a_o1,
java.lang.Object a_o2)
- Compares to objects by first casting them into their expected type
(e.g. Integer for IntegerGene) and then calling the compareTo-method
of the casted type.
- Parameters:
a_o1 - first object to be compared, always is not nulla_o2 - second object to be compared, always is not null
- 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
- 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.
- Parameters:
a_newValue - the new value of this Gene instance- Since:
- 1.1
mapValueToWithinBounds
protected abstract void mapValueToWithinBounds()
- Maps the value of this NumberGene to within the bounds specified by
the m_upperBounds and m_lowerBounds instance variables. The value's
relative position within the integer range will be preserved within the
bounds range (in other words, if the value is about halfway between the
integer max and min, then the resulting value will be about halfway
between the upper bounds and lower bounds). If the value is null or
is already within the bounds, it will be left unchanged.
- Since:
- 1.1
getInternalValue
protected java.lang.Object getInternalValue()
- Description copied from class:
BaseGene
- Each Gene implementation holds its own m_value object keeping the allele
value. In your Gene implementation, just return it with this method
(see
BooleanGene for example)
- Specified by:
getInternalValue in class BaseGene
- Returns:
- the m_value object