Documentation of 'org.jgap.Genotype' Java class
Genotype
org.jgap

Class Genotype

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Runnable
    Direct Known Subclasses:
    DistributedGenotype


    public class Genotype
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Runnable
    Genotypes are fixed-length populations of chromosomes. As an instance of a Genotype is evolved, all of its Chromosomes are also evolved. A Genotype may be constructed normally via constructor, or the static randomInitialGenotype() method can be used to generate a Genotype with a randomized Chromosome population.

    Please note that among all created Genotype instances there may only be one configuration, used by all Genotype instances.

    Since:
    1.0
    See Also:
    Serialized Form
    • Constructor Detail

      • Genotype

        public Genotype(Configuration a_configuration,
                        IChromosome[] a_initialChromosomes)
                 throws InvalidConfigurationException
        Deprecated. use Genotype(Configuration, Population) instead
        Constructs a new Genotype instance with the given array of Chromosomes and the given active Configuration instance. Note that the Configuration object must be in a valid state when this method is invoked, or a InvalidConfigurationException will be thrown.
        Parameters:
        a_configuration - the Configuration object to use
        a_initialChromosomes - the Chromosome population to be managed by this Genotype instance
        Throws:
        InvalidConfigurationException - if the given Configuration object is in an invalid state
        Since:
        1.0
      • Genotype

        public Genotype(Configuration a_configuration,
                        Population a_population)
                 throws InvalidConfigurationException
        Constructs a new Genotype instance with the given array of Chromosomes and the given active Configuration instance. Note that the Configuration object must be in a valid state when this method is invoked, or a InvalidconfigurationException will be thrown.
        Parameters:
        a_configuration - the Configuration object to use
        a_population - the Chromosome population to be managed by this Genotype instance
        Throws:
        InvalidConfigurationException
        Since:
        2.0
    • Method Detail

      • getChromosomes

        public IChromosome[] getChromosomes()
        Deprecated. uses getPopulation() instead
        Retrieves the array of Chromosomes that make up the population of this Genotype instance.
        Returns:
        the Population of Chromosomes
        Since:
        1.0
      • getPopulation

        public Population getPopulation()
        Returns:
        the current population of chromosomes
        Since:
        2.1
      • getFittestChromosome

        public IChromosome getFittestChromosome()
        Retrieves the Chromosome in the Population with the highest fitness value.
        Returns:
        the Chromosome with the highest fitness value, or null if there are no chromosomes in this Genotype
        Since:
        1.0
      • getFittestChromosome

        public IChromosome getFittestChromosome(int a_startIndex,
                                                int a_endIndex)
        Retrieves the Chromosome in the Population with the highest fitness value within the given indices.
        Parameters:
        a_startIndex - the index to start the determination with
        a_endIndex - the index to end the determination with
        Returns:
        the Chromosome with the highest fitness value within the given indices, or null if there are no chromosomes in this Genotype
        Since:
        3.0
      • getFittestChromosomes

        public java.util.List getFittestChromosomes(int a_numberOfChromosomes)
        Retrieves the top n Chromsomes in the population (the ones with the best fitness values).
        Parameters:
        a_numberOfChromosomes - the number of chromosomes desired
        Returns:
        the list of Chromosomes with the highest fitness values, or null if there are no chromosomes in this Genotype
        Since:
        2.4
      • evolve

        public void evolve()
        Evolves the population of Chromosomes within this Genotype. This will execute all of the genetic operators added to the present active configuration and then invoke the natural selector to choose which chromosomes will be included in the next generation population. Note that the population size not always remains constant (dependent on the NaturalSelectors used!). To consecutively call this method, use evolve(int)!!!
        Since:
        1.0
      • evolve

        public void evolve(int a_numberOfEvolutions)
        Evolves this Genotype the specified number of times. This is equivalent to invoking the standard evolve() method the given number of times in a row.
        Parameters:
        a_numberOfEvolutions - the number of times to evolve this Genotype before returning
        Since:
        1.1
      • evolve

        public java.util.List<java.lang.String> evolve(IEvolutionMonitor a_monitor)
        Evolves this genotype until the given monitor asks to quit the evolution cycle.
        Parameters:
        a_monitor - the monitor used to decide when to stop evolution
        Returns:
        messages of the registered evolution monitor. May indicate why the evolution was asked to be stopped. May be empty, depending on the implementation of the used monitor
        Since:
        3.4.4
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        Returns:
        string representation of this Genotype instance, useful for display or debug purposes
        Since:
        1.0
      • randomInitialGenotype

        public static Genotype randomInitialGenotype(Configuration a_configuration)
                                              throws InvalidConfigurationException
        Convenience method that returns a newly constructed Genotype instance configured according to the given Configuration instance. The population of Chromosomes will be created according to the setup of the sample Chromosome in the Configuration object, but the gene values (alleles) will be set to random legal values.
        Parameters:
        a_configuration - the current active Configuration object
        Returns:
        a newly constructed Genotype instance
        Throws:
        java.lang.IllegalArgumentException - if the given Configuration object is null
        InvalidConfigurationException - if the given Configuration instance is not in a valid state
        Since:
        2.3
      • equals

        public boolean equals(java.lang.Object a_other)
        Compares this Genotype against the specified object. The result is true if the argument is an instance of the Genotype class, has exactly the same number of chromosomes as the given Genotype, and, for each Chromosome in this Genotype, there is an equal chromosome in the given Genotype. The chromosomes do not need to appear in the same order within the population.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        a_other - the object to compare against
        Returns:
        true if the objects are the same, false otherwise
        Since:
        1.0
      • applyGeneticOperators

        public void applyGeneticOperators()
        Applies all GeneticOperators registered with the Configuration.
        Since:
        3.0
      • getStaticConfiguration

        public static Configuration getStaticConfiguration()
        Returns:
        the configuration to use with the Genetic Algorithm
        Since:
        2.0
      • setStaticConfiguration

        public static void setStaticConfiguration(Configuration a_configuration)
        Sets the configuration to use with the Genetic Algorithm.
        Parameters:
        a_configuration - the configuration to use
        Since:
        2.0
      • hashCode

        public int hashCode()
        Hashcode function for the genotype, tries to create a unique hashcode for the chromosomes within the population. The logic for the hashcode is Step Result ---- ------ 1 31*0 + hashcode_0 = y(1) 2 31*y(1) + hashcode_1 = y(2) 3 31*y(2) + hashcode_2 = y(3) n 31*y(n-1) + hashcode_n-1 = y(n)
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the computed hashcode
        Since:
        2.1
      • run

        public void run()
        If used in a Thread: runs the evolution forever. You have to implement a listener to stop computation sometime. See examples.simpleBooleanThreaded for a possible implementation of such a listener.
        Specified by:
        run in interface java.lang.Runnable
        Since:
        3.01
      • getEvolves

        public java.util.List<IEvolveJob> getEvolves(IPopulationSplitter a_splitter)
                                              throws java.lang.Exception
        Splits a population into pieces that can be evolved independently.
        Parameters:
        a_splitter - splits the population
        Returns:
        list of IEvolveJob objects
        Throws:
        java.lang.Exception
      • mergeResults

        public void mergeResults(IPopulationMerger a_merger,
                                 EvolveResult[] a_results)
                          throws java.lang.Exception
        Throws:
        java.lang.Exception

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.