SPEA2Replacement.java

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>If not specified, it defaults to not do any deduplication
29
	 * 
30
	 * @return
31
	 */
32
	@Value.Default
33
	public Optional<Comparator<Genotype>> deduplicate() {
34 1 1. deduplicate : removed call to java/util/Optional::empty → NO_COVERAGE
		return Optional.empty();
35
	}
36
37
	/**
38
	 * Determine the k-nearest distance to compute.
39
	 * <p>It will default to sqrt(|archive| + |population|)
40
	 * 
41
	 * @return
42
	 */
43
	@Value.Default
44
	public Optional<Integer> k() {
45 1 1. k : removed call to java/util/Optional::empty → NO_COVERAGE
		return Optional.empty();
46
	}
47
48
	/**
49
	 * Define how to compute distances in objective space between two solutions
50
	 * 
51
	 * @return Distance
52
	 */
53
	@Value.Parameter
54
	public abstract BiFunction<T, T, Double> distance();
55
56
	public static class Builder<T extends Comparable<T>> extends ImmutableSPEA2Replacement.Builder<T> {
57
	}
58
59
	public static <U extends Comparable<U>> Builder<U> builder() {
60 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>();
61
	}
62
63
	/**
64
	 * Factory method to instantiate a SPEA2Selection when fitness is defined as a FitnessVector of a Number
65
	 * 
66
	 * @param <U>         Type of the fitness measurement
67
	 * @param deduplicate Deduplicator comparator. Null value with disable deduplication
68
	 * @return A new instance of SPEA2Replacement
69
	 */
70
	public static <U extends Number & Comparable<U>> SPEA2Replacement<FitnessVector<U>> ofFitnessVector(
71
			final Comparator<Genotype> deduplicate) {
72
73 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>>();
74 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));
75
76 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) -> {
77
78 1 1. lambda$ofFitnessVector$1 : removed call to net/bmahe/genetics4j/moo/FitnessVector::dimensions → NO_COVERAGE
			final int dimensions = fv1.dimensions();
79
80 1 1. lambda$ofFitnessVector$1 : Substituted 0.0 with 1.0 → NO_COVERAGE
			double sum = 0.0;
81 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++) {
82 1 1. lambda$ofFitnessVector$1 : removed call to net/bmahe/genetics4j/moo/FitnessVector::get → NO_COVERAGE
				final double v1 = fv1.get(i)
83 1 1. lambda$ofFitnessVector$1 : removed call to java/lang/Number::doubleValue → NO_COVERAGE
						.doubleValue();
84 1 1. lambda$ofFitnessVector$1 : removed call to net/bmahe/genetics4j/moo/FitnessVector::get → NO_COVERAGE
				final double v2 = fv2.get(i)
85 1 1. lambda$ofFitnessVector$1 : removed call to java/lang/Number::doubleValue → NO_COVERAGE
						.doubleValue();
86
87 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);
88
			}
89
90 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 : replaced call to java/lang/Math::sqrt with argument → NO_COVERAGE
4. lambda$ofFitnessVector$1 : removed call to java/lang/Math::sqrt → NO_COVERAGE
			return Math.sqrt(sum);
91
		});
92
93 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();
94
	}
95
96
	/**
97
	 * Factory method to instantiate a SPEA2Selection when fitness is defined as a FitnessVector of a Number
98
	 * 
99
	 * @param <U> Type of the fitness measurement
100
	 * @return A new instance of SPEA2Replacement
101
	 */
102
	public static <U extends Number & Comparable<U>> SPEA2Replacement<FitnessVector<U>> ofFitnessVector() {
103
104 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);
105
	}
106
}

Mutations

23

1.1
Location : dominance
Killed by : none
replaced return value with null for net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement::dominance → NO_COVERAGE

2.2
Location : lambda$dominance$0
Killed by : none
removed call to java/lang/Comparable::compareTo → NO_COVERAGE

3.3
Location : lambda$dominance$0
Killed by : none
replaced int return with 0 for net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement::lambda$dominance$0 → NO_COVERAGE

34

1.1
Location : deduplicate
Killed by : none
removed call to java/util/Optional::empty → NO_COVERAGE

45

1.1
Location : k
Killed by : none
removed call to java/util/Optional::empty → NO_COVERAGE

60

