TrimTreeMutator.java

1
package net.bmahe.genetics4j.gp.mutation;
2
3
import java.util.List;
4
import java.util.random.RandomGenerator;
5
6
import org.apache.commons.lang3.Validate;
7
import org.apache.logging.log4j.LogManager;
8
import org.apache.logging.log4j.Logger;
9
10
import net.bmahe.genetics4j.core.Genotype;
11
import net.bmahe.genetics4j.core.chromosomes.Chromosome;
12
import net.bmahe.genetics4j.core.chromosomes.TreeChromosome;
13
import net.bmahe.genetics4j.core.chromosomes.TreeNode;
14
import net.bmahe.genetics4j.core.mutation.Mutator;
15
import net.bmahe.genetics4j.core.spec.AbstractEAConfiguration;
16
import net.bmahe.genetics4j.core.spec.chromosome.ChromosomeSpec;
17
import net.bmahe.genetics4j.gp.Operation;
18
import net.bmahe.genetics4j.gp.program.Program;
19
import net.bmahe.genetics4j.gp.program.ProgramGenerator;
20
import net.bmahe.genetics4j.gp.spec.chromosome.ProgramTreeChromosomeSpec;
21
import net.bmahe.genetics4j.gp.spec.mutation.TrimTree;
22
23
public class TrimTreeMutator implements Mutator {
24
	final static public Logger logger = LogManager.getLogger(TrimTreeMutator.class);
25
26
	private final ProgramGenerator programGenerator;
27
	private final RandomGenerator randomGenerator;
28
	private final AbstractEAConfiguration eaConfiguration;
29
	private final TrimTree trimTree;
30
31
	public TrimTreeMutator(final ProgramGenerator _programGenerator, final RandomGenerator _randomGenerator,
32
			final AbstractEAConfiguration _eaConfiguration, final TrimTree _trimTree) {
33
		Validate.notNull(_programGenerator);
34
		Validate.notNull(_randomGenerator);
35
		Validate.notNull(_eaConfiguration);
36
		Validate.notNull(_trimTree);
37
38 1 1. <init> : Removed assignment to member variable programGenerator → NO_COVERAGE
		this.programGenerator = _programGenerator;
39 1 1. <init> : Removed assignment to member variable randomGenerator → NO_COVERAGE
		this.randomGenerator = _randomGenerator;
40 1 1. <init> : Removed assignment to member variable eaConfiguration → NO_COVERAGE
		this.eaConfiguration = _eaConfiguration;
41 1 1. <init> : Removed assignment to member variable trimTree → NO_COVERAGE
		this.trimTree = _trimTree;
42
	}
43
44
	protected TreeNode<Operation<?>> duplicateAndMutate(final Program program, final TreeNode<Operation<?>> root,
45
			final int maxDepth, final int currentDepth) {
46
		Validate.notNull(program);
47
		Validate.notNull(root);
48
49 1 1. duplicateAndMutate : removed call to net/bmahe/genetics4j/core/chromosomes/TreeNode::getData → NO_COVERAGE
		final Operation<?> rootData = root.getData();
50
51 9 1. duplicateAndMutate : removed conditional - replaced comparison check with true → NO_COVERAGE
2. duplicateAndMutate : removed call to net/bmahe/genetics4j/core/chromosomes/TreeNode::getSize → NO_COVERAGE
3. duplicateAndMutate : Substituted 1 with 0 → NO_COVERAGE
4. duplicateAndMutate : removed conditional - replaced equality check with false → NO_COVERAGE
5. duplicateAndMutate : removed conditional - replaced comparison check with false → NO_COVERAGE
6. duplicateAndMutate : negated conditional → NO_COVERAGE
7. duplicateAndMutate : negated conditional → NO_COVERAGE
8. duplicateAndMutate : removed conditional - replaced equality check with true → NO_COVERAGE
9. duplicateAndMutate : changed conditional boundary → NO_COVERAGE
		if (currentDepth == maxDepth && root.getSize() > 1) {
52 4 1. duplicateAndMutate : removed call to net/bmahe/genetics4j/gp/Operation::returnedType → NO_COVERAGE
2. duplicateAndMutate : replaced return value with null for net/bmahe/genetics4j/gp/mutation/TrimTreeMutator::duplicateAndMutate → NO_COVERAGE
3. duplicateAndMutate : Substituted 1 with 0 → NO_COVERAGE
4. duplicateAndMutate : removed call to net/bmahe/genetics4j/gp/program/ProgramGenerator::generate → NO_COVERAGE
			return programGenerator.generate(program, 1, rootData.returnedType());
53
		}
54
55 1 1. duplicateAndMutate : removed call to net/bmahe/genetics4j/core/chromosomes/TreeNode::getChildren → NO_COVERAGE
		final List<TreeNode<Operation<?>>> children = root.getChildren();
56
57 1 1. duplicateAndMutate : removed call to net/bmahe/genetics4j/core/chromosomes/TreeNode::<init> → NO_COVERAGE
		final TreeNode<Operation<?>> duplicateRoot = new TreeNode<Operation<?>>(rootData);
58
59 6 1. duplicateAndMutate : removed conditional - replaced comparison check with true → NO_COVERAGE
2. duplicateAndMutate : removed call to java/util/List::size → NO_COVERAGE
3. duplicateAndMutate : Substituted 0 with 1 → NO_COVERAGE
4. duplicateAndMutate : removed conditional - replaced comparison check with false → NO_COVERAGE
5. duplicateAndMutate : negated conditional → NO_COVERAGE
6. duplicateAndMutate : changed conditional boundary → NO_COVERAGE
		for (int i = 0; i < children.size(); i++) {
60 1 1. duplicateAndMutate : removed call to java/util/List::get → NO_COVERAGE
			final TreeNode<Operation<?>> treeNode = children.get(i);
61 1 1. duplicateAndMutate : removed call to net/bmahe/genetics4j/core/chromosomes/TreeNode::getSize → NO_COVERAGE
			final int childSize = treeNode.getSize();
62
63 4 1. duplicateAndMutate : Substituted 1 with 0 → NO_COVERAGE
2. duplicateAndMutate : replaced call to net/bmahe/genetics4j/gp/mutation/TrimTreeMutator::duplicateAndMutate with argument → NO_COVERAGE
3. duplicateAndMutate : Replaced integer addition with subtraction → NO_COVERAGE
4. duplicateAndMutate : removed call to net/bmahe/genetics4j/gp/mutation/TrimTreeMutator::duplicateAndMutate → NO_COVERAGE
			final TreeNode<Operation<?>> childCopy = duplicateAndMutate(program, treeNode, maxDepth, currentDepth + 1);
64 1 1. duplicateAndMutate : removed call to net/bmahe/genetics4j/core/chromosomes/TreeNode::addChild → NO_COVERAGE
			duplicateRoot.addChild(childCopy);
65
		}
66
67 1 1. duplicateAndMutate : replaced return value with null for net/bmahe/genetics4j/gp/mutation/TrimTreeMutator::duplicateAndMutate → NO_COVERAGE
		return duplicateRoot;
68
	}
69
70
	private int maxDepthValue(final Program program, final TrimTree trimTree) {
71
		Validate.notNull(program);
72
		Validate.notNull(trimTree);
73
74 7 1. maxDepthValue : removed call to java/lang/Integer::intValue → NO_COVERAGE
2. lambda$maxDepthValue$0 : removed call to java/lang/Integer::valueOf → NO_COVERAGE
3. maxDepthValue : replaced int return with 0 for net/bmahe/genetics4j/gp/mutation/TrimTreeMutator::maxDepthValue → NO_COVERAGE
4. lambda$maxDepthValue$0 : removed call to net/bmahe/genetics4j/gp/program/Program::maxDepth → NO_COVERAGE
5. maxDepthValue : removed call to java/util/Optional::orElseGet → NO_COVERAGE
6. maxDepthValue : removed call to net/bmahe/genetics4j/gp/spec/mutation/TrimTree::maxDepth → NO_COVERAGE
7. lambda$maxDepthValue$0 : replaced Integer return value with 0 for net/bmahe/genetics4j/gp/mutation/TrimTreeMutator::lambda$maxDepthValue$0 → NO_COVERAGE
		return trimTree.maxDepth().orElseGet(() -> program.maxDepth());
75
	}
76
77
	@Override
78
	public Genotype mutate(final Genotype originalGenotype) {
79
		Validate.notNull(originalGenotype);
80
81
		logger.trace("Mutating genotype {}", originalGenotype);
82
83 1 1. mutate : removed call to net/bmahe/genetics4j/core/Genotype::getSize → NO_COVERAGE
		final Chromosome[] newChromosomes = new Chromosome[originalGenotype.getSize()];
84 1 1. mutate : removed call to net/bmahe/genetics4j/core/Genotype::getChromosomes → NO_COVERAGE
		final Chromosome[] chromosomes = originalGenotype.getChromosomes();
85 5 1. mutate : Substituted 0 with 1 → NO_COVERAGE
2. mutate : changed conditional boundary → NO_COVERAGE
3. mutate : removed conditional - replaced comparison check with true → NO_COVERAGE
4. mutate : negated conditional → NO_COVERAGE
5. mutate : removed conditional - replaced comparison check with false → NO_COVERAGE
		for (int chromosomeIndex = 0; chromosomeIndex < chromosomes.length; chromosomeIndex++) {
86 1 1. mutate : removed call to net/bmahe/genetics4j/core/spec/AbstractEAConfiguration::getChromosomeSpec → NO_COVERAGE
			final ChromosomeSpec chromosomeSpec = eaConfiguration.getChromosomeSpec(chromosomeIndex);
87
			final Chromosome chromosome = chromosomes[chromosomeIndex];
88
89 3 1. mutate : negated conditional → NO_COVERAGE
2. mutate : removed conditional - replaced equality check with true → NO_COVERAGE
3. mutate : removed conditional - replaced equality check with false → NO_COVERAGE
			if (chromosomeSpec instanceof ProgramTreeChromosomeSpec == false) {
90 2 1. mutate : removed call to java/lang/IllegalArgumentException::<init> → NO_COVERAGE
2. mutate : removed call to java/lang/String::valueOf → NO_COVERAGE
				throw new IllegalArgumentException("This mutator does not support chromosome specs " + chromosomeSpec);
91
			}
92
93 3 1. mutate : removed conditional - replaced equality check with false → NO_COVERAGE
2. mutate : removed conditional - replaced equality check with true → NO_COVERAGE
3. mutate : negated conditional → NO_COVERAGE
			if (chromosome instanceof TreeChromosome<?> == false) {
94
				throw new IllegalArgumentException(
95 3 1. mutate : removed call to java/lang/Class::getSimpleName → NO_COVERAGE
2. mutate : removed call to java/lang/IllegalArgumentException::<init> → NO_COVERAGE
3. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/Chromosome::getClass → NO_COVERAGE
						"This mutator does not support chromosome of type " + chromosome.getClass().getSimpleName());
96
			}
97
98
			final ProgramTreeChromosomeSpec programTreeChromosomeSpec = (ProgramTreeChromosomeSpec) chromosomeSpec;
99 1 1. mutate : removed call to net/bmahe/genetics4j/gp/spec/chromosome/ProgramTreeChromosomeSpec::program → NO_COVERAGE
			final Program program = programTreeChromosomeSpec.program();
100
101
			final TreeChromosome<Operation<?>> treeChromosome = (TreeChromosome<Operation<?>>) chromosome;
102
103 1 1. mutate : removed call to net/bmahe/genetics4j/gp/mutation/TrimTreeMutator::maxDepthValue → NO_COVERAGE
			final int maxDepthValue = maxDepthValue(program, trimTree);
104
105 6 1. mutate : removed conditional - replaced comparison check with true → NO_COVERAGE
2. mutate : removed conditional - replaced comparison check with false → NO_COVERAGE
3. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/TreeChromosome::getRoot → NO_COVERAGE
4. mutate : changed conditional boundary → NO_COVERAGE
5. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/TreeNode::getDepth → NO_COVERAGE
6. mutate : negated conditional → NO_COVERAGE
			if (treeChromosome.getRoot().getDepth() > maxDepthValue) {
106 1 1. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/TreeChromosome::getRoot → NO_COVERAGE
				final TreeNode<Operation<?>> root = treeChromosome.getRoot();
107 3 1. mutate : Substituted 0 with 1 → NO_COVERAGE
2. mutate : replaced call to net/bmahe/genetics4j/gp/mutation/TrimTreeMutator::duplicateAndMutate with argument → NO_COVERAGE
3. mutate : removed call to net/bmahe/genetics4j/gp/mutation/TrimTreeMutator::duplicateAndMutate → NO_COVERAGE
				final TreeNode<Operation<?>> newRoot = duplicateAndMutate(program, root, maxDepthValue, 0);
108 1 1. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/TreeChromosome::<init> → NO_COVERAGE
				final TreeChromosome<Operation<?>> newTreeChromosome = new TreeChromosome<>(newRoot);
109
				newChromosomes[chromosomeIndex] = newTreeChromosome;
110
			} else {
111
				newChromosomes[chromosomeIndex] = chromosome;
112
			}
113
114
			logger.trace("\tChromosome {} - {}", chromosomeIndex, newChromosomes[chromosomeIndex]);
115
		}
116
117 2 1. mutate : replaced return value with null for net/bmahe/genetics4j/gp/mutation/TrimTreeMutator::mutate → NO_COVERAGE
2. mutate : removed call to net/bmahe/genetics4j/core/Genotype::<init> → NO_COVERAGE
		return new Genotype(newChromosomes);
118
	}
119
}

