NSGA2Utils.java

1
package net.bmahe.genetics4j.moo.nsga2.impl;
2
3
import java.util.Comparator;
4
import java.util.List;
5
import java.util.Objects;
6
import java.util.function.Function;
7
import java.util.stream.IntStream;
8
9
import org.apache.commons.lang3.Validate;
10
11
import net.bmahe.genetics4j.moo.ObjectiveDistance;
12
13
public class NSGA2Utils {
14
15
	private NSGA2Utils() {
16
17
	}
18
19
	public static <T> double[] crowdingDistanceAssignment(final int numberObjectives, final List<T> fitnessScore,
20
			final Function<Integer, Comparator<T>> objectiveComparator, final ObjectiveDistance<T> objectiveDistance) {
21
		Validate.isTrue(numberObjectives > 0);
22
		Objects.requireNonNull(fitnessScore);
23
		Validate.isTrue(fitnessScore.isEmpty() == false, "Fitness score list must not be empty");
24
		Objects.requireNonNull(objectiveComparator);
25
		Objects.requireNonNull(objectiveDistance);
26
27 1 1. crowdingDistanceAssignment : removed call to java/util/List::size → KILLED
		final double[] distances = new double[fitnessScore.size()];
28
29 5 1. crowdingDistanceAssignment : negated conditional → SURVIVED
2. crowdingDistanceAssignment : Substituted 0 with 1 → SURVIVED
3. crowdingDistanceAssignment : removed conditional - replaced comparison check with false → SURVIVED
4. crowdingDistanceAssignment : removed conditional - replaced comparison check with true → KILLED
5. crowdingDistanceAssignment : changed conditional boundary → KILLED
		for (int m = 0; m < numberObjectives; m++) {
30 3 1. crowdingDistanceAssignment : replaced call to java/util/function/Function::apply with argument → KILLED
2. crowdingDistanceAssignment : removed call to java/util/function/Function::apply → KILLED
3. crowdingDistanceAssignment : removed call to java/lang/Integer::valueOf → KILLED
			final Comparator<T> objective = objectiveComparator.apply(m);
31
32 3 1. crowdingDistanceAssignment : Substituted 0 with 1 → SURVIVED
2. crowdingDistanceAssignment : removed call to java/util/stream/IntStream::range → KILLED
3. crowdingDistanceAssignment : removed call to java/util/List::size → KILLED
			final int[] sortedIndexes = IntStream.range(0, fitnessScore.size())
33 1 1. crowdingDistanceAssignment : removed call to java/util/stream/IntStream::boxed → KILLED
					.boxed()
34 8 1. lambda$crowdingDistanceAssignment$0 : removed call to java/lang/Integer::intValue → SURVIVED
2. lambda$crowdingDistanceAssignment$0 : removed call to java/lang/Integer::intValue → SURVIVED
3. crowdingDistanceAssignment : replaced call to java/util/stream/Stream::sorted with receiver → SURVIVED
4. lambda$crowdingDistanceAssignment$0 : removed call to java/util/Comparator::compare → SURVIVED
5. lambda$crowdingDistanceAssignment$0 : replaced int return with 0 for net/bmahe/genetics4j/moo/nsga2/impl/NSGA2Utils::lambda$crowdingDistanceAssignment$0 → SURVIVED
6. crowdingDistanceAssignment : removed call to java/util/stream/Stream::sorted → KILLED
7. lambda$crowdingDistanceAssignment$0 : removed call to java/util/List::get → KILLED
8. lambda$crowdingDistanceAssignment$0 : removed call to java/util/List::get → KILLED
					.sorted((a, b) -> objective.compare(fitnessScore.get(a), fitnessScore.get(b)))
35 3 1. lambda$crowdingDistanceAssignment$1 : removed call to java/lang/Integer::intValue → SURVIVED
2. lambda$crowdingDistanceAssignment$1 : replaced int return with 0 for net/bmahe/genetics4j/moo/nsga2/impl/NSGA2Utils::lambda$crowdingDistanceAssignment$1 → SURVIVED
3. crowdingDistanceAssignment : removed call to java/util/stream/Stream::mapToInt → KILLED
					.mapToInt(e -> e)
36 1 1. crowdingDistanceAssignment : removed call to java/util/stream/IntStream::toArray → KILLED
					.toArray();
37
38 2 1. crowdingDistanceAssignment : Substituted Infinity with 1.0 → SURVIVED
2. crowdingDistanceAssignment : Substituted 0 with 1 → SURVIVED
			distances[sortedIndexes[0]] = Double.POSITIVE_INFINITY;
39 3 1. crowdingDistanceAssignment : Substituted Infinity with 1.0 → SURVIVED
2. crowdingDistanceAssignment : Substituted 1 with 0 → KILLED
3. crowdingDistanceAssignment : Replaced integer subtraction with addition → KILLED
			distances[sortedIndexes[sortedIndexes.length - 1]] = Double.POSITIVE_INFINITY;
40
41 2 1. crowdingDistanceAssignment : Substituted 0 with 1 → SURVIVED
2. crowdingDistanceAssignment : removed call to java/util/List::get → KILLED
			final T minFitnessByObjective = fitnessScore.get(sortedIndexes[0]);
42 3 1. crowdingDistanceAssignment : Replaced integer subtraction with addition → KILLED
2. crowdingDistanceAssignment : Substituted 1 with 0 → KILLED
3. crowdingDistanceAssignment : removed call to java/util/List::get → KILLED
			final T maxFitnessByObjective = fitnessScore.get(sortedIndexes[sortedIndexes.length - 1]);
43 1 1. crowdingDistanceAssignment : removed call to net/bmahe/genetics4j/moo/ObjectiveDistance::distance → SURVIVED
			final double maxDistance = objectiveDistance.distance(minFitnessByObjective, maxFitnessByObjective, m);
44
45 7 1. crowdingDistanceAssignment : removed conditional - replaced comparison check with false → SURVIVED
2. crowdingDistanceAssignment : Substituted 1 with 0 → KILLED
3. crowdingDistanceAssignment : changed conditional boundary → KILLED
4. crowdingDistanceAssignment : Substituted 1 with 0 → KILLED
5. crowdingDistanceAssignment : negated conditional → KILLED
6. crowdingDistanceAssignment : removed conditional - replaced comparison check with true → KILLED
7. crowdingDistanceAssignment : Replaced integer subtraction with addition → KILLED
			for (int i = 1; i < sortedIndexes.length - 1; i++) {
46 3 1. crowdingDistanceAssignment : Replaced integer subtraction with addition → SURVIVED
2. crowdingDistanceAssignment : Substituted 1 with 0 → SURVIVED
3. crowdingDistanceAssignment : removed call to java/util/List::get → KILLED
				final T previousFitness = fitnessScore.get(sortedIndexes[i - 1]);
47 3 1. crowdingDistanceAssignment : Replaced integer addition with subtraction → SURVIVED
2. crowdingDistanceAssignment : Substituted 1 with 0 → SURVIVED
3. crowdingDistanceAssignment : removed call to java/util/List::get → KILLED
				final T nextFitness = fitnessScore.get(sortedIndexes[i + 1]);
48
49 5 1. crowdingDistanceAssignment : Substituted 0.0 with 1.0 → SURVIVED
2. crowdingDistanceAssignment : removed conditional - replaced comparison check with false → SURVIVED
3. crowdingDistanceAssignment : changed conditional boundary → SURVIVED
4. crowdingDistanceAssignment : removed conditional - replaced comparison check with true → SURVIVED
5. crowdingDistanceAssignment : negated conditional → SURVIVED
				if (maxDistance > 0.0) {
50 3 1. crowdingDistanceAssignment : Replaced double division with multiplication → SURVIVED
2. crowdingDistanceAssignment : Replaced double addition with subtraction → SURVIVED
3. crowdingDistanceAssignment : removed call to net/bmahe/genetics4j/moo/ObjectiveDistance::distance → SURVIVED
					distances[i] += objectiveDistance.distance(previousFitness, nextFitness, m) / maxDistance;
51
				}
52
			}
53
		}
54
55 1 1. crowdingDistanceAssignment : replaced return value with null for net/bmahe/genetics4j/moo/nsga2/impl/NSGA2Utils::crowdingDistanceAssignment → KILLED
		return distances;
56
	}
57
}

Mutations

27

1.1
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
removed call to java/util/List::size → KILLED

29

1.1
Location : crowdingDistanceAssignment
Killed by : none
negated conditional → SURVIVED
Covering tests

2.2
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
removed conditional - replaced comparison check with true → KILLED

3.3
Location : crowdingDistanceAssignment
Killed by : none
Substituted 0 with 1 → SURVIVED Covering tests

4.4
Location : crowdingDistanceAssignment
Killed by : none
removed conditional - replaced comparison check with false → SURVIVED Covering tests

5.5
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
changed conditional boundary → KILLED

30

1.1
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
replaced call to java/util/function/Function::apply with argument → KILLED

2.2
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
removed call to java/util/function/Function::apply → KILLED

3.3
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2SelectorTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2SelectorTest]/[method:simple()]
removed call to java/lang/Integer::valueOf → KILLED

32

1.1
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
removed call to java/util/stream/IntStream::range → KILLED

2.2
Location : crowdingDistanceAssignment
Killed by : none
Substituted 0 with 1 → SURVIVED
Covering tests

3.3
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
removed call to java/util/List::size → KILLED

33

1.1
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
removed call to java/util/stream/IntStream::boxed → KILLED

34

1.1
Location : lambda$crowdingDistanceAssignment$0
Killed by : none
removed call to java/lang/Integer::intValue → SURVIVED
Covering tests

2.2
Location : lambda$crowdingDistanceAssignment$0
Killed by : none
removed call to java/lang/Integer::intValue → SURVIVED Covering tests

3.3
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
removed call to java/util/stream/Stream::sorted → KILLED

4.4
Location : crowdingDistanceAssignment
Killed by : none
replaced call to java/util/stream/Stream::sorted with receiver → SURVIVED Covering tests

5.5
Location : lambda$crowdingDistanceAssignment$0
Killed by : none
removed call to java/util/Comparator::compare → SURVIVED Covering tests

6.6
Location : lambda$crowdingDistanceAssignment$0
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
removed call to java/util/List::get → KILLED

7.7
Location : lambda$crowdingDistanceAssignment$0
Killed by : none
replaced int return with 0 for net/bmahe/genetics4j/moo/nsga2/impl/NSGA2Utils::lambda$crowdingDistanceAssignment$0 → SURVIVED Covering tests

8.8
Location : lambda$crowdingDistanceAssignment$0
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
removed call to java/util/List::get → KILLED

35

1.1
Location : lambda$crowdingDistanceAssignment$1
Killed by : none
removed call to java/lang/Integer::intValue → SURVIVED
Covering tests

2.2
Location : lambda$crowdingDistanceAssignment$1
Killed by : none
replaced int return with 0 for net/bmahe/genetics4j/moo/nsga2/impl/NSGA2Utils::lambda$crowdingDistanceAssignment$1 → SURVIVED Covering tests

3.3
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
removed call to java/util/stream/Stream::mapToInt → KILLED

36

1.1
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
removed call to java/util/stream/IntStream::toArray → KILLED

38

1.1
Location : crowdingDistanceAssignment
Killed by : none
Substituted Infinity with 1.0 → SURVIVED
Covering tests

2.2
Location : crowdingDistanceAssignment
Killed by : none
Substituted 0 with 1 → SURVIVED Covering tests

39

1.1
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
Substituted 1 with 0 → KILLED

2.2
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
Replaced integer subtraction with addition → KILLED

3.3
Location : crowdingDistanceAssignment
Killed by : none
Substituted Infinity with 1.0 → SURVIVED
Covering tests

41

1.1
Location : crowdingDistanceAssignment
Killed by : none
Substituted 0 with 1 → SURVIVED
Covering tests

2.2
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
removed call to java/util/List::get → KILLED

42

1.1
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
Replaced integer subtraction with addition → KILLED

2.2
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
Substituted 1 with 0 → KILLED

3.3
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
removed call to java/util/List::get → KILLED

43

1.1
Location : crowdingDistanceAssignment
Killed by : none
removed call to net/bmahe/genetics4j/moo/ObjectiveDistance::distance → SURVIVED
Covering tests

45

1.1
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
Substituted 1 with 0 → KILLED

2.2
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
changed conditional boundary → KILLED

3.3
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
Substituted 1 with 0 → KILLED

4.4
Location : crowdingDistanceAssignment
Killed by : none
removed conditional - replaced comparison check with false → SURVIVED
Covering tests

5.5
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.TournamentNSGA2SelectorTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.TournamentNSGA2SelectorTest]/[method:simple()]
negated conditional → KILLED

6.6
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
removed conditional - replaced comparison check with true → KILLED

7.7
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
Replaced integer subtraction with addition → KILLED

46

1.1
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
removed call to java/util/List::get → KILLED

2.2
Location : crowdingDistanceAssignment
Killed by : none
Replaced integer subtraction with addition → SURVIVED
Covering tests

3.3
Location : crowdingDistanceAssignment
Killed by : none
Substituted 1 with 0 → SURVIVED Covering tests

47

1.1
Location : crowdingDistanceAssignment
Killed by : none
Replaced integer addition with subtraction → SURVIVED
Covering tests

2.2
Location : crowdingDistanceAssignment
Killed by : none
Substituted 1 with 0 → SURVIVED Covering tests

3.3
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.NSGA2UtilsTest]/[method:simple()]
removed call to java/util/List::get → KILLED

49

1.1
Location : crowdingDistanceAssignment
Killed by : none
Substituted 0.0 with 1.0 → SURVIVED
Covering tests

2.2
Location : crowdingDistanceAssignment
Killed by : none
removed conditional - replaced comparison check with false → SURVIVED Covering tests

3.3
Location : crowdingDistanceAssignment
Killed by : none
changed conditional boundary → SURVIVED Covering tests

4.4
Location : crowdingDistanceAssignment
Killed by : none
removed conditional - replaced comparison check with true → SURVIVED Covering tests

5.5
Location : crowdingDistanceAssignment
Killed by : none
negated conditional → SURVIVED Covering tests

50

1.1
Location : crowdingDistanceAssignment
Killed by : none
Replaced double division with multiplication → SURVIVED
Covering tests

2.2
Location : crowdingDistanceAssignment
Killed by : none
Replaced double addition with subtraction → SURVIVED Covering tests

3.3
Location : crowdingDistanceAssignment
Killed by : none
removed call to net/bmahe/genetics4j/moo/ObjectiveDistance::distance → SURVIVED Covering tests

55

1.1
Location : crowdingDistanceAssignment
Killed by : net.bmahe.genetics4j.moo.nsga2.impl.TournamentNSGA2SelectorTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.TournamentNSGA2SelectorTest]/[method:simple()]
replaced return value with null for net/bmahe/genetics4j/moo/nsga2/impl/NSGA2Utils::crowdingDistanceAssignment → KILLED

Active mutators

Tests examined


Report generated by PIT 1.25.7 support