Documentation of 'org.jgap.supergenes.AbstractSupergene' Java class
AbstractSupergene
org.jgap.supergenes

Class AbstractSupergene

    • Field Detail

      • GENE_DELIMITER

        public static final java.lang.String GENE_DELIMITER
        This field separates gene class name from the gene persistent representation string.
        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 CompositeGene 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 CompositeGene instances.
        See Also:
        Constant Field Values
      • MAX_RETRIES

        public static final int MAX_RETRIES
        Maximal number of retries for applyMutation and setToRandomValue. If the valid supergen cannot be created after this number of iterations, the error message is printed and the unchanged instance is returned.
        See Also:
        Constant Field Values
      • MAX_IMMUTABLE_GENES

        public static final int MAX_IMMUTABLE_GENES
        Maximal number of notes about immutable genes per single gene position
        See Also:
        Constant Field Values
    • Method Detail

      • getGenes

        public Gene[] getGenes()
        Description copied from interface: Supergene
        Get the array of genes - components of this supergene. The supergene components may be supergenes itself.
        Specified by:
        getGenes in interface Supergene
        Returns:
        the array of genes - components of this supergene. The supergene components may be supergenes itself
      • geneAt

        public final Gene geneAt(int a_index)
        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. This seems to be one of the bottlenecks, so it is declared final. I cannot imagine the reason for overriding this trivial single line method.
        Specified by:
        geneAt in interface ICompositeGene
        Specified by:
        geneAt in interface Supergene
        Parameters:
        a_index - the index of the gene value to be returned
        Returns:
        the Gene at the given index
      • isValid

        public boolean isValid()
        Test the allele combination of this supergene for validity. This method calls isValid for the current gene list.
        Specified by:
        isValid in interface Supergene
        Returns:
        true only if the supergene allele combination is valid or the setValidator (null) has been previously called
      • isValid

        public boolean isValid(Gene[] a_case,
                               Supergene a_forSupergene)
        Test the given gene list for validity. The genes must exactly the same as inside this supergene. At least about 5 % of the randomly generated Supergene suparallele values should be valid. If the valid combinations represents too small part of all possible combinations, it can take too long to find the suitable mutation that does not brake a supergene. If you face this problem, try to split the supergene into several sub-supergenes. This method is only called if you have not set any alternative validator (including null).
        Specified by:
        isValid in interface SupergeneValidator
        Parameters:
        a_case - ignored here
        a_forSupergene - ignored here
        Returns:
        true only if the supergene allele combination is valid
        Throws:
        java.lang.Error - by default. If you do not set external validator, you should always override this method
      • applyMutation

        public void applyMutation(int a_index,
                                  double a_percentage)
        Applies a mutation of a given intensity (percentage) onto the gene at the given index. Retries while isValid() returns true for the supergene. The method is delegated to the first element of the gene, indexed by a_index. See org.jgap.supergenes.AbstractSupergene.isValid()
        Specified by:
        applyMutation in interface Gene
        Parameters:
        a_index - index of atomic element, between 0 and size()-1
        a_percentage - percentage of mutation (greater than -1 and smaller than 1).
      • reset

        public static void reset()
        Discards all internal caches, ensuring correct repetetive tests of performance. Differently from cleanup(), discards also static references, that are assumed to be useful for the multiple instances of the Supergene. Clears the set of the alleles that are known to be immutable.
      • setToRandomValue

        public void setToRandomValue(RandomGenerator a_numberGenerator)
        Sets the value of this Gene to a random legal value for the implementation. It calls setToRandomValue for all subgenes and then validates. With a large number of subgenes and low percent of valid combinations this may take too long to complete. We think, at lease several % of the all possible combintations must be valid.
        Specified by:
        setToRandomValue in interface Gene
        Parameters:
        a_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
      • setAllele

        public void setAllele(java.lang.Object a_superAllele)
        Sets the allele.
        Specified by:
        setAllele in interface Gene
        Parameters:
        a_superAllele - must be an array of objects, size matching the number of genes
      • getAllele

        public java.lang.Object getAllele()
        Retrieves the allele value represented by this Supergene.
        Specified by:
        getAllele in interface Gene
        Overrides:
        getAllele in class BaseGene
        Returns:
        array of objects, each matching the subgene in this Supergene
      • getPersistentRepresentation

        public java.lang.String getPersistentRepresentation()
                                                     throws java.lang.UnsupportedOperationException
        Description copied from interface: Gene
        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. This string will be used to represent this Gene instance in XML persistence. This is an optional method but, if not implemented, XML persistence and possibly other features will not be available. An UnsupportedOperationException should be thrown if no implementation is provided.
        Specified by:
        getPersistentRepresentation in interface Gene
        Specified by:
        getPersistentRepresentation in interface IPersistentRepresentation
        Returns:
        a string representation of the value of this Supergene instance, using calls to the Supergene components. Supports other (nested) supergenes in this supergene
        Throws:
        java.lang.UnsupportedOperationException
      • cleanup

        public void cleanup()
        Calls cleanup() for each subgene.
        Specified by:
        cleanup in interface Gene
        Overrides:
        cleanup in class BaseGene
      • toString

        public java.lang.String toString()
        Description copied from class: BaseGene
        Retrieves a string representation of this Gene's value that may be useful for display purposes.
        Specified by:
        toString in interface Gene
        Overrides:
        toString in class BaseGene
        Returns:
        a string representation of the supergene, providing class name and calling toString() for all subgenes.
      • size

        public int size()
        Returns the number of the genes-components of this supergene.
        Specified by:
        size in interface Gene
        Overrides:
        size in class BaseGene
        Returns:
        the size of the gene, i.e the number of atomic elements. Always 1 for non-composed Gene types. Override for composed Gene types
      • compareTo

        public int compareTo(java.lang.Object o)
        Calls compareTo() for all subgenes. The passed parameter must be an instance of AbstractSupergene.
        Specified by:
        compareTo in interface java.lang.Comparable
      • equals

        public boolean equals(java.lang.Object a_gene)
        Calls equals() for each pair of genes. If the supplied object is an instance of the different class, returns false. Also, the genes are assumed to be different if they have different validator classes (or only one of the validators is set to null).
        Overrides:
        equals in class BaseGene
        Parameters:
        a_gene - the object to compare to this Gene for equality
        Returns:
        true if this Gene is equal to the given object, false otherwise
      • hashCode

        public int hashCode()
        Returns sum of hashCode() of the genes-components.
        Overrides:
        hashCode in class BaseGene
        Returns:
        this Gene's hash code
      • addGene

        public void addGene(Gene a_gene)
        Append a new gene to the gene array.
        Specified by:
        addGene in interface ICompositeGene
        Parameters:
        a_gene - the gene to add
      • setValidator

        public void setValidator(SupergeneValidator a_validator)
        Sets an object, responsible for deciding if the Supergene allele combination is valid. If it is set to null, no validation is performed (all combinations are assumed to be valid). If no validator is set, the method isValid (Gene [] ) is called.
        Specified by:
        setValidator in interface Supergene
      • getValidator

        public SupergeneValidator getValidator()
        Gets an object, responsible for deciding if the Supergene allele combination is valid. If no external validator was set and the class uses its own internal validation method, it returns this
        Specified by:
        getValidator in interface Supergene
      • getPersistent

        public java.lang.String getPersistent()
        The default implementation returns an empty string.
        Specified by:
        getPersistent in interface SupergeneValidator
        Returns:
        persistent string representation (if needed) of this validator. The method name is different allowing the same class to implement both Supergene and supergeneValidator.
      • setFromPersistent

        public void setFromPersistent(java.lang.String a_from)
        Set a persistend string representation (if needed) for this validator. The method name is different allowing the same class to implement both Supergene and supergeneValidator. The default implementation does nothing.
        Specified by:
        setFromPersistent in interface SupergeneValidator
      • getInternalValue

        public java.lang.Object getInternalValue()
        Description copied from class: BaseGene
        Each Gene implementation holds its own m_value object keeping the allele value. In your Gene implementation, just return it with this method (see BooleanGene for example)
        Returns:
        not needed for abstract supergene

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.