Class BooleanGene
- java.lang.Object
-
- org.jgap.BaseGene
-
- org.jgap.impl.BooleanGene
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Comparable, Gene, IBusinessKey, IPersistentRepresentation, IUniqueKey
public class BooleanGene extends BaseGene implements IPersistentRepresentation
A Gene implementation that supports two possible values (alleles) for each gene: true and false.NOTE: Since this Gene implementation only supports two different values (true and false), there's only a 50% chance that invocation of the setToRandomValue() method will actually change the value of this Gene (if it has a value). As a result, it may be desirable to use a higher overall mutation rate when this Gene implementation is in use.
- Since:
- 1.0
- 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 BooleanGene()Default constructor.BooleanGene(Configuration a_config)BooleanGene(Configuration a_config, boolean a_value)BooleanGene(Configuration a_config, java.lang.Boolean a_value)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidapplyMutation(int a_index, double a_percentage)Applies a mutation of a given intensity (percentage) onto the atomic element at given indexbooleanbooleanValue()Retrieves the boolean value of this Gene.intcompareTo(java.lang.Object a_other)Compares this BooleanGene with the specified object for order.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.inthashCode()Modified hashCode() function to return different hashcodes for differently ordered genes in a chromosomevoidsetAllele(java.lang.Object a_newValue)Sets the value of this Gene to the new given value.voidsetToRandomValue(RandomGenerator a_numberGenerator)Sets the value (allele) of this Gene to a random legal value.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.BaseGene
cleanup, equals, getAllele, getApplicationData, getBusinessKey, getConfiguration, getConstraintChecker, getEnergy, getUniqueID, getUniqueIDTemplate, isCompareApplicationData, newGene, setApplicationData, setCompareApplicationData, setConstraintChecker, setEnergy, setUniqueIDTemplate, size
-
-
-
-
Constructor Detail
-
BooleanGene
public BooleanGene() throws InvalidConfigurationExceptionDefault constructor.Attention: The configuration used is the one set with the static method Genotype.setConfiguration.
- Throws:
InvalidConfigurationException- Since:
- 2.4
-
BooleanGene
public BooleanGene(Configuration a_config) throws InvalidConfigurationException
- Parameters:
a_config- the configuration to use- Throws:
InvalidConfigurationException- Since:
- 3.0
-
BooleanGene
public BooleanGene(Configuration a_config, boolean a_value) throws InvalidConfigurationException
- Parameters:
a_config- the configuration to usea_value- allele value to setup the gene with- Throws:
InvalidConfigurationException- Since:
- 2.4
-
BooleanGene
public BooleanGene(Configuration a_config, java.lang.Boolean a_value) throws InvalidConfigurationException
- Parameters:
a_config- the configuration to usea_value- allele value to setup the gene with- Throws:
InvalidConfigurationException- Since:
- 2.4
-
-
Method Detail
-
setAllele
public void setAllele(java.lang.Object a_newValue)
Sets the value of this Gene to the new given value. This class expects the value to be a Boolean instance.
-
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
-
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.0
-
booleanValue
public boolean booleanValue()
Retrieves the boolean value of this Gene. This may be more convenient in some cases than the more general getAllele() method.- Returns:
- the boolean value of this Gene
-
setToRandomValue
public void setToRandomValue(RandomGenerator a_numberGenerator)
Sets the value (allele) of this Gene to a random legal value. This method exists for the benefit of mutation and other operations that simply desire to randomize the value of a gene.NOTE: Since this Gene implementation only supports two different values (true and false), there's only a 50% chance that invocation of this method will actually change the value of this Gene (if it has a value). As a result, it may be desirable to use a higher overall mutation rate when this Gene implementation is in use.
- 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
-
compareTo
public int compareTo(java.lang.Object a_other)
Compares this BooleanGene with the specified object for order. A false value is considered to be less than a true value. A null value is considered to be less than any non-null value.- Specified by:
compareToin interfacejava.lang.Comparable- Parameters:
a_other- the BooleanGene to be compared- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object
- Throws:
java.lang.ClassCastException- if the specified object's type prevents it from being compared to this BooleanGene- Since:
- 1.0
-
applyMutation
public void applyMutation(int a_index, double a_percentage)Applies a mutation of a given intensity (percentage) onto the atomic element at given index- Specified by:
applyMutationin interfaceGene- Parameters:
a_index- not used herea_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.
-
-
DMelt 3.0 © DataMelt by jWork.ORG