aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/chromosome
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/chromosome')
-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
5 files changed, 86 insertions, 35 deletions
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;