Class GenerationalReplacement<T>

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

public final class GenerationalReplacement<T> extends Object implements ReplacementStrategy<T>
Generational replacement replaces the entire population each generation. This is the classic replacement strategy of the simple genetic algorithm and other generational models.
  • Constructor Details

    • GenerationalReplacement

      public GenerationalReplacement()
      Constructs the replacement strategy.
  • 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

      public ReplacementStrategy<T> 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.