TournamentNSGA2Selection.java

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
 * Tournament based NSGA2 selection
16
 * <p>This method of selection follows the method describe in the NSGA2 paper where the individuals are sorted according
17
 * to NSGA2 and then selected through tournaments where they are compared based on their NSGA2 metric
18
 *
19
 * @param <T> Type of the fitness measurement
20
 */
21
@Value.Immutable
22
public abstract class TournamentNSGA2Selection<T extends Comparable<T>> implements SelectionPolicy {
23
24
	/**
25
	 * Describe how many objectives are embedded in T
26
	 * 
27
	 * @return Number of objectives embedded in T
28
	 */
29
	@Value.Parameter
30
	public abstract int numberObjectives();
31
32
	/**
33
	 * Override the dominance operator.
34
	 * <p>If not specified, it assumes the default comparator conforms to the Pareto dominance relation
35
	 * 
36
	 * @return
37
	 */
38
	@Value.Default
39
	public Comparator<T> dominance() {
40 3 1. lambda$dominance$0 : replaced int return with 0 for net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection::lambda$dominance$0 → SURVIVED
2. lambda$dominance$0 : removed call to java/lang/Comparable::compareTo → SURVIVED
3. dominance : replaced return value with null for net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection::dominance → KILLED
		return (a, b) -> a.compareTo(b);
41
	}
42
43
	/**
44
	 * Comparator used for deduplication of solution prior to processing
45
	 * <p>If not specified, it defaults to not do any deduplication
46
	 * 
47
	 * @return
48
	 */
49
	@Value.Default
50
	public Optional<Comparator<Genotype>> deduplicate() {
51 1 1. deduplicate : removed call to java/util/Optional::empty → KILLED
		return Optional.empty();
52
	}
53
54
	/**
55
	 * Sort T based on the objective passed as a parameter
56
	 * 
57
	 * @return
58
	 */
59
	@Value.Parameter
60
	public abstract Function<Integer, Comparator<T>> objectiveComparator();
61
62
	/**
63
	 * Define how to compute distances between fitness scores along their objectives
64
	 * 
65
	 * @return Distance computation method
66
	 */
67
	@Value.Parameter
68
	public abstract ObjectiveDistance<T> distance();
69
70
	/**
71
	 * Number of candidates in each tournament
72
	 * 
73
	 * @return Number of candidates in each tournament
74
	 */
75
	@Value.Parameter
76
	public abstract int numCandidates();
77
78
	public static class Builder<T extends Comparable<T>> extends ImmutableTournamentNSGA2Selection.Builder<T> {
79
	}
80
81
	public static <U extends Comparable<U>> Builder<U> builder() {
82 2 1. builder : removed call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::<init> → KILLED
2. builder : replaced return value with null for net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection::builder → KILLED
		return new Builder<U>();
83
	}
84
85
	/**
86
	 * Factory method to instantiate a Tournament based NSGA2 selection when fitness is defined as a FitnessVector of a
87
	 * Number
88
	 * 
89
	 * @param <U>              Type of the fitness measurement
90
	 * @param numberObjectives Number of objectives and dimensions of the FitnessVector
91
	 * @param numberCandidates Number of candidates in each tournament
92
	 * @param deduplicate      Deduplicator comparator. Null value with disable deduplication
93
	 * @return A new instance of TournamentNSGA2Selection
94
	 */
95
	public static <U extends Number & Comparable<U>> TournamentNSGA2Selection<FitnessVector<U>> ofFitnessVector(
96
			final int numberObjectives, final int numberCandidates, final Comparator<Genotype> deduplicate) {
97
98 1 1. ofFitnessVector : removed call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::<init> → NO_COVERAGE
		final var builder = new Builder<FitnessVector<U>>();
99
100 11 1. ofFitnessVector : replaced call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::objectiveComparator with receiver → NO_COVERAGE
2. lambda$ofFitnessVector$1 : removed call to net/bmahe/genetics4j/moo/FitnessVector::get → NO_COVERAGE
3. lambda$ofFitnessVector$1 : replaced int return with 0 for net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection::lambda$ofFitnessVector$1 → NO_COVERAGE
4. lambda$ofFitnessVector$1 : removed call to java/lang/Number::doubleValue → 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. ofFitnessVector : removed call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::objectiveComparator → NO_COVERAGE
8. lambda$ofFitnessVector$1 : removed call to java/lang/Integer::intValue → NO_COVERAGE
9. lambda$ofFitnessVector$1 : removed call to java/lang/Double::compare → NO_COVERAGE
10. lambda$ofFitnessVector$1 : removed call to java/lang/Integer::intValue → NO_COVERAGE
11. lambda$ofFitnessVector$2 : replaced return value with null for net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection::lambda$ofFitnessVector$2 → NO_COVERAGE
		builder.objectiveComparator((m) -> (a, b) -> Double.compare(a.get(m).doubleValue(), b.get(m).doubleValue()))
101 10 1. lambda$ofFitnessVector$3 : removed call to net/bmahe/genetics4j/moo/FitnessVector::get → NO_COVERAGE
2. lambda$ofFitnessVector$3 : replaced double return with 0.0d for net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection::lambda$ofFitnessVector$3 → NO_COVERAGE
3. lambda$ofFitnessVector$3 : removed call to java/lang/Number::doubleValue → NO_COVERAGE
4. ofFitnessVector : replaced call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::distance with receiver → NO_COVERAGE
5. lambda$ofFitnessVector$3 : Replaced double subtraction with addition → NO_COVERAGE
6. lambda$ofFitnessVector$3 : removed call to net/bmahe/genetics4j/moo/FitnessVector::get → NO_COVERAGE
7. lambda$ofFitnessVector$3 : removed call to java/lang/Number::doubleValue → NO_COVERAGE
8. lambda$ofFitnessVector$3 : removed call to java/lang/Math::abs → NO_COVERAGE
9. ofFitnessVector : removed call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::distance → 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()))
102 2 1. ofFitnessVector : replaced call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::numberObjectives with receiver → NO_COVERAGE
2. ofFitnessVector : removed call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::numberObjectives → NO_COVERAGE
				.numberObjectives(numberObjectives)
