aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/modules/mutator
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/modules/mutator')
-rw-r--r--src/jcgp/modules/mutator/Mutator.java11
-rw-r--r--src/jcgp/modules/mutator/PointMutator.java71
2 files changed, 0 insertions, 82 deletions
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<String, Parameter> localParameters;
-
- private ModuleStatus status = ModuleStatus.READY;
-
- public PointMutator() {
- mutationRate = new DoubleParameter(0.5, "Percent mutation");
-
- localParameters = new HashMap<String, Parameter>();
- 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<String, Parameter> 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;
- }
-}