diff options
author | Eduardo Pedroni <ep625@york.ac.uk> | 2014-05-06 14:29:37 +0100 |
---|---|---|
committer | Eduardo Pedroni <ep625@york.ac.uk> | 2014-05-06 14:29:37 +0100 |
commit | 8189116ea4b5db4675e31dfd04a5687d55e29262 (patch) | |
tree | c1815021452a888f8838f1628d8fb4689777e73e /src/jcgp/backend/modules/mutator/ProbabilisticMutator.java | |
parent | aa9e74e7f67789f6353fc26e02ee8e68e40609a2 (diff) |
Added javadocs, made minor changes to the comments
Diffstat (limited to 'src/jcgp/backend/modules/mutator/ProbabilisticMutator.java')
-rw-r--r-- | src/jcgp/backend/modules/mutator/ProbabilisticMutator.java | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/src/jcgp/backend/modules/mutator/ProbabilisticMutator.java b/src/jcgp/backend/modules/mutator/ProbabilisticMutator.java index c65fc22..9273558 100644 --- a/src/jcgp/backend/modules/mutator/ProbabilisticMutator.java +++ b/src/jcgp/backend/modules/mutator/ProbabilisticMutator.java @@ -25,17 +25,14 @@ public class ProbabilisticMutator extends Mutator { private DoubleParameter mutationProbability; private BooleanParameter report; - - private Resources resources; - + /** * Creates a new instance of ProbabilisticMutator. * * @param resources a reference to the experiment's resources. */ public ProbabilisticMutator(Resources resources) { - super(); - this.resources = resources; + super(resources); mutationProbability = new DoubleParameter(10, "Mutation probability", false, false) { @Override @@ -56,53 +53,53 @@ public class ProbabilisticMutator extends Mutator { } @Override - public void mutate(Chromosome chromosome, Resources resources) { - if (report.get()) resources.reportln("[Mutator] Starting mutations"); + public void mutate(Chromosome chromosome) { + if (report.get()) getResources().reportln("[Mutator] Starting mutations"); // go through nodes - [rows][columns] - for (int r = 0; r < resources.rows(); r++) { - for (int c = 0; c < resources.columns(); c++) { + for (int r = 0; r < getResources().rows(); r++) { + for (int c = 0; c < getResources().columns(); c++) { // go through all connections - for (int a = 0; a < resources.arity(); a++) { + for (int a = 0; a < getResources().arity(); a++) { if (mutateGene()) { Node n = chromosome.getNode(r, c); - if (report.get()) resources.report("[Mutator] Mutating " + n + + if (report.get()) getResources().report("[Mutator] Mutating " + n + ", changed connection " + a + " from " + n.getConnection(a) + " "); n.setConnection(a, chromosome.getRandomConnection(c)); - if (report.get()) resources.reportln("to " + n.getConnection(a)); + if (report.get()) getResources().reportln("to " + n.getConnection(a)); } } // deal with node function next if (mutateGene()) { Node n = chromosome.getNode(r, c); - if (report.get()) resources.report("[Mutator] Mutating " + n + + if (report.get()) getResources().report("[Mutator] Mutating " + n + ", changed function from " + n.getFunction()); - n.setFunction(resources.getRandomFunction()); + n.setFunction(getResources().getRandomFunction()); - if (report.get()) resources.reportln(" to " + n.getFunction()); + if (report.get()) getResources().reportln(" to " + n.getFunction()); } } } // finally, mutate outputs - for (int o = 0; o < resources.outputs(); o++) { + for (int o = 0; o < getResources().outputs(); o++) { if (mutateGene()) { Output out = chromosome.getOutput(o); - if (report.get()) resources.report("[Mutator] Mutating " + out + + if (report.get()) getResources().report("[Mutator] Mutating " + out + ", changed source from " + out.getSource()); out.setConnection(0, chromosome.getRandomConnection()); - if (report.get()) resources.reportln("to " + out.getSource()); + if (report.get()) getResources().reportln("to " + out.getSource()); } } - if (report.get()) resources.reportln("[Mutator] Mutation finished "); + if (report.get()) getResources().reportln("[Mutator] Mutation finished "); } @@ -115,6 +112,6 @@ public class ProbabilisticMutator extends Mutator { * @return true if a mutation should be performed, false if otherwise. */ private boolean mutateGene() { - return resources.getRandomDouble(100) < mutationProbability.get(); + return getResources().getRandomDouble(100) < mutationProbability.get(); } } |