Mutations

38

1.1
Location : <init>
Killed by : none
Removed assignment to member variable programGenerator → NO_COVERAGE

39

1.1
Location : <init>
Killed by : none
Removed assignment to member variable randomGenerator → NO_COVERAGE

40

1.1
Location : <init>
Killed by : none
Removed assignment to member variable eaConfiguration → NO_COVERAGE

41

1.1
Location : <init>
Killed by : none
Removed assignment to member variable trimTree → NO_COVERAGE

49

1.1
Location : duplicateAndMutate
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/TreeNode::getData → NO_COVERAGE

51

1.1
Location : duplicateAndMutate
Killed by : none
removed conditional - replaced comparison check with true → NO_COVERAGE

2.2
Location : duplicateAndMutate
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/TreeNode::getSize → NO_COVERAGE

3.3
Location : duplicateAndMutate
Killed by : none
Substituted 1 with 0 → NO_COVERAGE

4.4
Location : duplicateAndMutate
Killed by : none
removed conditional - replaced equality check with false → NO_COVERAGE

5.5
Location : duplicateAndMutate
Killed by : none
removed conditional - replaced comparison check with false → NO_COVERAGE

6.6
Location : duplicateAndMutate
Killed by : none
negated conditional → NO_COVERAGE

7.7
Location : duplicateAndMutate
Killed by : none
negated conditional → NO_COVERAGE

