diff options
Diffstat (limited to 'src/jcgp/backend/modules')
3 files changed, 12 insertions, 45 deletions
diff --git a/src/jcgp/backend/modules/es/TournamentSelection.java b/src/jcgp/backend/modules/es/TournamentSelection.java index 4070468..7cc9706 100644 --- a/src/jcgp/backend/modules/es/TournamentSelection.java +++ b/src/jcgp/backend/modules/es/TournamentSelection.java @@ -8,10 +8,10 @@ import jcgp.backend.resources.parameters.Parameter; public class TournamentSelection implements EvolutionaryStrategy { - private IntegerParameter tournament; + private IntegerParameter tournamentSize; - public TournamentSelection() { - tournament = new IntegerParameter(1, "Tournament size") { + public TournamentSelection(Resources resources) { + tournamentSize = new IntegerParameter(1, "Tournament size") { @Override public void validate(Number newValue) { // TODO this @@ -21,13 +21,13 @@ public class TournamentSelection implements EvolutionaryStrategy { @Override public Parameter<?>[] getLocalParameters() { - return new Parameter[] {tournament}; + return new Parameter[] {tournamentSize}; } @Override public void evolve(Population population, Mutator mutator, Resources parameters) { - tournament.set(tournament.get() + 1); + tournamentSize.set(tournamentSize.get() + 1); // TODO implement this } diff --git a/src/jcgp/backend/modules/problem/DigitalCircuitProblem.java b/src/jcgp/backend/modules/problem/DigitalCircuitProblem.java index e92989e..3c30e4c 100644 --- a/src/jcgp/backend/modules/problem/DigitalCircuitProblem.java +++ b/src/jcgp/backend/modules/problem/DigitalCircuitProblem.java @@ -49,8 +49,8 @@ public class DigitalCircuitProblem extends TestCaseProblem<UnsignedInteger> { } @Override - protected int getMaxFitness() { - int maxFitness = (int) Math.pow(2.0, (double) resources.inputs()) * resources.outputs(); + protected double getMaxFitness() { + double maxFitness = Math.pow(2.0, (double) resources.inputs()) * resources.outputs(); return maxFitness; } diff --git a/src/jcgp/backend/modules/problem/TestCaseProblem.java b/src/jcgp/backend/modules/problem/TestCaseProblem.java index ff13c2e..d8dd32b 100644 --- a/src/jcgp/backend/modules/problem/TestCaseProblem.java +++ b/src/jcgp/backend/modules/problem/TestCaseProblem.java @@ -1,13 +1,11 @@ package jcgp.backend.modules.problem; -import java.io.File; import java.util.List; import javafx.collections.FXCollections; import javafx.collections.ObservableList; -import jcgp.backend.parser.TestCaseParser; import jcgp.backend.resources.Resources; -import jcgp.backend.resources.parameters.IntegerParameter; +import jcgp.backend.resources.parameters.DoubleParameter; import jcgp.backend.resources.parameters.Parameter; /** @@ -49,43 +47,21 @@ public abstract class TestCaseProblem<U extends Object> extends Problem { } protected ObservableList<TestCase<U>> testCases; - protected IntegerParameter maxFitness; + protected DoubleParameter maxFitness; protected Resources resources; - protected TestCaseParser parser; - public TestCaseProblem(Resources resources) { super(); this.resources = resources; - maxFitness = new IntegerParameter(0, "Max fitness", true, false) { + maxFitness = new DoubleParameter(0, "Max fitness", true, false) { @Override public void validate(Number newValue) { // blank } }; testCases = FXCollections.observableArrayList(); - - parser = new TestCaseParser(this); - } - - public TestCaseProblem(Resources resources, File testCase) { - super(); - - this.resources = resources; - - maxFitness = new IntegerParameter(0, "Max fitness", true, false) { - @Override - public void validate(Number newValue) { - // blank - } - }; - testCases = FXCollections.observableArrayList(); - - parser = new TestCaseParser(this); - - parser.parse(testCase); } @Override @@ -93,7 +69,7 @@ public abstract class TestCaseProblem<U extends Object> extends Problem { return new Parameter[]{maxFitness}; } - protected int getMaxFitness() { + protected double getMaxFitness() { int fitness = 0; for (TestCase<U> tc : testCases) { @@ -115,7 +91,7 @@ public abstract class TestCaseProblem<U extends Object> extends Problem { public abstract void addTestCase(String[] inputs, String[] outputs); - public void addTestCase(TestCase<U> testCase) { + protected final void addTestCase(TestCase<U> testCase) { if (testCase.getInputs().length != resources.inputs()) { throw new IllegalArgumentException("Received test case with " + testCase.getInputs().length + " inputs but need exactly " + resources.inputs()); @@ -128,11 +104,6 @@ public abstract class TestCaseProblem<U extends Object> extends Problem { } } - public void removeTestCase(TestCase<U> testCase) { - testCases.remove(testCase); - maxFitness.set(getMaxFitness()); - } - public int getInputCount() { return resources.inputs(); } @@ -141,10 +112,6 @@ public abstract class TestCaseProblem<U extends Object> extends Problem { return resources.outputs(); } - public void parse(File file) { - parser.parse(file); - } - public void clearTestCases() { testCases.clear(); } |