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 interface
Element - type of elements collected (such as Solution)

public class Population<Fitness extends Comparable<Fitness>,Element> extends Object
A container for elements, sorted based on a measure of fitness. Duplicate fitness scores are possible, but duplicate elements are suppressed.
  • Constructor Details

    • Population

      public Population(int capacity)
      Instantiate a population with the specified capacity.
      Parameters:
      capacity - maximum number of elements (>1)
  • Method Details

    • add

      public void add(Element element, Fitness score)
      Add a single element to this population (unless it is a duplicate).
      Parameters:
      element - instance to add (not null)
      score - (may be null)
    • add

      public void add(List<Element> addList, Fitness score)
      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

      public Fitness 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

      public Element 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

      public List<Element> listElements()
      Enumerate all elements in the population, in descending order.
      Returns:
      a new list of elements
    • mergeFittestTo

      public int mergeFittestTo(int maxCount, Population<Fitness,Element> destination)
      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

      public int mergeSubsetTo(BitSet subset, Population<Fitness,Element> destination)
      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

      public void mergeTo(Population<Fitness,Element> destination)
      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

      public Fitness worstScore()
      Find the lowest score in this population.
      Returns:
      the pre-existing instance or null
      See Also: