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

Mutations

26

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

28

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()]
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()]
removed conditional - replaced comparison check with true → KILLED

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

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

29

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/function/Function::apply → 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 call to java/util/function/Function::apply with argument → 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

31

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 : 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

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

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::boxed → KILLED

33

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 : lambda$crowdingDistanceAssignment$0
Killed by : none
removed call to java/util/Comparator::compare → SURVIVED Covering tests

5.5
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

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

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

34

1.1
Location : lambda$crowdingDistanceAssignment$1
Killed by : none
removed call to java/lang/Integer::intValue → 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/stream/Stream::mapToInt → KILLED

3.3
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

35

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

37

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

38

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 : none
Substituted Infinity with 1.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()]
Substituted 1 with 0 → KILLED

40

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

41

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 : 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 : 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

42

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

44

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()]
Substituted 1 with 0 → KILLED

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

4.4
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

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()]
Replaced integer subtraction with addition → 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.TournamentNSGA2SelectorTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.moo.nsga2.impl.TournamentNSGA2SelectorTest]/[method:simple()]
negated conditional → KILLED

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()]
removed call to java/util/List::get → KILLED

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

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

46

1.1
Location : crowdingDistanceAssignment
Killed by : none
Replaced integer addition with subtraction → 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

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

48

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

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

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

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

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

49

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

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

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

54

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.19.6