1
|
|
package net.bmahe.genetics4j.core.mutation.chromosome.randommutation; |
2
|
|
|
3
|
|
import java.util.Arrays; |
4
|
|
import java.util.random.RandomGenerator; |
5
|
|
|
6
|
|
import org.apache.commons.lang3.Validate; |
7
|
|
|
8
|
|
import net.bmahe.genetics4j.core.chromosomes.Chromosome; |
9
|
|
import net.bmahe.genetics4j.core.chromosomes.DoubleChromosome; |
10
|
|
import net.bmahe.genetics4j.core.mutation.chromosome.ChromosomeMutationHandler; |
11
|
|
import net.bmahe.genetics4j.core.spec.chromosome.ChromosomeSpec; |
12
|
|
import net.bmahe.genetics4j.core.spec.chromosome.DoubleChromosomeSpec; |
13
|
|
import net.bmahe.genetics4j.core.spec.mutation.MutationPolicy; |
14
|
|
import net.bmahe.genetics4j.core.spec.mutation.RandomMutation; |
15
|
|
|
16
|
|
public class DoubleChromosomeRandomMutationHandler implements ChromosomeMutationHandler<DoubleChromosome> { |
17
|
|
|
18
|
|
private final RandomGenerator randomGenerator; |
19
|
|
|
20
|
|
public DoubleChromosomeRandomMutationHandler(final RandomGenerator _randomGenerator) { |
21
|
|
Validate.notNull(_randomGenerator); |
22
|
|
|
23
|
1
1. <init> : Removed assignment to member variable randomGenerator → KILLED
|
this.randomGenerator = _randomGenerator; |
24
|
|
} |
25
|
|
|
26
|
|
@Override |
27
|
|
public boolean canHandle(final MutationPolicy mutationPolicy, final ChromosomeSpec chromosome) { |
28
|
|
Validate.notNull(mutationPolicy); |
29
|
|
Validate.notNull(chromosome); |
30
|
|
|
31
|
9
1. canHandle : removed conditional - replaced equality check with true → SURVIVED
2. canHandle : Substituted 0 with 1 → KILLED
3. canHandle : removed conditional - replaced equality check with true → KILLED
4. canHandle : replaced boolean return with true for net/bmahe/genetics4j/core/mutation/chromosome/randommutation/DoubleChromosomeRandomMutationHandler::canHandle → KILLED
5. canHandle : negated conditional → KILLED
6. canHandle : removed conditional - replaced equality check with false → KILLED
7. canHandle : negated conditional → KILLED
8. canHandle : Substituted 1 with 0 → KILLED
9. canHandle : removed conditional - replaced equality check with false → KILLED
|
return mutationPolicy instanceof RandomMutation && chromosome instanceof DoubleChromosomeSpec; |
32
|
|
} |
33
|
|
|
34
|
|
@Override |
35
|
|
public DoubleChromosome mutate(final MutationPolicy mutationPolicy, final Chromosome chromosome) { |
36
|
|
Validate.notNull(mutationPolicy); |
37
|
|
Validate.notNull(chromosome); |
38
|
|
Validate.isInstanceOf(RandomMutation.class, mutationPolicy); |
39
|
|
Validate.isInstanceOf(DoubleChromosome.class, chromosome); |
40
|
|
|
41
|
|
final DoubleChromosome doubleChromosome = (DoubleChromosome) chromosome; |
42
|
1
1. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/DoubleChromosome::getMinValue → KILLED
|
final double minValue = doubleChromosome.getMinValue(); |
43
|
1
1. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/DoubleChromosome::getMaxValue → KILLED
|
final double maxValue = doubleChromosome.getMaxValue(); |
44
|
|
|
45
|
4
1. mutate : replaced call to java/util/Arrays::copyOf with argument → SURVIVED
2. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/DoubleChromosome::getNumAlleles → KILLED
3. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/DoubleChromosome::getValues → KILLED
4. mutate : removed call to java/util/Arrays::copyOf → KILLED
|
final double[] newValues = Arrays.copyOf(doubleChromosome.getValues(), doubleChromosome.getNumAlleles()); |
46
|
|
|
47
|
3
1. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/DoubleChromosome::getNumAlleles → SURVIVED
2. mutate : removed call to java/util/random/RandomGenerator::nextInt → KILLED
3. mutate : replaced call to java/util/random/RandomGenerator::nextInt with argument → KILLED
|
final int alleleFlipIndex = randomGenerator.nextInt(doubleChromosome.getNumAlleles()); |
48
|
4
1. mutate : removed call to java/util/random/RandomGenerator::nextDouble → KILLED
2. mutate : Replaced double multiplication with division → KILLED
3. mutate : Replaced double subtraction with addition → KILLED
4. mutate : Replaced double addition with subtraction → KILLED
|
newValues[alleleFlipIndex] = minValue + randomGenerator.nextDouble() * (maxValue - minValue); |
49
|
|
|
50
|
3
1. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/DoubleChromosome::<init> → KILLED
2. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/DoubleChromosome::getSize → KILLED
3. mutate : replaced return value with null for net/bmahe/genetics4j/core/mutation/chromosome/randommutation/DoubleChromosomeRandomMutationHandler::mutate → KILLED
|
return new DoubleChromosome(doubleChromosome.getSize(), minValue, maxValue, newValues); |
51
|
|
} |
52
|
|
} |
| | Mutations |
23 |
|
1.1 Location : <init> Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:mutateValidate()] Removed assignment to member variable randomGenerator → KILLED
|
31 |
|
1.1 Location : canHandle Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:canHandle()] Substituted 0 with 1 → KILLED
2.2 Location : canHandle Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:canHandle()] removed conditional - replaced equality check with true → KILLED
3.3 Location : canHandle Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:canHandle()] replaced boolean return with true for net/bmahe/genetics4j/core/mutation/chromosome/randommutation/DoubleChromosomeRandomMutationHandler::canHandle → KILLED
4.4 Location : canHandle Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:canHandle()] negated conditional → KILLED
5.5 Location : canHandle Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:canHandle()] removed conditional - replaced equality check with false → KILLED
6.6 Location : canHandle Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:canHandle()] negated conditional → KILLED
7.7 Location : canHandle Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:canHandle()] Substituted 1 with 0 → KILLED
8.8 Location : canHandle Killed by : none removed conditional - replaced equality check with true → SURVIVED
Covering tests
Covered by tests:
- net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:canHandle()]
- net.bmahe.genetics4j.core.mutation.SupersimpleTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.SupersimpleTest]/[method:simple()]
9.9 Location : canHandle Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:canHandle()] removed conditional - replaced equality check with false → KILLED
|
42 |
|
1.1 Location : mutate Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:mutateValidate()] removed call to net/bmahe/genetics4j/core/chromosomes/DoubleChromosome::getMinValue → KILLED
|
43 |
|
1.1 Location : mutate Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:mutateValidate()] removed call to net/bmahe/genetics4j/core/chromosomes/DoubleChromosome::getMaxValue → KILLED
|
45 |
|
1.1 Location : mutate Killed by : none replaced call to java/util/Arrays::copyOf with argument → SURVIVED
Covering tests
Covered by tests:
- net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:mutateValidate()]
2.2 Location : mutate Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:mutateValidate()] removed call to net/bmahe/genetics4j/core/chromosomes/DoubleChromosome::getNumAlleles → KILLED
3.3 Location : mutate Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:mutateValidate()] removed call to net/bmahe/genetics4j/core/chromosomes/DoubleChromosome::getValues → KILLED
4.4 Location : mutate Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:mutateValidate()] removed call to java/util/Arrays::copyOf → KILLED
|
47 |
|
1.1 Location : mutate Killed by : none removed call to net/bmahe/genetics4j/core/chromosomes/DoubleChromosome::getNumAlleles → SURVIVED
Covering tests
Covered by tests:
- net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:mutateValidate()]
2.2 Location : mutate Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:mutateValidate()] removed call to java/util/random/RandomGenerator::nextInt → KILLED
3.3 Location : mutate Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:mutateValidate()] replaced call to java/util/random/RandomGenerator::nextInt with argument → KILLED
|
48 |
|
1.1 Location : mutate Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:mutateValidate()] removed call to java/util/random/RandomGenerator::nextDouble → KILLED
2.2 Location : mutate Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:mutateValidate()] Replaced double multiplication with division → KILLED
3.3 Location : mutate Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:mutateValidate()] Replaced double subtraction with addition → KILLED
4.4 Location : mutate Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:mutateValidate()] Replaced double addition with subtraction → KILLED
|
50 |
|
1.1 Location : mutate Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:mutateValidate()] removed call to net/bmahe/genetics4j/core/chromosomes/DoubleChromosome::<init> → KILLED
2.2 Location : mutate Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:mutateValidate()] removed call to net/bmahe/genetics4j/core/chromosomes/DoubleChromosome::getSize → KILLED
3.3 Location : mutate Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.DoubleChromosomeRandomMutationHandlerTest]/[method:mutateValidate()] replaced return value with null for net/bmahe/genetics4j/core/mutation/chromosome/randommutation/DoubleChromosomeRandomMutationHandler::mutate → KILLED
|