1
|
|
package net.bmahe.genetics4j.neat.mutation.chromosome; |
2
|
|
|
3
|
|
import java.util.ArrayList; |
4
|
|
import java.util.List; |
5
|
|
import java.util.random.RandomGenerator; |
6
|
|
|
7
|
|
import org.apache.commons.lang3.Validate; |
8
|
|
import org.apache.logging.log4j.LogManager; |
9
|
|
import org.apache.logging.log4j.Logger; |
10
|
|
|
11
|
|
import net.bmahe.genetics4j.core.chromosomes.Chromosome; |
12
|
|
import net.bmahe.genetics4j.core.mutation.chromosome.ChromosomeMutationHandler; |
13
|
|
import net.bmahe.genetics4j.core.spec.chromosome.ChromosomeSpec; |
14
|
|
import net.bmahe.genetics4j.core.spec.mutation.MutationPolicy; |
15
|
|
import net.bmahe.genetics4j.neat.Connection; |
16
|
|
import net.bmahe.genetics4j.neat.chromosomes.NeatChromosome; |
17
|
|
import net.bmahe.genetics4j.neat.spec.NeatChromosomeSpec; |
18
|
|
import net.bmahe.genetics4j.neat.spec.mutation.DeleteConnection; |
19
|
|
|
20
|
|
public class NeatChromosomeDeleteConnection implements ChromosomeMutationHandler<NeatChromosome> { |
21
|
|
|
22
|
|
public static final Logger logger = LogManager.getLogger(NeatChromosomeDeleteConnection.class); |
23
|
|
|
24
|
|
private final RandomGenerator randomGenerator; |
25
|
|
|
26
|
|
public NeatChromosomeDeleteConnection(final RandomGenerator _randomGenerator) { |
27
|
|
Validate.notNull(_randomGenerator); |
28
|
|
|
29
|
1
1. <init> : Removed assignment to member variable randomGenerator → KILLED
|
this.randomGenerator = _randomGenerator; |
30
|
|
} |
31
|
|
|
32
|
|
@Override |
33
|
|
public boolean canHandle(final MutationPolicy mutationPolicy, final ChromosomeSpec chromosome) { |
34
|
|
Validate.notNull(mutationPolicy); |
35
|
|
Validate.notNull(chromosome); |
36
|
|
|
37
|
9
1. canHandle : negated conditional → KILLED
2. canHandle : replaced boolean return with true for net/bmahe/genetics4j/neat/mutation/chromosome/NeatChromosomeDeleteConnection::canHandle → KILLED
3. canHandle : negated conditional → KILLED
4. canHandle : removed conditional - replaced equality check with false → KILLED
5. canHandle : removed conditional - replaced equality check with true → KILLED
6. canHandle : removed conditional - replaced equality check with false → KILLED
7. canHandle : Substituted 1 with 0 → KILLED
8. canHandle : Substituted 0 with 1 → KILLED
9. canHandle : removed conditional - replaced equality check with true → KILLED
|
return mutationPolicy instanceof DeleteConnection && chromosome instanceof NeatChromosomeSpec; |
38
|
|
} |
39
|
|
|
40
|
|
@Override |
41
|
|
public NeatChromosome mutate(final MutationPolicy mutationPolicy, final Chromosome chromosome) { |
42
|
|
Validate.notNull(mutationPolicy); |
43
|
|
Validate.notNull(chromosome); |
44
|
|
Validate.isInstanceOf(DeleteConnection.class, mutationPolicy); |
45
|
|
Validate.isInstanceOf(NeatChromosome.class, chromosome); |
46
|
|
|
47
|
|
final var neatChromosome = (NeatChromosome) chromosome; |
48
|
1
1. mutate : removed call to net/bmahe/genetics4j/neat/chromosomes/NeatChromosome::getNumInputs → KILLED
|
final var numInputs = neatChromosome.getNumInputs(); |
49
|
1
1. mutate : removed call to net/bmahe/genetics4j/neat/chromosomes/NeatChromosome::getNumOutputs → KILLED
|
final var numOutputs = neatChromosome.getNumOutputs(); |
50
|
1
1. mutate : removed call to net/bmahe/genetics4j/neat/chromosomes/NeatChromosome::getMinWeightValue → SURVIVED
|
final var minValue = neatChromosome.getMinWeightValue(); |
51
|
1
1. mutate : removed call to net/bmahe/genetics4j/neat/chromosomes/NeatChromosome::getMaxWeightValue → SURVIVED
|
final var maxValue = neatChromosome.getMaxWeightValue(); |
52
|
|
|
53
|
1
1. mutate : removed call to net/bmahe/genetics4j/neat/chromosomes/NeatChromosome::getConnections → KILLED
|
final var oldConnections = neatChromosome.getConnections(); |
54
|
1
1. mutate : removed call to java/util/ArrayList::<init> → KILLED
|
final List<Connection> newConnections = new ArrayList<>(oldConnections); |
55
|
|
|
56
|
5
1. mutate : changed conditional boundary → KILLED
2. mutate : removed conditional - replaced comparison check with true → KILLED
3. mutate : negated conditional → KILLED
4. mutate : removed conditional - replaced comparison check with false → KILLED
5. mutate : removed call to java/util/List::size → KILLED
|
if (oldConnections.size() > 0) { |
57
|
3
1. mutate : removed call to java/util/List::size → SURVIVED
2. mutate : replaced call to java/util/random/RandomGenerator::nextInt with argument → KILLED
3. mutate : removed call to java/util/random/RandomGenerator::nextInt → KILLED
|
final int connectionToDeleteIndex = randomGenerator.nextInt(oldConnections.size()); |
58
|
1
1. mutate : removed call to java/util/List::remove → KILLED
|
newConnections.remove(connectionToDeleteIndex); |
59
|
|
} |
60
|
|
|
61
|
2
1. mutate : replaced return value with null for net/bmahe/genetics4j/neat/mutation/chromosome/NeatChromosomeDeleteConnection::mutate → KILLED
2. mutate : removed call to net/bmahe/genetics4j/neat/chromosomes/NeatChromosome::<init> → KILLED
|
return new NeatChromosome(numInputs, numOutputs, minValue, maxValue, newConnections); |
62
|
|
} |
63
|
|
} |
| | Mutations |
29 |
|
1.1 Location : <init> Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:mutateConnectionExist()] Removed assignment to member variable randomGenerator → KILLED
|
37 |
|
1.1 Location : canHandle Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:canHandle()] negated conditional → KILLED
2.2 Location : canHandle Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:canHandle()] replaced boolean return with true for net/bmahe/genetics4j/neat/mutation/chromosome/NeatChromosomeDeleteConnection::canHandle → KILLED
3.3 Location : canHandle Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:canHandle()] negated conditional → KILLED
4.4 Location : canHandle Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:canHandle()] removed conditional - replaced equality check with false → KILLED
5.5 Location : canHandle Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:canHandle()] removed conditional - replaced equality check with true → KILLED
6.6 Location : canHandle Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:canHandle()] removed conditional - replaced equality check with false → KILLED
7.7 Location : canHandle Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:canHandle()] Substituted 1 with 0 → KILLED
8.8 Location : canHandle Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:canHandle()] Substituted 0 with 1 → KILLED
9.9 Location : canHandle Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:canHandle()] removed conditional - replaced equality check with true → KILLED
|
48 |
|
1.1 Location : mutate Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:mutateEmptyConnection()] removed call to net/bmahe/genetics4j/neat/chromosomes/NeatChromosome::getNumInputs → KILLED
|
49 |
|
1.1 Location : mutate Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:mutateEmptyConnection()] removed call to net/bmahe/genetics4j/neat/chromosomes/NeatChromosome::getNumOutputs → KILLED
|
50 |
|
1.1 Location : mutate Killed by : none removed call to net/bmahe/genetics4j/neat/chromosomes/NeatChromosome::getMinWeightValue → SURVIVED
Covering tests
Covered by tests:
- net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:mutateEmptyConnection()]
- net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:mutateConnectionExist()]
|
51 |
|
1.1 Location : mutate Killed by : none removed call to net/bmahe/genetics4j/neat/chromosomes/NeatChromosome::getMaxWeightValue → SURVIVED
Covering tests
Covered by tests:
- net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:mutateEmptyConnection()]
- net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:mutateConnectionExist()]
|
53 |
|
1.1 Location : mutate Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:mutateEmptyConnection()] removed call to net/bmahe/genetics4j/neat/chromosomes/NeatChromosome::getConnections → KILLED
|
54 |
|
1.1 Location : mutate Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:mutateEmptyConnection()] removed call to java/util/ArrayList::<init> → KILLED
|
56 |
|
1.1 Location : mutate Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:mutateEmptyConnection()] changed conditional boundary → KILLED
2.2 Location : mutate Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:mutateEmptyConnection()] removed conditional - replaced comparison check with true → KILLED
3.3 Location : mutate Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:mutateEmptyConnection()] negated conditional → KILLED
4.4 Location : mutate Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:mutateConnectionExist()] removed conditional - replaced comparison check with false → KILLED
5.5 Location : mutate Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:mutateConnectionExist()] removed call to java/util/List::size → KILLED
|
57 |
|
1.1 Location : mutate Killed by : none removed call to java/util/List::size → SURVIVED
Covering tests
Covered by tests:
- net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:mutateConnectionExist()]
2.2 Location : mutate Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:mutateConnectionExist()] replaced call to java/util/random/RandomGenerator::nextInt with argument → KILLED
3.3 Location : mutate Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:mutateConnectionExist()] removed call to java/util/random/RandomGenerator::nextInt → KILLED
|
58 |
|
1.1 Location : mutate Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:mutateConnectionExist()] removed call to java/util/List::remove → KILLED
|
61 |
|
1.1 Location : mutate Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:mutateEmptyConnection()] replaced return value with null for net/bmahe/genetics4j/neat/mutation/chromosome/NeatChromosomeDeleteConnection::mutate → KILLED
2.2 Location : mutate Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeDeleteConnectionTest]/[method:mutateEmptyConnection()] removed call to net/bmahe/genetics4j/neat/chromosomes/NeatChromosome::<init> → KILLED
|