aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/population
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/population')
-rw-r--r--src/jcgp/population/Chromosome.java4
-rw-r--r--src/jcgp/population/MutableElement.java2
-rw-r--r--src/jcgp/population/Node.java14
-rw-r--r--src/jcgp/population/Output.java7
-rw-r--r--src/jcgp/population/Population.java2
5 files changed, 26 insertions, 3 deletions
diff --git a/src/jcgp/population/Chromosome.java b/src/jcgp/population/Chromosome.java
index 70e8836..f060e14 100644
--- a/src/jcgp/population/Chromosome.java
+++ b/src/jcgp/population/Chromosome.java
@@ -45,7 +45,7 @@ public class Chromosome {
for (int r = 0; r < rows; r++) {
//nodes[r] = new Node[Parameters.getColumns()];
for (int c = 0; c < columns; c++) {
- nodes[r][c] = new Node();
+ nodes[r][c] = new Node(c);
}
}
outputs = new Output[outputCount];
@@ -59,7 +59,7 @@ public class Chromosome {
// initialise nodes - [rows][columns]
for (int r = 0; r < nodes.length; r++) {
for (int c = 0; c < nodes.length; c++) {
- Connection[] connections = new Connection[Utilities.getMaxArity()];
+ Connection[] connections = new Connection[Parameters.getMaxArity()];
for (int i = 0; i < connections.length; i++) {
connections[i] = Utilities.getRandomConnection(this, c);
}
diff --git a/src/jcgp/population/MutableElement.java b/src/jcgp/population/MutableElement.java
index 5eae4ef..8ac3724 100644
--- a/src/jcgp/population/MutableElement.java
+++ b/src/jcgp/population/MutableElement.java
@@ -4,4 +4,6 @@ public interface MutableElement {
public void setConnection(Connection newConnection);
+ public int getColumn();
+
}
diff --git a/src/jcgp/population/Node.java b/src/jcgp/population/Node.java
index 8958475..fd0cd47 100644
--- a/src/jcgp/population/Node.java
+++ b/src/jcgp/population/Node.java
@@ -1,5 +1,6 @@
package jcgp.population;
+import jcgp.CGP.Parameters;
import jcgp.CGP.Utilities;
import jcgp.function.Function;
@@ -8,7 +9,12 @@ public class Node implements MutableElement, Connection {
private Function function;
private Connection[] connections;
+ private int column;
+ public Node(int col) {
+ column = col;
+ }
+
@Override
public int evaluate() {
return function.run(connections);
@@ -27,10 +33,16 @@ public class Node implements MutableElement, Connection {
function = newFunction;
- if (newConnections.length >= Utilities.getMaxArity()) {
+ if (newConnections.length >= Parameters.getMaxArity()) {
connections = newConnections;
} else {
throw new InsufficientConnectionsException();
}
}
+
+ @Override
+ public int getColumn() {
+
+ return column;
+ }
}
diff --git a/src/jcgp/population/Output.java b/src/jcgp/population/Output.java
index 1640deb..eeae743 100644
--- a/src/jcgp/population/Output.java
+++ b/src/jcgp/population/Output.java
@@ -1,5 +1,7 @@
package jcgp.population;
+import jcgp.CGP.Parameters;
+
public class Output implements MutableElement {
@@ -15,4 +17,9 @@ public class Output implements MutableElement {
}
+ @Override
+ public int getColumn() {
+ return Parameters.getColumns();
+ }
+
}
diff --git a/src/jcgp/population/Population.java b/src/jcgp/population/Population.java
index 55f756a..e171a2f 100644
--- a/src/jcgp/population/Population.java
+++ b/src/jcgp/population/Population.java
@@ -43,6 +43,8 @@ public class Population implements Iterable<Chromosome> {
@Override
public void remove() {
// not allowed
+ // since this would shift everything back one position, increment index
+ index++;
}
};