From 04b35ccdad6e18701ede823e333118b0b22907c2 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Sun, 30 Mar 2014 21:07:37 +0100 Subject: Running into some issues with running the CGP loop in the background with bindings. --- src/jcgp/modules/mutator/PointMutator.java | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'src/jcgp/modules/mutator') diff --git a/src/jcgp/modules/mutator/PointMutator.java b/src/jcgp/modules/mutator/PointMutator.java index e9be153..2298368 100644 --- a/src/jcgp/modules/mutator/PointMutator.java +++ b/src/jcgp/modules/mutator/PointMutator.java @@ -2,6 +2,7 @@ package jcgp.modules.mutator; import java.util.HashMap; +import jcgp.modules.ModuleStatus; import jcgp.parameters.DoubleParameter; import jcgp.parameters.Parameter; import jcgp.JCGP.Resources; @@ -12,9 +13,11 @@ import jcgp.population.Output; public class PointMutator implements Mutator { - private Parameter mutationRate; + private DoubleParameter mutationRate; private HashMap localParameters; + private ModuleStatus status = ModuleStatus.READY; + public PointMutator() { mutationRate = new DoubleParameter(0.5, "Percent mutation"); @@ -24,28 +27,23 @@ public class PointMutator implements Mutator { @Override public void mutate(Chromosome chromosome, Resources resources) { - int mutations = (int) Math.ceil((((double) mutationRate.getValue()) * (((((Integer) resources.get("nodes")).doubleValue() + ((Integer) resources.get("outputs")).doubleValue())) / (double) 100))); + int mutations = (int) Math.ceil(((mutationRate.get()) * ((((resources.getDouble("nodes")) + (resources.getDouble("outputs")))) / (double) 100))); for (int i = 0; i < mutations; i++) { MutableElement m = chromosome.getRandomMutableElement(); if (m instanceof Output) { m.setConnection(0, chromosome.getRandomConnection()); } else if (m instanceof Node) { - int geneType = resources.getRandomInt(1 + ((int) resources.get("arity"))); + int geneType = resources.getRandomInt(1 + resources.getInt("arity")); if (geneType < 1) { ((Node) m).setFunction(resources.getRandomFunction()); } else { - m.setConnection(resources.getRandomInt((int) resources.get("arity")), chromosome.getRandomConnection(((Node) m).getColumn())); + m.setConnection(resources.getRandomInt(resources.getInt("arity")), chromosome.getRandomConnection(((Node) m).getColumn())); } } } } - @Override - public void activate(Resources parameters) { - // nothing - } - @Override public HashMap getLocalParameters() { return localParameters; @@ -56,4 +54,18 @@ public class PointMutator implements Mutator { return "Point mutation"; } + @Override + public ModuleStatus getStatus(Resources resources) { + if (mutationRate.get() <= 0 || mutationRate.get() > 100) { + status = ModuleStatus.ERROR; + status.setDetails("Mutation rate must be > 0 and <= 100"); + } else if ((int) ((mutationRate.get() / 100) * resources.getDouble("nodes")) > 0) { + status = ModuleStatus.WARNING; + status.setDetails("With mutation rate " + mutationRate.get() + ", no mutations will occur."); + } else { + status = ModuleStatus.READY; + status.setDetails(""); + } + return status; + } } -- cgit v1.2.3