aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/modules/mutator
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-03-23 18:05:13 +0000
committerEduardo Pedroni <ep625@york.ac.uk>2014-03-23 18:05:13 +0000
commit0c288cc1952809294c8d70d86b9f41b04878ac2e (patch)
treeef9671b711fe665a3156594663c083595861a4e6 /src/jcgp/modules/mutator
parentd3527a63e12c0e5288f1e7d2e2dc18e61d16b760 (diff)
Majorly refactored, node grid is fully implemented. About to attempt active path locking.
Diffstat (limited to 'src/jcgp/modules/mutator')
-rw-r--r--src/jcgp/modules/mutator/Mutator.java6
-rw-r--r--src/jcgp/modules/mutator/PointMutator.java39
2 files changed, 30 insertions, 15 deletions
diff --git a/src/jcgp/modules/mutator/Mutator.java b/src/jcgp/modules/mutator/Mutator.java
index 10df8cd..5234f45 100644
--- a/src/jcgp/modules/mutator/Mutator.java
+++ b/src/jcgp/modules/mutator/Mutator.java
@@ -1,9 +1,11 @@
package jcgp.modules.mutator;
+import jcgp.CGP.Resources;
+import jcgp.modules.Module;
import jcgp.population.Chromosome;
-public interface Mutator {
+public interface Mutator extends Module {
- void mutate(Chromosome chromosome);
+ void mutate(Chromosome chromosome, Resources parameters);
}
diff --git a/src/jcgp/modules/mutator/PointMutator.java b/src/jcgp/modules/mutator/PointMutator.java
index b06d678..ea1ed32 100644
--- a/src/jcgp/modules/mutator/PointMutator.java
+++ b/src/jcgp/modules/mutator/PointMutator.java
@@ -1,36 +1,49 @@
package jcgp.modules.mutator;
-import jcgp.Utilities;
-import jcgp.parameters.IntegerParameter;
-import jcgp.parameters.Parameters;
+import java.util.HashMap;
+
+import jcgp.parameters.DoubleParameter;
+import jcgp.parameters.Parameter;
+import jcgp.CGP.Resources;
import jcgp.population.Chromosome;
import jcgp.population.MutableElement;
import jcgp.population.Node;
import jcgp.population.Output;
public class PointMutator implements Mutator {
-
+
+ private Parameter mutationRate;
+ private HashMap<String, Parameter> localParameters;
+
public PointMutator() {
- Parameters.add("mutRate", new IntegerParameter(10, "Mutation rate"));
+ mutationRate = new DoubleParameter(0.5, "Percent mutation");
+
+ localParameters = new HashMap<String, Parameter>();
+ localParameters.put("mutRate", mutationRate);
}
-
+
@Override
- public void mutate(Chromosome chromosome) {
- int mutations = (int) (((int) Parameters.get("mutRate").getValue()) * ((((double) Parameters.get("nodes").getValue()) + ((double) Parameters.get("outputs").getValue())) / 100));
-
+ 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)));
for (int i = 0; i < mutations; i++) {
MutableElement m = chromosome.getRandomMutableElement();
if (m instanceof Output) {
- m.setConnection(chromosome.getRandomConnection());
+ m.setConnection(0, chromosome.getRandomConnection());
} else if (m instanceof Node) {
- int geneType = Utilities.getRandomInt(1 + ((int) Parameters.get("Max arity").getValue()));
+ int geneType = resources.getRandomInt(1 + ((int) resources.get("arity")));
if (geneType < 1) {
- ((Node) m).setFunction(Utilities.getRandomFunction());
+ ((Node) m).setFunction(resources.getRandomFunction());
} else {
- m.setConnection(chromosome.getRandomConnection(((Node) m).getColumn()));
+ m.setConnection(resources.getRandomInt((int) resources.get("arity")), chromosome.getRandomConnection(((Node) m).getColumn()));
}
}
}
}
+
+ @Override
+ public HashMap<String, Parameter> activate(Resources parameters) {
+ return localParameters;
+ }
+
}