Class GenerationalElitistReplacement<T>

java.lang.Object
org.cicirello.search.evo.GenerationalElitistReplacement<T>
Type Parameters:
T - the representation of population members
All Implemented Interfaces:
Splittable<ReplacementStrategy<T>>, ReplacementStrategy<T>

public final class GenerationalElitistReplacement<T> extends Object implements ReplacementStrategy<T>
GenerationalElitistReplacement keeps the k best-fit distinct members of the current population without application of evolutionary operators, and replaces the other (N-k) members of the population. This is similar to the classic replacement strategy of the simple genetic algorithm and other generational models, but with a few elite members of the population.

If the representation of the population members doesn't implement the Object.hashCode() and Object.equals(Object) methods, then this replacement strategy will still partially function with the exception of failing to maintain distinct elite members. All of the directly supported representations within the library implement those methods, so this caveat is primarily for any custom representations you may use.

  • Constructor Details

    • GenerationalElitistReplacement

      public GenerationalElitistReplacement()
      Constructs the replacement strategy. The default behavior is 1 elite population member.
    • GenerationalElitistReplacement

      public GenerationalElitistReplacement(int elite)
      Constructs the replacement strategy.
      Parameters:
      elite - the number of elite population members, which must be at least 1. This implementation sets elite to 1 if you pass a value less than 1.
  • Method Details

    • replace

      public void replace(PopulationCandidates.IntegerFitness<T> parentPopulation, PopulationCandidates.IntegerFitness<T> childPopulation, ReplacementStrategy.Replacements replacements, int targetPopulationSize)
      Description copied from interface: ReplacementStrategy
      Chooses the members of the population of the next generation from among those currently in the population and the pool of candidates formed from crossover and mutation. Implementations must not attempt to further manipulate the state of the individuals in these sets. Doing so can lead to undefined behavior.
      Specified by:
      replace in interface ReplacementStrategy<T>
      Parameters:
      parentPopulation - the current population
      childPopulation - the members of the population chosen by the selection operator which have already gone through crossover, mutation, both, or neither (based on crossover rates, mutation rates, etc)
      replacements - records which members of the parent and child populations serve as replacements
      targetPopulationSize - the size of the target population for the next generation. In most cases this will likely be the same as parentPopulation.size(). But, do not make that assumption in your implementation to allow less common EA structures where population size may vary
    • replace

      public void replace(PopulationCandidates.DoubleFitness<T> parentPopulation, PopulationCandidates.DoubleFitness<T> childPopulation, ReplacementStrategy.Replacements replacements, int targetPopulationSize)
      Description copied from interface: ReplacementStrategy
      Chooses the members of the population of the next generation from among those currently in the population and the pool of candidates formed from crossover and mutation. Implementations must not attempt to further manipulate the state of the individuals in these sets. Doing so can lead to undefined behavior.
      Specified by:
      replace in interface ReplacementStrategy<T>
      Parameters:
      parentPopulation - the current population
      childPopulation - the members of the population chosen by the selection operator which have already gone through crossover, mutation, both, or neither (based on crossover rates, mutation rates, etc)
      replacements - records which members of the parent and child populations serve as replacements
      targetPopulationSize - the size of the target population for the next generation. In most cases this will likely be the same as parentPopulation.size(). But, do not make that assumption in your implementation to allow less common EA structures where population size may vary
    • split

      Description copied from interface: Splittable
      Generates a functionally identical copy of this object, for use in multithreaded implementations of search algorithms. The state of the object that is returned may or may not be identical to that of the original. Thus, this is a distinct concept from the functionality of the Copyable interface. Classes that implement this interface must ensure that the object returned performs the same functionality, and that it does not share any state data that would be either unsafe or inefficient for concurrent access by multiple threads. The split method is allowed to simply return the this reference, provided that it is both safe and efficient for multiple threads to share a single copy of the Splittable object. The intention is to provide a multithreaded search with the capability to provide spawned threads with their own distinct search operators. Such multithreaded algorithms can call the split method for each thread it spawns to generate a functionally identical copy of the operator, but with independent state.
      Specified by:
      split in interface Splittable<T>
      Returns:
      A functionally identical copy of the object, or a reference to this if it is both safe and efficient for multiple threads to share a single instance of this Splittable object.