org.jgap.impl
Class DoubleGene
- java.lang.Object
-
- org.jgap.BaseGene
-
- org.jgap.impl.NumberGene
-
- org.jgap.impl.DoubleGene
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Comparable, Gene, IBusinessKey, IPersistentRepresentation, IUniqueKey
public class DoubleGene extends NumberGene implements IPersistentRepresentation
A Gene implementation that supports a double values for its allele. Upper and lower bounds may optionally be provided to restrict the range of legal values allowed by this Gene instance.Partly copied from IntegerGene.
- Since:
- 1.1
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.jgap.BaseGene
DELTA, S_APPLICATION_DATA
-
Fields inherited from interface org.jgap.Gene
PERSISTENT_FIELD_DELIMITER
-
-
Constructor Summary
Constructors Constructor and Description DoubleGene()Constructs a new DoubleGene with default settings.DoubleGene(Configuration a_config)Constructs a new DoubleGene with default settings.DoubleGene(Configuration a_config, double a_lowerBound, double a_upperBound)Constructs a new DoubleGene with the specified lower and upper bounds for values (alleles) of this Gene instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidapplyMutation(int index, double a_percentage)See interface Gene for description.doubledoubleValue()Retrieves the double value of this Gene, which may be more convenient in some cases than the more general getAllele() method.doublegetLowerBound()java.lang.StringgetPersistentRepresentation()Retrieves a string representation of this Gene that includes any information required to reconstruct it at a later time, such as its value and internal state.doublegetUpperBound()inthashCode()Modified hashCode() function to return different hashcodes for differently ordered genes in a chromosome.voidsetToRandomValue(RandomGenerator a_numberGenerator)Sets the value (allele) of this Gene to a random Double value between the lower and upper bounds (if any) of this Gene.voidsetValueFromPersistentRepresentation(java.lang.String a_representation)Sets the value and internal state of this Gene from the string representation returned by a previous invocation of the getPersistentRepresentation() method.java.lang.StringtoString()Retrieves a string representation of this Gene's value that may be useful for display purposes.-
Methods inherited from class org.jgap.impl.NumberGene
compareTo, setAllele
-
Methods inherited from class org.jgap.BaseGene
cleanup, equals, getAllele, getApplicationData, getBusinessKey, getConfiguration, getConstraintChecker, getEnergy, getUniqueID, getUniqueIDTemplate, isCompareApplicationData, newGene, setApplicationData, setCompareApplicationData, setConstraintChecker, setEnergy, setUniqueIDTemplate, size
-
-
-
-
Constructor Detail
-
DoubleGene
public DoubleGene() throws InvalidConfigurationExceptionConstructs a new DoubleGene with default settings. No bounds will be put into effect for values (alleles) of this Gene instance, other than the standard range of double values.Attention: The configuration used is the one set with the static method Genotype.setConfiguration.
- Throws:
InvalidConfigurationException- Since:
- 1.1
-
DoubleGene
public DoubleGene(Configuration a_config) throws InvalidConfigurationException
Constructs a new DoubleGene with default settings. No bounds will be put into effect for values (alleles) of this Gene instance, other than the standard range of double values.- Parameters:
a_config- the configuration to use- Throws:
InvalidConfigurationException- Since:
- 3.0
-
DoubleGene
public DoubleGene(Configuration a_config, double a_lowerBound, double a_upperBound) throws InvalidConfigurationException
Constructs a new DoubleGene with the specified lower and upper bounds for values (alleles) of this Gene instance.- Parameters:
a_config- the configuration to usea_lowerBound- the lowest value that this Gene may possess, inclusivelya_upperBound- the highest value that this Gene may possess, inclusively- Throws:
InvalidConfigurationException- Since:
- 2.0
-
-
Method Detail
-
getPersistentRepresentation
public java.lang.String getPersistentRepresentation()
Retrieves a string representation of this Gene that includes any information required to reconstruct it at a later time, such as its value and internal state. This string will be used to represent this Gene in XML persistence. This is an optional method but, if not implemented, XML persistence and possibly other features will not be available. An UnsupportedOperationException should be thrown if no implementation is provided.- Specified by:
getPersistentRepresentationin interfaceGene- Specified by:
getPersistentRepresentationin interfaceIPersistentRepresentation- Returns:
- a string representation of this Gene's current state
- Since:
- 1.1
-
setValueFromPersistentRepresentation
public void setValueFromPersistentRepresentation(java.lang.String a_representation) throws UnsupportedRepresentationExceptionSets the value and internal state of this Gene from the string representation returned by a previous invocation of the getPersistentRepresentation() method. This is an optional method but, if not implemented, XML persistence and possibly other features will not be available. An UnsupportedOperationException should be thrown if no implementation is provided.- Specified by:
setValueFromPersistentRepresentationin interfaceGene- Specified by:
setValueFromPersistentRepresentationin interfaceIPersistentRepresentation- Parameters:
a_representation- the string representation retrieved from a prior call to the getPersistentRepresentation() method- Throws:
java.lang.UnsupportedOperationException- to indicate that no implementation is provided for this methodUnsupportedRepresentationException- if this Gene implementation does not support the given string representation- Since:
- 1.1
-
doubleValue
public double doubleValue()
Retrieves the double value of this Gene, which may be more convenient in some cases than the more general getAllele() method.- Returns:
- the double value of this Gene
- Since:
- 1.1
-
setToRandomValue
public void setToRandomValue(RandomGenerator a_numberGenerator)
Sets the value (allele) of this Gene to a random Double value between the lower and upper bounds (if any) of this Gene.- Specified by:
setToRandomValuein interfaceGene- Parameters:
a_numberGenerator- the random number generator that should be used to create any random values. It's important to use this generator to maintain the user's flexibility to configure the genetic engine to use the random number generator of their choice- Since:
- 1.1
-
applyMutation
public void applyMutation(int index, double a_percentage)See interface Gene for description.- Specified by:
applyMutationin interfaceGene- Parameters:
index- ignored (because there is only 1 atomic element)a_percentage- percentage of mutation (greater than -1 and smaller than 1)- Since:
- 1.1
-
hashCode
public int hashCode()
Modified hashCode() function to return different hashcodes for differently ordered genes in a chromosome.
-
toString
public java.lang.String toString()
Description copied from class:BaseGeneRetrieves a string representation of this Gene's value that may be useful for display purposes.
-
getLowerBound
public double getLowerBound()
- Returns:
- the lower bound set
- Since:
- 3.0
-
getUpperBound
public double getUpperBound()
- Returns:
- the upper bound set
- Since:
- 3.0
-
-
DMelt 3.0 © DataMelt by jWork.ORG