org.jgap.impl
Class IntegerGene

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

public class IntegerGene
extends NumberGene
implements Gene

A Gene implementation that supports an integer values for its allele. Upper and lower bounds may optionally be provided to restrict the range of legal values allowed by this Gene instance.

Since:
1.0
Author:
Neil Rotstan, Klaus Meffert
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.jgap.Gene
PERSISTENT_FIELD_DELIMITER
 
Constructor Summary
IntegerGene()
          Constructs a new IntegerGene with default settings.
IntegerGene(int a_lowerBounds, int a_upperBounds)
          Constructs a new IntegerGene 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
 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 intValue()
          Retrieves the int value of this Gene, which may be more convenient in some cases than the more general getAllele() method.
 Gene newGene()
          Provides an implementation-independent means for creating new Gene instances.
 void setToRandomValue(RandomGenerator a_numberGenerator)
          Sets the value (allele) of this Gene to a random Integer 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, getConstraintChecker, hashCode, setAllele, setConstraintChecker, size, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jgap.Gene
cleanup, getAllele, setAllele, size, toString
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Constructor Detail

IntegerGene

public IntegerGene()
Constructs a new IntegerGene with default settings. No bounds will be put into effect for values (alleles) of this Gene instance, other than the standard range of integer values.

Since:
1.0

IntegerGene

public IntegerGene(int a_lowerBounds,
                   int a_upperBounds)
Constructs a new IntegerGene 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.0

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.0

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.0

intValue

public int intValue()
Retrieves the int value of this Gene, which may be more convenient in some cases than the more general getAllele() method.

Returns:
the int value of this Gene.
Since:
1.0

setToRandomValue

public void setToRandomValue(RandomGenerator a_numberGenerator)
Sets the value (allele) of this Gene to a random Integer 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.0

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