aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/modules')
-rw-r--r--src/jcgp/modules/Module.java11
-rw-r--r--src/jcgp/modules/ModuleStatus.java16
-rw-r--r--src/jcgp/modules/ea/EvolutionaryAlgorithm.java15
-rw-r--r--src/jcgp/modules/ea/MuPlusLambda.java80
-rw-r--r--src/jcgp/modules/ea/TournamentSelection.java54
-rw-r--r--src/jcgp/modules/fitness/FitnessFunction.java11
-rw-r--r--src/jcgp/modules/fitness/TestCase.java29
-rw-r--r--src/jcgp/modules/fitness/TestCaseEvaluator.java45
-rw-r--r--src/jcgp/modules/mutator/Mutator.java11
-rw-r--r--src/jcgp/modules/mutator/PointMutator.java71
10 files changed, 0 insertions, 343 deletions
diff --git a/src/jcgp/modules/Module.java b/src/jcgp/modules/Module.java
deleted file mode 100644
index 9e0b267..0000000
--- a/src/jcgp/modules/Module.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package jcgp.modules;
-
-import java.util.HashMap;
-
-import jcgp.JCGP.Resources;
-import jcgp.parameters.Parameter;
-
-public interface Module {
- public HashMap<String, Parameter> getLocalParameters();
- public ModuleStatus getStatus(Resources resources);
-}
diff --git a/src/jcgp/modules/ModuleStatus.java b/src/jcgp/modules/ModuleStatus.java
deleted file mode 100644
index 02e2c01..0000000
--- a/src/jcgp/modules/ModuleStatus.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package jcgp.modules;
-
-public enum ModuleStatus {
- ERROR, WARNING, READY;
-
- private String details;
-
- public void setDetails(String details) {
- this.details = details;
- }
-
- public String getDetails() {
- return details;
- }
-
-}
diff --git a/src/jcgp/modules/ea/EvolutionaryAlgorithm.java b/src/jcgp/modules/ea/EvolutionaryAlgorithm.java
deleted file mode 100644
index 3bc7fcf..0000000
--- a/src/jcgp/modules/ea/EvolutionaryAlgorithm.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package jcgp.modules.ea;
-
-import jcgp.JCGP.Resources;
-import jcgp.modules.Module;
-import jcgp.modules.mutator.Mutator;
-import jcgp.population.Chromosome;
-import jcgp.population.Population;
-
-public interface EvolutionaryAlgorithm extends Module {
-
- public abstract void evolve(Population population, Mutator mutator, Resources parameters);
-
- public abstract Chromosome getFittestChromosome();
-
-}
diff --git a/src/jcgp/modules/ea/MuPlusLambda.java b/src/jcgp/modules/ea/MuPlusLambda.java
deleted file mode 100644
index 94900ca..0000000
--- a/src/jcgp/modules/ea/MuPlusLambda.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package jcgp.modules.ea;
-
-import java.util.HashMap;
-
-import jcgp.JCGP.Resources;
-import jcgp.modules.ModuleStatus;
-import jcgp.modules.mutator.Mutator;
-import jcgp.parameters.IntegerParameter;
-import jcgp.parameters.Parameter;
-import jcgp.population.Chromosome;
-import jcgp.population.Population;
-
-/**
- * (μ + λ) EA.
- *
- *
- * @author Eduardo Pedroni
- *
- */
-public class MuPlusLambda implements EvolutionaryAlgorithm {
-
- private Chromosome fittestChromosome;
-
- private IntegerParameter parents, offspring;
-
- private HashMap<String, Parameter> localParameters;
-
- public MuPlusLambda() {
- parents = new IntegerParameter(1, "Parents");
- offspring = new IntegerParameter(4, "Offspring");
-
- localParameters = new HashMap<String, Parameter>();
-
- localParameters.put("mu", parents);
- localParameters.put("lambda", offspring);
- }
-
- @Override
- public void evolve(Population population, Mutator mutator, Resources parameters) {
- // select fittest chromosome
- int fittest = 0;
-
- for (int i = 1; i < parameters.getInt("popSize"); i++) {
- if (population.getChromosome(i).getFitness() >= population.getChromosome(fittest).getFitness()) {
- fittest = i;
- }
- }
- fittestChromosome = population.getChromosome(fittest);
- population.setBestIndividual(fittest);
- // create copies of fittest chromosome, mutate them
- Chromosome fc = population.getChromosome(fittest);
- for (int i = 0; i < parameters.getInt("popSize"); i++) {
- if (i != fittest) {
- population.getChromosome(i).copyConnections(fc);
- mutator.mutate(population.getChromosome(i), parameters);
- }
- }
- }
-
- @Override
- public Chromosome getFittestChromosome() {
- return fittestChromosome;
- }
-
- @Override
- public HashMap<String, Parameter> getLocalParameters() {
- return localParameters;
- }
-
- @Override
- public String toString() {
- return "(μ + λ)";
- }
-
- @Override
- public ModuleStatus getStatus(Resources resources) {
- return ModuleStatus.READY;
- }
-
-}
diff --git a/src/jcgp/modules/ea/TournamentSelection.java b/src/jcgp/modules/ea/TournamentSelection.java
deleted file mode 100644
index c2915a5..0000000
--- a/src/jcgp/modules/ea/TournamentSelection.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package jcgp.modules.ea;
-
-import java.util.HashMap;
-
-import jcgp.JCGP.Resources;
-import jcgp.modules.ModuleStatus;
-import jcgp.modules.mutator.Mutator;
-import jcgp.parameters.IntegerParameter;
-import jcgp.parameters.Parameter;
-import jcgp.population.Chromosome;
-import jcgp.population.Population;
-
-public class TournamentSelection implements EvolutionaryAlgorithm {
-
- private Chromosome fittestChromosome;
-
- private IntegerParameter tournament;
- private HashMap<String, Parameter> localParameters;
-
- public TournamentSelection() {
- tournament = new IntegerParameter(1, "Tournament size");
-
- localParameters = new HashMap<String, Parameter>();
- localParameters.put("tournament", tournament);
- }
-
- @Override
- public HashMap<String, Parameter> getLocalParameters() {
- return localParameters;
- }
-
- @Override
- public void evolve(Population population, Mutator mutator,
- Resources parameters) {
-
- // TODO implement this
-
- }
-
- @Override
- public Chromosome getFittestChromosome() {
- return fittestChromosome;
- }
-
- @Override
- public String toString() {
- return "Tournament";
- }
-
- @Override
- public ModuleStatus getStatus(Resources resources) {
- return null;
- }
-}
diff --git a/src/jcgp/modules/fitness/FitnessFunction.java b/src/jcgp/modules/fitness/FitnessFunction.java
deleted file mode 100644
index f0800b0..0000000
--- a/src/jcgp/modules/fitness/FitnessFunction.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package jcgp.modules.fitness;
-
-import jcgp.JCGP.Resources;
-import jcgp.modules.Module;
-import jcgp.population.Population;
-
-public interface FitnessFunction extends Module {
-
- public void evaluate(Population population, Resources resources);
-
-}
diff --git a/src/jcgp/modules/fitness/TestCase.java b/src/jcgp/modules/fitness/TestCase.java
deleted file mode 100644
index 081a257..0000000
--- a/src/jcgp/modules/fitness/TestCase.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package jcgp.modules.fitness;
-
-public class TestCase {
-
- private Object[] inputs;
- private Object[] outputs;
-
- public TestCase(Object[] inputs, Object[] outputs) {
- this.inputs = inputs;
- this.outputs = outputs;
- }
-
- public Object getInput(int index) {
- return inputs[index];
- }
-
- public Object getOutput(int index) {
- return outputs[index];
- }
-
- public Object[] getInputs() {
- return inputs;
- }
-
- public Object[] getOutputs() {
- return outputs;
- }
-
-}
diff --git a/src/jcgp/modules/fitness/TestCaseEvaluator.java b/src/jcgp/modules/fitness/TestCaseEvaluator.java
deleted file mode 100644
index d8c1255..0000000
--- a/src/jcgp/modules/fitness/TestCaseEvaluator.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package jcgp.modules.fitness;
-
-import java.util.HashMap;
-
-import jcgp.JCGP.Resources;
-import jcgp.modules.ModuleStatus;
-import jcgp.parameters.Parameter;
-import jcgp.population.Population;
-
-public class TestCaseEvaluator implements FitnessFunction {
-
- @Override
- public void evaluate(Population population, Resources resources) {
- // for every chromosome in the population
- for (int i = 0; i < resources.getInt("popSize"); i++) {
- int fitness = 0;
- // for every test case
- for (int t = 0; t < resources.getTestCaseCount(); t++) {
- population.getChromosome(i).setInputs(resources.getTestCase(t).getInputs());
- // check every output
- for (int o = 0; o < resources.getInt("outputs"); o++) {
- if (population.getChromosome(i).getOutput(o).calculate() == resources.getTestCase(t).getOutput(o)) {
- fitness++;
- }
- }
- }
- population.getChromosome(i).setFitness(fitness);
- }
- }
-
- @Override
- public HashMap<String, Parameter> getLocalParameters() {
- return null;
- }
-
- @Override
- public String toString() {
- return "Test case";
- }
-
- @Override
- public ModuleStatus getStatus(Resources resources) {
- return null;
- }
-}
diff --git a/src/jcgp/modules/mutator/Mutator.java b/src/jcgp/modules/mutator/Mutator.java
deleted file mode 100644
index 8dfa0f9..0000000
--- a/src/jcgp/modules/mutator/Mutator.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package jcgp.modules.mutator;
-
-import jcgp.JCGP.Resources;
-import jcgp.modules.Module;
-import jcgp.population.Chromosome;
-
-public interface Mutator extends Module {
-
- void mutate(Chromosome chromosome, Resources parameters);
-
-}
diff --git a/src/jcgp/modules/mutator/PointMutator.java b/src/jcgp/modules/mutator/PointMutator.java
deleted file mode 100644
index 2298368..0000000
--- a/src/jcgp/modules/mutator/PointMutator.java
+++ /dev/null
@@ -1,71 +0,0 @@
-package jcgp.modules.mutator;
-
-import java.util.HashMap;
-
-import jcgp.modules.ModuleStatus;
-import jcgp.parameters.DoubleParameter;
-import jcgp.parameters.Parameter;
-import jcgp.JCGP.Resources;
-import jcgp.population.Chromosome;
-import jcgp.population.MutableElement;
-import jcgp.population.Node;
-import jcgp.population.Output;
-
-public class PointMutator implements Mutator {
-
- private DoubleParameter mutationRate;
- private HashMap<String, Parameter> localParameters;
-
- private ModuleStatus status = ModuleStatus.READY;
-
- public PointMutator() {
- mutationRate = new DoubleParameter(0.5, "Percent mutation");
-
- localParameters = new HashMap<String, Parameter>();
- localParameters.put("mutRate", mutationRate);
- }
-
- @Override
- public void mutate(Chromosome chromosome, Resources resources) {
- int mutations = (int) Math.ceil(((mutationRate.get()) * ((((resources.getDouble("nodes")) + (resources.getDouble("outputs")))) / (double) 100)));
- for (int i = 0; i < mutations; i++) {
- MutableElement m = chromosome.getRandomMutableElement();
-
- if (m instanceof Output) {
- m.setConnection(0, chromosome.getRandomConnection());
- } else if (m instanceof Node) {
- int geneType = resources.getRandomInt(1 + resources.getInt("arity"));
- if (geneType < 1) {
- ((Node) m).setFunction(resources.getRandomFunction());
- } else {
- m.setConnection(resources.getRandomInt(resources.getInt("arity")), chromosome.getRandomConnection(((Node) m).getColumn()));
- }
- }
- }
- }
-
- @Override
- public HashMap<String, Parameter> getLocalParameters() {
- return localParameters;
- }
-
- @Override
- public String toString() {
- return "Point mutation";
- }
-
- @Override
- public ModuleStatus getStatus(Resources resources) {
- if (mutationRate.get() <= 0 || mutationRate.get() > 100) {
- status = ModuleStatus.ERROR;
- status.setDetails("Mutation rate must be > 0 and <= 100");
- } else if ((int) ((mutationRate.get() / 100) * resources.getDouble("nodes")) > 0) {
- status = ModuleStatus.WARNING;
- status.setDetails("With mutation rate " + mutationRate.get() + ", no mutations will occur.");
- } else {
- status = ModuleStatus.READY;
- status.setDetails("");
- }
- return status;
- }
-}