aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/modules/mutator/PointMutator.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/backend/modules/mutator/PointMutator.java')
-rw-r--r--src/jcgp/backend/modules/mutator/PointMutator.java32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/jcgp/backend/modules/mutator/PointMutator.java b/src/jcgp/backend/modules/mutator/PointMutator.java
index 54d5f3d..1f38cfe 100644
--- a/src/jcgp/backend/modules/mutator/PointMutator.java
+++ b/src/jcgp/backend/modules/mutator/PointMutator.java
@@ -1,11 +1,11 @@
package jcgp.backend.modules.mutator;
-import jcgp.backend.function.Function;
import jcgp.backend.population.Chromosome;
import jcgp.backend.population.MutableElement;
import jcgp.backend.population.Node;
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.Parameter;
import jcgp.backend.resources.parameters.ParameterStatus;
@@ -13,6 +13,7 @@ import jcgp.backend.resources.parameters.ParameterStatus;
public class PointMutator implements Mutator {
private DoubleParameter mutationRate;
+ private BooleanParameter report;
public PointMutator(final Resources resources) {
mutationRate = new DoubleParameter(50, "Percent mutation", false, false) {
@@ -29,23 +30,44 @@ public class PointMutator implements Mutator {
}
}
};
+
+ report = new BooleanParameter(false, "Report") {
+ @Override
+ public void validate(boolean newValue) {
+ // blank
+ }
+ };
}
@Override
public void mutate(Chromosome chromosome, Resources resources) {
int mutations = (int) ((mutationRate.get()) * ((((resources.getDouble("nodes")) + (resources.getDouble("outputs")))) / 100));
+ if (report.get()) resources.reportln("[Mutator] Number of mutations to be performed: " + mutations);
for (int i = 0; i < mutations; i++) {
MutableElement m = chromosome.getRandomMutableElement();
+ if (report.get()) resources.report("[Mutator] Mutation " + i + " selected " + m.toString() + ", ");
if (m instanceof Output) {
+ if (report.get()) resources.report("changed source from " + ((Output) m).getSource().toString() + " ");
+
m.setConnection(0, chromosome.getRandomConnection());
+
+ if (report.get()) resources.reportln("to " + ((Output) m).getSource().toString());
} else if (m instanceof Node) {
int geneType = resources.getRandomInt(1 + resources.getInt("arity"));
if (geneType < 1) {
- Function f = resources.getRandomFunction();
- ((Node) m).setFunction(f);
+ if (report.get()) resources.report("changed function from " + ((Node) m).getFunction().getName() + " ");
+
+ ((Node) m).setFunction(resources.getRandomFunction());
+
+ if (report.get()) resources.reportln("to " + ((Node) m).getFunction().getName());
} else {
- m.setConnection(resources.getRandomInt(resources.getInt("arity")), chromosome.getRandomConnection(((Node) m).getColumn()));
+ int connection = resources.getRandomInt(resources.getInt("arity"));
+ if (report.get()) resources.report("changed connection " + connection + " from " + ((Node) m).getConnection(connection) + " ");
+
+ m.setConnection(connection, chromosome.getRandomConnection(((Node) m).getColumn()));
+
+ if (report.get()) resources.reportln("to " + ((Node) m).getConnection(connection));
}
}
}
@@ -53,7 +75,7 @@ public class PointMutator implements Mutator {
@Override
public Parameter[] getLocalParameters() {
- return new Parameter[] {mutationRate};
+ return new Parameter[] {mutationRate, report};
}
@Override