|
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.FixedBinaryGene
public class FixedBinaryGene
A Gene implementation that supports two possible values (alleles, 1 and 0) with a fixed length of alleles.
NOTE: Since this Gene implementation only supports two different values (1 and 0), 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.
Partly adapted stuff from the JAGA (Java API for Genetic Algorithms) package (see jaga).
| 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 | |
|---|---|
FixedBinaryGene(Configuration a_config,
FixedBinaryGene a_toCopy)
|
|
FixedBinaryGene(Configuration a_config,
int a_length)
|
|
| Method Summary | |
|---|---|
void |
applyMutation(int a_index,
double a_percentage)
Applies a mutation of a given intensity (percentage) onto the atomic element at given index |
protected void |
checkIndex(int a_index)
|
protected int |
checkSubLength(int a_from,
int a_to)
|
java.lang.Object |
clone()
|
int |
compareTo(java.lang.Object a_other)
Compares this Gene with the specified object for order. |
void |
flip(int a_index)
|
java.lang.Object |
getAllele()
Retrieves the allele value represented by this Gene. |
boolean |
getBit(int a_index)
|
java.lang.String |
getBusinessKey()
|
protected java.lang.Object |
getInternalValue()
Not called as getAllele() is overridden. |
int[] |
getIntValues()
|
int |
getLength()
|
java.lang.String |
getPersistentRepresentation()
Returns a persistent representation of an entity (such as a chromosome or a gene). |
protected boolean |
getUnchecked(int a_index)
|
protected int[] |
getValue()
|
int |
hashCode()
Modified hashCode() function to return different hashcodes for differently ordered genes in a chromosome --> does not work as internal value always initialized! |
protected Gene |
newGeneInternal()
|
void |
setAllele(java.lang.Object a_newValue)
Sets the value of this Gene to the new given value. |
void |
setBit(int a_index,
boolean a_value)
|
void |
setBit(int a_index,
int a_value)
|
void |
setBit(int a_from,
int a_to,
boolean a_value)
|
void |
setBit(int a_from,
int a_to,
FixedBinaryGene a_values)
|
void |
setToRandomValue(RandomGenerator a_numberGenerator)
Sets the value of this Gene to a random legal value for the implementation. |
void |
setUnchecked(int a_index,
boolean a_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. |
int |
size()
|
FixedBinaryGene |
substring(int a_from,
int a_to)
|
java.lang.String |
toString()
Retrieves a string representation of this Gene's value that may be useful for display purposes. |
| Methods inherited from class org.jgap.BaseGene |
|---|
cleanup, compareApplicationData, decode, encode, equals, getApplicationData, getConfiguration, getConstraintChecker, getEnergy, isCompareApplicationData, newGene, setApplicationData, setCompareApplicationData, setConstraintChecker, setEnergy |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public FixedBinaryGene(Configuration a_config,
int a_length)
throws InvalidConfigurationException
a_config - the configuration to usea_length - the fixed length of the gene
InvalidConfigurationException
public FixedBinaryGene(Configuration a_config,
FixedBinaryGene a_toCopy)
throws InvalidConfigurationException
InvalidConfigurationException| Method Detail |
|---|
protected Gene newGeneInternal()
newGeneInternal in class BaseGeneprotected int[] getValue()
public int getLength()
public java.lang.Object clone()
clone in class java.lang.Objectpublic void setAllele(java.lang.Object a_newValue)
Gene
setAllele in interface Genea_newValue - the new value of this Gene instancepublic java.lang.Object getAllele()
BaseGene
getAllele in interface GenegetAllele in class BaseGenepublic int[] getIntValues()
public boolean getBit(int a_index)
public void setBit(int a_index,
boolean a_value)
public void setBit(int a_index,
int a_value)
public void setBit(int a_from,
int a_to,
boolean a_value)
public void setBit(int a_from,
int a_to,
FixedBinaryGene a_values)
public FixedBinaryGene substring(int a_from,
int a_to)
public void flip(int a_index)
protected int checkSubLength(int a_from,
int a_to)
protected void checkIndex(int a_index)
protected boolean getUnchecked(int a_index)
public void setUnchecked(int a_index,
boolean a_value)
public java.lang.String getPersistentRepresentation()
IPersistentRepresentation
getPersistentRepresentation in interface GenegetPersistentRepresentation in interface IPersistentRepresentation
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 representationpublic void setToRandomValue(RandomGenerator a_numberGenerator)
Gene
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 choicepublic java.lang.String toString()
BaseGene
toString in interface GenetoString in class BaseGenepublic java.lang.String getBusinessKey()
getBusinessKey in interface IBusinessKeygetBusinessKey in class BaseGenepublic int size()
size in interface Genesize in class BaseGene
public void applyMutation(int a_index,
double a_percentage)
applyMutation in interface Genea_index - index of atomic element, between 0 and size()-1a_percentage - percentage of mutation (greater than -1 and smaller
than 1)public int compareTo(java.lang.Object a_other)
compareTo in interface java.lang.Comparablea_other - the FixedBinaryGene to be compared
java.lang.ClassCastException - if the specified object's type prevents it
from being compared to this Geneprotected java.lang.Object getInternalValue()
getInternalValue in class BaseGenepublic int hashCode()
hashCode in class BaseGene
|
JGAP | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||