org.jgap.gp.impl
Class GPPopulation
- java.lang.Object
-
- org.jgap.gp.impl.GPPopulation
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Comparable
public class GPPopulation extends java.lang.Object implements java.io.Serializable, java.lang.ComparablePopulation for GP programs.- Since:
- 3.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static doubleDELTA
-
Constructor Summary
Constructors Constructor and Description GPPopulation()Default constructor, only for dynamic instantiation.GPPopulation(GPConfiguration a_config, int a_size)GPPopulation(GPPopulation a_pop)GPPopulation(GPPopulation a_pop, boolean a_keepPrograms)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddFittestProgram(IGPProgram a_toAdd)Adds a GP program to this Population.voidclear()Clears the list of programs.intcompareTo(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).voidcopyGPPrograms(GPPopulation a_pop)Sets the GPPrograms of the given population to this population.voidcreate(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.voidcreate(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.voidcreate(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.IGPProgramcreate(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.IGPProgramcreate(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)IGPProgramcreate(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.ListdetermineFittestChromosomes(int a_numberOfPrograms)Sorts the GPPrograms list and returns the fittest n GPPrograms in the population.IGPProgramdetermineFittestProgram()Determines the fittest GPProgram in the population (the one with the highest fitness value) and memorizes it.IGPProgramdetermineFittestProgramComputed()Determines the fittest GPProgram in the population, but only considers programs with already computed fitness value.booleanequals(java.lang.Object a_pop)The equals-method.floatgetFitnessRank(int a_index)float[]getFitnessRanks()GPConfigurationgetGPConfiguration()IGPProgramgetGPProgram(int a_index)IGPProgram[]getGPPrograms()java.lang.StringgetPersistentRepresentation()intgetPopSize()booleanisChanged()booleanisFirstEmpty()voidsetGPProgram(int a_index, IGPProgram a_program)Sets the given GPProgram at the given index in the list of GPProgram's.voidsetGPPrograms(GPPopulation a_pop)Sets the GPPrograms of the given population to this population.voidsetGPPrograms(IGPProgram[] a_progs)Sets the GPPrograms of the given array to this population.voidsetGPPrograms(java.util.List a_pop)Sets the GPPrograms of the given population to this population.intsize()voidsort(java.util.Comparator c)Sorts the population into "ascending" order using some criterion for "ascending".voidsortByFitness()Sorts the programs within the population according to their fitness value using GPProgramFitnessComparator.
-
-
-
Field Detail
-
DELTA
public static final double DELTA
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
GPPopulation
public GPPopulation() throws java.lang.ExceptionDefault constructor, only for dynamic instantiation.- Throws:
java.lang.Exception- Since:
- 3.3.4
-
GPPopulation
public GPPopulation(GPConfiguration a_config, int a_size) throws InvalidConfigurationException
- Throws:
InvalidConfigurationException
-
GPPopulation
public GPPopulation(GPPopulation a_pop) throws InvalidConfigurationException
- Throws:
InvalidConfigurationException
-
GPPopulation
public GPPopulation(GPPopulation a_pop, boolean a_keepPrograms) throws InvalidConfigurationException
- Parameters:
a_pop- the population to retrieve the parameters froma_keepPrograms- true copy programs of given population to this one- Throws:
InvalidConfigurationException
-
-
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 InvalidConfigurationExceptionCreates a population.- Parameters:
a_types- the type for each chromosome, the length of the array represents the number of chromosomesa_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 chromosomea_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 nodesa_minDepths- contains the minimum depth allowed for each chromosomea_maxDepths- contains the maximum depth allowed for each chromosomea_maxNodes- reserve space for a_maxNodes number of nodesa_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 InvalidConfigurationExceptionCreates a population.- Parameters:
a_types- the type for each chromosome, the length of the array represents the number of chromosomesa_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 chromosomea_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 nodesa_minDepths- contains the minimum depth allowed for each chromosomea_maxDepths- contains the maximum depth allowed for each chromosomea_maxNodes- reserve space for a_maxNodes number of nodesa_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 InvalidConfigurationExceptionCreates a population.- Parameters:
a_types- the type for each chromosome, the length of the array represents the number of chromosomesa_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 chromosomea_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 nodesa_minDepths- contains the minimum depth allowed for each chromosomea_maxDepths- contains the maximum depth allowed for each chromosomea_maxNodes- reserve space for a_maxNodes number of nodesa_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 witha_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- inta_grow- booleana_maxNodes- inta_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- inta_types- Class[]a_argTypes- Class[][]a_nodeSets- CommandGene[][]a_minDepths- int[]a_maxDepths- int[]a_depth- inta_grow- booleana_maxNodes- inta_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 populationa_types- the type of each chromosome, the length is the number of chromosomesa_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 chromosomea_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 nodesa_minDepths- contains the minimum depth allowed for each chromosomea_maxDepths- contains the maximum depth allowed for each chromosomea_depth- the maximum depth of the program to createa_grow- true: grow mode, false: full modea_maxNodes- reserve space for a_maxNodes number of nodesa_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 programa_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 ina_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:
compareToin interfacejava.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:
equalsin classjava.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