org.jgap
Class BaseChromosome
- java.lang.Object
-
- org.jgap.BaseChromosome
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Comparable, IBusinessKey, IChromosome, IHandler, IInitializer, IPersistentRepresentation, IUniqueKey, ICloneable
- Direct Known Subclasses:
- Chromosome
public abstract class BaseChromosome extends java.lang.Object implements IChromosome, IInitializer, IPersistentRepresentation, IBusinessKey
Base class for any implementation of interface IChromosome.- Since:
- 3.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static java.lang.StringCHROM_DELIMITERSeparates chromosome-related information.static java.lang.StringGENE_DELIMITERThis field separates gene class name from the gene persistent representation string.static java.lang.StringGENE_DELIMITER_CLOSINGRepresents the closing delimiter that is used to separate genes in the persistent representation of Chromosome instances.static java.lang.StringGENE_DELIMITER_HEADINGRepresents the heading delimiter that is used to separate genes in the persistent representation of Chromosome instances.-
Fields inherited from interface org.jgap.IChromosome
S_ALLELES, S_APPLICATION_DATA, S_FITNESS_VALUE, S_SIZE
-
-
Constructor Summary
Constructors Constructor and Description BaseChromosome(Configuration a_configuration)The only constructor in this class.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description abstract java.lang.Objectclone()Creates and returns a copy of this object.intgetAge()java.lang.StringgetBusinessKey()ConfigurationgetConfiguration()GenegetGene(int a_desiredLocus)Returns the Gene at the given index (locus) within the Chromosome.Gene[]getGenes()Retrieves the set of genes that make up this Chromosome.java.lang.StringBuffergetGenesPersistentRepresentation()voidgetGenesPersistentRepresentation(java.lang.StringBuffer a_buffer)Retrieves the persistent representation of the chromosome by considering its genes.java.lang.StringgetPersistentRepresentation()Returns a persistent representation of this chromosome, see interface Gene for description.java.lang.StringgetUniqueID()java.lang.StringgetUniqueIDTemplate(int a_index)voidincreaseAge()Increases the number of evolutionary rounds of chromosome in which it has not been changed by one.voidincreaseOperatedOn()Increase information of number of genetic operations performed on chromosome in current evolution round.intoperatedOn()voidresetAge()Reset age of chromosome because it has been changed.voidresetOperatedOn()Resets the information of how many genetic operators have been performed on the chromosome in the current round of evolution.voidsetAge(int a_age)voidsetGene(int a_index, Gene a_gene)voidsetGenes(Gene[] a_genes)Sets the genes for the chromosome.voidsetUniqueIDTemplate(java.lang.String a_templateID, int a_index)A template is a chromosome that is the logical predecessor of the current chromosome.voidsetValueFromPersistentRepresentation(java.lang.String a_representation)Counterpart of getPersistentRepresentation.intsize()Returns the size of this Chromosome (the number of genes it contains).-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jgap.IChromosome
cleanup, getApplicationData, getFitnessValue, getFitnessValueDirectly, isSelectedForNextGeneration, setApplicationData, setConstraintChecker, setFitnessValue, setFitnessValueDirectly, setIsSelectedForNextGeneration
-
Methods inherited from interface org.jgap.IHandler
isHandlerFor, perform
-
-
-
-
Field Detail
-
GENE_DELIMITER
public static final java.lang.String GENE_DELIMITER
This field separates gene class name from the gene persistent representation string. '*' does not work properly with URLEncoder!- See Also:
- Constant Field Values
-
GENE_DELIMITER_HEADING
public static final java.lang.String GENE_DELIMITER_HEADING
Represents the heading delimiter that is used to separate genes in the persistent representation of Chromosome instances.- See Also:
- Constant Field Values
-
GENE_DELIMITER_CLOSING
public static final java.lang.String GENE_DELIMITER_CLOSING
Represents the closing delimiter that is used to separate genes in the persistent representation of Chromosome instances.- See Also:
- Constant Field Values
-
CHROM_DELIMITER
public static final java.lang.String CHROM_DELIMITER
Separates chromosome-related information.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BaseChromosome
public BaseChromosome(Configuration a_configuration) throws InvalidConfigurationException
The only constructor in this class. Sets the immutable configuration.- Parameters:
a_configuration- the configuration to set- Throws:
InvalidConfigurationException- if configuration is null- Since:
- 3.0
-
-
Method Detail
-
getUniqueID
public java.lang.String getUniqueID()
- Specified by:
getUniqueIDin interfaceIUniqueKey- Returns:
- unique ID of the chromosome, 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 chromosome that is the logical predecessor of the current chromosome. A template can occur in mutation or crossing over. In the latter case can be at least two template chromosomes. 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 chromosome 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
-
getConfiguration
public Configuration getConfiguration()
- Specified by:
getConfigurationin interfaceIChromosome- Returns:
- the configuration used
- Since:
- 3.0
-
clone
public abstract java.lang.Object clone()
Creates and returns a copy of this object.- Specified by:
clonein interfaceICloneable- Overrides:
clonein classjava.lang.Object- Returns:
- a clone of this instance
- Throws:
java.lang.IllegalStateException- instead of CloneNotSupportedException- Since:
- 3.0
-
increaseAge
public void increaseAge()
Increases the number of evolutionary rounds of chromosome in which it has not been changed by one.- Specified by:
increaseAgein interfaceIChromosome- Since:
- 3.2
-
resetAge
public void resetAge()
Reset age of chromosome because it has been changed.- Specified by:
resetAgein interfaceIChromosome- Since:
- 3.2
-
getAge
public int getAge()
- Specified by:
getAgein interfaceIChromosome- Returns:
- 0: Chromosome newly created in this generation. This means it does not need being crossed over with another newly created one
- Since:
- 3.2
-
setAge
public void setAge(int a_age)
- Specified by:
setAgein interfaceIChromosome- Parameters:
a_age- set the age of the chromosome, see BestChromosomesSelector for a use-case- Since:
- 3.3.3
-
increaseOperatedOn
public void increaseOperatedOn()
Increase information of number of genetic operations performed on chromosome in current evolution round.- Specified by:
increaseOperatedOnin interfaceIChromosome- Since:
- 3.2
-
resetOperatedOn
public void resetOperatedOn()
Resets the information of how many genetic operators have been performed on the chromosome in the current round of evolution.- Specified by:
resetOperatedOnin interfaceIChromosome- Since:
- 3.2
-
operatedOn
public int operatedOn()
- Specified by:
operatedOnin interfaceIChromosome- Returns:
- number of genetic operations performed on chromosome in current evolution round
- Since:
- 3.2
-
getGenes
public Gene[] getGenes()
Retrieves the set of genes that make up this Chromosome. This method exists primarily for the benefit of GeneticOperators that require the ability to manipulate Chromosomes at a low level.- Specified by:
getGenesin interfaceIChromosome- Returns:
- an array of the Genes contained within this Chromosome
- Since:
- 1.0
-
setGenes
public void setGenes(Gene[] a_genes) throws InvalidConfigurationException
Sets the genes for the chromosome.- Specified by:
setGenesin interfaceIChromosome- Parameters:
a_genes- the genes to set for the chromosome- Throws:
InvalidConfigurationException- in case constraint checker is provided- Since:
- 3.2 (previously in class Chromosome)
-
getGene
public Gene getGene(int a_desiredLocus)
Returns the Gene at the given index (locus) within the Chromosome. The first gene is at index zero and the last gene is at the index equal to the size of this Chromosome - 1.- Specified by:
getGenein interfaceIChromosome- Parameters:
a_desiredLocus- index of the gene value to be returned- Returns:
- Gene at the given index
- Since:
- 1.0
-
setGene
public void setGene(int a_index, Gene a_gene)
-
size
public int size()
Returns the size of this Chromosome (the number of genes it contains). A Chromosome's size is constant and will not change, until setGenes(...) is used.- Specified by:
sizein interfaceIChromosome- Returns:
- number of genes contained within this Chromosome instance
- Since:
- 1.0
-
getPersistentRepresentation
public java.lang.String getPersistentRepresentation()
Returns a persistent representation of this chromosome, see interface Gene for description. Similar to CompositeGene's routine. But does not include all information of the chromosome (yet).- Specified by:
getPersistentRepresentationin interfaceIPersistentRepresentation- Returns:
- string representation of this Chromosome's relevant parts of its current state
- Throws:
java.lang.UnsupportedOperationException- Since:
- 3.2
-
getGenesPersistentRepresentation
public java.lang.StringBuffer getGenesPersistentRepresentation()
- Returns:
- the persistent representation of the chromosome by considering its genes.
-
getBusinessKey
public java.lang.String getBusinessKey()
- Specified by:
getBusinessKeyin interfaceIBusinessKey- Returns:
- business key of the chromosome
- Since:
- 3.2
-
getGenesPersistentRepresentation
public void getGenesPersistentRepresentation(java.lang.StringBuffer a_buffer)
Retrieves the persistent representation of the chromosome by considering its genes.- Parameters:
a_buffer- the variable to store the persistent representation in
-
setValueFromPersistentRepresentation
public void setValueFromPersistentRepresentation(java.lang.String a_representation) throws UnsupportedRepresentationExceptionCounterpart of getPersistentRepresentation.- Specified by:
setValueFromPersistentRepresentationin interfaceIPersistentRepresentation- Parameters:
a_representation- the string representation retrieved from a prior call to the getPersistentRepresentation() method- Throws:
UnsupportedRepresentationException- Since:
- 3.2
-
-
DMelt 3.0 © DataMelt by jWork.ORG