aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/modules/mutator
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-03-09 23:32:05 +0000
committerEduardo Pedroni <ep625@york.ac.uk>2014-03-09 23:32:05 +0000
commitc0269683bcc7fde0d437ae84cd89a93d9d8fd81b (patch)
tree62ef738e29ae310dff513cc44193c5169c4ea4ca /src/jcgp/modules/mutator
parentd63d3145f0f2abcee1bb88457324f4aaf9b9320e (diff)
Started refactoring backend in preparation for integration with the GUI
Diffstat (limited to 'src/jcgp/modules/mutator')
-rw-r--r--src/jcgp/modules/mutator/PointMutator.java (renamed from src/jcgp/modules/mutator/StandardMutator.java)11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/jcgp/modules/mutator/StandardMutator.java b/src/jcgp/modules/mutator/PointMutator.java
index 17bd0be..b06d678 100644
--- a/src/jcgp/modules/mutator/StandardMutator.java
+++ b/src/jcgp/modules/mutator/PointMutator.java
@@ -1,17 +1,22 @@
package jcgp.modules.mutator;
import jcgp.Utilities;
+import jcgp.parameters.IntegerParameter;
import jcgp.parameters.Parameters;
import jcgp.population.Chromosome;
import jcgp.population.MutableElement;
import jcgp.population.Node;
import jcgp.population.Output;
-public class StandardMutator implements Mutator {
+public class PointMutator implements Mutator {
+ public PointMutator() {
+ Parameters.add("mutRate", new IntegerParameter(10, "Mutation rate"));
+ }
+
@Override
public void mutate(Chromosome chromosome) {
- int mutations = (int) (Parameters.getMutationRate() * (((double) Parameters.getNodeCount() + Parameters.getOutputs()) / 100));
+ int mutations = (int) (((int) Parameters.get("mutRate").getValue()) * ((((double) Parameters.get("nodes").getValue()) + ((double) Parameters.get("outputs").getValue())) / 100));
for (int i = 0; i < mutations; i++) {
MutableElement m = chromosome.getRandomMutableElement();
@@ -19,7 +24,7 @@ public class StandardMutator implements Mutator {
if (m instanceof Output) {
m.setConnection(chromosome.getRandomConnection());
} else if (m instanceof Node) {
- int geneType = Utilities.getRandomInt(1 + Parameters.getMaxArity());
+ int geneType = Utilities.getRandomInt(1 + ((int) Parameters.get("Max arity").getValue()));
if (geneType < 1) {
((Node) m).setFunction(Utilities.getRandomFunction());
} else {