| 1 | package net.bmahe.genetics4j.core.spec.replacement; | |
| 2 | ||
| 3 | import org.apache.commons.lang3.Validate; | |
| 4 | import org.immutables.value.Value; | |
| 5 | ||
| 6 | import net.bmahe.genetics4j.core.spec.selection.SelectionPolicy; | |
| 7 | ||
| 8 | /** | |
| 9 | * Specify an elitism based replacement strategy | |
| 10 | * <p>Elitism will retain the best individuals of both offsprings and survivors of the previous generation. | |
| 11 | */ | |
| 12 | @Value.Immutable | |
| 13 | public interface Elitism extends ReplacementStrategy { | |
| 14 | static final double DEFAULT_OFFSPRING_RATIO = 0.99; | |
| 15 | ||
| 16 | static final int DEFAULT_AT_LEAST_NUM_OFFSPRINGS = 0; | |
| 17 | static final int DEFAULT_AT_LEAST_NUM_SURVIVORS = 1; | |
| 18 | ||
| 19 | /** | |
| 20 | * {@return the policy used to select offsprings for the next generation} | |
| 21 | */ | |
| 22 | SelectionPolicy offspringSelectionPolicy(); | |
| 23 | ||
| 24 | /** | |
| 25 | * {@return how many offsprings that elitism will always select} | |
| 26 | */ | |
| 27 | @Value.Default | |
| 28 | default int atLeastNumOffsprings() { | |
| 29 |
1
1. atLeastNumOffsprings : Substituted 0 with 1 → SURVIVED |
return DEFAULT_AT_LEAST_NUM_OFFSPRINGS; |
| 30 | } | |
| 31 | ||
| 32 | /** | |
| 33 | * {@return the policy used to select survivors for the next generation} | |
| 34 | */ | |
| 35 | SelectionPolicy survivorSelectionPolicy(); | |
| 36 | ||
| 37 | /** | |
| 38 | * {@return how many survivors that elitism will always select} | |
| 39 | */ | |
| 40 | @Value.Default | |
| 41 | default int atLeastNumSurvivors() { | |
| 42 |
2
1. atLeastNumSurvivors : Substituted 1 with 0 → SURVIVED 2. atLeastNumSurvivors : replaced int return with 0 for net/bmahe/genetics4j/core/spec/replacement/Elitism::atLeastNumSurvivors → SURVIVED |
return DEFAULT_AT_LEAST_NUM_SURVIVORS; |
| 43 | } | |
| 44 | ||
| 45 | /** | |
| 46 | * {@return how many children will be generated at each iteration. Value must be between 0 and 1 (inclusive) | |
| 47 | * <p>The number of survivor will be the complement of it, or 1 - offspringRatio()} | |
| 48 | */ | |
| 49 | @Value.Default | |
| 50 | default double offspringRatio() { | |
| 51 |
2
1. offspringRatio : replaced double return with 0.0d for net/bmahe/genetics4j/core/spec/replacement/Elitism::offspringRatio → NO_COVERAGE 2. offspringRatio : Substituted 0.99 with 1.0 → NO_COVERAGE |
return DEFAULT_OFFSPRING_RATIO; |
| 52 | } | |
| 53 | ||
| 54 | @Value.Check | |
| 55 | default void check() { | |
| 56 | Validate.inclusiveBetween(0.0, 1.0, offspringRatio()); | |
| 57 | Validate.isTrue(atLeastNumOffsprings() >= 0); | |
| 58 | Validate.isTrue(atLeastNumSurvivors() >= 0); | |
| 59 | } | |
| 60 | ||
| 61 | class Builder extends ImmutableElitism.Builder { | |
| 62 | } | |
| 63 | ||
| 64 | public static Builder builder() { | |
| 65 |
2
1. builder : removed call to net/bmahe/genetics4j/core/spec/replacement/Elitism$Builder::<init> → KILLED 2. builder : replaced return value with null for net/bmahe/genetics4j/core/spec/replacement/Elitism::builder → KILLED |
return new Builder(); |
| 66 | } | |
| 67 | } | |
Mutations | ||
| 29 |
1.1 |
|
| 42 |
1.1 2.2 |
|
| 51 |
1.1 2.2 |
|
| 65 |
1.1 2.2 |