|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jgap.supergenes.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. |
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 interface org.jgap.Gene |
PERSISTENT_FIELD_DELIMITER |
| Constructor Summary | |
abstractSupergene()
Always provide the parameterless constructor for the derived class. |
|
abstractSupergene(Gene[] a_genes)
Constructs abstract supergene with the given gene list. |
|
| Method Summary | |
void |
addGene(Gene g)
Append a new gene to the gene array. |
void |
applyMutation(int 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. |
boolean |
equals(java.lang.Object a_gene)
Calls equals() for each pair of genes. |
java.lang.Object |
getAllele()
Retrieves the allele value represented by this Supergene. |
Gene |
getGene(int a_index)
Returns the Gene at the given index (locus) within the Chromosome. |
Gene[] |
getGenes()
Get the array of genes - components of this supergene. |
java.lang.String |
getPersistent()
Get a persistent string representation (if needed) of this validator. The name is different allowing the same class to implement both Supergene and supergeneValidator. The default implementation returns an empty string. |
java.lang.String |
getPersistentRepresentation()
Retrieves a string representation of the value of this Supergene instance, using calls to the Supergene components. |
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. |
Gene |
newGene()
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. The name is different allowing the same class to implement both Supergene and supergeneValidator. The default implementation does nothing. |
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. |
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
getClass, notify, notifyAll, wait, wait, wait |
| 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 int MAX_RETRIES
public static int MAX_IMMUTABLE_GENES
| Constructor Detail |
public abstractSupergene(Gene[] a_genes)
a_genes - array of genes for this Supergenepublic abstractSupergene()
newGene only. The parameterless
constructor need not (and cannot) assign the private
genes array.
| Method Detail |
public Gene[] getGenes()
getGenes in interface Supergenepublic final Gene getGene(int a_index)
getGene in interface Supergenepublic boolean isValid()
isValid in interface Supergenein the interface header. *
public boolean isValid(Gene[] a_case,
Supergene a_forSupergene)
isValid in interface supergeneValidatorjava.lang.Error - by default. If you do not set external validator,
you should always override this method.public Gene newGene()
newGene in interface Genejava.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 index,
double a_percentage)
index.
applyMutation in interface Geneindex - index of atomic element, between 0 and size()-1a_percentage - percentage of mutation (greater than -1 and smaller
than 1).org.jgap.supergenes.abstractSupergene.isValid()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
choice.
an - error if unable to get a valid random instance in
the number of loops, defined by MAX_RETRIES.public void setAllele(java.lang.Object a_superAllele)
setAllele in interface Genea_superAllele - the new value of this Gene instance.public java.lang.Object getAllele()
getAllele in interface Gene
public java.lang.String getPersistentRepresentation()
throws java.lang.UnsupportedOperationException
getPersistentRepresentation in interface Genejava.lang.UnsupportedOperationException - to indicate that no implementation
is provided for this method.
public void setValueFromPersistentRepresentation(java.lang.String a_representation)
throws UnsupportedRepresentationException
setValueFromPersistentRepresentation in interface Genea_representation - the string representation retrieved from a
prior call to the getPersistentRepresentation() method.
UnsupportedRepresentationExceptionpublic void cleanup()
cleanup in interface Genepublic java.lang.String toString()
toString in interface Genepublic int size()
size in interface Genepublic int compareTo(java.lang.Object o)
compareTo in interface java.lang.Comparablepublic boolean equals(java.lang.Object a_gene)
public int hashCode()
public void addGene(Gene g)
public 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 supergeneValidator
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||