8.8
Location : duplicateAndMutate
Killed by : none
removed conditional - replaced equality check with true → NO_COVERAGE

9.9
Location : duplicateAndMutate
Killed by : none
changed conditional boundary → NO_COVERAGE

52

1.1
Location : duplicateAndMutate
Killed by : none
removed call to net/bmahe/genetics4j/gp/Operation::returnedType → NO_COVERAGE

2.2
Location : duplicateAndMutate
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gp/mutation/TrimTreeMutator::duplicateAndMutate → NO_COVERAGE

3.3
Location : duplicateAndMutate
Killed by : none
Substituted 1 with 0 → NO_COVERAGE

4.4
Location : duplicateAndMutate
Killed by : none
removed call to net/bmahe/genetics4j/gp/program/ProgramGenerator::generate → NO_COVERAGE

55

1.1
Location : duplicateAndMutate
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/TreeNode::getChildren → NO_COVERAGE

57

1.1
Location : duplicateAndMutate
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/TreeNode::<init> → NO_COVERAGE

59

1.1
Location : duplicateAndMutate
Killed by : none
removed conditional - replaced comparison check with true → NO_COVERAGE

2.2
Location : duplicateAndMutate
Killed by : none
removed call to java/util/List::size → NO_COVERAGE

3.3
Location : duplicateAndMutate
Killed by : none
Substituted 0 with 1 → NO_COVERAGE

