aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/backend/modules')
-rw-r--r--src/jcgp/backend/modules/es/MuPlusLambda.java10
-rw-r--r--src/jcgp/backend/modules/mutator/ProbabilisticMutator.java8
-rw-r--r--src/jcgp/backend/modules/problem/Problem.java21
-rw-r--r--src/jcgp/backend/modules/problem/TestCaseProblem.java3
-rw-r--r--src/jcgp/backend/modules/problem/TravellingSalesmanProblem.java2
5 files changed, 31 insertions, 13 deletions
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
@@ -76,6 +76,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
* mu chromosomes intact
@@ -95,11 +100,6 @@ public class MuPlusLambda implements EvolutionaryStrategy {
}
@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
+ * <br><br>
+ * 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.
+ * <br><br>
+ * 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<U extends Object> 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
}