GPEAExecutionContexts.java

1
package net.bmahe.genetics4j.gp.spec;
2
3
import java.util.Objects;
4
import java.util.random.RandomGenerator;
5
6
import net.bmahe.genetics4j.core.chromosomes.factory.ImmutableChromosomeFactoryProvider;
7
import net.bmahe.genetics4j.core.spec.ImmutableEAExecutionContext;
8
import net.bmahe.genetics4j.core.spec.ImmutableEAExecutionContext.Builder;
9
import net.bmahe.genetics4j.gp.chromosomes.factory.ProgramTreeChromosomeFactory;
10
import net.bmahe.genetics4j.gp.combination.ProgramRandomCombineHandler;
11
import net.bmahe.genetics4j.gp.mutation.NodeReplacementPolicyHandler;
12
import net.bmahe.genetics4j.gp.mutation.ProgramRandomMutatePolicyHandler;
13
import net.bmahe.genetics4j.gp.mutation.ProgramRandomPrunePolicyHandler;
14
import net.bmahe.genetics4j.gp.mutation.ProgramRulesApplicatorPolicyHandler;
15
import net.bmahe.genetics4j.gp.mutation.TrimTreePolicyHandler;
16
import net.bmahe.genetics4j.gp.program.ProgramGenerator;
17
import net.bmahe.genetics4j.gp.program.ProgramHelper;
18
import net.bmahe.genetics4j.gp.program.RampedHalfAndHalfProgramGenerator;
19
20
/**
21
 * Defines multiple factory and helper methods to create and manage EAExecutionContexts appropriate for Genetic
22
 * Programming
23
 */
