diff options
Diffstat (limited to 'src/jcgp/backend')
-rw-r--r-- | src/jcgp/backend/exceptions/ParameterMismatchException.java | 2 | ||||
-rw-r--r-- | src/jcgp/backend/modules/problem/DigitalCircuit.java (renamed from src/jcgp/backend/modules/fitness/DigitalCircuit.java) | 9 | ||||
-rw-r--r-- | src/jcgp/backend/modules/problem/Problem.java (renamed from src/jcgp/backend/modules/fitness/Problem.java) | 2 | ||||
-rw-r--r-- | src/jcgp/backend/modules/problem/SymbolicRegression.java (renamed from src/jcgp/backend/modules/fitness/SymbolicRegression.java) | 10 | ||||
-rw-r--r-- | src/jcgp/backend/modules/problem/TestCaseProblem.java (renamed from src/jcgp/backend/modules/fitness/TestCaseProblem.java) | 60 |
5 files changed, 70 insertions, 13 deletions
diff --git a/src/jcgp/backend/exceptions/ParameterMismatchException.java b/src/jcgp/backend/exceptions/ParameterMismatchException.java index 3ab9fa1..83e2ba2 100644 --- a/src/jcgp/backend/exceptions/ParameterMismatchException.java +++ b/src/jcgp/backend/exceptions/ParameterMismatchException.java @@ -6,5 +6,5 @@ public class ParameterMismatchException extends RuntimeException { * */ private static final long serialVersionUID = -3161318886125868134L; - + } diff --git a/src/jcgp/backend/modules/fitness/DigitalCircuit.java b/src/jcgp/backend/modules/problem/DigitalCircuit.java index 8677d5f..d94197d 100644 --- a/src/jcgp/backend/modules/fitness/DigitalCircuit.java +++ b/src/jcgp/backend/modules/problem/DigitalCircuit.java @@ -1,4 +1,6 @@ -package jcgp.backend.modules.fitness; +package jcgp.backend.modules.problem; + +import java.util.ArrayList; import jcgp.backend.function.BitwiseLogic; import jcgp.backend.resources.Resources; @@ -8,6 +10,11 @@ public class DigitalCircuit extends TestCaseProblem<Integer> { public DigitalCircuit(Resources resources) { super(resources); functionSet = new BitwiseLogic(); + + ArrayList<TestCase<Integer>> tc = new ArrayList<TestCase<Integer>>(); + tc.add(new TestCase<Integer>(new Integer[]{1, 2, 3}, new Integer[]{-4, 5, 6})); + + setTestCases(tc); } @Override diff --git a/src/jcgp/backend/modules/fitness/Problem.java b/src/jcgp/backend/modules/problem/Problem.java index 1e70c13..d01f5b0 100644 --- a/src/jcgp/backend/modules/fitness/Problem.java +++ b/src/jcgp/backend/modules/problem/Problem.java @@ -1,4 +1,4 @@ -package jcgp.backend.modules.fitness; +package jcgp.backend.modules.problem; import jcgp.backend.function.FunctionSet; import jcgp.backend.modules.Module; diff --git a/src/jcgp/backend/modules/fitness/SymbolicRegression.java b/src/jcgp/backend/modules/problem/SymbolicRegression.java index cb9d1a7..c92d183 100644 --- a/src/jcgp/backend/modules/fitness/SymbolicRegression.java +++ b/src/jcgp/backend/modules/problem/SymbolicRegression.java @@ -1,4 +1,6 @@ -package jcgp.backend.modules.fitness; +package jcgp.backend.modules.problem; + +import java.util.ArrayList; import jcgp.backend.function.IntegerArithmetic; import jcgp.backend.resources.Resources; @@ -8,6 +10,12 @@ public class SymbolicRegression extends TestCaseProblem<Integer> { public SymbolicRegression(Resources resources) { super(resources); functionSet = new IntegerArithmetic(); + + ArrayList<TestCase<Integer>> tc = new ArrayList<TestCase<Integer>>(); + tc.add(new TestCase<Integer>(new Integer[]{1, 2, 3}, new Integer[]{-4, 5, 6})); + tc.add(new TestCase<Integer>(new Integer[]{3, 2, 5}, new Integer[]{2, 5, 9})); + + setTestCases(tc); } @Override diff --git a/src/jcgp/backend/modules/fitness/TestCaseProblem.java b/src/jcgp/backend/modules/problem/TestCaseProblem.java index 7dd24af..68318cf 100644 --- a/src/jcgp/backend/modules/fitness/TestCaseProblem.java +++ b/src/jcgp/backend/modules/problem/TestCaseProblem.java @@ -1,8 +1,9 @@ -package jcgp.backend.modules.fitness; +package jcgp.backend.modules.problem; -import java.util.ArrayList; import java.util.List; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import jcgp.backend.population.Chromosome; import jcgp.backend.population.Population; import jcgp.backend.resources.Resources; @@ -19,10 +20,9 @@ import jcgp.backend.resources.parameters.Parameter; * @author Eduardo Pedroni * */ -public abstract class TestCaseProblem<U> extends Problem { +public abstract class TestCaseProblem<U extends Object> extends Problem { public static class TestCase<T> { - private T[] inputs; private T[] outputs; @@ -48,19 +48,26 @@ public abstract class TestCaseProblem<U> extends Problem { } } - private ArrayList<TestCase<U>> testCases; + private ObservableList<TestCase<U>> testCases; private IntegerParameter maxFitness; + private final int inputCount, outputCount; + + private U type; public TestCaseProblem(Resources resources) { super(); + inputCount = resources.inputs(); + outputCount = resources.outputs(); + maxFitness = new IntegerParameter(0, "Max fitness", true, false) { @Override public void validate(Number newValue) { // blank } }; - testCases = new ArrayList<TestCase<U>>(); + testCases = FXCollections.observableArrayList(); + //testCases = new ObservableList<TestCase<U>>(); } @@ -90,6 +97,11 @@ public abstract class TestCaseProblem<U> extends Problem { return new Parameter[]{maxFitness}; } + @Override + public boolean isPerfectSolution(Chromosome fittest) { + return fittest.getFitness() >= maxFitness.get(); + } + private int getMaxFitness() { int fitness = 0; @@ -106,9 +118,39 @@ public abstract class TestCaseProblem<U> extends Problem { maxFitness.set(getMaxFitness()); } - @Override - public boolean isPerfectSolution(Chromosome fittest) { - return fittest.getFitness() >= maxFitness.get(); + public ObservableList<TestCase<U>> getTestCases() { + return testCases; + } + + public void addTestCase(TestCase<U> testCase) { + if (testCase.getInputs().length != inputCount) { + throw new IllegalArgumentException("Received test case with " + testCase.getInputs().length + + "inputs but need exactly " + inputCount); + } else if (testCase.getOutputs().length != outputCount) { + throw new IllegalArgumentException("Received test case with " + testCase.getOutputs().length + + "outputs but need exactly " + outputCount); + } else { + this.testCases.add(testCase); + maxFitness.set(getMaxFitness()); + } + } + + public void removeTestCase(TestCase<U> testCase) { + testCases.remove(testCase); + maxFitness.set(getMaxFitness()); + } + + public int getInputCount() { + return inputCount; + } + + public int getOutputCount() { + return outputCount; + } + + public Class<?> getType() { + return type.getClass(); } } + |