1 | package net.bmahe.genetics4j.moo.nsga2.spec; | |
2 | ||
3 | import java.util.Comparator; | |
4 | import java.util.Optional; | |
5 | import java.util.function.Function; | |
6 | ||
7 | import org.immutables.value.Value; | |
8 | ||
9 | import net.bmahe.genetics4j.core.Genotype; | |
10 | import net.bmahe.genetics4j.core.spec.selection.SelectionPolicy; | |
11 | import net.bmahe.genetics4j.moo.FitnessVector; | |
12 | import net.bmahe.genetics4j.moo.ObjectiveDistance; | |
13 | ||
14 | /** | |
15 | * NSGA2 Selection specification | |
16 | * <p> | |
17 | * Select individuals based on their NSGA2 score, going from the most dominating | |
18 | * ones to the lesser ones | |
19 | * | |
20 | * @param <T> Type of the fitness measurement | |
21 | */ | |
22 | @Value.Immutable | |
23 | public abstract class NSGA2Selection<T extends Comparable<T>> implements SelectionPolicy { | |
24 | ||
25 | /** | |
26 | * Number of objectives | |
27 | * | |
28 | * @return | |
29 | */ | |
30 | @Value.Parameter | |
31 | public abstract int numberObjectives(); | |
32 | ||
33 | /** | |
34 | * Override the dominance operator. | |
35 | * <p> | |
36 | * If not specified, it assumes the default comparator conforms to the Pareto | |
37 | * dominance relation | |
38 | * | |
39 | * @return | |
40 | */ | |
41 | @Value.Default | |
42 | public Comparator<T> dominance() { | |
43 |
3
1. lambda$dominance$0 : replaced int return with 0 for net/bmahe/genetics4j/moo/nsga2/spec/NSGA2Selection::lambda$dominance$0 → KILLED 2. dominance : replaced return value with null for net/bmahe/genetics4j/moo/nsga2/spec/NSGA2Selection::dominance → KILLED 3. lambda$dominance$0 : removed call to java/lang/Comparable::compareTo → KILLED |
return (a, b) -> a.compareTo(b); |
44 | } | |
45 | ||
46 | /** | |
47 | * Comparator used for deduplication of solution prior to processing | |
48 | * <p> | |
49 | * If not specified, it defaults to not do any deduplication | |
50 | * | |
51 | * @return | |
52 | */ | |
53 | @Value.Default | |
54 | public Optional<Comparator<Genotype>> deduplicate() { | |
55 |
1
1. deduplicate : removed call to java/util/Optional::empty → KILLED |
return Optional.empty(); |
56 | } | |
57 | ||
58 | /** | |
59 | * Sort T based on the objective passed as a parameter | |
60 | * | |
61 | * @return | |
62 | */ | |
63 | @Value.Parameter | |
64 | public abstract Function<Integer, Comparator<T>> objectiveComparator(); | |
65 | ||
66 | /** | |
67 | * Define how to compute distances between fitness scores along their objectives | |
68 | * | |
69 | * @return Distance computation method | |
70 | */ | |
71 | @Value.Parameter | |
72 | public abstract ObjectiveDistance<T> distance(); | |
73 | ||
74 | public static class Builder<T extends Comparable<T>> extends ImmutableNSGA2Selection.Builder<T> { | |
75 | } | |
76 | ||
77 | public static <U extends Comparable<U>> Builder<U> builder() { | |
78 |
2
1. builder : removed call to net/bmahe/genetics4j/moo/nsga2/spec/NSGA2Selection$Builder::<init> → KILLED 2. builder : replaced return value with null for net/bmahe/genetics4j/moo/nsga2/spec/NSGA2Selection::builder → KILLED |
return new Builder<U>(); |
79 | } | |
80 | ||
81 | /** | |
82 | * Factory method to instantiate a NSGA2Selection when fitness is defined as a | |
83 | * FitnessVector of a Number | |
84 | * | |
85 | * @param <U> Type of the fitness measurement | |
86 | * @param numberObjectives Number of objectives and dimensions of the | |
87 | * FitnessVector | |
88 | * @param deduplicate Deduplicator comparator. Null value with disable | |
89 | * deduplication | |
90 | * @return A new instance of NSGA2Selection | |
91 | */ | |
92 | public static <U extends Number & Comparable<U>> NSGA2Selection<FitnessVector<U>> | |
93 | ofFitnessVector(final int numberObjectives, final Comparator<Genotype> deduplicate) { | |
94 | ||
95 |
1
1. ofFitnessVector : removed call to net/bmahe/genetics4j/moo/nsga2/spec/NSGA2Selection$Builder::<init> → NO_COVERAGE |
final var builder = new Builder<FitnessVector<U>>(); |
96 | ||
97 |
11
1. ofFitnessVector : replaced call to net/bmahe/genetics4j/moo/nsga2/spec/NSGA2Selection$Builder::objectiveComparator with receiver → NO_COVERAGE 2. lambda$ofFitnessVector$1 : replaced int return with 0 for net/bmahe/genetics4j/moo/nsga2/spec/NSGA2Selection::lambda$ofFitnessVector$1 → NO_COVERAGE 3. lambda$ofFitnessVector$1 : removed call to java/lang/Number::doubleValue → NO_COVERAGE 4. lambda$ofFitnessVector$1 : removed call to net/bmahe/genetics4j/moo/FitnessVector::get → NO_COVERAGE 5. lambda$ofFitnessVector$1 : removed call to java/lang/Number::doubleValue → NO_COVERAGE 6. lambda$ofFitnessVector$1 : removed call to net/bmahe/genetics4j/moo/FitnessVector::get → NO_COVERAGE 7. lambda$ofFitnessVector$1 : removed call to java/lang/Double::compare → NO_COVERAGE 8. lambda$ofFitnessVector$1 : removed call to java/lang/Integer::intValue → NO_COVERAGE 9. lambda$ofFitnessVector$2 : replaced return value with null for net/bmahe/genetics4j/moo/nsga2/spec/NSGA2Selection::lambda$ofFitnessVector$2 → NO_COVERAGE 10. lambda$ofFitnessVector$1 : removed call to java/lang/Integer::intValue → NO_COVERAGE 11. ofFitnessVector : removed call to net/bmahe/genetics4j/moo/nsga2/spec/NSGA2Selection$Builder::objectiveComparator → NO_COVERAGE |
builder.objectiveComparator((m) -> (a, b) -> Double.compare(a.get(m).doubleValue(), b.get(m).doubleValue())) |
98 |
10
1. lambda$ofFitnessVector$3 : removed call to java/lang/Math::abs → NO_COVERAGE 2. lambda$ofFitnessVector$3 : removed call to java/lang/Number::doubleValue → NO_COVERAGE 3. lambda$ofFitnessVector$3 : replaced double return with 0.0d for net/bmahe/genetics4j/moo/nsga2/spec/NSGA2Selection::lambda$ofFitnessVector$3 → NO_COVERAGE 4. ofFitnessVector : replaced call to net/bmahe/genetics4j/moo/nsga2/spec/NSGA2Selection$Builder::distance with receiver → NO_COVERAGE 5. lambda$ofFitnessVector$3 : removed call to net/bmahe/genetics4j/moo/FitnessVector::get → NO_COVERAGE 6. ofFitnessVector : removed call to net/bmahe/genetics4j/moo/nsga2/spec/NSGA2Selection$Builder::distance → NO_COVERAGE 7. lambda$ofFitnessVector$3 : removed call to java/lang/Number::doubleValue → NO_COVERAGE 8. lambda$ofFitnessVector$3 : removed call to net/bmahe/genetics4j/moo/FitnessVector::get → NO_COVERAGE 9. lambda$ofFitnessVector$3 : Replaced double subtraction with addition → NO_COVERAGE 10. lambda$ofFitnessVector$3 : replaced call to java/lang/Math::abs with argument → NO_COVERAGE |
.distance((a, b, m) -> Math.abs(b.get(m).doubleValue() - a.get(m).doubleValue())) |
99 |
2
1. ofFitnessVector : replaced call to net/bmahe/genetics4j/moo/nsga2/spec/NSGA2Selection$Builder::numberObjectives with receiver → NO_COVERAGE 2. ofFitnessVector : removed call to net/bmahe/genetics4j/moo/nsga2/spec/NSGA2Selection$Builder::numberObjectives → NO_COVERAGE |
.numberObjectives(numberObjectives) |
100 |
3
1. ofFitnessVector : removed call to net/bmahe/genetics4j/moo/nsga2/spec/NSGA2Selection$Builder::deduplicate → NO_COVERAGE 2. ofFitnessVector : replaced call to net/bmahe/genetics4j/moo/nsga2/spec/NSGA2Selection$Builder::deduplicate with receiver → NO_COVERAGE 3. ofFitnessVector : removed call to java/util/Optional::ofNullable → NO_COVERAGE |
.deduplicate(Optional.ofNullable(deduplicate)); |
101 | ||
102 |
2
1. ofFitnessVector : replaced return value with null for net/bmahe/genetics4j/moo/nsga2/spec/NSGA2Selection::ofFitnessVector → NO_COVERAGE 2. ofFitnessVector : removed call to net/bmahe/genetics4j/moo/nsga2/spec/NSGA2Selection$Builder::build → NO_COVERAGE |
return builder.build(); |
103 | } | |
104 | ||
105 | /** | |
106 | * Factory method to instantiate a NSGA2Selection when fitness is defined as a | |
107 | * FitnessVector of a Number | |
108 | * | |
109 | * @param <U> Type of the fitness measurement | |
110 | * @param numberObjectives Number of objectives and dimensions of the | |
111 | * FitnessVector | |
112 | * @return A new instance of NSGA2Selection | |
113 | */ | |
114 | public static <U extends Number & Comparable<U>> NSGA2Selection<FitnessVector<U>> | |
115 | ofFitnessVector(final int numberObjectives) { | |
116 | ||
117 |
2
1. ofFitnessVector : removed call to net/bmahe/genetics4j/moo/nsga2/spec/NSGA2Selection::ofFitnessVector → NO_COVERAGE 2. ofFitnessVector : replaced return value with null for net/bmahe/genetics4j/moo/nsga2/spec/NSGA2Selection::ofFitnessVector → NO_COVERAGE |
return ofFitnessVector(numberObjectives, null); |
118 | } | |
119 | } | |
Mutations | ||
43 |
1.1 2.2 3.3 |
|
55 |
1.1 |
|
78 |
1.1 2.2 |
|
95 |
1.1 |
|
97 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 11.11 |
|
98 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 |
|
99 |
1.1 2.2 |
|
100 |
1.1 2.2 3.3 |
|
102 |
1.1 2.2 |
|
117 |
1.1 2.2 |