24
public class GPEAExecutionContexts {
25
26
	private GPEAExecutionContexts() {
27
	}
28
29
	/**
30
	 * Create a new EAExecutionContext pre-configured to support Genetic Programming.
31
	 * <p>It adds support for some operators to select, mutate and combine programs.
32
	 * 
33
	 * @param <T>              Type of the fitness measurement
34
	 * @param randomGenerator  Random Generator
35
	 * @param programHelper    Instance of ProgramHelper
36
	 * @param programGenerator Instance of a program generator which will be used to generate individuals
37
	 * @return A new instance of a EAExecutionContext
38
	 */
39
	public static <T extends Comparable<T>> Builder<T> forGP(final RandomGenerator randomGenerator,
40
			final ProgramHelper programHelper, final ProgramGenerator programGenerator) {
41
		Objects.requireNonNull(randomGenerator);
42
		Objects.requireNonNull(programHelper);
43
		Objects.requireNonNull(programGenerator);
44
45 1 1. forGP : removed call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext::builder → NO_COVERAGE
		final var builder = ImmutableEAExecutionContext.<T>builder();
46 2 1. forGP : replaced call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::randomGenerator with receiver → NO_COVERAGE
2. forGP : removed call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::randomGenerator → NO_COVERAGE
		builder.randomGenerator(randomGenerator);
47
48 8 1. forGP : Substituted 5 with 6 → NO_COVERAGE
2. forGP : Substituted 1 with 0 → NO_COVERAGE
3. forGP : replaced call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::addMutationPolicyHandlerFactories with receiver → NO_COVERAGE
4. forGP : Substituted 0 with 1 → NO_COVERAGE
5. forGP : Substituted 2 with 3 → NO_COVERAGE
6. forGP : Substituted 3 with 4 → NO_COVERAGE
7. forGP : removed call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::addMutationPolicyHandlerFactories → NO_COVERAGE
8. forGP : Substituted 4 with 5 → NO_COVERAGE
		builder.addMutationPolicyHandlerFactories(
49 3 1. lambda$forGP$0 : replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$0 → NO_COVERAGE
2. lambda$forGP$0 : removed call to net/bmahe/genetics4j/core/spec/AbstractEAExecutionContext::randomGenerator → NO_COVERAGE
3. lambda$forGP$0 : removed call to net/bmahe/genetics4j/gp/mutation/ProgramRandomPrunePolicyHandler::<init> → NO_COVERAGE
				gsd -> new ProgramRandomPrunePolicyHandler<>(gsd.randomGenerator(), programHelper),
50 3 1. lambda$forGP$1 : replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$1 → NO_COVERAGE
2. lambda$forGP$1 : removed call to net/bmahe/genetics4j/gp/mutation/ProgramRandomMutatePolicyHandler::<init> → NO_COVERAGE
3. lambda$forGP$1 : removed call to net/bmahe/genetics4j/core/spec/AbstractEAExecutionContext::randomGenerator → NO_COVERAGE
					gsd -> new ProgramRandomMutatePolicyHandler<>(gsd.randomGenerator(), programGenerator),
51 2 1. lambda$forGP$2 : removed call to net/bmahe/genetics4j/gp/mutation/NodeReplacementPolicyHandler::<init> → NO_COVERAGE
2. lambda$forGP$2 : replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$2 → NO_COVERAGE
					gsd -> new NodeReplacementPolicyHandler<>(randomGenerator, programHelper),
52 2 1. lambda$forGP$3 : removed call to net/bmahe/genetics4j/gp/mutation/ProgramRulesApplicatorPolicyHandler::<init> → NO_COVERAGE
2. lambda$forGP$3 : replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$3 → NO_COVERAGE
					gsd -> new ProgramRulesApplicatorPolicyHandler<>(),
53 2 1. lambda$forGP$4 : replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$4 → NO_COVERAGE
2. lambda$forGP$4 : removed call to net/bmahe/genetics4j/gp/mutation/TrimTreePolicyHandler::<init> → NO_COVERAGE
					gsd -> new TrimTreePolicyHandler<>(randomGenerator, programGenerator));
54
55 5 1. lambda$forGP$5 : replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$5 → NO_COVERAGE
2. forGP : replaced call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::addChromosomeCombinatorHandlerFactories with receiver → NO_COVERAGE
3. forGP : removed call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::addChromosomeCombinatorHandlerFactories → NO_COVERAGE
4. lambda$forGP$5 : removed call to net/bmahe/genetics4j/gp/combination/ProgramRandomCombineHandler::<init> → NO_COVERAGE
5. lambda$forGP$5 : removed call to net/bmahe/genetics4j/core/spec/AbstractEAExecutionContext::randomGenerator → NO_COVERAGE
		builder.addChromosomeCombinatorHandlerFactories(gsd -> new ProgramRandomCombineHandler<T>(gsd.randomGenerator()));
56
57 1 1. forGP : removed call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider::builder → NO_COVERAGE
		final var chromosomeFactoryProviderBuilder = ImmutableChromosomeFactoryProvider.builder();
58 2 1. forGP : replaced call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider$Builder::randomGenerator with receiver → NO_COVERAGE
2. forGP : removed call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider$Builder::randomGenerator → NO_COVERAGE
		chromosomeFactoryProviderBuilder.randomGenerator(randomGenerator);
59
		chromosomeFactoryProviderBuilder
60 4 1. forGP : removed call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider$Builder::addChromosomeFactoriesGenerator → NO_COVERAGE
2. lambda$forGP$6 : removed call to net/bmahe/genetics4j/gp/chromosomes/factory/ProgramTreeChromosomeFactory::<init> → NO_COVERAGE
3. forGP : replaced call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider$Builder::addChromosomeFactoriesGenerator with receiver → NO_COVERAGE
4. lambda$forGP$6 : replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$6 → NO_COVERAGE
				.addChromosomeFactoriesGenerator(cdp -> new ProgramTreeChromosomeFactory(programGenerator));
61 3 1. forGP : removed call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::chromosomeFactoryProvider → NO_COVERAGE
2. forGP : removed call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider$Builder::build → NO_COVERAGE
3. forGP : replaced call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::chromosomeFactoryProvider with receiver → NO_COVERAGE
		builder.chromosomeFactoryProvider(chromosomeFactoryProviderBuilder.build());
62
63 1 1. forGP : replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::forGP → NO_COVERAGE
		return builder;
64
	}
65
66
	/**
67
	 * Create a new EAExecutionContext pre-configured to support Genetic Programming.
68
	 * <p>It adds support for some operators to select, mutate and combine programs. It also configure a default program
69
	 * generation based on ramped hald and half.
70
	 * 
71
	 * @param <T>             Type of the fitness measurement
72
	 * @param randomGenerator Random Generator
73
	 * @return A new instance of a EAExecutionContext
74
	 */
75
	public static <T extends Comparable<T>> Builder<T> forGP(final RandomGenerator randomGenerator) {
76
		Objects.requireNonNull(randomGenerator);
77
78 1 1. forGP : removed call to net/bmahe/genetics4j/gp/program/ProgramHelper::<init> → NO_COVERAGE
		final var programHelper = new ProgramHelper(randomGenerator);
79 1 1. forGP : removed call to net/bmahe/genetics4j/gp/program/RampedHalfAndHalfProgramGenerator::<init> → NO_COVERAGE
		final var programGenerator = new RampedHalfAndHalfProgramGenerator(randomGenerator, programHelper);
80
81 2 1. forGP : removed call to net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::forGP → NO_COVERAGE
2. forGP : replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::forGP → NO_COVERAGE
		return forGP(randomGenerator, programHelper, programGenerator);
82
	}
83
}

Mutations

45

1.1
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext::builder → NO_COVERAGE

46

1.1
Location : forGP
Killed by : none
replaced call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::randomGenerator with receiver → NO_COVERAGE

2.2
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::randomGenerator → NO_COVERAGE

48

1.1
Location : forGP
Killed by : none
Substituted 5 with 6 → NO_COVERAGE

