ec
Class Subpopulation
- java.lang.Object
-
- ec.Subpopulation
-
- Direct Known Subclasses:
- Spatial1DSubpopulation
public class Subpopulation extends java.lang.Object implements Group
Subpopulation is a group which is basically an array of Individuals. There is always one or more Subpopulations in the Population. Each Subpopulation has a Species, which governs the formation of the Individuals in that Subpopulation. Subpopulations also contain a Fitness prototype which is cloned to form Fitness objects for individuals in the subpopulation.An initial subpopulation is populated with new random individuals using the populate(...) method. This method typically populates by filling the array with individuals created using the Subpopulations' species' emptyClone() method, though you might override this to create them with other means, by loading from text files for example.
In a multithreaded area of a run, Subpopulations should be considered immutable. That is, once they are created, they should not be modified, nor anything they contain. This protocol helps ensure read-safety under multithreading race conditions.
Parameters
base.size
int >= 1(total number of individuals in the subpopulation) base.species
classname, inherits and != ec.Species(the class of the subpopulations' Species) base.fitness
classname, inherits and != ec.Fitness(the class for the prototypical Fitness for individuals in this subpopulation) base.file
String(pathname of file from which the population is to be loaded. If not defined, or empty, then the population will be initialized at random in the standard manner) base.duplicate-retries
int >= 0(during initialization, when we produce an individual which already exists in the subpopulation, the number of times we try to replace it with something unique. Ignored if we're loading from a file.) Default Base
ec.subpopParameter bases
base.species species (the subpopulations' species) - See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description intextraBehaviorWhat is our fill behavior beyond files?Parameterfilestatic intFILLstatic java.lang.StringINDIVIDUAL_INDEX_PREAMBLEIndividual[]individualsThe subpopulation's individuals.booleanloadIndsstatic java.lang.StringNUM_INDIVIDUALS_PREAMBLEintnumDuplicateRetriesDo we allow duplicates?static java.lang.StringP_EXTRA_BEHAVIORstatic java.lang.StringP_FILEstatic java.lang.StringP_RETRIESstatic java.lang.StringP_SPECIESstatic java.lang.StringP_SUBPOPSIZEstatic java.lang.StringP_SUBPOPULATIONSpeciesspeciesThe species for individuals in this subpopulation.static intTRUNCATEstatic java.lang.StringV_FILLstatic java.lang.StringV_TRUNCATEstatic java.lang.StringV_WRAPstatic intWRAP
-
Constructor Summary
Constructors Constructor and Description Subpopulation()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description voidclear()Sets all Individuals in the Subpopulation to null, preparing it to be reused.ParameterdefaultBase()GroupemptyClone()Returns an instance of Subpopulation just like it had been before it was populated with individuals.voidpopulate(EvolutionState state, int thread)voidprintSubpopulation(EvolutionState state, int log)Prints an entire subpopulation in a form readable by humans but also parseable by the computer using readSubpopulation(EvolutionState, LineNumberReader) with a verbosity of Output.V_NO_GENERAL.voidprintSubpopulation(EvolutionState state, int log, int verbosity)Deprecated.Verbosity no longer has meaningvoidprintSubpopulation(EvolutionState state, java.io.PrintWriter writer)Prints an entire subpopulation in a form readable by humans but also parseable by the computer using readSubpopulation(EvolutionState, LineNumberReader).voidprintSubpopulationForHumans(EvolutionState state, int log)Prints an entire subpopulation in a form readable by humans, with a verbosity of Output.V_NO_GENERAL.voidprintSubpopulationForHumans(EvolutionState state, int log, int verbosity)Deprecated.Verbosity no longer has meaningvoidreadSubpopulation(EvolutionState state, java.io.DataInput dataInput)Reads a subpopulation in binary form, from the format generated by writeSubpopulation(...).voidreadSubpopulation(EvolutionState state, java.io.LineNumberReader reader)Reads a subpopulation from the format generated by printSubpopulation(....).voidsetup(EvolutionState state, Parameter base)Sets up the object by reading it from the parameters stored in state, built off of the parameter base base.voidwriteSubpopulation(EvolutionState state, java.io.DataOutput dataOutput)Writes a subpopulation in binary form, in a format readable by readSubpopulation(EvolutionState, DataInput).
-
-
-
Field Detail
-
loadInds
public boolean loadInds
-
file
public Parameter file
-
species
public Species species
The species for individuals in this subpopulation.
-
individuals
public Individual[] individuals
The subpopulation's individuals.
-
numDuplicateRetries
public int numDuplicateRetries
Do we allow duplicates?
-
extraBehavior
public int extraBehavior
What is our fill behavior beyond files?
-
P_SUBPOPULATION
public static final java.lang.String P_SUBPOPULATION
- See Also:
- Constant Field Values
-
P_FILE
public static final java.lang.String P_FILE
- See Also:
- Constant Field Values
-
P_SUBPOPSIZE
public static final java.lang.String P_SUBPOPSIZE
- See Also:
- Constant Field Values
-
P_SPECIES
public static final java.lang.String P_SPECIES
- See Also:
- Constant Field Values
-
P_RETRIES
public static final java.lang.String P_RETRIES
- See Also:
- Constant Field Values
-
P_EXTRA_BEHAVIOR
public static final java.lang.String P_EXTRA_BEHAVIOR
- See Also:
- Constant Field Values
-
V_TRUNCATE
public static final java.lang.String V_TRUNCATE
- See Also:
- Constant Field Values
-
V_WRAP
public static final java.lang.String V_WRAP
- See Also:
- Constant Field Values
-
V_FILL
public static final java.lang.String V_FILL
- See Also:
- Constant Field Values
-
NUM_INDIVIDUALS_PREAMBLE
public static final java.lang.String NUM_INDIVIDUALS_PREAMBLE
- See Also:
- Constant Field Values
-
INDIVIDUAL_INDEX_PREAMBLE
public static final java.lang.String INDIVIDUAL_INDEX_PREAMBLE
- See Also:
- Constant Field Values
-
TRUNCATE
public static final int TRUNCATE
- See Also:
- Constant Field Values
-
WRAP
public static final int WRAP
- See Also:
- Constant Field Values
-
FILL
public static final int FILL
- See Also:
- Constant Field Values
-
-
Method Detail
-
defaultBase
public Parameter defaultBase()
-
emptyClone
public Group emptyClone()
Returns an instance of Subpopulation just like it had been before it was populated with individuals. You may need to override this if you override Subpopulation. IMPORTANT NOTE: if the size of the array in Subpopulation has been changed, then the clone will take on the new array size. This helps some evolution strategies.- Specified by:
emptyClonein interfaceGroup- See Also:
Group.emptyClone()
-
clear
public void clear()
Sets all Individuals in the Subpopulation to null, preparing it to be reused.
-
setup
public void setup(EvolutionState state, Parameter base)
Description copied from interface:SetupSets up the object by reading it from the parameters stored in state, built off of the parameter base base. If an ancestor implements this method, be sure to call super.setup(state,base); before you do anything else.
-
populate
public void populate(EvolutionState state, int thread)
-
printSubpopulationForHumans
public final void printSubpopulationForHumans(EvolutionState state, int log, int verbosity)
Deprecated. Verbosity no longer has meaningPrints an entire subpopulation in a form readable by humans.
-
printSubpopulation
public final void printSubpopulation(EvolutionState state, int log, int verbosity)
Deprecated. Verbosity no longer has meaningPrints an entire subpopulation in a form readable by humans but also parseable by the computer using readSubpopulation(EvolutionState, LineNumberReader).
-
printSubpopulationForHumans
public void printSubpopulationForHumans(EvolutionState state, int log)
Prints an entire subpopulation in a form readable by humans, with a verbosity of Output.V_NO_GENERAL.
-
printSubpopulation
public void printSubpopulation(EvolutionState state, int log)
Prints an entire subpopulation in a form readable by humans but also parseable by the computer using readSubpopulation(EvolutionState, LineNumberReader) with a verbosity of Output.V_NO_GENERAL.
-
printSubpopulation
public void printSubpopulation(EvolutionState state, java.io.PrintWriter writer)
Prints an entire subpopulation in a form readable by humans but also parseable by the computer using readSubpopulation(EvolutionState, LineNumberReader).
-
readSubpopulation
public void readSubpopulation(EvolutionState state, java.io.LineNumberReader reader) throws java.io.IOException
Reads a subpopulation from the format generated by printSubpopulation(....). If the number of individuals is not identical, the individuals array will be deleted and replaced with a new array, and a warning will be generated as individuals will have to be created using newIndividual(...) rather than readIndividual(...).- Throws:
java.io.IOException
-
writeSubpopulation
public void writeSubpopulation(EvolutionState state, java.io.DataOutput dataOutput) throws java.io.IOException
Writes a subpopulation in binary form, in a format readable by readSubpopulation(EvolutionState, DataInput).- Throws:
java.io.IOException
-
readSubpopulation
public void readSubpopulation(EvolutionState state, java.io.DataInput dataInput) throws java.io.IOException
Reads a subpopulation in binary form, from the format generated by writeSubpopulation(...). If the number of individuals is not identical, the individuals array will be deleted and replaced with a new array, and a warning will be generated as individuals will have to be created using newIndividual(...) rather than readIndividual(...)- Throws:
java.io.IOException
-
-
DMelt 3.0 © DataMelt by jWork.ORG