Documentation of 'org.jgap.gp.impl.GPPopulation' Java class
GPPopulation
org.jgap.gp.impl

Class GPPopulation

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable


    public class GPPopulation
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Comparable
    Population for GP programs.
    Since:
    3.0
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static double DELTA 
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void addFittestProgram(IGPProgram a_toAdd)
      Adds a GP program to this Population.
      void clear()
      Clears the list of programs.
      int compareTo(java.lang.Object a_pop)
      This method is not producing symmetric results as -1 is more often returned than 1 (see description of return value).
      void copyGPPrograms(GPPopulation a_pop)
      Sets the GPPrograms of the given population to this population.
      void create(java.lang.Class[] a_types, java.lang.Class[][] a_argTypes, CommandGene[][] a_nodeSets, int[] a_minDepths, int[] a_maxDepths, int a_maxNodes, boolean[] a_fullModeAllowed)
      Creates a population.
      void create(java.lang.Class[] a_types, java.lang.Class[][] a_argTypes, CommandGene[][] a_nodeSets, int[] a_minDepths, int[] a_maxDepths, int a_maxNodes, boolean[] a_fullModeAllowed, IProgramCreator a_programCreator)
      Creates a population.
      void create(java.lang.Class[] a_types, java.lang.Class[][] a_argTypes, CommandGene[][] a_nodeSets, int[] a_minDepths, int[] a_maxDepths, int a_maxNodes, boolean[] a_fullModeAllowed, IProgramCreator a_programCreator, int a_offset)
      Creates a population.
      IGPProgram create(java.lang.Class[] a_types, java.lang.Class[][] a_argTypes, CommandGene[][] a_nodeSets, int[] a_minDepths, int[] a_maxDepths, int a_depth, boolean a_grow, int a_maxNodes, boolean[] a_fullModeAllowed, int a_tries)
      Creates a population.
      IGPProgram create(int a_programIndex, java.lang.Class[] a_types, java.lang.Class[][] a_argTypes, CommandGene[][] a_nodeSets, int[] a_minDepths, int[] a_maxDepths, int a_depth, boolean a_grow, int a_maxNodes, boolean[] a_fullModeAllowed, int a_tries) 
      IGPProgram create(int a_programIndex, java.lang.Class[] a_types, java.lang.Class[][] a_argTypes, CommandGene[][] a_nodeSets, int[] a_minDepths, int[] a_maxDepths, int a_depth, boolean a_grow, int a_maxNodes, boolean[] a_fullModeAllowed, int a_tries, IProgramCreator a_programCreator)
      Creates a valid IGPProgram.
      java.util.List determineFittestChromosomes(int a_numberOfPrograms)
      Sorts the GPPrograms list and returns the fittest n GPPrograms in the population.
      IGPProgram determineFittestProgram()
      Determines the fittest GPProgram in the population (the one with the highest fitness value) and memorizes it.
      IGPProgram determineFittestProgramComputed()
      Determines the fittest GPProgram in the population, but only considers programs with already computed fitness value.
      boolean equals(java.lang.Object a_pop)
      The equals-method.
      float getFitnessRank(int a_index) 
      float[] getFitnessRanks() 
      GPConfiguration getGPConfiguration() 
      IGPProgram getGPProgram(int a_index) 
      IGPProgram[] getGPPrograms() 
      java.lang.String getPersistentRepresentation() 
      int getPopSize() 
      boolean isChanged() 
      boolean isFirstEmpty() 
      void setGPProgram(int a_index, IGPProgram a_program)
      Sets the given GPProgram at the given index in the list of GPProgram's.
      void setGPPrograms(GPPopulation a_pop)
      Sets the GPPrograms of the given population to this population.
      void setGPPrograms(IGPProgram[] a_progs)
      Sets the GPPrograms of the given array to this population.
      void setGPPrograms(java.util.List a_pop)
      Sets the GPPrograms of the given population to this population.
      int size() 
      void sort(java.util.Comparator c)
      Sorts the population into "ascending" order using some criterion for "ascending".
      void sortByFitness()
      Sorts the programs within the population according to their fitness value using GPProgramFitnessComparator.
      • Methods inherited from class java.lang.Object

        getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • sort

        public void sort(java.util.Comparator c)
        Sorts the population into "ascending" order using some criterion for "ascending". A Comparator is given which will compare two individuals, and if one individual compares lower than another individual, the first individual will appear in the population before the second individual.
        Parameters:
        c - the Comparator to use
        Since:
        3.0
      • create

        public void create(java.lang.Class[] a_types,
                           java.lang.Class[][] a_argTypes,
                           CommandGene[][] a_nodeSets,
                           int[] a_minDepths,
                           int[] a_maxDepths,
                           int a_maxNodes,
                           boolean[] a_fullModeAllowed)
                    throws InvalidConfigurationException
        Creates a population.
        Parameters:
        a_types - the type for each chromosome, the length of the array represents the number of chromosomes
        a_argTypes - the types of the arguments to each chromosome, must be an array of arrays, the first dimension of which is the number of chromosomes and the second dimension of which is the number of arguments to the chromosome
        a_nodeSets - the nodes which are allowed to be used by each chromosome, must be an array of arrays, the first dimension of which is the number of chromosomes and the second dimension of which is the number of nodes
        a_minDepths - contains the minimum depth allowed for each chromosome
        a_maxDepths - contains the maximum depth allowed for each chromosome
        a_maxNodes - reserve space for a_maxNodes number of nodes
        a_fullModeAllowed - array of boolean values. For each chromosome there is one value indicating whether the full mode for creating chromosome generations during evolution is allowed (true) or not (false)
        Throws:
        InvalidConfigurationException
        Since:
        3.0
      • create

        public void create(java.lang.Class[] a_types,
                           java.lang.Class[][] a_argTypes,
                           CommandGene[][] a_nodeSets,
                           int[] a_minDepths,
                           int[] a_maxDepths,
                           int a_maxNodes,
                           boolean[] a_fullModeAllowed,
                           IProgramCreator a_programCreator)
                    throws InvalidConfigurationException
        Creates a population.
        Parameters:
        a_types - the type for each chromosome, the length of the array represents the number of chromosomes
        a_argTypes - the types of the arguments to each chromosome, must be an array of arrays, the first dimension of which is the number of chromosomes and the second dimension of which is the number of arguments to the chromosome
        a_nodeSets - the nodes which are allowed to be used by each chromosome, must be an array of arrays, the first dimension of which is the number of chromosomes and the second dimension of which is the number of nodes
        a_minDepths - contains the minimum depth allowed for each chromosome
        a_maxDepths - contains the maximum depth allowed for each chromosome
        a_maxNodes - reserve space for a_maxNodes number of nodes
        a_fullModeAllowed - array of boolean values. For each chromosome there is one value indicating whether the full mode for creating chromosome generations during evolution is allowed (true) or not (false)
        a_programCreator - service to create new programs with
        Throws:
        InvalidConfigurationException
        Since:
        3.2.2
      • create

        public void create(java.lang.Class[] a_types,
                           java.lang.Class[][] a_argTypes,
                           CommandGene[][] a_nodeSets,
                           int[] a_minDepths,
                           int[] a_maxDepths,
                           int a_maxNodes,
                           boolean[] a_fullModeAllowed,
                           IProgramCreator a_programCreator,
                           int a_offset)
                    throws InvalidConfigurationException
        Creates a population.
        Parameters:
        a_types - the type for each chromosome, the length of the array represents the number of chromosomes
        a_argTypes - the types of the arguments to each chromosome, must be an array of arrays, the first dimension of which is the number of chromosomes and the second dimension of which is the number of arguments to the chromosome
        a_nodeSets - the nodes which are allowed to be used by each chromosome, must be an array of arrays, the first dimension of which is the number of chromosomes and the second dimension of which is the number of nodes
        a_minDepths - contains the minimum depth allowed for each chromosome
        a_maxDepths - contains the maximum depth allowed for each chromosome
        a_maxNodes - reserve space for a_maxNodes number of nodes
        a_fullModeAllowed - array of boolean values. For each chromosome there is one value indicating whether the full mode for creating chromosome generations during evolution is allowed (true) or not (false)
        a_programCreator - service to create new programs with
        a_offset - start index for new programs to put into the configuration
        Throws:
        InvalidConfigurationException
        Since:
        3.3.3
      • create

        public IGPProgram create(java.lang.Class[] a_types,
                                 java.lang.Class[][] a_argTypes,
                                 CommandGene[][] a_nodeSets,
                                 int[] a_minDepths,
                                 int[] a_maxDepths,
                                 int a_depth,
                                 boolean a_grow,
                                 int a_maxNodes,
                                 boolean[] a_fullModeAllowed,
                                 int a_tries)
                          throws InvalidConfigurationException
        Creates a population.
        Parameters:
        a_types - Class[]
        a_argTypes - Class[][]
        a_nodeSets - CommandGene[][]
        a_minDepths - int[]
        a_maxDepths - int[]
        a_depth - int
        a_grow - boolean
        a_maxNodes - int
        a_fullModeAllowed - boolean[]
        a_tries - int
        Returns:
        IGPProgram
        Throws:
        InvalidConfigurationException
        Since:
        3.2.2
      • create

        public IGPProgram create(int a_programIndex,
                                 java.lang.Class[] a_types,
                                 java.lang.Class[][] a_argTypes,
                                 CommandGene[][] a_nodeSets,
                                 int[] a_minDepths,
                                 int[] a_maxDepths,
                                 int a_depth,
                                 boolean a_grow,
                                 int a_maxNodes,
                                 boolean[] a_fullModeAllowed,
                                 int a_tries)
                          throws InvalidConfigurationException
        Parameters:
        a_programIndex - int
        a_types - Class[]
        a_argTypes - Class[][]
        a_nodeSets - CommandGene[][]
        a_minDepths - int[]
        a_maxDepths - int[]
        a_depth - int
        a_grow - boolean
        a_maxNodes - int
        a_fullModeAllowed - boolean[]
        a_tries - int
        Returns:
        IGPProgram
        Throws:
        InvalidConfigurationException
        Since:
        3.3
      • create

        public IGPProgram create(int a_programIndex,
                                 java.lang.Class[] a_types,
                                 java.lang.Class[][] a_argTypes,
                                 CommandGene[][] a_nodeSets,
                                 int[] a_minDepths,
                                 int[] a_maxDepths,
                                 int a_depth,
                                 boolean a_grow,
                                 int a_maxNodes,
                                 boolean[] a_fullModeAllowed,
                                 int a_tries,
                                 IProgramCreator a_programCreator)
                          throws InvalidConfigurationException
        Creates a valid IGPProgram. No fitness computation is initiated here!
        Parameters:
        a_programIndex - index of the program in the population
        a_types - the type of each chromosome, the length is the number of chromosomes
        a_argTypes - the types of the arguments to each chromosome, must be an array of arrays, the first dimension of which is the number of chromosomes and the second dimension of which is the number of arguments to the chromosome
        a_nodeSets - the nodes which are allowed to be used by each chromosome, must be an array of arrays, the first dimension of which is the number of chromosomes and the second dimension of which is the number of nodes
        a_minDepths - contains the minimum depth allowed for each chromosome
        a_maxDepths - contains the maximum depth allowed for each chromosome
        a_depth - the maximum depth of the program to create
        a_grow - true: grow mode, false: full mode
        a_maxNodes - reserve space for a_maxNodes number of nodes
        a_fullModeAllowed - array of boolean values. For each chromosome there is one value indicating whether the full mode for creating chromosomes during evolution is allowed (true) or not (false)
        a_tries - maximum number of tries to get a valid program
        a_programCreator - strategy class to create programs for the population
        Returns:
        valid program
        Throws:
        InvalidConfigurationException
        Since:
        3.0
      • getPopSize

        public int getPopSize()
        Returns:
        fixed size of the population
        Since:
        3.0
      • getGPConfiguration

        public GPConfiguration getGPConfiguration()
        Returns:
        the GPConfiguration set
        Since:
        3.0
      • setGPProgram

        public void setGPProgram(int a_index,
                                 IGPProgram a_program)
        Sets the given GPProgram at the given index in the list of GPProgram's. If the given index is exceeding the list by one, the chromosome is appended.
        Parameters:
        a_index - the index to set the GPProgram in
        a_program - the GPProgram to be set
        Since:
        3.0
      • getGPProgram

        public IGPProgram getGPProgram(int a_index)
      • setGPPrograms

        public void setGPPrograms(GPPopulation a_pop)
        Sets the GPPrograms of the given population to this population.
        Parameters:
        a_pop - the population to use as template
        Since:
        3.3.3
      • setGPPrograms

        public void setGPPrograms(IGPProgram[] a_progs)
        Sets the GPPrograms of the given array to this population.
        Parameters:
        a_progs - the programs to set
        Since:
        3.3.3
      • copyGPPrograms

        public void copyGPPrograms(GPPopulation a_pop)
        Sets the GPPrograms of the given population to this population.
        Parameters:
        a_pop - the population to use as template
        Since:
        3.3.3
      • setGPPrograms

        public void setGPPrograms(java.util.List a_pop)
        Sets the GPPrograms of the given population to this population.
        Parameters:
        a_pop - the population to use as template
        Since:
        3.3.3
      • getGPPrograms

        public IGPProgram[] getGPPrograms()
      • size

        public int size()
      • determineFittestProgram

        public IGPProgram determineFittestProgram()
        Determines the fittest GPProgram in the population (the one with the highest fitness value) and memorizes it. This is an optimized version compared to calling determineFittesPrograms(1).
        Returns:
        the fittest GPProgram of the population
        Since:
        3.0
      • determineFittestProgramComputed

        public IGPProgram determineFittestProgramComputed()
        Determines the fittest GPProgram in the population, but only considers programs with already computed fitness value.
        Returns:
        the fittest GPProgram of the population
        Since:
        3.2
      • determineFittestChromosomes

        public java.util.List determineFittestChromosomes(int a_numberOfPrograms)
        Sorts the GPPrograms list and returns the fittest n GPPrograms in the population.
        Parameters:
        a_numberOfPrograms - number of top performer GPPrograms to be returned
        Returns:
        list of the fittest n GPPrograms of the population, or the fittest x GPPrograms with x = number of GPPrograms in case n > x.
        Since:
        3.0
      • sortByFitness

        public void sortByFitness()
        Sorts the programs within the population according to their fitness value using GPProgramFitnessComparator.
        Since:
        3.0
      • getFitnessRanks

        public float[] getFitnessRanks()
      • getFitnessRank

        public float getFitnessRank(int a_index)
      • isChanged

        public boolean isChanged()
        Returns:
        true: population's programs (maybe) were changed, false: not changed for sure
        Since:
        3.0
      • compareTo

        public int compareTo(java.lang.Object a_pop)
        This method is not producing symmetric results as -1 is more often returned than 1 (see description of return value).
        Specified by:
        compareTo in interface java.lang.Comparable
        Parameters:
        a_pop - the other population to compare
        Returns:
        1: a_pop is null or having fewer programs or equal number of programs but at least one not contained. 0: both populations containing exactly the same programs. -1: this population contains fewer programs than a_pop
        Since:
        2.6
      • equals

        public boolean equals(java.lang.Object a_pop)
        The equals-method.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        a_pop - the population instance to compare with
        Returns:
        true: given object equal to comparing one
        Since:
        3.0
      • addFittestProgram

        public void addFittestProgram(IGPProgram a_toAdd)
        Adds a GP program to this Population. Does nothing when given null. The injection is actually executed in method create(..)
        Parameters:
        a_toAdd - the program to add
        Since:
        3.2
      • clear

        public void clear()
        Clears the list of programs. Normally, this should not be necessary. But especially in distributed computing, a fresh population has to be provided sometimes.
        Since:
        3.2
      • isFirstEmpty

        public boolean isFirstEmpty()
      • getPersistentRepresentation

        public java.lang.String getPersistentRepresentation()
        Returns:
        the persistent representation of the population, including all GP programs
        Since:
        3.2.3

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.