diff options
author | Eduardo Pedroni <ep625@york.ac.uk> | 2014-05-19 01:36:03 +0100 |
---|---|---|
committer | Eduardo Pedroni <ep625@york.ac.uk> | 2014-05-19 01:36:03 +0100 |
commit | f13ebf70037a6aa28dc53804c1f0cef6e2f23102 (patch) | |
tree | 2295186b9655207d036df6c871902a760743e993 /src/jcgp/backend/modules | |
parent | 2a655a0b1654a2721089f0f8d99b846d7e198f38 (diff) |
Minor refactorings
Diffstat (limited to 'src/jcgp/backend/modules')
4 files changed, 9 insertions, 25 deletions
diff --git a/src/jcgp/backend/modules/problem/DigitalCircuitProblem.java b/src/jcgp/backend/modules/problem/DigitalCircuitProblem.java index e2f17c3..ff77a0d 100644 --- a/src/jcgp/backend/modules/problem/DigitalCircuitProblem.java +++ b/src/jcgp/backend/modules/problem/DigitalCircuitProblem.java @@ -31,9 +31,9 @@ public class DigitalCircuitProblem extends TestCaseProblem<UnsignedInteger> { } @Override - public void evaluate(Population population, Resources resources) { + public void evaluate(Population population) { // for every chromosome in the population - for (int i = 0; i < resources.populationSize(); i++) { + for (int i = 0; i < getResources().populationSize(); i++) { // assume an initial fitness of 0 int fitness = 0; @@ -41,13 +41,13 @@ public class DigitalCircuitProblem extends TestCaseProblem<UnsignedInteger> { for (int t = 0; t < testCases.size(); t++) { population.get(i).setInputs((Object[]) testCases.get(t).getInputs()); // check each output - for (int o = 0; o < resources.outputs(); o++) { + for (int o = 0; o < getResources().outputs(); o++) { Integer output = ((UnsignedInteger) population.get(i).getOutput(o).calculate()).get(); - Integer matches = ~(output ^ testCases.get(t).getOutput(o).get()); + Integer matches = ~(output ^ testCases.get(t).getOutputs()[o].get()); // check only the relevant bits int bits; - if (resources.inputs() < 5) { - bits = (int) Math.pow(2.0, (double) resources.inputs()); + if (getResources().inputs() < 5) { + bits = (int) Math.pow(2.0, (double) getResources().inputs()); } else { bits = 32; } diff --git a/src/jcgp/backend/modules/problem/Problem.java b/src/jcgp/backend/modules/problem/Problem.java index 2af2373..6785733 100644 --- a/src/jcgp/backend/modules/problem/Problem.java +++ b/src/jcgp/backend/modules/problem/Problem.java @@ -74,7 +74,7 @@ public abstract class Problem extends Module { * @param population the population to be evaluated. * @param resources parameters and utilities for optional reference. */ - public abstract void evaluate(Population population, Resources resources); + public abstract void evaluate(Population population); /** * Used to assert whether a given population contains a perfect solution diff --git a/src/jcgp/backend/modules/problem/SymbolicRegressionProblem.java b/src/jcgp/backend/modules/problem/SymbolicRegressionProblem.java index 3b5f539..6bc4790 100644 --- a/src/jcgp/backend/modules/problem/SymbolicRegressionProblem.java +++ b/src/jcgp/backend/modules/problem/SymbolicRegressionProblem.java @@ -84,7 +84,7 @@ public class SymbolicRegressionProblem extends TestCaseProblem<Double> { } @Override - public void evaluate(Population population, Resources resources) { + public void evaluate(Population population) { // for every chromosome in the population for (int i = 0; i < getResources().populationSize(); i++) { // assume an initial fitness of 0 @@ -95,7 +95,7 @@ public class SymbolicRegressionProblem extends TestCaseProblem<Double> { // check each output for (int o = 0; o < getResources().outputs(); o++) { Double cgpValue = (Double) population.get(i).getOutput(o).calculate(); - Double dataValue = testCases.get(t).getOutput(o); + Double dataValue = testCases.get(t).getOutputs()[o]; if (hitsBasedFitness.get()) { if (Math.abs(cgpValue - dataValue) <= errorThreshold.get()) { fitness++; diff --git a/src/jcgp/backend/modules/problem/TestCaseProblem.java b/src/jcgp/backend/modules/problem/TestCaseProblem.java index 188e236..964860c 100644 --- a/src/jcgp/backend/modules/problem/TestCaseProblem.java +++ b/src/jcgp/backend/modules/problem/TestCaseProblem.java @@ -50,22 +50,6 @@ public abstract class TestCaseProblem<T> extends Problem { } /** - * @param index the index to return. - * @return the indexed input. - */ - public U getInput(int index) { - return inputs[index]; - } - - /** - * @param index the index to return. - * @return the indexed output. - */ - public U getOutput(int index) { - return outputs[index]; - } - - /** * @return the complete array of inputs. */ public U[] getInputs() { |