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 @Value.Immutable
14 public interface DeleteNLast extends ReplacementStrategy {
15
16 static final double DEFAULT_WEAK_RATIO = 0.05;
17
18
19
20
21
22
23 @Value.Default
24 @Value.Parameter
25 default double weakRatio() {
26 return DEFAULT_WEAK_RATIO;
27 }
28
29
30
31
32
33
34 @Value.Parameter
35 public abstract SelectionPolicy offspringSelectionPolicy();
36
37 @Value.Check
38 default void check() {
39 Validate.inclusiveBetween(0.0, 1.0, weakRatio());
40 }
41
42 class Builder extends ImmutableDeleteNLast.Builder {
43 }
44
45 static Builder builder() {
46 return new Builder();
47 }
48
49 static DeleteNLast of(final double weakRatio, final SelectionPolicy selectionPolicy) {
50 return builder().weakRatio(weakRatio).offspringSelectionPolicy(selectionPolicy).build();
51 }
52 }