1.1
Location : builder
Killed by : none
replaced return value with null for net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement::builder → NO_COVERAGE

2.2
Location : builder
Killed by : none
removed call to net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement$Builder::<init> → NO_COVERAGE

73

1.1
Location : ofFitnessVector
Killed by : none
removed call to net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement$Builder::<init> → NO_COVERAGE

74

1.1
Location : ofFitnessVector
Killed by : none
removed call to net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement$Builder::deduplicate → NO_COVERAGE

2.2
Location : ofFitnessVector
Killed by : none
removed call to java/util/Optional::ofNullable → NO_COVERAGE

3.3
Location : ofFitnessVector
Killed by : none
replaced call to net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement$Builder::deduplicate with receiver → NO_COVERAGE

76

1.1
Location : ofFitnessVector
Killed by : none
removed call to net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement$Builder::distance → NO_COVERAGE

2.2
Location : ofFitnessVector
Killed by : none
replaced call to net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement$Builder::distance with receiver → NO_COVERAGE

78

1.1
Location : lambda$ofFitnessVector$1
Killed by : none
removed call to net/bmahe/genetics4j/moo/FitnessVector::dimensions → NO_COVERAGE

80

1.1
Location : lambda$ofFitnessVector$1
Killed by : none
Substituted 0.0 with 1.0 → NO_COVERAGE

81

1.1
Location : lambda$ofFitnessVector$1
Killed by : none
Substituted 0 with 1 → NO_COVERAGE

2.2
Location : lambda$ofFitnessVector$1
Killed by : none
removed conditional - replaced comparison check with false → NO_COVERAGE

3.3
Location : lambda$ofFitnessVector$1
Killed by : none
negated conditional → NO_COVERAGE

4.4
Location : lambda$ofFitnessVector$1
Killed by : none
changed conditional boundary → NO_COVERAGE

5.5
Location : lambda$ofFitnessVector$1
Killed by : none
removed conditional - replaced comparison check with true → NO_COVERAGE

82

1.1
Location : lambda$ofFitnessVector$1
Killed by : none
removed call to net/bmahe/genetics4j/moo/FitnessVector::get → NO_COVERAGE

83

1.1
Location : lambda$ofFitnessVector$1
Killed by : none
removed call to java/lang/Number::doubleValue → NO_COVERAGE

84

1.1
Location : lambda$ofFitnessVector$1
Killed by : none
removed call to net/bmahe/genetics4j/moo/FitnessVector::get → NO_COVERAGE

85

1.1
Location : lambda$ofFitnessVector$1
Killed by : none
removed call to java/lang/Number::doubleValue → NO_COVERAGE

87

1.1
Location : lambda$ofFitnessVector$1
Killed by : none
Replaced double subtraction with addition → NO_COVERAGE

2.2
Location : lambda$ofFitnessVector$1
Killed by : none
Replaced double addition with subtraction → NO_COVERAGE

3.3
Location : lambda$ofFitnessVector$1
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

4.4
Location : lambda$ofFitnessVector$1
Killed by : none
Replaced double subtraction with addition → NO_COVERAGE

90

1.1
Location : lambda$ofFitnessVector$1
Killed by : none
replaced Double return value with 0 for net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement::lambda$ofFitnessVector$1 → NO_COVERAGE

2.2
Location : lambda$ofFitnessVector$1
Killed by : none
removed call to java/lang/Double::valueOf → NO_COVERAGE

3.3
Location : lambda$ofFitnessVector$1
Killed by : none
replaced call to java/lang/Math::sqrt with argument → NO_COVERAGE

4.4
Location : lambda$ofFitnessVector$1
Killed by : none
removed call to java/lang/Math::sqrt → NO_COVERAGE

93

1.1
Location : ofFitnessVector
Killed by : none
replaced return value with null for net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement::ofFitnessVector → NO_COVERAGE

2.2
Location : ofFitnessVector
Killed by : none
removed call to net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement$Builder::build → NO_COVERAGE

104

1.1
Location : ofFitnessVector
Killed by : none
removed call to net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement::ofFitnessVector → NO_COVERAGE

2.2
Location : ofFitnessVector
Killed by : none
replaced return value with null for net/bmahe/genetics4j/moo/spea2/spec/replacement/SPEA2Replacement::ofFitnessVector → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.20.3