Package edu.cnu.mdi.sim.ga.triimage
Class ElitistReplacement<C extends GASolution<C>>
java.lang.Object
edu.cnu.mdi.sim.ga.triimage.ElitistReplacement<C>
- All Implemented Interfaces:
ReplacementOperator<C>
public final class ElitistReplacement<C extends GASolution<C>>
extends Object
implements ReplacementOperator<C>
Elitist replacement operator for genetic algorithms. This operator preserves a specified number of the best
individuals (eliteCount) from the current population and fills the rest of the next generation with offspring.
The elite individuals are selected based on their fitness, ensuring that the best solutions are retained across
generations.
-
Constructor Summary
ConstructorsConstructorDescriptionElitistReplacement(int eliteCount) Create an elitist replacement operator with the given number of elite individuals to preserve. -
Method Summary
Modifier and TypeMethodDescriptionintoffspringCount(int populationSize) Return the number of offspring required to form a population of the given size.replace(List<C> population, List<C> offspring, double[] popFitness, double[] offFitness, Random rng) Form the next generation from the current population and its offspring.
-
Constructor Details
-
ElitistReplacement
public ElitistReplacement(int eliteCount) Create an elitist replacement operator with the given number of elite individuals to preserve.- Parameters:
eliteCount- the number of best individuals to preserve from the current population
-
-
Method Details
-
offspringCount
public int offspringCount(int populationSize) Description copied from interface:ReplacementOperatorReturn the number of offspring required to form a population of the given size. Replacement policies that retain current individuals may request fewer offspring.- Specified by:
offspringCountin interfaceReplacementOperator<C extends GASolution<C>>- Parameters:
populationSize- current population size- Returns:
- required offspring count in
[0, populationSize]
-
replace
public List<C> replace(List<C> population, List<C> offspring, double[] popFitness, double[] offFitness, Random rng) Description copied from interface:ReplacementOperatorForm the next generation from the current population and its offspring. Fitness arrays are aligned with their corresponding lists. The returned ordering is unrestricted, but its size must equal the current population.- Specified by:
replacein interfaceReplacementOperator<C extends GASolution<C>>- Parameters:
population- current populationoffspring- newly created offspringpopFitness- current-population fitness valuesoffFitness- offspring fitness valuesrng- source of randomness- Returns:
- complete next generation
-