Package jme3utilities.math
Class Population<Fitness extends Comparable<Fitness>,Element>
java.lang.Object
jme3utilities.math.Population<Fitness,Element>
- Type Parameters:
Fitness- type of fitness score (such as Float or ScoreDoubles, must implement Comparable interfaceElement- type of elements collected (such as Solution)
A container for elements, sorted based on a measure of fitness. Duplicate
fitness scores are possible, but duplicate elements are suppressed.
-
Constructor Summary
ConstructorsConstructorDescriptionPopulation(int capacity) Instantiate a population with the specified capacity. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a single element to this population (unless it is a duplicate).voidAdd a list of elements (all with the same fitness score) to this population, excluding duplicates.Find the highest fitness score in this population.voidcull(int targetSize) Cull this population, based solely on fitness, until no more than the specified number of elements remain.fittest()Find the fittest (highest-scoring) element in this population.intRead the capacity of this population.Enumerate all elements in the population, in descending order.intmergeFittestTo(int maxCount, Population<Fitness, Element> destination) Merge the fittest elements into another population.intmergeSubsetTo(BitSet subset, Population<Fitness, Element> destination) Merge the specified subset of this population into another population.voidmergeTo(Population<Fitness, Element> destination) Merge all elements into another population.intmergeUniformTo(int maxCount, Generator generator, Population<Fitness, Element> destination) Merge a uniformly-distributed sample into another population.voidsetCapacity(int newCapacity) Alter the capacity of this container.intsize()Read the number of elements in this population.Find the lowest score in this population.
-
Constructor Details
-
Population
public Population(int capacity) Instantiate a population with the specified capacity.- Parameters:
capacity- maximum number of elements (>1)
-
-
Method Details
-
add
Add a single element to this population (unless it is a duplicate).- Parameters:
element- instance to add (not null)score- (may be null)
-
add
Add a list of elements (all with the same fitness score) to this population, excluding duplicates.- Parameters:
addList- list of elements to add (not null, all elements non-null)score- (may be null)
-
bestScore
Find the highest fitness score in this population.- Returns:
- the pre-existing instance or null
- See Also:
-
cull
public void cull(int targetSize) Cull this population, based solely on fitness, until no more than the specified number of elements remain.- Parameters:
targetSize- target number of elements (≥0)
-
fittest
Find the fittest (highest-scoring) element in this population.- Returns:
- the pre-existing instance or null if none
-
getCapacity
public int getCapacity()Read the capacity of this population.- Returns:
- number of elements (>0)
- See Also:
-
listElements
Enumerate all elements in the population, in descending order.- Returns:
- a new list of elements
-
mergeFittestTo
Merge the fittest elements into another population.- Parameters:
maxCount- maximum number of elements to merge (≥0)destination- population to merge into (not null, modified)- Returns:
- the number of elements merged (≥0, ≤maxCount)
-
mergeSubsetTo
Merge the specified subset of this population into another population.- Parameters:
subset- set bits specify which elements to merge, bit 0 indicating the least fit element (not null, unaffected)destination- population to merge into (not null, modified)- Returns:
- count of elements merged (≥0, ≤maxCount)
-
mergeTo
Merge all elements into another population.- Parameters:
destination- population to merge into (not null, modified)
-
mergeUniformTo
public int mergeUniformTo(int maxCount, Generator generator, Population<Fitness, Element> destination) Merge a uniformly-distributed sample into another population.- Parameters:
maxCount- maximum number of elements to merge (≥0)generator- pseudo-random generator to use (not null)destination- (not null, modified)- Returns:
- count of elements merged (≥0, ≤maxCount)
-
setCapacity
public void setCapacity(int newCapacity) Alter the capacity of this container.- Parameters:
newCapacity- number of elements (>0)- See Also:
-
size
public int size()Read the number of elements in this population.- Returns:
- count of elements (≥0)
- See Also:
-
worstScore
Find the lowest score in this population.- Returns:
- the pre-existing instance or null
- See Also:
-