|
JGAP | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jgap.BaseGene
org.jgap.impl.CompositeGene
public class CompositeGene
Ordered container for multiple genes Has the same interface as a single gene and could be used accordingly. Use the addGene(Gene) method to add single genes (possibly CompositeGenes) after construction, an empty CompositeGene without genes makes no sense. Beware that there are two equalities defined for a CompositeGene in respect to its contained genes: a) Two genes are (only) equal if they are identical b) Two genes are (seen as) equal if their equals method returns true This influences several methods such as addGene. Notice that it is safer to use addGene(a_gene, false) than addGene(a_gene, true) because the second variant only allows to add genes not seen as equal to already added genes in respect to their equals function. But: the equals function returns true for two different DoubleGenes (e.g.) just after their creation. If no specific (and hopefully different) allele is set for these DoubleGenes they are seen as equal!
| Field Summary | |
|---|---|
static java.lang.String |
GENE_DELIMITER
This field separates gene class name from the gene persistent representation string. '*' does not work properly with URLEncoder! |
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. |
| Fields inherited from class org.jgap.BaseGene |
|---|
DELTA, S_APPLICATION_DATA |
| Fields inherited from interface org.jgap.Gene |
|---|
PERSISTENT_FIELD_DELIMITER |
| Constructor Summary | |
|---|---|
CompositeGene()
Default constructor. |
|
CompositeGene(Configuration a_config)
|
|
CompositeGene(Configuration a_config,
Gene a_geneTypeAllowed)
Allows to specify which Gene implementation is allowed to be added to the CompositeGene. |
|
| Method Summary | |
|---|---|
void |
addGene(Gene a_gene)
Adds a gene to the CompositeGene. |
void |
addGene(Gene a_gene,
boolean a_strict)
Adds a gene to the CompositeGene's container. |
void |
applyMutation(int a_index,
double a_percentage)
Don't use this method, is makes no sense here. |
void |
cleanup()
Executed by the genetic engine when this Gene instance is no longer needed and should perform any necessary resource cleanup. |
int |
compareTo(java.lang.Object a_other)
Compares this CompositeGene with the specified object for order. |
boolean |
containsGeneByIdentity(Gene gene)
Checks whether a specific gene is already contained. |
protected Gene |
createGene(java.lang.String a_geneClassName,
java.lang.String a_persistentRepresentation)
Creates a new instance of gene. |
Gene |
geneAt(int a_index)
|
java.lang.Object |
getAllele()
Retrieves the value represented by this Gene. |
java.lang.String |
getBusinessKey()
|
java.util.List<Gene> |
getGenes()
|
Gene |
getGeneTypeAllowed()
|
protected java.lang.Object |
getInternalValue()
This method is not called internally because BaseGene.getAllele() is overridden here! |
java.lang.String |
getPersistentRepresentation()
See interface Gene for description. |
int |
hashCode()
Retrieves the hash code value for this Gene. |
boolean |
isEmpty()
|
protected Gene |
newGeneInternal()
Provides an implementation-independent means for creating new Gene instances. |
boolean |
removeGene(Gene a_gene)
Removes the given gene from the collection of genes. |
boolean |
removeGeneByIdentity(Gene a_gene)
Removes the given gene from the collection of genes. |
void |
setAllele(java.lang.Object a_newValue)
Sets the value of the contained Genes to the new given value. |
void |
setToRandomValue(RandomGenerator a_numberGenerator)
See interface Gene for description. |
void |
setValueFromPersistentRepresentation(java.lang.String a_representation)
See interface Gene for description. |
int |
size()
|
protected static java.util.List |
split(java.lang.String a_string)
Splits a_string into individual gene representations. |
java.lang.String |
toString()
Retrieves a string representation of this CompositeGene's value that may be useful for display purposes. |
| Methods inherited from class org.jgap.BaseGene |
|---|
compareApplicationData, decode, encode, equals, getApplicationData, 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
| Constructor Detail |
|---|
public CompositeGene()
throws InvalidConfigurationException
Attention: The configuration used is the one set with the static method Genotype.setConfiguration.
InvalidConfigurationException
public CompositeGene(Configuration a_config)
throws InvalidConfigurationException
a_config - the configuration to use
InvalidConfigurationException
public CompositeGene(Configuration a_config,
Gene a_geneTypeAllowed)
throws InvalidConfigurationException
a_config - the configuration to usea_geneTypeAllowed - the class of Genes to be allowed to be added to
the CompositeGene
InvalidConfigurationException| Method Detail |
|---|
public void addGene(Gene a_gene)
addGene in interface ICompositeGenea_gene - the gene to addpublic Gene getGeneTypeAllowed()
public void addGene(Gene a_gene,
boolean a_strict)
a_gene - the gene to be addeda_strict - false: add the given gene except the gene itself already is
contained within the CompositeGene's container. true: add the gene if
there is no other gene being equal to the given gene in request to the
Gene's equals methodpublic boolean removeGeneByIdentity(Gene a_gene)
a_gene - the gene to be removed
public boolean removeGene(Gene a_gene)
a_gene - the gene to be removed
public void cleanup()
cleanup in interface Genecleanup in class BaseGenepublic 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
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
UnsupportedRepresentationException
protected Gene createGene(java.lang.String a_geneClassName,
java.lang.String a_persistentRepresentation)
throws java.lang.Exception
a_geneClassName - name of the gene classa_persistentRepresentation - persistent representation of the gene to
create (could be obtained via getPersistentRepresentation)
java.lang.Exception
public java.lang.String getPersistentRepresentation()
throws java.lang.UnsupportedOperationException
getPersistentRepresentation in interface GenegetPersistentRepresentation in interface IPersistentRepresentationjava.lang.UnsupportedOperationExceptionpublic java.lang.Object getAllele()
getAllele in interface GenegetAllele in class BaseGenepublic void setAllele(java.lang.Object a_newValue)
setAllele in interface Genea_newValue - the new value of this Gene instanceprotected Gene newGeneInternal()
newGeneInternal in class BaseGenepublic int compareTo(java.lang.Object a_other)
compareTo in interface java.lang.Comparablea_other - the CompositeGene to be compared
java.lang.ClassCastException - if the specified object's type prevents it
from being compared to this CompositeGenepublic java.lang.String toString()
toString in interface GenetoString in class BaseGenepublic boolean isEmpty()
public Gene geneAt(int a_index)
geneAt in interface ICompositeGenea_index - index to return the gene at
public java.util.List<Gene> getGenes()
public int size()
size in interface Genesize in class BaseGenepublic boolean containsGeneByIdentity(Gene gene)
gene - the gene under test
public void applyMutation(int a_index,
double a_percentage)
applyMutation in interface Genea_index - does not matter herea_percentage - does not matter here
protected static final java.util.List split(java.lang.String a_string)
throws UnsupportedRepresentationException
a_string - the string to split
UnsupportedRepresentationExceptionpublic int hashCode()
hashCode in class BaseGeneprotected java.lang.Object getInternalValue()
getInternalValue in class BaseGenepublic java.lang.String getBusinessKey()
getBusinessKey in interface IBusinessKeygetBusinessKey in class BaseGene
|
JGAP | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||