4.4
Location : duplicateAndMutate
Killed by : none
removed conditional - replaced comparison check with false → NO_COVERAGE

5.5
Location : duplicateAndMutate
Killed by : none
negated conditional → NO_COVERAGE

6.6
Location : duplicateAndMutate
Killed by : none
changed conditional boundary → NO_COVERAGE

60

1.1
Location : duplicateAndMutate
Killed by : none
removed call to java/util/List::get → NO_COVERAGE

61

1.1
Location : duplicateAndMutate
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/TreeNode::getSize → NO_COVERAGE

63

1.1
Location : duplicateAndMutate
Killed by : none
Substituted 1 with 0 → NO_COVERAGE

2.2
Location : duplicateAndMutate
Killed by : none
replaced call to net/bmahe/genetics4j/gp/mutation/TrimTreeMutator::duplicateAndMutate with argument → NO_COVERAGE

3.3
Location : duplicateAndMutate
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

4.4
Location : duplicateAndMutate
Killed by : none
removed call to net/bmahe/genetics4j/gp/mutation/TrimTreeMutator::duplicateAndMutate → NO_COVERAGE

64

1.1
Location : duplicateAndMutate
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/TreeNode::addChild → NO_COVERAGE

67

1.1
Location : duplicateAndMutate
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gp/mutation/TrimTreeMutator::duplicateAndMutate → NO_COVERAGE

74

