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> | |
11 | * Elitism will retain the best individuals of both offsprings and survivors of | |
12 | * the previous generation. | |
13 | */ | |
14 | @Value.Immutable | |
15 | public interface Elitism extends ReplacementStrategy { | |
16 | static final double DEFAULT_OFFSPRING_RATIO = 0.99; | |
17 | ||
18 | static final int DEFAULT_AT_LEAST_NUM_OFFSPRINGS = 0; | |
19 | static final int DEFAULT_AT_LEAST_NUM_SURVIVORS = 1; | |
20 | ||
21 | /** | |
22 | * {@return the policy used to select offsprings for the next generation} | |
23 | */ | |
24 | SelectionPolicy offspringSelectionPolicy(); | |
25 | ||
26 | /** | |
27 | * {@return how many offsprings that elitism will always select} | |
28 | */ | |
29 | @Value.Default | |
30 | default int atLeastNumOffsprings() { | |
31 |
1
1. atLeastNumOffsprings : Substituted 0 with 1 → SURVIVED |
return DEFAULT_AT_LEAST_NUM_OFFSPRINGS; |
32 | } | |
33 | ||
34 | /** | |
35 | * {@return the policy used to select survivors for the next generation} | |
36 | */ | |
37 | SelectionPolicy survivorSelectionPolicy(); | |
38 | ||
39 | /** | |
40 | * {@return how many survivors that elitism will always select} | |
41 | */ | |
42 | @Value.Default | |
43 | default int atLeastNumSurvivors() { | |
44 |
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; |
45 | } | |
46 | ||
47 | /** | |
48 | * {@return how many children will be generated at each iteration. Value | |
49 | * must be between 0 and 1 (inclusive) | |
50 | * <p> | |
51 | * The number of survivor will be the complement of it, or 1 - offspringRatio()} | |
52 | */ | |
53 | @Value.Default | |
54 | default double offspringRatio() { | |
55 |
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; |
56 | } | |
57 | ||
58 | @Value.Check | |
59 | default void check() { | |
60 | Validate.inclusiveBetween(0.0, 1.0, offspringRatio()); | |
61 | Validate.isTrue(atLeastNumOffsprings() >= 0); | |
62 | Validate.isTrue(atLeastNumSurvivors() >= 0); | |
63 | } | |
64 | ||
65 | class Builder extends ImmutableElitism.Builder { | |
66 | } | |
67 | ||
68 | public static Builder builder() { | |
69 |
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(); |
70 | } | |
71 | } | |
Mutations | ||
31 |
1.1 |
|
44 |
1.1 2.2 |
|
55 |
1.1 2.2 |
|
69 |
1.1 2.2 |