|
JGAP | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jgap.BaseGene
org.jgap.impl.StringGene
public class StringGene
A Gene implementation that supports a string for its allele. The valid alphabet as well as the minimum and maximum length of the string can be specified.
An alphabet == null indicates that all characters are seen as valid.
An alphabet == "" indicates that no character is seen to be valid.
Partly copied from IntegerGene.
| Field Summary | |
|---|---|
static java.lang.String |
ALPHABET_CHARACTERS_DIGITS
|
static java.lang.String |
ALPHABET_CHARACTERS_LOWER
|
static java.lang.String |
ALPHABET_CHARACTERS_SPECIAL
|
static java.lang.String |
ALPHABET_CHARACTERS_UPPER
|
| Fields inherited from class org.jgap.BaseGene |
|---|
DELTA, S_APPLICATION_DATA |
| Fields inherited from interface org.jgap.Gene |
|---|
PERSISTENT_FIELD_DELIMITER |
| Constructor Summary | |
|---|---|
StringGene()
Default constructor, sets minimum and maximum length to arbitrary. |
|
StringGene(Configuration a_config)
Default constructor, sets minimum and maximum length to arbitrary. |
|
StringGene(Configuration a_config,
int a_minLength,
int a_maxLength)
Constructor, allows to specify minimum and maximum lengths of the string held by this gene. |
|
StringGene(Configuration a_config,
int a_minLength,
int a_maxLength,
java.lang.String a_alphabet)
Constructor, allows to specify minimum and maximum lengths of the string held by this gene, as well as the valid alphabet. |
|
| Method Summary | |
|---|---|
void |
applyMutation(int index,
double a_percentage)
Applies a mutation of a given intensity (percentage) onto the atomic element at given index (NumberGenes only have one atomic element). |
int |
compareTo(java.lang.Object a_other)
Compares this StringGene with the specified object (which must also be a StringGene) for order, which is determined by the String value of this Gene compared to the one provided for comparison. |
java.lang.String |
getAlphabet()
|
java.lang.String |
getBusinessKey()
|
protected java.lang.Object |
getInternalValue()
Each Gene implementation holds its own m_value object keeping the allele value. |
int |
getMaxLength()
|
int |
getMinLength()
|
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. |
protected Gene |
newGeneInternal()
Provides an implementation-independent means for creating new Gene instances. |
void |
setAllele(java.lang.Object a_newValue)
Sets the value (allele) of this Gene to the new given value. |
void |
setAlphabet(java.lang.String a_alphabet)
Sets the valid alphabet of the StringGene. |
void |
setMaxLength(int m_maxLength)
|
void |
setMinLength(int m_minLength)
|
void |
setToRandomValue(RandomGenerator a_numberGenerator)
Sets the value (allele) of this Gene to a random String according to the valid alphabet and boundaries of length. |
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. |
int |
size()
|
java.lang.String |
stringValue()
Retrieves the String value of this Gene, which may be more convenient in some cases than the more general getAllele() method. |
java.lang.String |
toString()
Retrieves a string representation of this StringGene's value that may be useful for display purposes. |
| Methods inherited from class org.jgap.BaseGene |
|---|
cleanup, compareApplicationData, decode, encode, equals, getAllele, getApplicationData, getConfiguration, getConstraintChecker, getEnergy, getUniqueID, getUniqueIDTemplate, hashCode, isCompareApplicationData, newGene, setApplicationData, setCompareApplicationData, setConstraintChecker, setEnergy, setUniqueIDTemplate |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String ALPHABET_CHARACTERS_UPPER
public static final java.lang.String ALPHABET_CHARACTERS_LOWER
public static final java.lang.String ALPHABET_CHARACTERS_DIGITS
public static final java.lang.String ALPHABET_CHARACTERS_SPECIAL
| Constructor Detail |
|---|
public StringGene()
throws InvalidConfigurationException
Do not use this constructor with a sample chromosome set in the configuration.
Attention: The configuration used is the one set with the static method Genotype.setConfiguration.
InvalidConfigurationException
public StringGene(Configuration a_config)
throws InvalidConfigurationException
Do not use this constructor with a sample chromosome set in the configuration.
a_config - the configuration to use
InvalidConfigurationException
public StringGene(Configuration a_config,
int a_minLength,
int a_maxLength)
throws InvalidConfigurationException
Do not use this constructor with a sample chromosome set in the configuration.
a_config - the configuration to usea_minLength - minimum valid length of allelea_maxLength - maximum valid length of allele
InvalidConfigurationException
public StringGene(Configuration a_config,
int a_minLength,
int a_maxLength,
java.lang.String a_alphabet)
throws InvalidConfigurationException
a_config - the configuration to usea_minLength - minimum valid length of an allelea_maxLength - maximum valid length of an allelea_alphabet - valid alphabet for an allele
InvalidConfigurationException| Method Detail |
|---|
public void setToRandomValue(RandomGenerator a_numberGenerator)
setToRandomValue in interface Genea_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
public void setValueFromPersistentRepresentation(java.lang.String a_representation)
throws UnsupportedRepresentationException
setValueFromPersistentRepresentation in interface GenesetValueFromPersistentRepresentation in interface IPersistentRepresentationa_representation - the string representation retrieved from a prior
call to the getPersistentRepresentation() method
UnsupportedRepresentationException - if this Gene implementation
does not support the given string representation
public java.lang.String getPersistentRepresentation()
throws java.lang.UnsupportedOperationException
getPersistentRepresentation in interface GenegetPersistentRepresentation in interface IPersistentRepresentationjava.lang.UnsupportedOperationException - to indicate that no implementation
is provided for this methodpublic java.lang.String getBusinessKey()
getBusinessKey in interface IBusinessKeygetBusinessKey in class BaseGenepublic void setAllele(java.lang.Object a_newValue)
setAllele in interface Genea_newValue - the new value of this Gene instanceprotected Gene newGeneInternal()
newGeneInternal in class BaseGenepublic int compareTo(java.lang.Object a_other)
compareTo in interface java.lang.Comparablea_other - the StringGene to be compared to this StringGene
java.lang.ClassCastException - if the specified object's type prevents it
from being compared to this StringGenepublic int size()
size in interface Genesize in class BaseGenepublic int getMaxLength()
public int getMinLength()
public void setMinLength(int m_minLength)
public void setMaxLength(int m_maxLength)
public java.lang.String getAlphabet()
public void setAlphabet(java.lang.String a_alphabet)
a_alphabet - valid alphabet for allelepublic java.lang.String toString()
toString in interface GenetoString in class BaseGenepublic java.lang.String stringValue()
public void applyMutation(int index,
double a_percentage)
applyMutation in interface Geneindex - index of atomic element, between 0 and size()-1a_percentage - percentage of mutation (greater than -1 and smaller
than 1).protected java.lang.Object getInternalValue()
BaseGeneBooleanGene for example)
getInternalValue in class BaseGene
|
JGAP | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||