Package ec
Class Subpopulation
java.lang.Object
ec.Subpopulation
- All Implemented Interfaces:
Setup,Serializable,Cloneable
- Direct Known Subclasses:
Spatial1DSubpopulation
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.subpop
Parameter bases
| base.species | species (the subpopulations' species) |
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionintWhat is our fill behavior beyond files?static final intstatic final StringThe subpopulation's individuals.intinitial expected size of the subpopulationbooleanstatic final StringintDo we allow duplicates?static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringThe species for individuals in this subpopulation.static final intstatic final Stringstatic final Stringstatic final Stringstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Sets all Individuals in the Subpopulation to null, preparing it to be reused.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.final voidprintSubpopulation(EvolutionState state, int log, int verbosity) Prints an entire subpopulation in a form readable by humans but also parseable by the computer using readSubpopulation(EvolutionState, LineNumberReader).voidprintSubpopulation(EvolutionState state, 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) final voidprintSubpopulationForHumans(EvolutionState state, int log, int verbosity) Prints an entire subpopulation in a form readable by humans.voidreadSubpopulation(EvolutionState state, DataInput dataInput) Reads a subpopulation in binary form, from the format generated by writeSubpopulation(...).voidreadSubpopulation(EvolutionState state, 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.voidtruncate(int toThis) Truncates the Subpopulation to a new size.voidwriteSubpopulation(EvolutionState state, DataOutput dataOutput) Writes a subpopulation in binary form, in a format readable by readSubpopulation(EvolutionState, DataInput).
-
Field Details
-
loadInds
public boolean loadInds -
file
-
species
The species for individuals in this subpopulation. -
individuals
The subpopulation's individuals. -
initialSize
public int initialSizeinitial expected size of the subpopulation -
numDuplicateRetries
public int numDuplicateRetriesDo we allow duplicates? -
extraBehavior
public int extraBehaviorWhat is our fill behavior beyond files? -
P_SUBPOPULATION
- See Also:
-
P_FILE
- See Also:
-
P_SUBPOPSIZE
- See Also:
-
P_SPECIES
- See Also:
-
P_RETRIES
- See Also:
-
P_EXTRA_BEHAVIOR
- See Also:
-
V_TRUNCATE
- See Also:
-
V_WRAP
- See Also:
-
V_FILL
- See Also:
-
NUM_INDIVIDUALS_PREAMBLE
- See Also:
-
INDIVIDUAL_INDEX_PREAMBLE
- See Also:
-
TRUNCATE
public static final int TRUNCATE- See Also:
-
WRAP
public static final int WRAP- See Also:
-
FILL
public static final int FILL- See Also:
-
-
Constructor Details
-
Subpopulation
public Subpopulation()
-
-
Method Details
-
defaultBase
-
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. -
truncate
public void truncate(int toThis) Truncates the Subpopulation to a new size. The Subpopulation is truncated such that the higher indexed individuals may be deleted. -
clear
public void clear()Sets all Individuals in the Subpopulation to null, preparing it to be reused. -
setup
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
-
printSubpopulationForHumans
Prints an entire subpopulation in a form readable by humans. -
printSubpopulation
Prints an entire subpopulation in a form readable by humans but also parseable by the computer using readSubpopulation(EvolutionState, LineNumberReader). -
printSubpopulationForHumans
-
printSubpopulation
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
Prints an entire subpopulation in a form readable by humans but also parseable by the computer using readSubpopulation(EvolutionState, LineNumberReader). -
readSubpopulation
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:
IOException
-
writeSubpopulation
Writes a subpopulation in binary form, in a format readable by readSubpopulation(EvolutionState, DataInput).- Throws:
IOException
-
readSubpopulation
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:
IOException
-