103 2 1. ofFitnessVector : removed call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::numCandidates → NO_COVERAGE
2. ofFitnessVector : replaced call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::numCandidates with receiver → NO_COVERAGE
				.numCandidates(numberCandidates)
104 3 1. ofFitnessVector : removed call to java/util/Optional::ofNullable → NO_COVERAGE
2. ofFitnessVector : replaced call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::deduplicate with receiver → NO_COVERAGE
3. ofFitnessVector : removed call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::deduplicate → NO_COVERAGE
				.deduplicate(Optional.ofNullable(deduplicate));
105
106 2 1. ofFitnessVector : removed call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::build → NO_COVERAGE
2. ofFitnessVector : replaced return value with null for net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection::ofFitnessVector → NO_COVERAGE
		return builder.build();
107
	}
108
109
	/**
110
	 * Factory method to instantiate a Tournament based NSGA2 selection when fitness is defined as a FitnessVector of a
111
	 * Number
112
	 * 
113
	 * @param <U>              Type of the fitness measurement
114
	 * @param numberObjectives Number of objectives and dimensions of the FitnessVector
115
	 * @param numberCandidates Number of candidates in each tournament
116
	 * @return A new instance of TournamentNSGA2Selection
117
	 */
118
	public static <U extends Number & Comparable<U>> TournamentNSGA2Selection<FitnessVector<U>> ofFitnessVector(
119
			final int numberObjectives, final int numberCandidates) {
120
121 2 1. ofFitnessVector : replaced return value with null for net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection::ofFitnessVector → NO_COVERAGE
2. ofFitnessVector : removed call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection::ofFitnessVector → NO_COVERAGE
		return ofFitnessVector(numberObjectives, numberCandidates, null);
122
	}
