1
|
|
package net.bmahe.genetics4j.core.combination.singlepointcrossover; |
2
|
|
|
3
|
|
import java.util.List; |
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.FloatChromosome; |
10
|
|
import net.bmahe.genetics4j.core.combination.ChromosomeCombinator; |
11
|
|
import net.bmahe.genetics4j.core.spec.AbstractEAConfiguration; |
12
|
|
|
13
|
|
public class FloatChromosomeSinglePointCrossover<T extends Comparable<T>> implements ChromosomeCombinator<T> { |
14
|
|
|
15
|
|
private final RandomGenerator randomGenerator; |
16
|
|
|
17
|
|
public FloatChromosomeSinglePointCrossover(final RandomGenerator _randomGenerator) { |
18
|
|
Validate.notNull(_randomGenerator); |
19
|
|
|
20
|
1
1. <init> : Removed assignment to member variable randomGenerator → KILLED
|
this.randomGenerator = _randomGenerator; |
21
|
|
} |
22
|
|
|
23
|
|
@Override |
24
|
|
public List<Chromosome> combine(final AbstractEAConfiguration<T> eaConfiguration, final Chromosome chromosome1, |
25
|
|
final T firstParentFitness, final Chromosome chromosome2, final T secondParentFitness) { |
26
|
|
Validate.notNull(chromosome1); |
27
|
|
Validate.notNull(chromosome2); |
28
|
|
Validate.isInstanceOf(FloatChromosome.class, chromosome1); |
29
|
|
Validate.isInstanceOf(FloatChromosome.class, chromosome2); |
30
|
|
Validate.isTrue(chromosome1.getNumAlleles() == chromosome2.getNumAlleles()); |
31
|
|
|
32
|
3
1. combine : removed call to net/bmahe/genetics4j/core/chromosomes/Chromosome::getNumAlleles → SURVIVED
2. combine : removed call to java/util/random/RandomGenerator::nextInt → KILLED
3. combine : replaced call to java/util/random/RandomGenerator::nextInt with argument → KILLED
|
final int alleleSplit = randomGenerator.nextInt(chromosome1.getNumAlleles()); |
33
|
|
|
34
|
|
final var floatChromosome1 = (FloatChromosome) chromosome1; |
35
|
|
final var floatChromosome2 = (FloatChromosome) chromosome2; |
36
|
|
|
37
|
1
1. combine : removed call to net/bmahe/genetics4j/core/chromosomes/Chromosome::getNumAlleles → KILLED
|
final int numAlleles = chromosome1.getNumAlleles(); |
38
|
|
final float[] firstChildValues = new float[numAlleles]; |
39
|
|
final float[] secondChildValues = new float[numAlleles]; |
40
|
|
|
41
|
5
1. combine : removed conditional - replaced comparison check with false → KILLED
2. combine : removed conditional - replaced comparison check with true → KILLED
3. combine : negated conditional → KILLED
4. combine : Substituted 0 with 1 → KILLED
5. combine : changed conditional boundary → KILLED
|
for (int i = 0; i < numAlleles; i++) { |
42
|
|
|
43
|
4
1. combine : negated conditional → KILLED
2. combine : removed conditional - replaced comparison check with true → KILLED
3. combine : removed conditional - replaced comparison check with false → KILLED
4. combine : changed conditional boundary → KILLED
|
if (i < alleleSplit) { |
44
|
1
1. combine : removed call to net/bmahe/genetics4j/core/chromosomes/FloatChromosome::getAllele → KILLED
|
firstChildValues[i] = floatChromosome1.getAllele(i); |
45
|
1
1. combine : removed call to net/bmahe/genetics4j/core/chromosomes/FloatChromosome::getAllele → KILLED
|
secondChildValues[i] = floatChromosome2.getAllele(i); |
46
|
|
} else { |
47
|
1
1. combine : removed call to net/bmahe/genetics4j/core/chromosomes/FloatChromosome::getAllele → KILLED
|
firstChildValues[i] = floatChromosome2.getAllele(i); |
48
|
1
1. combine : removed call to net/bmahe/genetics4j/core/chromosomes/FloatChromosome::getAllele → KILLED
|
secondChildValues[i] = floatChromosome1.getAllele(i); |
49
|
|
} |
50
|
|
} |
51
|
|
|
52
|
|
/** |
53
|
|
* TODO Should the min/max values be extended based on the lowest/highest |
54
|
|
* values? |
55
|
|
*/ |
56
|
1
1. combine : removed call to net/bmahe/genetics4j/core/chromosomes/FloatChromosome::getMinValue → SURVIVED
|
final float minValue = floatChromosome1.getMinValue(); |
57
|
1
1. combine : removed call to net/bmahe/genetics4j/core/chromosomes/FloatChromosome::getMaxValue → SURVIVED
|
final float maxValue = floatChromosome2.getMaxValue(); |
58
|
|
|
59
|
4
1. combine : replaced return value with Collections.emptyList for net/bmahe/genetics4j/core/combination/singlepointcrossover/FloatChromosomeSinglePointCrossover::combine → KILLED
2. combine : removed call to net/bmahe/genetics4j/core/chromosomes/FloatChromosome::<init> → KILLED
3. combine : removed call to net/bmahe/genetics4j/core/chromosomes/FloatChromosome::<init> → KILLED
4. combine : removed call to java/util/List::of → KILLED
|
return List.of(new FloatChromosome(numAlleles, minValue, maxValue, firstChildValues), |
60
|
|
new FloatChromosome(numAlleles, minValue, maxValue, secondChildValues)); |
61
|
|
} |
62
|
|
} |
| | Mutations |
20 |
|
1.1 Location : <init> Killed by : net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()] Removed assignment to member variable randomGenerator → KILLED
|
32 |
|
1.1 Location : combine Killed by : net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()] removed call to java/util/random/RandomGenerator::nextInt → KILLED
2.2 Location : combine Killed by : none removed call to net/bmahe/genetics4j/core/chromosomes/Chromosome::getNumAlleles → SURVIVED
Covering tests
Covered by tests:
- net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()]
3.3 Location : combine Killed by : net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()] replaced call to java/util/random/RandomGenerator::nextInt with argument → KILLED
|
37 |
|
1.1 Location : combine Killed by : net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()] removed call to net/bmahe/genetics4j/core/chromosomes/Chromosome::getNumAlleles → KILLED
|
41 |
|
1.1 Location : combine Killed by : net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()] removed conditional - replaced comparison check with false → KILLED
2.2 Location : combine Killed by : net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()] removed conditional - replaced comparison check with true → KILLED
3.3 Location : combine Killed by : net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()] negated conditional → KILLED
4.4 Location : combine Killed by : net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()] Substituted 0 with 1 → KILLED
5.5 Location : combine Killed by : net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()] changed conditional boundary → KILLED
|
43 |
|
1.1 Location : combine Killed by : net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()] negated conditional → KILLED
2.2 Location : combine Killed by : net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()] removed conditional - replaced comparison check with true → KILLED
3.3 Location : combine Killed by : net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()] removed conditional - replaced comparison check with false → KILLED
4.4 Location : combine Killed by : net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()] changed conditional boundary → KILLED
|
44 |
|
1.1 Location : combine Killed by : net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()] removed call to net/bmahe/genetics4j/core/chromosomes/FloatChromosome::getAllele → KILLED
|
45 |
|
1.1 Location : combine Killed by : net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()] removed call to net/bmahe/genetics4j/core/chromosomes/FloatChromosome::getAllele → KILLED
|
47 |
|
1.1 Location : combine Killed by : net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()] removed call to net/bmahe/genetics4j/core/chromosomes/FloatChromosome::getAllele → KILLED
|
48 |
|
1.1 Location : combine Killed by : net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()] removed call to net/bmahe/genetics4j/core/chromosomes/FloatChromosome::getAllele → KILLED
|
56 |
|
1.1 Location : combine Killed by : none removed call to net/bmahe/genetics4j/core/chromosomes/FloatChromosome::getMinValue → SURVIVED
Covering tests
Covered by tests:
- net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()]
|
57 |
|
1.1 Location : combine Killed by : none removed call to net/bmahe/genetics4j/core/chromosomes/FloatChromosome::getMaxValue → SURVIVED
Covering tests
Covered by tests:
- net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()]
|
59 |
|
1.1 Location : combine Killed by : net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()] replaced return value with Collections.emptyList for net/bmahe/genetics4j/core/combination/singlepointcrossover/FloatChromosomeSinglePointCrossover::combine → KILLED
2.2 Location : combine Killed by : net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()] removed call to net/bmahe/genetics4j/core/chromosomes/FloatChromosome::<init> → KILLED
3.3 Location : combine Killed by : net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()] removed call to net/bmahe/genetics4j/core/chromosomes/FloatChromosome::<init> → KILLED
4.4 Location : combine Killed by : net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.combination.singlepointcrossover.FloatChromosomeSinglePointCrossoverTest]/[method:combineTest()] removed call to java/util/List::of → KILLED
|