1.1
Location : maxDepthValue
Killed by : none
removed call to java/lang/Integer::intValue → NO_COVERAGE

2.2
Location : lambda$maxDepthValue$0
Killed by : none
removed call to java/lang/Integer::valueOf → NO_COVERAGE

3.3
Location : maxDepthValue
Killed by : none
replaced int return with 0 for net/bmahe/genetics4j/gp/mutation/TrimTreeMutator::maxDepthValue → NO_COVERAGE

4.4
Location : lambda$maxDepthValue$0
Killed by : none
removed call to net/bmahe/genetics4j/gp/program/Program::maxDepth → NO_COVERAGE

5.5
Location : maxDepthValue
Killed by : none
removed call to java/util/Optional::orElseGet → NO_COVERAGE

6.6
Location : maxDepthValue
Killed by : none
removed call to net/bmahe/genetics4j/gp/spec/mutation/TrimTree::maxDepth → NO_COVERAGE

7.7
Location : lambda$maxDepthValue$0
Killed by : none
replaced Integer return value with 0 for net/bmahe/genetics4j/gp/mutation/TrimTreeMutator::lambda$maxDepthValue$0 → NO_COVERAGE

83

1.1
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/Genotype::getSize → NO_COVERAGE

84

1.1
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/Genotype::getChromosomes → NO_COVERAGE

85

1.1
Location : mutate
Killed by : none
Substituted 0 with 1 → NO_COVERAGE

2.2
Location : mutate
Killed by : none
changed conditional boundary → NO_COVERAGE

3.3
Location : mutate
Killed by : none
removed conditional - replaced comparison check with true → NO_COVERAGE

4.4
Location : mutate
Killed by : none
negated conditional → NO_COVERAGE

5.5
Location : mutate
Killed by : none
removed conditional - replaced comparison check with false → NO_COVERAGE

86

1.1
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/spec/AbstractEAConfiguration::getChromosomeSpec → NO_COVERAGE

89

1.1
Location : mutate
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : mutate
Killed by : none
removed conditional - replaced equality check with true → NO_COVERAGE

3.3
Location : mutate
Killed by : none
removed conditional - replaced equality check with false → NO_COVERAGE

90

1.1
Location : mutate
Killed by : none
removed call to java/lang/IllegalArgumentException::<init> → NO_COVERAGE

2.2
Location : mutate
Killed by : none
removed call to java/lang/String::valueOf → NO_COVERAGE

93

1.1
Location : mutate
Killed by : none
removed conditional - replaced equality check with false → NO_COVERAGE

2.2
Location : mutate
Killed by : none
removed conditional - replaced equality check with true → NO_COVERAGE

3.3
Location : mutate
Killed by : none
negated conditional → NO_COVERAGE

95

1.1
Location : mutate
Killed by : none
removed call to java/lang/Class::getSimpleName → NO_COVERAGE

2.2
Location : mutate
Killed by : none
removed call to java/lang/IllegalArgumentException::<init> → NO_COVERAGE

3.3
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/Chromosome::getClass → NO_COVERAGE

99

1.1
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/gp/spec/chromosome/ProgramTreeChromosomeSpec::program → NO_COVERAGE

103

1.1
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/gp/mutation/TrimTreeMutator::maxDepthValue → NO_COVERAGE

105

1.1
Location : mutate
Killed by : none
removed conditional - replaced comparison check with true → NO_COVERAGE

2.2
Location : mutate
Killed by : none
removed conditional - replaced comparison check with false → NO_COVERAGE

3.3
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/TreeChromosome::getRoot → NO_COVERAGE

4.4
Location : mutate
Killed by : none
changed conditional boundary → NO_COVERAGE

5.5
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/TreeNode::getDepth → NO_COVERAGE

6.6
Location : mutate
Killed by : none
negated conditional → NO_COVERAGE

106

1.1
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/TreeChromosome::getRoot → NO_COVERAGE

107

1.1
Location : mutate
Killed by : none
Substituted 0 with 1 → NO_COVERAGE

2.2
Location : mutate
Killed by : none
replaced call to net/bmahe/genetics4j/gp/mutation/TrimTreeMutator::duplicateAndMutate with argument → NO_COVERAGE

3.3
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/gp/mutation/TrimTreeMutator::duplicateAndMutate → NO_COVERAGE

108

1.1
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/TreeChromosome::<init> → NO_COVERAGE

117

1.1
Location : mutate
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gp/mutation/TrimTreeMutator::mutate → NO_COVERAGE

2.2
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/Genotype::<init> → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.19.6