|
JGAP | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jgap.BaseChromosome
org.jgap.Chromosome
public class Chromosome
Chromosomes represent potential solutions and consist of a fixed-length collection of genes. Each gene represents a discrete part of the solution. Each gene in the Chromosome may be backed by a different concrete implementation of the Gene interface, but all genes in a respective position (locus) must share the same concrete implementation across Chromosomes within a single population (genotype). In other words, gene 1 in a chromosome must share the same concrete implementation as gene 1 in all other chromosomes in the population.
| Field Summary | |
|---|---|
protected double |
m_fitnessValue
Stores the fitness value of this Chromosome as determined by the active fitness function. |
| Fields inherited from class org.jgap.BaseChromosome |
|---|
CHROM_DELIMITER, GENE_DELIMITER, GENE_DELIMITER_CLOSING, GENE_DELIMITER_HEADING |
| Fields inherited from interface org.jgap.IChromosome |
|---|
S_ALLELES, S_APPLICATION_DATA, S_FITNESS_VALUE, S_SIZE |
| Constructor Summary | |
|---|---|
Chromosome()
Default constructor, only provided for dynamic instantiation. |
|
Chromosome(Configuration a_configuration)
Constructor, provided for dynamic or minimal instantiation. |
|
Chromosome(Configuration a_configuration,
Gene[] a_initialGenes)
Constructs a Chromosome separate from any specific Configuration. |
|
Chromosome(Configuration a_configuration,
Gene[] a_initialGenes,
IGeneConstraintChecker a_constraintChecker)
Constructs a Chromosome separate from any specific Configuration. |
|
Chromosome(Configuration a_configuration,
Gene a_sampleGene,
int a_desiredSize)
Constructs a Chromosome of the given size separate from any specific Configuration. |
|
Chromosome(Configuration a_configuration,
Gene a_sampleGene,
int a_desiredSize,
IGeneConstraintChecker a_constraintChecker)
|
|
Chromosome(Configuration a_configuration,
int a_desiredSize)
Constructor for specifying the number of genes. |
|
Chromosome(Configuration a_configuration,
java.lang.String a_persistentRepresentatuion)
Constructor, provided for instantiation via persistent representation. |
|
| Method Summary | |
|---|---|
protected double |
calcFitnessValue()
|
protected void |
checkGenes(Gene[] a_initialGenes)
Helper: called by constructors only to verify the initial genes. |
void |
cleanup()
Invoked when this Chromosome is no longer needed and should perform any necessary cleanup. |
java.lang.Object |
clone()
Returns a copy of this Chromosome. |
static java.lang.Object |
cloneObject(Configuration a_config,
java.lang.Object a_object,
java.lang.Object a_master)
Static convenience method. |
protected java.lang.Object |
cloneObject(java.lang.Object a_object)
Clones an object by using clone handlers. |
int |
compareTo(java.lang.Object other)
Compares the given Chromosome to this Chromosome. |
boolean |
equals(java.lang.Object other)
Compares this Chromosome against the specified object. |
java.lang.Object |
getApplicationData()
Retrieves the application-specific data that is attached to this Chromosome. |
IGeneConstraintChecker |
getConstraintChecker()
|
double |
getFitnessValue()
Retrieves the fitness value of this Chromosome, as determined by the active fitness function. |
double |
getFitnessValueDirectly()
|
java.util.List |
getMultiObjectives()
|
int |
hashCode()
Retrieve a hash code for this Chromosome. |
protected void |
initFromGene(Gene a_sampleGene)
|
boolean |
isCompareApplicationData()
|
boolean |
isHandlerFor(java.lang.Object a_obj,
java.lang.Class a_class)
Determines whether the handler is suitable for the given object instance or class. |
boolean |
isSelectedForNextGeneration()
Retrieves whether this Chromosome has been selected by the natural selector to continue to the next generation. |
java.lang.Object |
perform(java.lang.Object a_obj,
java.lang.Class a_class,
java.lang.Object a_params)
Performs a task for the given object or class. |
static IChromosome |
randomInitialChromosome(Configuration a_configuration)
Convenience method that returns a new Chromosome instance with its genes values (alleles) randomized. |
void |
setApplicationData(java.lang.Object a_newData)
This sets the application-specific data that is attached to this Chromosome. |
void |
setCompareApplicationData(boolean a_doCompare)
Should we also consider the application data when comparing? |
void |
setConstraintChecker(IGeneConstraintChecker a_constraintChecker)
Sets the constraint checker to be used for this gene whenever method setAllele(Object) is called. |
void |
setFitnessValue(double a_newFitnessValue)
Sets the fitness value of this Chromosome. |
void |
setFitnessValueDirectly(double a_newFitnessValue)
Sets the fitness value of this Chromosome directly without any constraint checks, conversions or checks. |
void |
setGenes(Gene[] a_genes)
Sets the genes for the chromosome. |
void |
setIsSelectedForNextGeneration(boolean a_isSelected)
Sets whether this Chromosome has been selected by the natural selector to continue to the next generation or manually (e.g. via an add-method). |
void |
setMultiObjectives(java.util.List a_values)
|
java.lang.String |
toString()
|
protected void |
verify(IGeneConstraintChecker a_constraintChecker)
Verifies the state of the chromosome. |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected double m_fitnessValue
| Constructor Detail |
|---|
public Chromosome()
throws InvalidConfigurationException
Attention: The configuration used is the one set with the static method Genotype.setConfiguration.
InvalidConfigurationException
public Chromosome(Configuration a_configuration)
throws InvalidConfigurationException
a_configuration - the configuration to use
InvalidConfigurationException
public Chromosome(Configuration a_configuration,
java.lang.String a_persistentRepresentatuion)
throws InvalidConfigurationException,
UnsupportedRepresentationException
a_configuration - the configuration to usea_persistentRepresentatuion - valid persistent representation that
was most likely obtained via getPersistentRepresentation()
InvalidConfigurationException
UnsupportedRepresentationException
public Chromosome(Configuration a_configuration,
int a_desiredSize)
throws InvalidConfigurationException
a_configuration - the configuration to usea_desiredSize - number of genes the chromosome contains of
InvalidConfigurationException
public Chromosome(Configuration a_configuration,
Gene a_sampleGene,
int a_desiredSize)
throws InvalidConfigurationException
a_configuration - the configuration to usea_sampleGene - a concrete sampleGene instance that will be used
as a template for all of the genes in this Chromosomea_desiredSize - the desired size (number of genes) of this Chromosome
InvalidConfigurationException
public Chromosome(Configuration a_configuration,
Gene a_sampleGene,
int a_desiredSize,
IGeneConstraintChecker a_constraintChecker)
throws InvalidConfigurationException
InvalidConfigurationException
public Chromosome(Configuration a_configuration,
Gene[] a_initialGenes)
throws InvalidConfigurationException
a_configuration - the configuration to usea_initialGenes - the initial genes of this Chromosome
InvalidConfigurationException
public Chromosome(Configuration a_configuration,
Gene[] a_initialGenes,
IGeneConstraintChecker a_constraintChecker)
throws InvalidConfigurationException
a_configuration - the configuration to usea_initialGenes - the initial genes of this Chromosomea_constraintChecker - constraint checker to use
InvalidConfigurationException - in case the constraint checker
reports a configuration error| Method Detail |
|---|
protected void initFromGene(Gene a_sampleGene)
protected void checkGenes(Gene[] a_initialGenes)
a_initialGenes - the initial genes of this Chromosome to verifypublic java.lang.Object clone()
clone in interface ICloneableclone in class BaseChromosomejava.lang.IllegalStateException - instead of CloneNotSupportedException
protected java.lang.Object cloneObject(java.lang.Object a_object)
throws java.lang.Exception
a_object - the object to clone
java.lang.Exception
public static java.lang.Object cloneObject(Configuration a_config,
java.lang.Object a_object,
java.lang.Object a_master)
throws java.lang.Exception
a_config - a valid configuration to obtain the JGAPFactory froma_object - the object to clonea_master - the super object of a_object, e.g. a chromosome in case of
application to be cloned
java.lang.Exceptionpublic double getFitnessValue()
Attention: should not be called from toString() as the fitness value would be computed if it was initial!
public double getFitnessValueDirectly()
protected double calcFitnessValue()
public void setFitnessValue(double a_newFitnessValue)
a_newFitnessValue - a positive integer representing the fitness
of this Chromosomepublic void setFitnessValueDirectly(double a_newFitnessValue)
a_newFitnessValue - a positive integer representing the fitness
of this Chromosomepublic java.lang.String toString()
toString in class java.lang.Object
public static IChromosome randomInitialChromosome(Configuration a_configuration)
throws InvalidConfigurationException
a_configuration - the configuration to use
InvalidConfigurationException - if the given Configuration
instance is invalid
java.lang.IllegalArgumentException - if the given Configuration instance
is nullpublic boolean equals(java.lang.Object other)
equals in class java.lang.Objectother - the object to compare against
public int hashCode()
hashCode in class java.lang.Objectpublic int compareTo(java.lang.Object other)
other - the Chromosome against which to compare this chromosome
public void setIsSelectedForNextGeneration(boolean a_isSelected)
a_isSelected - true if this Chromosome has been selected, false
otherwisepublic boolean isSelectedForNextGeneration()
public void cleanup()
public void setApplicationData(java.lang.Object a_newData)
a_newData - the new application-specific data to attach to this
Chromosome. Should be an instance of IApplicationDatapublic java.lang.Object getApplicationData()
public void setGenes(Gene[] a_genes)
throws InvalidConfigurationException
setGenes in interface IChromosomesetGenes in class BaseChromosomea_genes - the genes to set for the chromosome
InvalidConfigurationException - in case constraint checker is
providedpublic void setCompareApplicationData(boolean a_doCompare)
a_doCompare - true: consider application data in method compareTopublic boolean isCompareApplicationData()
public void setConstraintChecker(IGeneConstraintChecker a_constraintChecker)
throws InvalidConfigurationException
a_constraintChecker - the constraint checker to be set
InvalidConfigurationExceptionpublic IGeneConstraintChecker getConstraintChecker()
protected void verify(IGeneConstraintChecker a_constraintChecker)
throws InvalidConfigurationException
a_constraintChecker - the constraint checker to verify
InvalidConfigurationException
public boolean isHandlerFor(java.lang.Object a_obj,
java.lang.Class a_class)
a_obj - the object instance to checka_class - the class to check, alternatively if no object instance is
available (some handlers could need to get an object and would always
return false if only a class is provided)
public java.lang.Object perform(java.lang.Object a_obj,
java.lang.Class a_class,
java.lang.Object a_params)
throws java.lang.Exception
a_obj - the object instance to perform the handler task fora_class - the class to perform the handler task for, in case no object
instance is available (some handlers could need to get an object and would
always throw an exception if only a class is provided)a_params - optional parameters needed for the handler to perform its
task
java.lang.Exception - in case of any errorpublic void setMultiObjectives(java.util.List a_values)
public java.util.List getMultiObjectives()
|
JGAP | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||