From ccdecd80ffe482fbe994515e98eeae68fb4ca401 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Tue, 11 Feb 2014 22:17:30 +0000 Subject: Finished writing chromosome tests, implemented active node detection, started writing node tests. --- src/jcgp/population/Chromosome.java | 11 +++++------ src/jcgp/population/Connection.java | 7 ++++++- src/jcgp/population/Input.java | 9 +++++++++ src/jcgp/population/Node.java | 14 +++++++++++++- src/jcgp/population/Output.java | 7 +++++-- 5 files changed, 38 insertions(+), 10 deletions(-) (limited to 'src/jcgp/population') diff --git a/src/jcgp/population/Chromosome.java b/src/jcgp/population/Chromosome.java index 1f264f2..08ff9b9 100644 --- a/src/jcgp/population/Chromosome.java +++ b/src/jcgp/population/Chromosome.java @@ -104,7 +104,7 @@ public class Chromosome { // populate with connections equivalent to clone Connection copyConnection; for (int i = 0; i < connections.length; i++) { - copyConnection = clone.getNode(r, c).getConnections(i); + copyConnection = clone.getNode(r, c).getConnection(i); if (copyConnection instanceof Input) { connections[i] = inputs[((Input) copyConnection).getIndex()]; } else if (copyConnection instanceof Node) { @@ -251,12 +251,11 @@ public class Chromosome { recomputeActiveNodes = false; activeNodes = new ArrayList(); - for (int r = 0; r < nodes.length; r++) { - for (int c = 0; c < nodes[r].length; c++) { - - } + for (Output output : outputs) { + output.getActiveNodes(activeNodes); } - } + + } return activeNodes; } diff --git a/src/jcgp/population/Connection.java b/src/jcgp/population/Connection.java index 4e69e99..12e92d6 100644 --- a/src/jcgp/population/Connection.java +++ b/src/jcgp/population/Connection.java @@ -1,6 +1,11 @@ package jcgp.population; +import java.util.ArrayList; + public interface Connection { - public abstract int getValue(); + public int getValue(); + + public void getActive(ArrayList activeNodes); + } diff --git a/src/jcgp/population/Input.java b/src/jcgp/population/Input.java index ee008ce..f3199b8 100644 --- a/src/jcgp/population/Input.java +++ b/src/jcgp/population/Input.java @@ -1,5 +1,7 @@ package jcgp.population; +import java.util.ArrayList; + public class Input implements Connection { private int value = 0, index; @@ -21,4 +23,11 @@ public class Input implements Connection { return index; } + @Override + public void getActive(ArrayList activeNodes) { + if (!activeNodes.contains(this)) { + activeNodes.add(this); + } + } + } diff --git a/src/jcgp/population/Node.java b/src/jcgp/population/Node.java index 40ffa52..c09532c 100644 --- a/src/jcgp/population/Node.java +++ b/src/jcgp/population/Node.java @@ -1,5 +1,7 @@ package jcgp.population; +import java.util.ArrayList; + import jcgp.Parameters; import jcgp.Utilities; import jcgp.function.Function; @@ -58,7 +60,17 @@ public class Node implements MutableElement, Connection { return function; } - public Connection getConnections(int index) { + public Connection getConnection(int index) { return connections[index]; } + + @Override + public void getActive(ArrayList activeNodes) { + if (!activeNodes.contains(this)) { + activeNodes.add(this); + } + for (int i = 0; i < function.getArity(); i++) { + connections[i].getActive(activeNodes); + } + } } diff --git a/src/jcgp/population/Output.java b/src/jcgp/population/Output.java index 68045b0..b3cb648 100644 --- a/src/jcgp/population/Output.java +++ b/src/jcgp/population/Output.java @@ -1,5 +1,7 @@ package jcgp.population; +import java.util.ArrayList; + public class Output implements MutableElement { @@ -29,7 +31,8 @@ public class Output implements MutableElement { public Connection getSource() { return source; } - - + public void getActiveNodes(ArrayList activeNodes) { + source.getActive(activeNodes); + } } -- cgit v1.2.3