|
JGAP | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jgap.BaseGene
org.jgap.supergenes.AbstractSupergene
public abstract class AbstractSupergene
Combined implementation of both Supergene and SupergeneValidator.
A working supergene can be easily created from this class just by
adding genes and overriding
isValid (Gene [], Supergene)
method. For more complex cases, you may need to set your own
Validator.
| Field Summary | |
|---|---|
static java.lang.String |
GENE_DELIMITER
This field separates gene class name from the gene persistent representation string. |
static java.lang.String |
GENE_DELIMITER_CLOSING
Represents the closing delimiter that is used to separate genes in the persistent representation of CompositeGene instances. |
static java.lang.String |
GENE_DELIMITER_HEADING
Represents the heading delimiter that is used to separate genes in the persistent representation of CompositeGene instances. |
protected SupergeneValidator |
m_validator
A validator (initially set to this |
static int |
MAX_IMMUTABLE_GENES
Maximal number of notes about immutable genes per single gene position |
static int |
MAX_RETRIES
Maximal number of retries for applyMutation and setToRandomValue. |
| Fields inherited from class org.jgap.BaseGene |
|---|
DELTA, S_APPLICATION_DATA |
| Fields inherited from interface org.jgap.Gene |
|---|
PERSISTENT_FIELD_DELIMITER |
| Constructor Summary | |
|---|---|
AbstractSupergene()
Default constructor for dynamic instantiation. |
|
AbstractSupergene(Configuration a_config)
Constructor for dynamic instantiation. |
|
AbstractSupergene(Configuration a_conf,
Gene[] a_genes)
Constructs abstract supergene with the given gene list. |
|
| Method Summary | |
|---|---|
void |
addGene(Gene a_gene)
Append a new gene to the gene array. |
void |
applyMutation(int a_index,
double a_percentage)
Applies a mutation of a given intensity (percentage) onto the gene at the given index. |
void |
cleanup()
Calls cleanup() for each subgene. |
int |
compareTo(java.lang.Object o)
Calls compareTo() for all subgenes. |
protected Gene |
createGene(java.lang.String a_geneClassName,
java.lang.String a_persistentRepresentation)
Creates a new instance of gene. |
protected SupergeneValidator |
createValidator(java.lang.String a_rep)
Create validator from the string representation. |
boolean |
equals(java.lang.Object a_gene)
Calls equals() for each pair of genes. |
Gene |
geneAt(int a_index)
Returns the Gene at the given index (locus) within the Chromosome. |
java.lang.Object |
getAllele()
Retrieves the allele value represented by this Supergene. |
Gene[] |
getGenes()
Get the array of genes - components of this supergene. |
java.lang.Object |
getInternalValue()
Each Gene implementation holds its own m_value object keeping the allele value. |
java.lang.String |
getPersistent()
The default implementation returns an empty string. |
java.lang.String |
getPersistentRepresentation()
Retrieves a string representation of the value of this Gene instance that includes any information required to reconstruct it at a later time, such as its value and internal state. |
SupergeneValidator |
getValidator()
Gets an object, responsible for deciding if the Supergene allele combination is valid. |
int |
hashCode()
Returns sum of hashCode() of the genes-components. |
boolean |
isValid()
Test the allele combination of this supergene for validity. |
boolean |
isValid(Gene[] a_case,
Supergene a_forSupergene)
Test the given gene list for validity. |
protected Gene |
newGeneInternal()
Creates a new instance of this Supergene class with the same number of genes, calling newGene() for each subgene. |
static void |
reset()
Discards all internal caches, ensuring correct repetetive tests of performance. |
void |
setAllele(java.lang.Object a_superAllele)
Sets the allele. |
void |
setFromPersistent(java.lang.String a_from)
Set a persistend string representation (if needed) for this validator. |
void |
setToRandomValue(RandomGenerator a_numberGenerator)
Sets the value of this Gene to a random legal value for the implementation. |
void |
setValidator(SupergeneValidator a_validator)
Sets an object, responsible for deciding if the Supergene allele combination is valid. |
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()
Returns the number of the genes-components of this supergene. |
protected static java.util.List |
split(java.lang.String a_string)
Splits the string a_x into individual gene representations |
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 |
|---|
compareApplicationData, decode, encode, getApplicationData, getBusinessKey, getConfiguration, getConstraintChecker, getEnergy, getUniqueID, getUniqueIDTemplate, isCompareApplicationData, newGene, setApplicationData, setCompareApplicationData, setConstraintChecker, setEnergy, setUniqueIDTemplate |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.jgap.Gene |
|---|
getApplicationData, getConfiguration, getEnergy, isCompareApplicationData, newGene, setApplicationData, setCompareApplicationData, setConstraintChecker, setEnergy |
| Methods inherited from interface org.jgap.IUniqueKey |
|---|
getUniqueID, getUniqueIDTemplate, setUniqueIDTemplate |
| Field Detail |
|---|
public static final java.lang.String GENE_DELIMITER
public static final java.lang.String GENE_DELIMITER_HEADING
public static final java.lang.String GENE_DELIMITER_CLOSING
public static final int MAX_RETRIES
public static final int MAX_IMMUTABLE_GENES
protected SupergeneValidator m_validator
| Constructor Detail |
|---|
public AbstractSupergene()
throws InvalidConfigurationException
InvalidConfigurationException
public AbstractSupergene(Configuration a_config)
throws InvalidConfigurationException
a_config - the configuration to use
InvalidConfigurationException
public AbstractSupergene(Configuration a_conf,
Gene[] a_genes)
throws InvalidConfigurationException
a_conf - the configuration to usea_genes - array of genes for this Supergene
InvalidConfigurationException| Method Detail |
|---|
public Gene[] getGenes()
Supergene
getGenes in interface Supergenepublic final Gene geneAt(int a_index)
geneAt in interface ICompositeGenegeneAt in interface Supergenea_index - the index of the gene value to be returned
public boolean isValid()
isValid in interface Supergene
public boolean isValid(Gene[] a_case,
Supergene a_forSupergene)
isValid in interface SupergeneValidatora_case - ignored herea_forSupergene - ignored here
java.lang.Error - by default. If you do not set external validator,
you should always override this methodprotected Gene newGeneInternal()
newGeneInternal in class BaseGenejava.lang.Error - if the instance of this cannot be instantiated
(for example, if it is not public or the parameterless constructor is
not provided).
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 static void reset()
public void setToRandomValue(RandomGenerator a_numberGenerator)
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 void setAllele(java.lang.Object a_superAllele)
setAllele in interface Genea_superAllele - must be an array of objects, size matching the
number of genespublic java.lang.Object getAllele()
getAllele in interface GenegetAllele in class BaseGene
public java.lang.String getPersistentRepresentation()
throws java.lang.UnsupportedOperationException
Gene
getPersistentRepresentation in interface GenegetPersistentRepresentation in interface IPersistentRepresentationjava.lang.UnsupportedOperationException
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
UnsupportedRepresentationExceptionprotected SupergeneValidator createValidator(java.lang.String a_rep)
protected Gene createGene(java.lang.String a_geneClassName,
java.lang.String a_persistentRepresentation)
throws java.lang.Exception
java.lang.Exceptionpublic void cleanup()
cleanup in interface Genecleanup in class BaseGenepublic java.lang.String toString()
BaseGene
toString in interface GenetoString in class BaseGenepublic int size()
size in interface Genesize in class BaseGenepublic int compareTo(java.lang.Object o)
compareTo in interface java.lang.Comparablepublic boolean equals(java.lang.Object a_gene)
equals in class BaseGenea_gene - the object to compare to this Gene for equality
public int hashCode()
hashCode in class BaseGene
protected static final java.util.List split(java.lang.String a_string)
throws UnsupportedRepresentationException
a_string - the string to split
UnsupportedRepresentationExceptionpublic void addGene(Gene a_gene)
addGene in interface ICompositeGenea_gene - the gene to addpublic void setValidator(SupergeneValidator a_validator)
isValid (Gene [] ) is called.
setValidator in interface Supergenepublic SupergeneValidator getValidator()
getValidator in interface Supergenepublic java.lang.String getPersistent()
getPersistent in interface SupergeneValidatorpublic void setFromPersistent(java.lang.String a_from)
setFromPersistent in interface SupergeneValidatorpublic java.lang.Object getInternalValue()
BaseGeneBooleanGene for example)
getInternalValue in class BaseGene
|
JGAP | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||