aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/modules/mutator
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-04-06 21:58:53 +0100
committerEduardo Pedroni <ep625@york.ac.uk>2014-04-06 21:58:53 +0100
commite6dd7711c7dad5e000445208eb5845801f4ccffc (patch)
tree1454bd20a8dd7069b1283184c42f4def6d5f7e6f /src/jcgp/backend/modules/mutator
parentc7969623b44f375e30fa3f15dcd7581609276a0f (diff)
About to make big changes to the way fitness works, committing just in case
Diffstat (limited to 'src/jcgp/backend/modules/mutator')
-rw-r--r--src/jcgp/backend/modules/mutator/Mutator.java2
-rw-r--r--src/jcgp/backend/modules/mutator/PointMutator.java40
2 files changed, 17 insertions, 25 deletions
diff --git a/src/jcgp/backend/modules/mutator/Mutator.java b/src/jcgp/backend/modules/mutator/Mutator.java
index fd7cd27..ffdd35c 100644
--- a/src/jcgp/backend/modules/mutator/Mutator.java
+++ b/src/jcgp/backend/modules/mutator/Mutator.java
@@ -1,8 +1,8 @@
package jcgp.backend.modules.mutator;
-import jcgp.JCGP.Resources;
import jcgp.backend.modules.Module;
import jcgp.backend.population.Chromosome;
+import jcgp.backend.resources.Resources;
public interface Mutator extends Module {
diff --git a/src/jcgp/backend/modules/mutator/PointMutator.java b/src/jcgp/backend/modules/mutator/PointMutator.java
index cdac8bb..54d5f3d 100644
--- a/src/jcgp/backend/modules/mutator/PointMutator.java
+++ b/src/jcgp/backend/modules/mutator/PointMutator.java
@@ -1,33 +1,39 @@
package jcgp.backend.modules.mutator;
import jcgp.backend.function.Function;
-import jcgp.backend.modules.ModuleStatus;
-import jcgp.backend.parameters.DoubleParameter;
-import jcgp.backend.parameters.Parameter;
import jcgp.backend.population.Chromosome;
import jcgp.backend.population.MutableElement;
import jcgp.backend.population.Node;
import jcgp.backend.population.Output;
-import jcgp.JCGP.Resources;
+import jcgp.backend.resources.Resources;
+import jcgp.backend.resources.parameters.DoubleParameter;
+import jcgp.backend.resources.parameters.Parameter;
+import jcgp.backend.resources.parameters.ParameterStatus;
public class PointMutator implements Mutator {
private DoubleParameter mutationRate;
- private ModuleStatus status = ModuleStatus.READY;
-
- public PointMutator() {
- mutationRate = new DoubleParameter(0.5, "Percent mutation", false, false) {
+ public PointMutator(final Resources resources) {
+ mutationRate = new DoubleParameter(50, "Percent mutation", false, false) {
@Override
public void validate(double newValue) {
- // TODO this
+ if (newValue <= 0 || newValue > 100) {
+ status = ParameterStatus.INVALID;
+ status.setDetails("Mutation rate must be > 0 and <= 100");
+ } else if ((int) ((newValue / 100) * resources.getDouble("nodes")) <= 0) {
+ status = ParameterStatus.WARNING;
+ status.setDetails("With mutation rate " + mutationRate.get() + ", 0 genes will be mutated.");
+ } else {
+ status = ParameterStatus.VALID;
+ }
}
};
}
@Override
public void mutate(Chromosome chromosome, Resources resources) {
- int mutations = (int) Math.ceil(((mutationRate.get()) * ((((resources.getDouble("nodes")) + (resources.getDouble("outputs")))) / (double) 100)));
+ int mutations = (int) ((mutationRate.get()) * ((((resources.getDouble("nodes")) + (resources.getDouble("outputs")))) / 100));
for (int i = 0; i < mutations; i++) {
MutableElement m = chromosome.getRandomMutableElement();
@@ -55,18 +61,4 @@ 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;
- }
}