From 02fd2bc7059da416937beb1abe67e5ca60379030 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Tue, 1 Apr 2014 23:00:53 +0100 Subject: Settings pane now actually controls the parameters, not much left to do. --- src/jcgp/modules/mutator/Mutator.java | 11 ----- src/jcgp/modules/mutator/PointMutator.java | 71 ------------------------------ 2 files changed, 82 deletions(-) delete mode 100644 src/jcgp/modules/mutator/Mutator.java delete mode 100644 src/jcgp/modules/mutator/PointMutator.java (limited to 'src/jcgp/modules/mutator') diff --git a/src/jcgp/modules/mutator/Mutator.java b/src/jcgp/modules/mutator/Mutator.java deleted file mode 100644 index 8dfa0f9..0000000 --- a/src/jcgp/modules/mutator/Mutator.java +++ /dev/null @@ -1,11 +0,0 @@ -package jcgp.modules.mutator; - -import jcgp.JCGP.Resources; -import jcgp.modules.Module; -import jcgp.population.Chromosome; - -public interface Mutator extends Module { - - void mutate(Chromosome chromosome, Resources parameters); - -} diff --git a/src/jcgp/modules/mutator/PointMutator.java b/src/jcgp/modules/mutator/PointMutator.java deleted file mode 100644 index 2298368..0000000 --- a/src/jcgp/modules/mutator/PointMutator.java +++ /dev/null @@ -1,71 +0,0 @@ -package jcgp.modules.mutator; - -import java.util.HashMap; - -import jcgp.modules.ModuleStatus; -import jcgp.parameters.DoubleParameter; -import jcgp.parameters.Parameter; -import jcgp.JCGP.Resources; -import jcgp.population.Chromosome; -import jcgp.population.MutableElement; -import jcgp.population.Node; -import jcgp.population.Output; - -public class PointMutator implements Mutator { - - private DoubleParameter mutationRate; - private HashMap localParameters; - - private ModuleStatus status = ModuleStatus.READY; - - public PointMutator() { - mutationRate = new DoubleParameter(0.5, "Percent mutation"); - - localParameters = new HashMap(); - localParameters.put("mutRate", mutationRate); - } - - @Override - public void mutate(Chromosome chromosome, Resources resources) { - 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 + resources.getInt("arity")); - if (geneType < 1) { - ((Node) m).setFunction(resources.getRandomFunction()); - } else { - m.setConnection(resources.getRandomInt(resources.getInt("arity")), chromosome.getRandomConnection(((Node) m).getColumn())); - } - } - } - } - - @Override - public HashMap getLocalParameters() { - return localParameters; - } - - @Override - public String toString() { - 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