From 4c8de2402f2878cde7587c7f3bbf4ffaea86efd4 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Sat, 26 Apr 2014 19:56:24 +0100 Subject: Moved files around to different folders, and commented some more packages. Aiming to have the entire backend fully commented by the end of today --- src/jcgp/backend/modules/es/MuPlusLambda.java | 10 +++++----- .../modules/mutator/ProbabilisticMutator.java | 8 ++++---- src/jcgp/backend/modules/problem/Problem.java | 21 ++++++++++++++++++++- .../backend/modules/problem/TestCaseProblem.java | 3 +-- .../modules/problem/TravellingSalesmanProblem.java | 2 +- 5 files changed, 31 insertions(+), 13 deletions(-) (limited to 'src/jcgp/backend/modules') diff --git a/src/jcgp/backend/modules/es/MuPlusLambda.java b/src/jcgp/backend/modules/es/MuPlusLambda.java index 50bf265..754e89b 100644 --- a/src/jcgp/backend/modules/es/MuPlusLambda.java +++ b/src/jcgp/backend/modules/es/MuPlusLambda.java @@ -75,6 +75,11 @@ public class MuPlusLambda implements EvolutionaryStrategy { }; } + @Override + public Parameter[] getLocalParameters() { + return new Parameter[] {mu, lambda, report}; + } + @Override public void evolve(Population population, Mutator mutator, Resources resources) { /* Population is sorted in ascending order of fitness, so leave the last @@ -94,11 +99,6 @@ public class MuPlusLambda implements EvolutionaryStrategy { if (report.get()) resources.reportln("[ES] Generation is complete"); } - @Override - public Parameter[] getLocalParameters() { - return new Parameter[] {mu, lambda, report}; - } - @Override public String toString() { return "(μ + λ)"; diff --git a/src/jcgp/backend/modules/mutator/ProbabilisticMutator.java b/src/jcgp/backend/modules/mutator/ProbabilisticMutator.java index e3c1d03..cacb451 100644 --- a/src/jcgp/backend/modules/mutator/ProbabilisticMutator.java +++ b/src/jcgp/backend/modules/mutator/ProbabilisticMutator.java @@ -70,7 +70,7 @@ public class ProbabilisticMutator implements Mutator { for (int c = 0; c < resources.columns(); c++) { // go through all connections for (int a = 0; a < resources.arity(); a++) { - if (mutate()) { + if (mutateGene()) { Node n = chromosome.getNode(r, c); if (report.get()) resources.report("[Mutator] Mutating " + n + @@ -83,7 +83,7 @@ public class ProbabilisticMutator implements Mutator { } } // deal with node function next - if (mutate()) { + if (mutateGene()) { Node n = chromosome.getNode(r, c); if (report.get()) resources.report("[Mutator] Mutating " + n + ", changed function from " + n.getFunction()); @@ -96,7 +96,7 @@ public class ProbabilisticMutator implements Mutator { } // finally, mutate outputs for (int o = 0; o < resources.outputs(); o++) { - if (mutate()) { + if (mutateGene()) { Output out = chromosome.getOutput(o); if (report.get()) resources.report("[Mutator] Mutating " + out + @@ -120,7 +120,7 @@ public class ProbabilisticMutator implements Mutator { * * @return true if a mutation should be performed, false if otherwise. */ - private boolean mutate() { + private boolean mutateGene() { return resources.getRandomDouble(100) < mutationProbability.get(); } diff --git a/src/jcgp/backend/modules/problem/Problem.java b/src/jcgp/backend/modules/problem/Problem.java index 07183ea..368d512 100644 --- a/src/jcgp/backend/modules/problem/Problem.java +++ b/src/jcgp/backend/modules/problem/Problem.java @@ -9,6 +9,25 @@ import jcgp.backend.population.Population; import jcgp.backend.resources.ModifiableResources; import jcgp.backend.resources.Resources; +/** + * Defines the general behaviour of a CGP problem. The primary function of Problem + * is to evaluate a population and assign + *

+ * Parameters may be specified to control the implemented problem. Any parameters + * returned by {@code getLocalParameters()} should be displayed by the user interface, + * if it is being used. See {@link Parameter} for more information. + *

+ * It is advisable to use {@code Resources.reportln()} and {@code Resources.report()} + * to print any relevant information. Note that reportln() and report() are affected + * by the report interval base parameter. Use {@code Resources.println()} and + * {@code Resources.print()} to print information regardless of the current generation. + * See {@link Resources} for more information. + * + * @see Module + * + * @author Eduardo Pedroni + * + */ public abstract class Problem implements Module { protected FunctionSet functionSet; @@ -23,7 +42,7 @@ public abstract class Problem implements Module { public abstract boolean isPerfectSolution(Chromosome fittest); - public abstract void parse(File file, ModifiableResources resources); + public abstract void parseProblemData(File file, ModifiableResources resources); public void setFileExtension(String fileExtension) { this.fileExtension = fileExtension; diff --git a/src/jcgp/backend/modules/problem/TestCaseProblem.java b/src/jcgp/backend/modules/problem/TestCaseProblem.java index 6c4a7dc..7ce0327 100644 --- a/src/jcgp/backend/modules/problem/TestCaseProblem.java +++ b/src/jcgp/backend/modules/problem/TestCaseProblem.java @@ -119,8 +119,7 @@ public abstract class TestCaseProblem extends Problem { testCases.clear(); } - public void parse(File file, ModifiableResources resources) { - TestCaseParser.parseParameters(file, resources); + public void parseProblemData(File file, ModifiableResources resources) { TestCaseParser.parse(file, this, resources); } } diff --git a/src/jcgp/backend/modules/problem/TravellingSalesmanProblem.java b/src/jcgp/backend/modules/problem/TravellingSalesmanProblem.java index 6491ec6..8363ef8 100644 --- a/src/jcgp/backend/modules/problem/TravellingSalesmanProblem.java +++ b/src/jcgp/backend/modules/problem/TravellingSalesmanProblem.java @@ -36,7 +36,7 @@ public class TravellingSalesmanProblem extends Problem { } @Override - public void parse(File file, ModifiableResources resources) { + public void parseProblemData(File file, ModifiableResources resources) { // TODO Auto-generated method stub } -- cgit v1.2.3