|
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.MapGene
public class MapGene
Creates a gene instance in which individual alleles have both a label (key) and a value with a distinct meaning. This allows to realize a gene with a set of valid values instead of a range of values. For example, IntegerGene only allows for values having a continuous range, and does not have a function where it is possible to specify setValue...
This implementation does not support specifying a range of valid integer values. Instead it is planned to provide a constraint checker plugin later on. With this, the current implementation will stay unchanged and can be as performant as possible without losing flexibility.
examples.MapGeneExample,
Serialized Form| 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 | |
|---|---|
MapGene()
Default constructor. |
|
MapGene(Configuration a_config)
|
|
MapGene(Configuration a_config,
java.util.Map a_alleles)
Constructor setting up valid alleles directly. |
|
| Method Summary | |
|---|---|
void |
addAllele(int a_value)
Convenience method for addAllele (Object's that are Integer's) |
void |
addAllele(java.lang.Object a_value)
Adds a potential allele value to the collection. |
void |
addAllele(java.lang.Object a_key,
java.lang.Object a_value)
Adds a potential allele value to the collection. |
void |
addAlleles(java.util.Map a_alleles)
Add a set of potential allele values to the collection |
void |
applyMutation(int a_index,
double a_percentage)
See interface Gene for description of applyMutation. |
int |
compareTo(java.lang.Object a_other)
Compares this NumberGene with the specified object (which must also be a NumberGene) for order, which is determined by the number value of this Gene compared to the one provided for comparison. |
java.util.Map |
getAlleles()
|
protected java.lang.Object |
getInternalValue()
Each Gene implementation holds its own m_value object keeping the allele value. |
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()
Modified hashCode() function to return different hashcodes for differently ordered genes in a chromosome |
protected Gene |
newGeneInternal()
|
void |
removeAlleles(java.lang.Object a_key)
Removes a potential allele or set of alleles from the collection. |
void |
setAllele(java.lang.Object a_newValue)
Sets the value (allele) of this Gene to the new given value. |
void |
setToRandomValue(RandomGenerator a_numberGenerator)
Sets the allele value to be a random value using a defined random number generator. |
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 Gene's value that may be useful for display purposes. |
| Methods inherited from class org.jgap.BaseGene |
|---|
cleanup, compareApplicationData, decode, encode, equals, getAllele, getApplicationData, getBusinessKey, getConfiguration, getConstraintChecker, getEnergy, getUniqueID, getUniqueIDTemplate, isCompareApplicationData, newGene, setApplicationData, setCompareApplicationData, setConstraintChecker, setEnergy, setUniqueIDTemplate, size |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public MapGene()
throws InvalidConfigurationException
Attention: The configuration used is the one set with the static method Genotype.setConfiguration.
InvalidConfigurationException
public MapGene(Configuration a_config)
throws InvalidConfigurationException
a_config - the configuration to use
InvalidConfigurationException
public MapGene(Configuration a_config,
java.util.Map a_alleles)
throws InvalidConfigurationException
a_config - the configuration to usea_alleles - the valid alleles of the gene
InvalidConfigurationException| Method Detail |
|---|
protected Gene newGeneInternal()
newGeneInternal in class BaseGene
public void addAllele(java.lang.Object a_key,
java.lang.Object a_value)
a_key - the key to be added, e.g. a descriptive string valuea_value - the Integer value to be addedpublic void addAllele(java.lang.Object a_value)
a_value - the value to be added, also used as keypublic void addAllele(int a_value)
a_value - the int value to be added, also used as keypublic void addAlleles(java.util.Map a_alleles)
a_alleles - the set of alleles to be addedpublic void removeAlleles(java.lang.Object a_key)
a_key - the unique value(s) of the object(s) to be removedpublic java.util.Map getAlleles()
public void setToRandomValue(RandomGenerator a_numberGenerator)
setToRandomValue in interface Genea_numberGenerator - the random generator to use
public void applyMutation(int a_index,
double a_percentage)
applyMutation in interface Genea_index - ignored herea_percentage - ignored here
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.
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.
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 void setAllele(java.lang.Object a_newValue)
setAllele in interface Genea_newValue - the new value of this Gene instancepublic int compareTo(java.lang.Object a_other)
compareTo in interface java.lang.Comparablea_other - the NumberGene to be compared to this NumberGene
java.lang.ClassCastException - if the specified object's type prevents it from
being compared to this Geneprotected java.lang.Object getInternalValue()
BaseGeneBooleanGene for example)
getInternalValue in class BaseGenepublic int hashCode()
hashCode in class BaseGenepublic java.lang.String toString()
toString in interface GenetoString in class BaseGene
|
JGAP | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||