org.jgap.impl
Class DoubleGene

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

public class DoubleGene
extends NumberGene
implements Gene

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
Author:
Klaus Meffert
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.jgap.Gene
PERSISTENT_FIELD_DELIMITER
 
Constructor Summary
DoubleGene()
          Constructs a new DoubleGene with default settings.
DoubleGene(double a_lowerBounds, double a_upperBounds)
          Constructs a new DoubleGene with the specified lower and upper bounds for values (alleles) of this Gene instance.
 
Method Summary
 void applyMutation(int index, double a_percentage)
          See interface Gene for description
 double doubleValue()
          Retrieves the double value of this Gene, which may be more convenient in some cases than the more general getAllele() method.
 IGeneConstraintChecker getConstraintChecker()
           
 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.
 Gene newGene()
          Provides an implementation-independent means for creating new Gene instances.
 void setAllele(java.lang.Object a_newValue)
          See NumberGene.setAllele(Object)
 void setConstraintChecker(IGeneConstraintChecker a_constraintChecker)
          Sets the constraint checker to be used for this gene whenever method setAllele(Object a_newValue) is called
 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.
 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.
 
Methods inherited from class org.jgap.impl.NumberGene
cleanup, compareTo, equals, getAllele, hashCode, size, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jgap.Gene
cleanup, getAllele, size, toString
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Constructor Detail

DoubleGene

public DoubleGene()
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.

Since:
1.1

DoubleGene

public DoubleGene(double a_lowerBounds,
                  double a_upperBounds)
Constructs a new DoubleGene with the specified lower and upper bounds for values (alleles) of this Gene instance.

Parameters:
a_lowerBounds - The lowest value that this Gene may possess, inclusive.
a_upperBounds - The highest value that this Gene may possess, inclusive.
Since:
2.0
Method Detail

newGene

public Gene newGene()
Provides an implementation-independent means for creating new Gene instances. The new instance that is created and returned should be setup with any implementation-dependent configuration that this Gene instance is setup with (aside from the actual value, of course). For example, if this Gene were setup with bounds on its value, then the Gene instance returned from this method should also be setup with those same bounds. This is important, as the JGAP core will invoke this method on each Gene in the sample Chromosome in order to create each new Gene in the same respective gene position for a new Chromosome.

It should be noted that nothing is guaranteed about the actual value of the returned Gene and it should therefore be considered to be undefined.

Specified by:
newGene in interface Gene
Returns:
A new Gene instance of the same type and with the same setup as this concrete Gene.
Since:
1.1

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.

Specified by:
getPersistentRepresentation in interface Gene
Returns:
A string representation of this Gene's current state.
Throws:
java.lang.UnsupportedOperationException - to indicate that no implementation is provided for this method.
Since:
1.1

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.

Specified by:
setValueFromPersistentRepresentation in interface Gene
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.
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:
setToRandomValue in interface Gene
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:
applyMutation in interface Gene
Specified by:
applyMutation in class NumberGene
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

setAllele

public void setAllele(java.lang.Object a_newValue)
See NumberGene.setAllele(Object)

Specified by:
setAllele in interface Gene
Overrides:
setAllele in class NumberGene
Parameters:
a_newValue - sic
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

Overrides:
setConstraintChecker in class NumberGene
Parameters:
a_constraintChecker - the constraint checker to be set
Since:
2.0

getConstraintChecker

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