123
124
}

Mutations

40

1.1
Location : lambda$dominance$0
Killed by : none
replaced int return with 0 for net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection::lambda$dominance$0 → SURVIVED
Covering tests

2.2
Location : dominance
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.TournamentNSGA2SelectorTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.TournamentNSGA2SelectorTest]/[method:ctorAllNull()]
replaced return value with null for net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection::dominance → KILLED

3.3
Location : lambda$dominance$0
Killed by : none
removed call to java/lang/Comparable::compareTo → SURVIVED Covering tests

51

1.1
Location : deduplicate
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.TournamentNSGA2SelectorTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.TournamentNSGA2SelectorTest]/[method:ctorAllNull()]
removed call to java/util/Optional::empty → KILLED

82

1.1
Location : builder
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.TournamentNSGA2SelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.TournamentNSGA2SelectionPolicyHandlerTest]/[method:canHandle()]
removed call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::<init> → KILLED

2.2
Location : builder
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.TournamentNSGA2SelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.TournamentNSGA2SelectionPolicyHandlerTest]/[method:canHandle()]
replaced return value with null for net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection::builder → KILLED

98

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

100

1.1
Location : ofFitnessVector
Killed by : none
replaced call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::objectiveComparator with receiver → NO_COVERAGE

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

3.3
Location : lambda$ofFitnessVector$1
Killed by : none
replaced int return with 0 for net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection::lambda$ofFitnessVector$1 → NO_COVERAGE

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

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

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

7.7
Location : ofFitnessVector
Killed by : none
removed call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::objectiveComparator → NO_COVERAGE

8.8
Location : lambda$ofFitnessVector$1
Killed by : none
removed call to java/lang/Integer::intValue → NO_COVERAGE

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

10.10
Location : lambda$ofFitnessVector$1
Killed by : none
removed call to java/lang/Integer::intValue → NO_COVERAGE

11.11
Location : lambda$ofFitnessVector$2
Killed by : none
replaced return value with null for net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection::lambda$ofFitnessVector$2 → NO_COVERAGE

101

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

2.2
Location : lambda$ofFitnessVector$3
Killed by : none
replaced double return with 0.0d for net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection::lambda$ofFitnessVector$3 → NO_COVERAGE

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

4.4
Location : ofFitnessVector
Killed by : none
replaced call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::distance with receiver → NO_COVERAGE

5.5
Location : lambda$ofFitnessVector$3
Killed by : none
Replaced double subtraction with addition → NO_COVERAGE

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

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

8.8
Location : lambda$ofFitnessVector$3
Killed by : none
removed call to java/lang/Math::abs → NO_COVERAGE

9.9
Location : ofFitnessVector
Killed by : none
removed call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::distance → NO_COVERAGE

10.10
Location : lambda$ofFitnessVector$3
Killed by : none
replaced call to java/lang/Math::abs with argument → NO_COVERAGE

102

1.1
Location : ofFitnessVector
Killed by : none
replaced call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::numberObjectives with receiver → NO_COVERAGE

2.2
Location : ofFitnessVector
Killed by : none
removed call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::numberObjectives → NO_COVERAGE

103

1.1
Location : ofFitnessVector
Killed by : none
removed call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::numCandidates → NO_COVERAGE

2.2
Location : ofFitnessVector
Killed by : none
replaced call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::numCandidates with receiver → NO_COVERAGE

104

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

2.2
Location : ofFitnessVector
Killed by : none
replaced call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::deduplicate with receiver → NO_COVERAGE

3.3
Location : ofFitnessVector
Killed by : none
removed call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::deduplicate → NO_COVERAGE

106

1.1
Location : ofFitnessVector
Killed by : none
removed call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection$Builder::build → NO_COVERAGE

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

121

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

2.2
Location : ofFitnessVector
Killed by : none
removed call to net/bmahe/genetics4j/moo/nsga2/spec/TournamentNSGA2Selection::ofFitnessVector → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.20.3