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
10
11
12
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
23
24 SelectionPolicy offspringSelectionPolicy();
25
26
27
28
29 @Value.Default
30 default int atLeastNumOffsprings() {
31 return DEFAULT_AT_LEAST_NUM_OFFSPRINGS;
32 }
33
34
35
36
37 SelectionPolicy survivorSelectionPolicy();
38
39
40
41
42 @Value.Default
43 default int atLeastNumSurvivors() {
44 return DEFAULT_AT_LEAST_NUM_SURVIVORS;
45 }
46
47
48
49
50
51
52
53 @Value.Default
54 default double offspringRatio() {
55 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 return new Builder();
70 }
71 }