aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-01-30 21:41:33 +0000
committerEduardo Pedroni <ep625@york.ac.uk>2014-01-30 21:41:33 +0000
commit8f7874fa75c532bab994af8e6553d37afe42ec4c (patch)
treed2cf0e234fbf5b329abde422c1123675baa71125
parent761021e0551beaaaac1120ef6da37a70281974b2 (diff)
Chromosome data structure partially refactored, also added higher level classes.
-rw-r--r--src/jcgp/CGP.java12
-rw-r--r--src/jcgp/chromosome/Chromosome.java66
-rw-r--r--src/jcgp/chromosome/Population.java16
-rw-r--r--src/jcgp/chromosome/element/MutableElement.java7
-rw-r--r--src/jcgp/chromosome/element/Node.java18
-rw-r--r--src/jcgp/chromosome/element/Output.java14
-rw-r--r--src/jcgp/mutator/Mutator.java15
7 files changed, 113 insertions, 35 deletions
diff --git a/src/jcgp/CGP.java b/src/jcgp/CGP.java
new file mode 100644
index 0000000..d2cae80
--- /dev/null
+++ b/src/jcgp/CGP.java
@@ -0,0 +1,12 @@
+package jcgp;
+
+public class CGP<T> {
+
+ public static int ROWS, COLUMNS, INPUTS, OUTPUTS, MUTATION_RATE, GENERATIONS, RUNS;
+
+ public CGP() {
+
+ }
+
+
+}
diff --git a/src/jcgp/chromosome/Chromosome.java b/src/jcgp/chromosome/Chromosome.java
index 19d7e77..cdf2e4b 100644
--- a/src/jcgp/chromosome/Chromosome.java
+++ b/src/jcgp/chromosome/Chromosome.java
@@ -2,16 +2,78 @@ package jcgp.chromosome;
import java.util.ArrayList;
-import jcgp.chromosome.element.ChromosomeElement;
+import jcgp.CGP;
+import jcgp.chromosome.element.Input;
+import jcgp.chromosome.element.Node;
+import jcgp.chromosome.element.Output;
public class Chromosome {
- private ArrayList<ArrayList<? extends ChromosomeElement>> nodes;
+ private ArrayList<Input> inputs;
+ private ArrayList<ArrayList<Node>> nodes;
+ private ArrayList<Output> outputs;
+ /**
+ * Good citizen.
+ *
+ */
public Chromosome() {
+ inputs = new ArrayList<Input>(CGP.INPUTS);
+ for (int i = 0; i < CGP.INPUTS; i++) {
+ inputs.add(new Input());
+ }
+ // rows first
+ nodes = new ArrayList<ArrayList<Node>>(CGP.ROWS);
+ for (int r = 0; r < CGP.ROWS; r++) {
+ nodes.add(new ArrayList<Node>(CGP.COLUMNS));
+ for (int c = 0; c < CGP.COLUMNS; c++) {
+ nodes.get(r).add(new Node());
+ }
+ }
+ outputs = new ArrayList<Output>(CGP.OUTPUTS);
+ for (int o = 0; o < CGP.OUTPUTS; o++) {
+ outputs.add(new Output());
+ }
+ }
+
+ public int getActiveNodeCount() {
+ return 0;
+ }
+
+ /**
+ * @return the inputs
+ */
+ public final ArrayList<Input> getInputs() {
+ return inputs;
+ }
+
+ /**
+ * @return the nodes
+ */
+ public final ArrayList<ArrayList<Node>> getNodes() {
+ return nodes;
+ }
+
+ /**
+ * @return the outputs
+ */
+ public final ArrayList<Output> 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);
}
}
diff --git a/src/jcgp/chromosome/Population.java b/src/jcgp/chromosome/Population.java
new file mode 100644
index 0000000..e720a24
--- /dev/null
+++ b/src/jcgp/chromosome/Population.java
@@ -0,0 +1,16 @@
+package jcgp.chromosome;
+
+import java.util.ArrayList;
+
+public class Population {
+
+ private ArrayList<Chromosome> population;
+
+ public Population(int size) {
+ population = new ArrayList<Chromosome>(size);
+ for (int c = 0; c < size; c++) {
+ population.add(new Chromosome());
+ }
+ }
+
+}
diff --git a/src/jcgp/chromosome/element/MutableElement.java b/src/jcgp/chromosome/element/MutableElement.java
index ed7e23c..0122c69 100644
--- a/src/jcgp/chromosome/element/MutableElement.java
+++ b/src/jcgp/chromosome/element/MutableElement.java
@@ -1,12 +1,5 @@
package jcgp.chromosome.element;
-import jcgp.chromosome.Chromosome;
-import jcgp.chromosome.functions.FunctionSet;
-
public interface MutableElement {
- public void initialise(Chromosome chromosome, FunctionSet functions);
-
- public void mutate(Chromosome chromosome, FunctionSet functions);
-
}
diff --git a/src/jcgp/chromosome/element/Node.java b/src/jcgp/chromosome/element/Node.java
index f97c680..761c3c9 100644
--- a/src/jcgp/chromosome/element/Node.java
+++ b/src/jcgp/chromosome/element/Node.java
@@ -1,22 +1,16 @@
package jcgp.chromosome.element;
-import jcgp.chromosome.Chromosome;
-import jcgp.chromosome.functions.FunctionSet;
+import jcgp.chromosome.functions.Function;
-public class Node extends ChromosomeElement implements MutableElement {
- @Override
- public void initialise(Chromosome chromosome, FunctionSet functions) {
- // TODO Auto-generated method stub
-
- }
+public class Node extends ChromosomeElement implements MutableElement {
+
+ private Function function;
- @Override
- public void mutate(Chromosome chromosome, FunctionSet functions) {
- // TODO Auto-generated method stub
+ public Node() {
}
-
+
@Override
public int evaluate() {
// TODO Auto-generated method stub
diff --git a/src/jcgp/chromosome/element/Output.java b/src/jcgp/chromosome/element/Output.java
index 261e77d..ee4d204 100644
--- a/src/jcgp/chromosome/element/Output.java
+++ b/src/jcgp/chromosome/element/Output.java
@@ -1,23 +1,9 @@
package jcgp.chromosome.element;
-import jcgp.chromosome.Chromosome;
-import jcgp.chromosome.functions.FunctionSet;
public class Output extends ChromosomeElement implements MutableElement {
@Override
- public void initialise(Chromosome chromosome, FunctionSet functions) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void mutate(Chromosome chromosome, FunctionSet functions) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
public int evaluate() {
// TODO Auto-generated method stub
return 0;
diff --git a/src/jcgp/mutator/Mutator.java b/src/jcgp/mutator/Mutator.java
new file mode 100644
index 0000000..577aa42
--- /dev/null
+++ b/src/jcgp/mutator/Mutator.java
@@ -0,0 +1,15 @@
+package jcgp.mutator;
+
+import jcgp.chromosome.Population;
+
+public class Mutator {
+
+ public Mutator() {
+
+ }
+
+ public void mutate(Population population, int rate) {
+
+ }
+
+}