2.2
Location : forGP
Killed by : none
Substituted 1 with 0 → NO_COVERAGE

3.3
Location : forGP
Killed by : none
replaced call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::addMutationPolicyHandlerFactories with receiver → NO_COVERAGE

4.4
Location : forGP
Killed by : none
Substituted 0 with 1 → NO_COVERAGE

5.5
Location : forGP
Killed by : none
Substituted 2 with 3 → NO_COVERAGE

6.6
Location : forGP
Killed by : none
Substituted 3 with 4 → NO_COVERAGE

7.7
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::addMutationPolicyHandlerFactories → NO_COVERAGE

8.8
Location : forGP
Killed by : none
Substituted 4 with 5 → NO_COVERAGE

49

1.1
Location : lambda$forGP$0
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$0 → NO_COVERAGE

2.2
Location : lambda$forGP$0
Killed by : none
removed call to net/bmahe/genetics4j/core/spec/AbstractEAExecutionContext::randomGenerator → NO_COVERAGE

3.3
Location : lambda$forGP$0
Killed by : none
removed call to net/bmahe/genetics4j/gp/mutation/ProgramRandomPrunePolicyHandler::<init> → NO_COVERAGE

50

1.1
Location : lambda$forGP$1
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$1 → NO_COVERAGE

2.2
Location : lambda$forGP$1
Killed by : none
removed call to net/bmahe/genetics4j/gp/mutation/ProgramRandomMutatePolicyHandler::<init> → NO_COVERAGE

3.3
Location : lambda$forGP$1
Killed by : none
removed call to net/bmahe/genetics4j/core/spec/AbstractEAExecutionContext::randomGenerator → NO_COVERAGE

51

1.1
Location : lambda$forGP$2
Killed by : none
removed call to net/bmahe/genetics4j/gp/mutation/NodeReplacementPolicyHandler::<init> → NO_COVERAGE

2.2
Location : lambda$forGP$2
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$2 → NO_COVERAGE

52

1.1
Location : lambda$forGP$3
Killed by : none
removed call to net/bmahe/genetics4j/gp/mutation/ProgramRulesApplicatorPolicyHandler::<init> → NO_COVERAGE

2.2
Location : lambda$forGP$3
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$3 → NO_COVERAGE

53

1.1
Location : lambda$forGP$4
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$4 → NO_COVERAGE

2.2
Location : lambda$forGP$4
Killed by : none
removed call to net/bmahe/genetics4j/gp/mutation/TrimTreePolicyHandler::<init> → NO_COVERAGE

55

1.1
Location : lambda$forGP$5
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$5 → NO_COVERAGE

2.2
Location : forGP
Killed by : none
replaced call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::addChromosomeCombinatorHandlerFactories with receiver → NO_COVERAGE

3.3
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::addChromosomeCombinatorHandlerFactories → NO_COVERAGE

4.4
Location : lambda$forGP$5
Killed by : none
removed call to net/bmahe/genetics4j/gp/combination/ProgramRandomCombineHandler::<init> → NO_COVERAGE

5.5
Location : lambda$forGP$5
Killed by : none
removed call to net/bmahe/genetics4j/core/spec/AbstractEAExecutionContext::randomGenerator → NO_COVERAGE

57

1.1
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider::builder → NO_COVERAGE

58

1.1
Location : forGP
Killed by : none
replaced call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider$Builder::randomGenerator with receiver → NO_COVERAGE

2.2
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider$Builder::randomGenerator → NO_COVERAGE

60

1.1
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider$Builder::addChromosomeFactoriesGenerator → NO_COVERAGE

2.2
Location : lambda$forGP$6
Killed by : none
removed call to net/bmahe/genetics4j/gp/chromosomes/factory/ProgramTreeChromosomeFactory::<init> → NO_COVERAGE

3.3
Location : forGP
Killed by : none
replaced call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider$Builder::addChromosomeFactoriesGenerator with receiver → NO_COVERAGE

4.4
Location : lambda$forGP$6
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::lambda$forGP$6 → NO_COVERAGE

61

1.1
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::chromosomeFactoryProvider → NO_COVERAGE

2.2
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/factory/ImmutableChromosomeFactoryProvider$Builder::build → NO_COVERAGE

3.3
Location : forGP
Killed by : none
replaced call to net/bmahe/genetics4j/core/spec/ImmutableEAExecutionContext$Builder::chromosomeFactoryProvider with receiver → NO_COVERAGE

63

1.1
Location : forGP
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::forGP → NO_COVERAGE

78

1.1
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/gp/program/ProgramHelper::<init> → NO_COVERAGE

79

1.1
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/gp/program/RampedHalfAndHalfProgramGenerator::<init> → NO_COVERAGE

81

1.1
Location : forGP
Killed by : none
removed call to net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::forGP → NO_COVERAGE

2.2
Location : forGP
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gp/spec/GPEAExecutionContexts::forGP → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.25.7 support