From a02f1fff03ab58416da812597e67a0c7e21fdbd5 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Fri, 31 Jan 2014 13:06:54 +0000 Subject: Created most of the classes that will be necessary, content is blank for now. --- src/jcgp/population/Chromosome.java | 89 +++++++++++++++++++++++++++++++++ src/jcgp/population/Connection.java | 6 +++ src/jcgp/population/Input.java | 16 ++++++ src/jcgp/population/MutableElement.java | 5 ++ src/jcgp/population/Node.java | 28 +++++++++++ src/jcgp/population/Output.java | 11 ++++ src/jcgp/population/Population.java | 46 +++++++++++++++++ 7 files changed, 201 insertions(+) create mode 100644 src/jcgp/population/Chromosome.java create mode 100644 src/jcgp/population/Connection.java create mode 100644 src/jcgp/population/Input.java create mode 100644 src/jcgp/population/MutableElement.java create mode 100644 src/jcgp/population/Node.java create mode 100644 src/jcgp/population/Output.java create mode 100644 src/jcgp/population/Population.java (limited to 'src/jcgp/population') diff --git a/src/jcgp/population/Chromosome.java b/src/jcgp/population/Chromosome.java new file mode 100644 index 0000000..2e22cf9 --- /dev/null +++ b/src/jcgp/population/Chromosome.java @@ -0,0 +1,89 @@ +package jcgp.population; + +import java.util.ArrayList; + +public class Chromosome { + + private ArrayList inputs; + private ArrayList> nodes; + private ArrayList outputs; + + private int fitness = 0; + + /** + * Good citizen. + * @param outputs + * @param columns + * @param rows + * @param inputs + * + */ + public Chromosome(int inputCount, int rows, int columns, int outputCount) { + + inputs = new ArrayList(inputCount); + for (int i = 0; i < inputCount; i++) { + inputs.add(new Input()); + } + + // rows first + nodes = new ArrayList>(rows); + for (int r = 0; r < rows; r++) { + nodes.add(new ArrayList(columns)); + for (int c = 0; c < columns; c++) { + nodes.get(r).add(new Node()); + } + } + + outputs = new ArrayList(outputCount); + for (int o = 0; o < outputCount; o++) { + outputs.add(new Output()); + } + + } + + public int getActiveNodeCount() { + return 0; + } + + /** + * @return the inputs + */ + public final ArrayList getInputs() { + return inputs; + } + + /** + * @return the nodes + */ + public final ArrayList> getNodes() { + return nodes; + } + + /** + * @return the outputs + */ + public final ArrayList getOutputs() { + return outputs; + } + + public final Node getNode(int row, int column) { + return nodes.get(row).get(column); + } + + public final Output getOutput(int index) { + return outputs.get(index); + } + + public final Input getInputs(int index) { + return inputs.get(index); + } + + public int getFitness() { + return fitness; + } + + public void setFitness(int newFitness) { + fitness = newFitness; + } + +} diff --git a/src/jcgp/population/Connection.java b/src/jcgp/population/Connection.java new file mode 100644 index 0000000..fa02a22 --- /dev/null +++ b/src/jcgp/population/Connection.java @@ -0,0 +1,6 @@ +package jcgp.population; + +public interface Connection { + + public abstract int evaluate(); +} diff --git a/src/jcgp/population/Input.java b/src/jcgp/population/Input.java new file mode 100644 index 0000000..b9c127f --- /dev/null +++ b/src/jcgp/population/Input.java @@ -0,0 +1,16 @@ +package jcgp.population; + +public class Input implements Connection { + + private int value = 0; + + public void setValue(int newValue) { + value = newValue; + } + + @Override + public int evaluate() { + return value; + } + +} diff --git a/src/jcgp/population/MutableElement.java b/src/jcgp/population/MutableElement.java new file mode 100644 index 0000000..4397e46 --- /dev/null +++ b/src/jcgp/population/MutableElement.java @@ -0,0 +1,5 @@ +package jcgp.population; + +public interface MutableElement { + +} diff --git a/src/jcgp/population/Node.java b/src/jcgp/population/Node.java new file mode 100644 index 0000000..cce8dfd --- /dev/null +++ b/src/jcgp/population/Node.java @@ -0,0 +1,28 @@ +package jcgp.population; + +import jcgp.function.Function; + + +public class Node implements MutableElement, Connection { + + private Function function; + private Connection[] connections; + + public Node() { + + } + + @Override + public int evaluate() { + return function.run(connections[0], connections[1]); + } + + public void setFunction(Function newFunction) { + function = newFunction; + } + + public void setConnection(Connection newConnection) { + + } + +} diff --git a/src/jcgp/population/Output.java b/src/jcgp/population/Output.java new file mode 100644 index 0000000..2f2df6e --- /dev/null +++ b/src/jcgp/population/Output.java @@ -0,0 +1,11 @@ +package jcgp.population; + + +public class Output implements MutableElement { + + public int calculate() { + // TODO Auto-generated method stub + return 0; + } + +} diff --git a/src/jcgp/population/Population.java b/src/jcgp/population/Population.java new file mode 100644 index 0000000..e1a9a3c --- /dev/null +++ b/src/jcgp/population/Population.java @@ -0,0 +1,46 @@ +package jcgp.population; + +import java.util.ArrayList; +import java.util.Iterator; + +public final class Population implements Iterable { + + private ArrayList population; + + public Population(int inputs, int rows, int columns, int outputs, int size) { + population = new ArrayList(size); + for (int c = 0; c < size; c++) { + population.add(new Chromosome(inputs, rows, columns, outputs)); + } + } + + @Override + public Iterator iterator() { + return new Iterator() { + + private int index = 0; + + @Override + public boolean hasNext() { + if (index < population.size()) { + return true; + } else { + return false; + } + } + + @Override + public Chromosome next() { + Chromosome next = population.get(index); + index++; + return next; + } + + @Override + public void remove() { + // not allowed + } + + }; + } +} -- cgit v1.2.3