org.jgap.impl
Class BooleanAllele

java.lang.Object
  extended byorg.jgap.Allele
      extended byorg.jgap.impl.BooleanAllele
All Implemented Interfaces:
java.lang.Comparable

public class BooleanAllele
extends Allele

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.


Field Summary
protected static java.lang.Boolean FALSE_BOOLEAN
          Shared constant representing the "false" boolean value.
protected  Configuration m_activeConfiguration
          The current active configuration that is in use.
protected  java.lang.Boolean m_value
          References the internal boolean value of this Gene.
protected static java.lang.Boolean TRUE_BOOLEAN
          Shared constant representing the "true" boolean value.
 
Constructor Summary
BooleanAllele()
          Constructs a new BooleanGene with default settings.
BooleanAllele(java.lang.Long an_id)
          Constructs a new BooleanGene with default settings.
 
Method Summary
 boolean booleanValue()
          Retrieves the boolean value of this Gene.
 void cleanup()
          Executed by the genetic engine when this Gene instance is no longer needed and should perform any necessary resource cleanup.
 Allele cloneAllele()
           
 double distance(Allele target)
           
 boolean equals(java.lang.Object other)
          Compares this BooleanGene with the given object and returns true if the other object is a BooleanGene and has the same value as this BooleanGene.
 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.
 int hashCode()
          Retrieves the hash code value of this BooleanGene.
 void setToRandomValue(java.util.Random a_numberGenerator)
          Sets the value (allele) of this Gene to a random legal value.
 void setValue(java.lang.Object a_newValue)
          Sets the value of this Gene to the new given value.
 void setValueFromPersistentRepresentation(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.String toString()
          Retrieves a string representation of this BooleanGene's value that may be useful for display purposes.
 
Methods inherited from class org.jgap.Allele
compareTo, getGene, getGenes, getInnovationId
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TRUE_BOOLEAN

protected static final java.lang.Boolean TRUE_BOOLEAN
Shared constant representing the "true" boolean value. Shared constants are used to save memory so that a new Boolean object doesn't have to be constructed each time.


FALSE_BOOLEAN

protected static final java.lang.Boolean FALSE_BOOLEAN
Shared constant representing the "false" boolean value. Shared constants are used to save memory so that a new Boolean object doesn't have to be constructed each time.


m_value

protected java.lang.Boolean m_value
References the internal boolean value of this Gene.


m_activeConfiguration

protected Configuration m_activeConfiguration
The current active configuration that is in use.

Constructor Detail

BooleanAllele

public BooleanAllele()
Constructs a new BooleanGene with default settings.


BooleanAllele

public BooleanAllele(java.lang.Long an_id)
Constructs a new BooleanGene with default settings.

Parameters:
an_id -
Method Detail

cloneAllele

public Allele cloneAllele()
Specified by:
cloneAllele in class Allele
Returns:
clone of this allele

setValue

public void setValue(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.

Parameters:
a_newValue - the new value of this Gene instance.

getPersistentRepresentation

public java.lang.String getPersistentRepresentation()
                                             throws java.lang.UnsupportedOperationException
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.

Returns:
A string representation of this Gene's current state.
Throws:
java.lang.UnsupportedOperationException - to indicate that no implementation is provided for this method.

setValueFromPersistentRepresentation

public void setValueFromPersistentRepresentation(java.lang.String a_representation)
                                          throws UnsupportedRepresentationException
Sets 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.

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 method.
UnsupportedRepresentationException - if this Gene implementation does not support the given string representation.

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(java.util.Random 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:
setToRandomValue in class Allele
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.

equals

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

Overrides:
equals in class Allele
Parameters:
other - the object to compare to this BooleanGene for equality.
Returns:
true if this BooleanGene is equal to the given object, false otherwise.
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Retrieves the hash code value of this BooleanGene.

Overrides:
hashCode in class Allele
Returns:
this BooleanGene's hash code.
See Also:
Object.hashCode()

toString

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

Overrides:
toString in class Allele
Returns:
a string representation of this BooleanGene's value.
See Also:
Object.toString()

cleanup

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


distance

public double distance(Allele target)
Specified by:
distance in class Allele
Parameters:
target - should be same implementation class and same innovation ID as this gene
Returns:
positive distance between genes, where a value closer to 0 represents more similar genes; used in computing distance between chromosomes, which in turn is used to compute speciation compatibility.
See Also:
Allele.distance(org.jgap.Allele)