1 | package net.bmahe.genetics4j.moo.spea2.spec.replacement; | |
2 | ||
3 | import java.util.Comparator; | |
4 | import java.util.Optional; | |
5 | import java.util.function.BiFunction; | |
6 | ||
7 | import org.immutables.value.Value; | |
8 | ||
9 | import net.bmahe.genetics4j.core.Genotype; | |
10 | import net.bmahe.genetics4j.core.spec.replacement.ReplacementStrategy; | |
11 | import net.bmahe.genetics4j.moo.FitnessVector; | |
12 | ||
13 | @Value.Immutable | |
14 | public abstract class SPEA2Replacement<T extends Comparable<T>> implements ReplacementStrategy { | |
15 | ||
16 | /** | |
17 | * Defines the Pareto dominance relation | |
18 | * | |
19 | * @return | |
20 | */ | |
21 | @Value.Default | |
22 | public Comparator<T> dominance() { | |
23 |
3
1. dominance : replaced return value with null for net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement::dominance → NO_COVERAGE 2. lambda$dominance$0 : removed call to java/lang/Comparable::compareTo → NO_COVERAGE 3. lambda$dominance$0 : replaced int return with 0 for net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement::lambda$dominance$0 → NO_COVERAGE |
return (a, b) -> a.compareTo(b); |
24 | } | |
25 | ||
26 | /** | |
27 | * Comparator used for deduplication of solution prior to processing | |
28 | * <p> | |
29 | * If not specified, it defaults to not do any deduplication | |
30 | * | |
31 | * @return | |
32 | */ | |
33 | @Value.Default | |
34 | public Optional<Comparator<Genotype>> deduplicate() { | |
35 |
1
1. deduplicate : removed call to java/util/Optional::empty → NO_COVERAGE |
return Optional.empty(); |
36 | } | |
37 | ||
38 | /** | |
39 | * Determine the k-nearest distance to compute. | |
40 | * <p> | |
41 | * It will default to sqrt(|archive| + |population|) | |
42 | * | |
43 | * @return | |
44 | */ | |
45 | @Value.Default | |
46 | public Optional<Integer> k() { | |
47 |
1
1. k : removed call to java/util/Optional::empty → NO_COVERAGE |
return Optional.empty(); |
48 | } | |
49 | ||
50 | /** | |
51 | * Define how to compute distances in objective space between two solutions | |
52 | * | |
53 | * @return Distance | |
54 | */ | |
55 | @Value.Parameter | |
56 | public abstract BiFunction<T, T, Double> distance(); | |
57 | ||
58 | public static class Builder<T extends Comparable<T>> extends ImmutableSPEA2Replacement.Builder<T> { | |
59 | } | |
60 | ||
61 | public static <U extends Comparable<U>> Builder<U> builder() { | |
62 |
2
1. builder : replaced return value with null for net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement::builder → NO_COVERAGE 2. builder : removed call to net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement$Builder::<init> → NO_COVERAGE |
return new Builder<U>(); |
63 | } | |
64 | ||
65 | /** | |
66 | * Factory method to instantiate a SPEA2Selection when fitness is defined as a | |
67 | * FitnessVector of a Number | |
68 | * | |
69 | * @param <U> Type of the fitness measurement | |
70 | * @param deduplicate Deduplicator comparator. Null value with disable | |
71 | * deduplication | |
72 | * @return A new instance of SPEA2Replacement | |
73 | */ | |
74 | public static <U extends Number & Comparable<U>> SPEA2Replacement<FitnessVector<U>> | |
75 | ofFitnessVector(final Comparator<Genotype> deduplicate) { | |
76 | ||
77 |
1
1. ofFitnessVector : removed call to net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement$Builder::<init> → NO_COVERAGE |
final var builder = new Builder<FitnessVector<U>>(); |
78 |
3
1. ofFitnessVector : removed call to net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement$Builder::deduplicate → NO_COVERAGE 2. ofFitnessVector : removed call to java/util/Optional::ofNullable → NO_COVERAGE 3. ofFitnessVector : replaced call to net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement$Builder::deduplicate with receiver → NO_COVERAGE |
builder.deduplicate(Optional.ofNullable(deduplicate)); |
79 | ||
80 |
2
1. ofFitnessVector : removed call to net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement$Builder::distance → NO_COVERAGE 2. ofFitnessVector : replaced call to net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement$Builder::distance with receiver → NO_COVERAGE |
builder.distance((fv1, fv2) -> { |
81 | ||
82 |
1
1. lambda$ofFitnessVector$1 : removed call to net/bmahe/genetics4j/moo/FitnessVector::dimensions → NO_COVERAGE |
final int dimensions = fv1.dimensions(); |
83 | ||
84 |
1
1. lambda$ofFitnessVector$1 : Substituted 0.0 with 1.0 → NO_COVERAGE |
double sum = 0.0; |
85 |
5
1. lambda$ofFitnessVector$1 : Substituted 0 with 1 → NO_COVERAGE 2. lambda$ofFitnessVector$1 : removed conditional - replaced comparison check with false → NO_COVERAGE 3. lambda$ofFitnessVector$1 : negated conditional → NO_COVERAGE 4. lambda$ofFitnessVector$1 : changed conditional boundary → NO_COVERAGE 5. lambda$ofFitnessVector$1 : removed conditional - replaced comparison check with true → NO_COVERAGE |
for (int i = 0; i < dimensions; i++) { |
86 |
2
1. lambda$ofFitnessVector$1 : removed call to net/bmahe/genetics4j/moo/FitnessVector::get → NO_COVERAGE 2. lambda$ofFitnessVector$1 : removed call to java/lang/Number::doubleValue → NO_COVERAGE |
final double v1 = fv1.get(i).doubleValue(); |
87 |
2
1. lambda$ofFitnessVector$1 : removed call to net/bmahe/genetics4j/moo/FitnessVector::get → NO_COVERAGE 2. lambda$ofFitnessVector$1 : removed call to java/lang/Number::doubleValue → NO_COVERAGE |
final double v2 = fv2.get(i).doubleValue(); |
88 | ||
89 |
4
1. lambda$ofFitnessVector$1 : Replaced double subtraction with addition → NO_COVERAGE 2. lambda$ofFitnessVector$1 : Replaced double addition with subtraction → NO_COVERAGE 3. lambda$ofFitnessVector$1 : Replaced double multiplication with division → NO_COVERAGE 4. lambda$ofFitnessVector$1 : Replaced double subtraction with addition → NO_COVERAGE |
sum += (v2 - v1) * (v2 - v1); |
90 | } | |
91 | ||
92 |
4
1. lambda$ofFitnessVector$1 : replaced Double return value with 0 for net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement::lambda$ofFitnessVector$1 → NO_COVERAGE 2. lambda$ofFitnessVector$1 : removed call to java/lang/Double::valueOf → NO_COVERAGE 3. lambda$ofFitnessVector$1 : removed call to java/lang/Math::sqrt → NO_COVERAGE 4. lambda$ofFitnessVector$1 : replaced call to java/lang/Math::sqrt with argument → NO_COVERAGE |
return Math.sqrt(sum); |
93 | }); | |
94 | ||
95 |
2
1. ofFitnessVector : replaced return value with null for net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement::ofFitnessVector → NO_COVERAGE 2. ofFitnessVector : removed call to net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement$Builder::build → NO_COVERAGE |
return builder.build(); |
96 | } | |
97 | ||
98 | /** | |
99 | * Factory method to instantiate a SPEA2Selection when fitness is defined as a | |
100 | * FitnessVector of a Number | |
101 | * | |
102 | * @param <U> Type of the fitness measurement | |
103 | * @return A new instance of SPEA2Replacement | |
104 | */ | |
105 | public static <U extends Number & Comparable<U>> SPEA2Replacement<FitnessVector<U>> ofFitnessVector() { | |
106 | ||
107 |
2
1. ofFitnessVector : removed call to net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement::ofFitnessVector → NO_COVERAGE 2. ofFitnessVector : replaced return value with null for net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement::ofFitnessVector → NO_COVERAGE |
return ofFitnessVector(null); |
108 | } | |
109 | } | |
Mutations | ||
23 |
1.1 2.2 3.3 |
|
35 |
1.1 |
|
47 |
1.1 |
|
62 |
1.1 2.2 |
|
77 |
1.1 |
|
78 |
1.1 2.2 3.3 |
|
80 |
1.1 2.2 |
|
82 |
1.1 |
|
84 |
1.1 |
|
85 |
1.1 2.2 3.3 4.4 5.5 |
|
86 |
1.1 2.2 |
|
87 |
1.1 2.2 |
|
89 |
1.1 2.2 3.3 4.4 |
|
92 |
1.1 2.2 3.3 4.4 |
|
95 |
1.1 2.2 |
|
107 |
1.1 2.2 |