org.jgap.impl
Class MapGene
- java.lang.Object
-
- org.jgap.BaseGene
-
- org.jgap.impl.MapGene
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Comparable, Gene, IBusinessKey, IPersistentRepresentation, IUniqueKey
public class MapGene extends BaseGene implements IPersistentRepresentation
ATTENTION: This class is preliminary and subject of future adaptations! Use with care or wait for a more mature version we are working on.Creates a gene instance in which individual alleles have both a label (key) and a value with a distinct meaning. 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.
- Since:
- 2.4
- See Also:
- 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
Constructors Constructor and Description MapGene()Default constructor.MapGene(Configuration a_config)MapGene(Configuration a_config, java.util.Map a_alleles)Constructor setting up valid alleles directly.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddAllele(int a_value)Convenience method for addAllele (Object's that are Integer's)voidaddAllele(java.lang.Object a_value)Adds a potential allele value to the collection.voidaddAllele(java.lang.Object a_key, java.lang.Object a_value)Adds a potential allele value to the collection.voidaddAlleles(java.util.Map a_alleles)Add a set of potential allele values to the collectionvoidapplyMutation(int a_index, double a_percentage)See interface Gene for description of applyMutation.intcompareTo(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.MapgetAlleles()java.lang.StringgetPersistentRepresentation()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.inthashCode()Modified hashCode() function to return different hashcodes for differently ordered genes in a chromosomevoidremoveAlleles(java.lang.Object a_key)Removes a potential allele or set of alleles from the collection.voidsetAllele(java.lang.Object a_newValue)Sets the value (allele) of this Gene to the new given value.voidsetToRandomValue(RandomGenerator a_numberGenerator)Sets the allele value to be a random value using a defined random number generator.voidsetValueFromPersistentRepresentation(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.StringtoString()Retrieves a string representation of this Gene's value that may be useful for display purposes.-
Methods inherited from class org.jgap.BaseGene
cleanup, equals, getAllele, getApplicationData, getBusinessKey, getConfiguration, getConstraintChecker, getEnergy, getUniqueID, getUniqueIDTemplate, isCompareApplicationData, newGene, setApplicationData, setCompareApplicationData, setConstraintChecker, setEnergy, setUniqueIDTemplate, size
-
-
-
-
Constructor Detail
-
MapGene
public MapGene() throws InvalidConfigurationExceptionDefault constructor.Attention: The configuration used is the one set with the static method Genotype.setConfiguration.
- Throws:
InvalidConfigurationException- Since:
- 2.4
-
MapGene
public MapGene(Configuration a_config) throws InvalidConfigurationException
- Parameters:
a_config- the configuration to use- Throws:
InvalidConfigurationException- Since:
- 3.0
-
MapGene
public MapGene(Configuration a_config, java.util.Map a_alleles) throws InvalidConfigurationException
Constructor setting up valid alleles directly.- Parameters:
a_config- the configuration to usea_alleles- the valid alleles of the gene- Throws:
InvalidConfigurationException- Since:
- 2.4
-
-
Method Detail
-
addAllele
public void addAllele(java.lang.Object a_key, java.lang.Object a_value)Adds a potential allele value to the collection.- Parameters:
a_key- the key to be addeda_value- the Integer value to be added- Since:
- 2.4
-
addAllele
public void addAllele(java.lang.Object a_value)
Adds a potential allele value to the collection.- Parameters:
a_value- the value to be added, also used as key- Since:
- 2.4
-
addAllele
public void addAllele(int a_value)
Convenience method for addAllele (Object's that are Integer's)- Parameters:
a_value- the int value to be added, also used as key- Since:
- 2.4
-
addAlleles
public void addAlleles(java.util.Map a_alleles)
Add a set of potential allele values to the collection- Parameters:
a_alleles- the set of alleles to be added- Since:
- 2.4
-
removeAlleles
public void removeAlleles(java.lang.Object a_key)
Removes a potential allele or set of alleles from the collection.- Parameters:
a_key- the unique value(s) of the object(s) to be removed- Since:
- 2.4
-
getAlleles
public java.util.Map getAlleles()
- Returns:
- the map of alleles
- Since:
- 3.0
-
setToRandomValue
public void setToRandomValue(RandomGenerator a_numberGenerator)
Sets the allele value to be a random value using a defined random number generator. If no valid alleles are defined, any allele is allowed. Then, a new Integer with random value is set as random value. Override this method if you want a different behaviour, such as a Double instead of the Integer type.- Specified by:
setToRandomValuein interfaceGene- Parameters:
a_numberGenerator- the random generator to use- Since:
- 2.4
-
applyMutation
public void applyMutation(int a_index, double a_percentage)See interface Gene for description of applyMutation. For this kind of gene, providing an index and a percentage of mutation would have no significance because the individual allele forms are independent of one another. In mutating, they can only change from one form to another. It may be possible to weight the likelihood of mutation to different forms, but that is not implemented currently.- Specified by:
applyMutationin interfaceGene- Parameters:
a_index- ignored herea_percentage- ignored here- Since:
- 2.4
-
setValueFromPersistentRepresentation
public void setValueFromPersistentRepresentation(java.lang.String a_representation) throws UnsupportedRepresentationExceptionSets 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:
setValueFromPersistentRepresentationin interfaceGene- Specified by:
setValueFromPersistentRepresentationin interfaceIPersistentRepresentation- 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 methodUnsupportedRepresentationException- if this Gene implementation does not support the given string representation.- Since:
- 2.4
-
getPersistentRepresentation
public java.lang.String getPersistentRepresentation() throws java.lang.UnsupportedOperationExceptionRetrieves 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:
getPersistentRepresentationin interfaceGene- Specified by:
getPersistentRepresentationin interfaceIPersistentRepresentation- Returns:
- string representation of this Gene's current state
- Throws:
java.lang.UnsupportedOperationException- to indicate that no implementation is provided for this method- Since:
- 2.4
-
setAllele
public void setAllele(java.lang.Object a_newValue)
Sets the value (allele) of this Gene to the new given value. This class expects the value to be an instance of current type (e.g. Integer).
-
compareTo
public 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.- Specified by:
compareToin interfacejava.lang.Comparable- Parameters:
a_other- the NumberGene to be compared to this NumberGene- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the object provided for comparison
- Throws:
java.lang.ClassCastException- if the specified object's type prevents it from being compared to this Gene- Since:
- 2.4
-
hashCode
public int hashCode()
Modified hashCode() function to return different hashcodes for differently ordered genes in a chromosome
-
-
DMelt 3.0 © DataMelt by jWork.ORG