org.jgap
Class BaseGene
- java.lang.Object
-
- org.jgap.BaseGene
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Comparable, Gene, IBusinessKey, IUniqueKey
- Direct Known Subclasses:
- AbstractSupergene, BooleanGene, CompositeGene, FixedBinaryGene, MapGene, NumberGene, SetGene, StringGene
public abstract class BaseGene extends java.lang.Object implements Gene, IBusinessKey
Abstract base class for all genes. Provides default implementations.- Since:
- 2.2
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static doubleDELTADelta, useful for comparing doubles and floats.static java.lang.StringS_APPLICATION_DATAConstants for toString()-
Fields inherited from interface org.jgap.Gene
PERSISTENT_FIELD_DELIMITER
-
-
Constructor Summary
Constructors Constructor and Description BaseGene(Configuration a_configuration)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidcleanup()Executed by the genetic engine when this Gene instance is no longer needed and should perform any necessary resource cleanup.booleanequals(java.lang.Object a_other)Compares this Gene with the given object and returns true if the other object is a Gene of the same type and has the same value (allele) as this Gene.java.lang.ObjectgetAllele()Retrieves the allele value represented by this Gene.java.lang.ObjectgetApplicationData()Retrieves the application-specific data that is attached to this Gene.java.lang.StringgetBusinessKey()ConfigurationgetConfiguration()IGeneConstraintCheckergetConstraintChecker()doublegetEnergy()java.lang.StringgetUniqueID()java.lang.StringgetUniqueIDTemplate(int a_index)inthashCode()Retrieves the hash code value for a Gene.booleanisCompareApplicationData()GenenewGene()Provides implementation-independent means for creating new Gene instances.voidsetApplicationData(java.lang.Object a_newData)This sets the application-specific data that is attached to this Gene.voidsetCompareApplicationData(boolean a_doCompare)Should we also consider the application data when comparing? Default is "false" as "true" means a Gene is losing its identity when application data is set differently!voidsetConstraintChecker(IGeneConstraintChecker a_constraintChecker)Sets the constraint checker to be used for this gene whenever method setAllele(Object) is called.voidsetEnergy(double a_energy)Sets the energy of the genevoidsetUniqueIDTemplate(java.lang.String a_templateID, int a_index)A template is a gene that is the logical predecessor of the current gene.intsize()java.lang.StringtoString()Retrieves a string representation of this Gene's value that may be useful for display purposes.-
Methods inherited from interface org.jgap.Gene
applyMutation, getPersistentRepresentation, setAllele, setToRandomValue, setValueFromPersistentRepresentation
-
-
-
-
Field Detail
-
S_APPLICATION_DATA
public static final java.lang.String S_APPLICATION_DATA
Constants for toString()- See Also:
- Constant Field Values
-
DELTA
public static final double DELTA
Delta, useful for comparing doubles and floats.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BaseGene
public BaseGene(Configuration a_configuration) throws InvalidConfigurationException
- Parameters:
a_configuration- the configuration to use- Throws:
InvalidConfigurationException- Since:
- 3.0
-
-
Method Detail
-
getAllele
public java.lang.Object getAllele()
Retrieves the allele value represented by this Gene.
-
hashCode
public int hashCode()
Retrieves the hash code value for a Gene. Override if another hashCode() implementation is necessary or more appropriate than this default implementation.- Overrides:
hashCodein classjava.lang.Object- Returns:
- this Gene's hash code
- Since:
- 1.0
-
cleanup
public void cleanup()
Executed by the genetic engine when this Gene instance is no longer needed and should perform any necessary resource cleanup. If you need a special cleanup, override this method.
-
toString
public java.lang.String toString()
Retrieves a string representation of this Gene's value that may be useful for display purposes.
-
size
public int size()
-
equals
public boolean equals(java.lang.Object a_other)
Compares this Gene with the given object and returns true if the other object is a Gene of the same type and has the same value (allele) as this Gene. Otherwise it returns false.- Overrides:
equalsin classjava.lang.Object- Parameters:
a_other- the object to compare to this Gene for equality- Returns:
- true if this Gene is equal to the given object, false otherwise
- Since:
- 1.1
-
getEnergy
public double getEnergy()
-
setEnergy
public void setEnergy(double a_energy)
Sets the energy of the gene
-
setApplicationData
public void setApplicationData(java.lang.Object a_newData)
This sets the application-specific data that is attached to this Gene. Attaching application-specific data may be useful for some applications when it comes time to distinguish a Gene from another. JGAP ignores this data functionally.- Specified by:
setApplicationDatain interfaceGene- Parameters:
a_newData- the new application-specific data to attach to this Gene- Since:
- 2.4
-
getApplicationData
public java.lang.Object getApplicationData()
Retrieves the application-specific data that is attached to this Gene. Attaching application-specific data may be useful for some applications when it comes time to distinguish a Gene from another. JGAP ignores this data functionally.- Specified by:
getApplicationDatain interfaceGene- Returns:
- the application-specific data previously attached to this Gene, or null if there is no data attached
- Since:
- 2.4
-
setCompareApplicationData
public void setCompareApplicationData(boolean a_doCompare)
Should we also consider the application data when comparing? Default is "false" as "true" means a Gene is losing its identity when application data is set differently!- Specified by:
setCompareApplicationDatain interfaceGene- Parameters:
a_doCompare- true: consider application data in method compareTo- Since:
- 2.4
-
isCompareApplicationData
public boolean isCompareApplicationData()
- Specified by:
isCompareApplicationDatain interfaceGene
-
setConstraintChecker
public void setConstraintChecker(IGeneConstraintChecker a_constraintChecker)
Sets the constraint checker to be used for this gene whenever method setAllele(Object) is called.- Specified by:
setConstraintCheckerin interfaceGene- Parameters:
a_constraintChecker- the constraint checker to be set- Since:
- 2.5 (moved from CompositeGene, where it was since 2.0)
-
getConstraintChecker
public IGeneConstraintChecker getConstraintChecker()
- Returns:
- IGeneConstraintChecker the constraint checker to be used whenever method setAllele(Object) is called.
- Since:
- 2.5 (moved from CompositeGene, where it was since 2.0)
-
newGene
public Gene newGene()
Provides 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.
-
getConfiguration
public Configuration getConfiguration()
- Specified by:
getConfigurationin interfaceGene- Returns:
- the configuration set
- Since:
- 3.0
-
getBusinessKey
public java.lang.String getBusinessKey()
- Specified by:
getBusinessKeyin interfaceIBusinessKey- Returns:
- business key
-
getUniqueID
public java.lang.String getUniqueID()
- Specified by:
getUniqueIDin interfaceIUniqueKey- Returns:
- unique ID of the gene, which allows to distinct this instance from others, in the best case worldwide
- Since:
- 3.5
-
setUniqueIDTemplate
public void setUniqueIDTemplate(java.lang.String a_templateID, int a_index)A template is a gene that is the logical predecessor of the current gene. A template can occur in mutation or crossing over. In the latter case can be at least two template genes. This is why in this setter method the parameter a_index exists.- Specified by:
setUniqueIDTemplatein interfaceIUniqueKey- Parameters:
a_templateID- the unique ID of the templatea_index- the index of the template, e.g. in crossing over for the second candidate gene this is 2- Since:
- 3.5
-
getUniqueIDTemplate
public java.lang.String getUniqueIDTemplate(int a_index)
- Specified by:
getUniqueIDTemplatein interfaceIUniqueKey- Parameters:
a_index- the index of the template to retrieve the key for- Returns:
- String
- Since:
- 3.5
-
-
DMelt 3.0 © DataMelt by jWork.ORG