aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/population
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-02-16 22:41:46 +0000
committerEduardo Pedroni <ep625@york.ac.uk>2014-02-16 22:41:46 +0000
commitef7a850a8f2f81ccaa07f25d9b7ad602e84d88c9 (patch)
tree9f9c6206a140bdfad4bb1b44354e6c7314d8b605 /src/jcgp/population
parente9290a500b228e2561a8537adbc13e86f1356747 (diff)
Light refactoring, a good amount of testing done, added some new functions.
Diffstat (limited to 'src/jcgp/population')
-rw-r--r--src/jcgp/population/Chromosome.java18
-rw-r--r--src/jcgp/population/Connection.java1
-rw-r--r--src/jcgp/population/Input.java5
-rw-r--r--src/jcgp/population/Node.java6
-rw-r--r--src/jcgp/population/Output.java6
5 files changed, 35 insertions, 1 deletions
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;
}