aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/modules/mutator
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/backend/modules/mutator')
-rw-r--r--src/jcgp/backend/modules/mutator/PointMutator.java17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/jcgp/backend/modules/mutator/PointMutator.java b/src/jcgp/backend/modules/mutator/PointMutator.java
index ab8efad..44c453a 100644
--- a/src/jcgp/backend/modules/mutator/PointMutator.java
+++ b/src/jcgp/backend/modules/mutator/PointMutator.java
@@ -7,18 +7,21 @@ import jcgp.backend.population.Output;
import jcgp.backend.resources.Resources;
import jcgp.backend.resources.parameters.BooleanParameter;
import jcgp.backend.resources.parameters.DoubleParameter;
+import jcgp.backend.resources.parameters.IntegerParameter;
import jcgp.backend.resources.parameters.Parameter;
import jcgp.backend.resources.parameters.ParameterStatus;
public class PointMutator implements Mutator {
private DoubleParameter mutationRate;
+ private IntegerParameter nodesMutated;
private BooleanParameter report;
public PointMutator(final Resources resources) {
mutationRate = new DoubleParameter(50, "Percent mutation", false, false) {
@Override
public void validate(Number newValue) {
+ nodesMutated.set((int) ((newValue.intValue()) * (((((double) resources.nodes() + resources.outputs()))) / 100)));
if (newValue.doubleValue() <= 0 || newValue.doubleValue() > 100) {
status = ParameterStatus.INVALID;
status.setDetails("Mutation rate must be > 0 and <= 100");
@@ -30,7 +33,12 @@ public class PointMutator implements Mutator {
}
}
};
-
+ nodesMutated = new IntegerParameter(0, "Genes mutated", true, false) {
+ @Override
+ public void validate(Number newValue) {
+ // blank
+ }
+ };
report = new BooleanParameter(false, "Report") {
@Override
public void validate(Boolean newValue) {
@@ -41,9 +49,8 @@ public class PointMutator implements Mutator {
@Override
public void mutate(Chromosome chromosome, Resources resources) {
- int mutations = (int) ((mutationRate.get()) * (((((double) resources.nodes() + resources.outputs()))) / 100));
- if (report.get()) resources.reportln("[Mutator] Number of mutations to be performed: " + mutations);
- for (int i = 0; i < mutations; i++) {
+ if (report.get()) resources.reportln("[Mutator] Number of mutations to be performed: " + nodesMutated.get());
+ for (int i = 0; i < nodesMutated.get(); i++) {
MutableElement m = chromosome.getRandomMutableElement();
if (report.get()) resources.report("[Mutator] Mutation " + i + " selected " + m.toString() + ", ");
@@ -75,7 +82,7 @@ public class PointMutator implements Mutator {
@Override
public Parameter<?>[] getLocalParameters() {
- return new Parameter[] {mutationRate, report};
+ return new Parameter[] {mutationRate, nodesMutated, report};
}
@Override