From ef7a850a8f2f81ccaa07f25d9b7ad602e84d88c9 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Sun, 16 Feb 2014 22:41:46 +0000 Subject: Light refactoring, a good amount of testing done, added some new functions. --- src/jcgp/population/Chromosome.java | 18 ++++++++++++++++++ src/jcgp/population/Connection.java | 1 + src/jcgp/population/Input.java | 5 +++++ src/jcgp/population/Node.java | 6 ++++++ src/jcgp/population/Output.java | 6 +++++- 5 files changed, 35 insertions(+), 1 deletion(-) (limited to 'src/jcgp/population') diff --git a/src/jcgp/population/Chromosome.java b/src/jcgp/population/Chromosome.java index 3e61a10..996e765 100644 --- a/src/jcgp/population/Chromosome.java +++ b/src/jcgp/population/Chromosome.java @@ -300,4 +300,22 @@ public class Chromosome { } return false; } + + public void printNodes() { + for (int r = 0; r < Parameters.getRows(); r++) { + System.out.print("r: " + r + "\t"); + for (int c = 0; c < Parameters.getColumns(); c++) { + System.out.print("N: (" + r + ", " + c + ") "); + for (int i = 0; i < Parameters.getMaxArity(); i++) { + System.out.print("C" + i + ": (" + nodes[r][c].getConnection(i).getDescription() + ") "); + } + System.out.print("F: " + nodes[r][c].getFunction().toString() + "\t"); + } + System.out.print("\n"); + } + + for (int o = 0; o < Parameters.getOutputs(); o++) { + System.out.print("o: " + o + " (" + outputs[o].getSource().getDescription() + ")\t"); + } + } } diff --git a/src/jcgp/population/Connection.java b/src/jcgp/population/Connection.java index 751fe10..63a171e 100644 --- a/src/jcgp/population/Connection.java +++ b/src/jcgp/population/Connection.java @@ -4,5 +4,6 @@ public interface Connection { public Object getValue(); + public String getDescription(); } diff --git a/src/jcgp/population/Input.java b/src/jcgp/population/Input.java index e793bf6..5c545d6 100644 --- a/src/jcgp/population/Input.java +++ b/src/jcgp/population/Input.java @@ -21,4 +21,9 @@ public class Input implements Connection { public int getIndex() { return index; } + + @Override + public String getDescription() { + return "i: " + index; + } } diff --git a/src/jcgp/population/Node.java b/src/jcgp/population/Node.java index 35d33cb..1741235 100644 --- a/src/jcgp/population/Node.java +++ b/src/jcgp/population/Node.java @@ -25,6 +25,7 @@ public class Node implements MutableElement, Connection { @Override public Object getValue() { + //System.out.print("Calculating node: (" + row + ", " + column + ") > "); return function.run(Arrays.copyOfRange(connections, 0, function.getArity())); } @@ -110,4 +111,9 @@ public class Node implements MutableElement, Connection { } return false; } + + @Override + public String getDescription() { + return "n: " + row + ", " + column; + } } diff --git a/src/jcgp/population/Output.java b/src/jcgp/population/Output.java index b3ce74f..0df51e9 100644 --- a/src/jcgp/population/Output.java +++ b/src/jcgp/population/Output.java @@ -2,6 +2,8 @@ package jcgp.population; import java.util.ArrayList; +import jcgp.Parameters; + public class Output implements MutableElement { private Connection source; @@ -15,7 +17,9 @@ public class Output implements MutableElement { public Object calculate() { Object result = source.getValue(); - System.out.println("Output " + index + ": " + result); + if (Parameters.getDebug()) { + System.out.println("Output " + index + ": " + result); + } return result; } -- cgit v1.2.3