aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/modules/fitness
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/backend/modules/fitness')
-rw-r--r--src/jcgp/backend/modules/fitness/DigitalCircuit.java18
-rw-r--r--src/jcgp/backend/modules/fitness/Problem.java20
-rw-r--r--src/jcgp/backend/modules/fitness/SymbolicRegression.java18
-rw-r--r--src/jcgp/backend/modules/fitness/TestCaseProblem.java114
4 files changed, 0 insertions, 170 deletions
diff --git a/src/jcgp/backend/modules/fitness/DigitalCircuit.java b/src/jcgp/backend/modules/fitness/DigitalCircuit.java
deleted file mode 100644
index 8677d5f..0000000
--- a/src/jcgp/backend/modules/fitness/DigitalCircuit.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package jcgp.backend.modules.fitness;
-
-import jcgp.backend.function.BitwiseLogic;
-import jcgp.backend.resources.Resources;
-
-public class DigitalCircuit extends TestCaseProblem<Integer> {
-
- public DigitalCircuit(Resources resources) {
- super(resources);
- functionSet = new BitwiseLogic();
- }
-
- @Override
- public String toString() {
- return "Digital circuit";
- }
-
-}
diff --git a/src/jcgp/backend/modules/fitness/Problem.java b/src/jcgp/backend/modules/fitness/Problem.java
deleted file mode 100644
index 1e70c13..0000000
--- a/src/jcgp/backend/modules/fitness/Problem.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package jcgp.backend.modules.fitness;
-
-import jcgp.backend.function.FunctionSet;
-import jcgp.backend.modules.Module;
-import jcgp.backend.population.Chromosome;
-import jcgp.backend.population.Population;
-import jcgp.backend.resources.Resources;
-
-public abstract class Problem implements Module {
-
- protected FunctionSet functionSet;
-
- public abstract void evaluate(Population population, Resources resources);
-
- public FunctionSet getFunctionSet() {
- return functionSet;
- }
-
- public abstract boolean isPerfectSolution(Chromosome fittest);
-}
diff --git a/src/jcgp/backend/modules/fitness/SymbolicRegression.java b/src/jcgp/backend/modules/fitness/SymbolicRegression.java
deleted file mode 100644
index cb9d1a7..0000000
--- a/src/jcgp/backend/modules/fitness/SymbolicRegression.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package jcgp.backend.modules.fitness;
-
-import jcgp.backend.function.IntegerArithmetic;
-import jcgp.backend.resources.Resources;
-
-public class SymbolicRegression extends TestCaseProblem<Integer> {
-
- public SymbolicRegression(Resources resources) {
- super(resources);
- functionSet = new IntegerArithmetic();
- }
-
- @Override
- public String toString() {
- return "Symbolic regression";
- }
-
-}
diff --git a/src/jcgp/backend/modules/fitness/TestCaseProblem.java b/src/jcgp/backend/modules/fitness/TestCaseProblem.java
deleted file mode 100644
index 7dd24af..0000000
--- a/src/jcgp/backend/modules/fitness/TestCaseProblem.java
+++ /dev/null
@@ -1,114 +0,0 @@
-package jcgp.backend.modules.fitness;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import jcgp.backend.population.Chromosome;
-import jcgp.backend.population.Population;
-import jcgp.backend.resources.Resources;
-import jcgp.backend.resources.parameters.IntegerParameter;
-import jcgp.backend.resources.parameters.Parameter;
-
-/**
- *
- * This fitness function module implements a simple test case evaluator.
- *
- * A TestCase object is a
- *
- *
- * @author Eduardo Pedroni
- *
- */
-public abstract class TestCaseProblem<U> extends Problem {
-
- public static class TestCase<T> {
-
- private T[] inputs;
- private T[] outputs;
-
- public TestCase(T[] inputs, T[] outputs) {
- this.inputs = inputs;
- this.outputs = outputs;
- }
-
- public T getInput(int index) {
- return inputs[index];
- }
-
- public T getOutput(int index) {
- return outputs[index];
- }
-
- public T[] getInputs() {
- return inputs;
- }
-
- public T[] getOutputs() {
- return outputs;
- }
- }
-
- private ArrayList<TestCase<U>> testCases;
- private IntegerParameter maxFitness;
-
- public TestCaseProblem(Resources resources) {
- super();
-
- maxFitness = new IntegerParameter(0, "Max fitness", true, false) {
- @Override
- public void validate(Number newValue) {
- // blank
- }
- };
- testCases = new ArrayList<TestCase<U>>();
- }
-
-
- @Override
- public void evaluate(Population population, Resources resources) {
- // for every chromosome in the population
- for (int i = 0; i < resources.populationSize(); i++) {
- // assume an initial fitness of 0
- int fitness = 0;
- // for each test case
- for (int t = 0; t < testCases.size(); t++) {
- population.getChromosome(i).setInputs(testCases.get(t).getInputs());
- // check each output
- for (int o = 0; o < resources.outputs(); o++) {
- if (population.getChromosome(i).getOutput(o).calculate() == testCases.get(t).getOutput(o)) {
- fitness++;
- }
- }
- }
- // assign the resulting fitness to the respective individual
- population.getChromosome(i).setFitness(fitness);
- }
- }
-
- @Override
- public Parameter<?>[] getLocalParameters() {
- return new Parameter[]{maxFitness};
- }
-
- private int getMaxFitness() {
- int fitness = 0;
-
- for (TestCase<U> tc : testCases) {
- fitness += tc.getOutputs().length;
- }
-
- return fitness;
- }
-
- public void setTestCases(List<TestCase<U>> testCases) {
- this.testCases.clear();
- this.testCases.addAll(testCases);
- maxFitness.set(getMaxFitness());
- }
-
- @Override
- public boolean isPerfectSolution(Chromosome fittest) {
- return fittest.getFitness() >= maxFitness.get();
- }
-}
-