From 1fd678821cf133c7c431daea687f3467bb0be2dd Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Tue, 4 Feb 2014 16:20:33 +0000 Subject: Added fitness evaluation mechanism, though it might not be a very good design. Tests will be done to verify that. --- src/jcgp/population/Chromosome.java | 4 ++-- src/jcgp/population/MutableElement.java | 2 ++ src/jcgp/population/Node.java | 14 +++++++++++++- src/jcgp/population/Output.java | 7 +++++++ src/jcgp/population/Population.java | 2 ++ 5 files changed, 26 insertions(+), 3 deletions(-) (limited to 'src/jcgp/population') 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 { @Override public void remove() { // not allowed + // since this would shift everything back one position, increment index + index++; } }; -- cgit v1.2.3