diff options
author | Eduardo Pedroni <ep625@york.ac.uk> | 2014-03-30 21:07:37 +0100 |
---|---|---|
committer | Eduardo Pedroni <ep625@york.ac.uk> | 2014-03-30 21:07:37 +0100 |
commit | 04b35ccdad6e18701ede823e333118b0b22907c2 (patch) | |
tree | 0e993a5ffee4e63c4a2a6eca137da72b2453f868 /src/jcgp/tests | |
parent | 2bf2d3ac2c578de481ecfd545d58be73c5628996 (diff) |
Running into some issues with running the CGP loop in the background with bindings.
Diffstat (limited to 'src/jcgp/tests')
-rw-r--r-- | src/jcgp/tests/ChromosomeTests.java | 36 | ||||
-rw-r--r-- | src/jcgp/tests/NodeTests.java | 4 | ||||
-rw-r--r-- | src/jcgp/tests/PopulationTests.java | 2 |
3 files changed, 21 insertions, 21 deletions
diff --git a/src/jcgp/tests/ChromosomeTests.java b/src/jcgp/tests/ChromosomeTests.java index f4ed79c..eb4b5d1 100644 --- a/src/jcgp/tests/ChromosomeTests.java +++ b/src/jcgp/tests/ChromosomeTests.java @@ -62,7 +62,7 @@ public class ChromosomeTests { // compare all elements, one by one // check outputs - for (int o = 0; o < (int) resources.get("outputs"); o++) { + for (int o = 0; o < resources.getInt("outputs"); o++) { // check that no cross-references exist between chromosomes assertTrue("Cloned chromosome contains a reference to a member of the original chromosome.", clone.getOutput(o) != chromosome.getOutput(o) && @@ -80,8 +80,8 @@ public class ChromosomeTests { } } // check nodes, rows first - for (int row = 0; row < (int) resources.get("rows"); row++) { - for (int column = 0; column < (int) resources.get("columns"); column++) { + for (int row = 0; row < resources.getInt("rows"); row++) { + for (int column = 0; column < resources.getInt("columns"); column++) { // check that nodes are not pointers to the same instance assertTrue("Both chromosomes contain a reference to the same node.", clone.getNode(row, column) != chromosome.getNode(row, column)); // check that both nodes reference their own position in the grid correctly @@ -91,7 +91,7 @@ public class ChromosomeTests { assertTrue("Equivalent nodes have different functions.", clone.getNode(row, column).getFunction() == chromosome.getNode(row, column).getFunction()); // compare each connection - for (int connection = 0; connection < (int) resources.get("arity"); connection++) { + for (int connection = 0; connection < resources.getInt("arity"); connection++) { // first look at whether they are actually the same instance assertTrue("Nodes are connected to the same connection instance.", clone.getNode(row, column).getConnection(connection) != chromosome.getNode(row, column).getConnection(connection)); @@ -130,12 +130,12 @@ public class ChromosomeTests { clone.setInputs((Object[]) testInputs); // check that both chromosomes have the same outputs - for (int i = 0; i < (int) resources.get("outputs"); i++) { + for (int i = 0; i < resources.getInt("outputs"); i++) { assertTrue("Incorrect output returned", ((Integer) chromosome.getOutput(i).calculate()) == ((Integer) clone.getOutput(i).calculate())); } // mutate an output in clone, check that the same node in chromosome produces a different output - clone.getOutput(1).setConnection(resources.getRandomInt((int) resources.get("arity")), clone.getInput(2)); + clone.getOutput(1).setConnection(resources.getRandomInt(resources.getInt("arity")), clone.getInput(2)); assertTrue("Mutation affected nodes in both chromosomes.", clone.getOutput(1).calculate() != chromosome.getOutput(1).calculate()); @@ -164,7 +164,7 @@ public class ChromosomeTests { // get random connections with the last column as reference, check that they're all within range int connectionNodes = 0, connectionOutOfRange = 0, connectionInputs = 0, connectionPicks = 100000; - int chosenColumn = (int) resources.get("columns") - 1; + int chosenColumn = resources.getInt("columns") - 1; for (int i = 0; i < connectionPicks; i++) { Connection c = chromosome.getRandomConnection(chosenColumn); if (c instanceof Node) { @@ -180,10 +180,10 @@ public class ChromosomeTests { } } - System.out.println("Out of " + connectionPicks + " connections picked from " + ((chosenColumn >= (int) resources.get("levelsBack")) ? (int) resources.get("levelsBack") : chosenColumn) * (int) resources.get("rows") + - " allowed nodes and " + (int) resources.get("inputs") + " inputs, " + connectionNodes + " were nodes and " + connectionInputs + " were inputs."); + System.out.println("Out of " + connectionPicks + " connections picked from " + ((chosenColumn >= resources.getInt("levelsBack")) ? resources.getInt("levelsBack") : chosenColumn) * resources.getInt("rows") + + " allowed nodes and " + resources.getInt("inputs") + " inputs, " + connectionNodes + " were nodes and " + connectionInputs + " were inputs."); - System.out.println("Node/input ratio: " + ((Integer) (((chosenColumn >= (int) resources.get("levelsBack")) ? (int) resources.get("levelsBack") : chosenColumn) * (Integer) resources.get("rows"))).doubleValue() / ((Integer) resources.get("inputs")).doubleValue() + + System.out.println("Node/input ratio: " + (chosenColumn >= resources.getInt("levelsBack") ? resources.getInt("levelsBack") : chosenColumn) * resources.getDouble("rows") / resources.getDouble("inputs") + ", picked ratio: " + (double) connectionNodes / (double) connectionInputs); System.out.println(connectionOutOfRange + " nodes that disrespected levels back were picked."); @@ -207,10 +207,10 @@ public class ChromosomeTests { fail("Return is neither Node nor Output."); } } - System.out.println("Out of " + mutablePicks + " mutable elements picked from " + (int) resources.get("nodes") + - " nodes and " + (int) resources.get("outputs") + " outputs, " + mutableNodes + " were nodes and " + + System.out.println("Out of " + mutablePicks + " mutable elements picked from " + resources.getInt("nodes") + + " nodes and " + resources.getInt("outputs") + " outputs, " + mutableNodes + " were nodes and " + mutableOutputs + " were outputs."); - System.out.println("Node/output ratio: " + ((Integer) resources.get("nodes")).doubleValue() / ((Integer) resources.get("outputs")).doubleValue() + + System.out.println("Node/output ratio: " + resources.getDouble("nodes") / resources.getDouble("outputs") + ", picked ratio: " + (double) mutableNodes / (double) mutableOutputs + "\n"); } @@ -234,12 +234,12 @@ public class ChromosomeTests { @Test public void setInputTest() { // set input values, check that acquired values are correct - Integer[] testInputs = new Integer[(int) resources.get("inputs")]; - for (int i = 0; i < (int) resources.get("inputs"); i++) { + Integer[] testInputs = new Integer[resources.getInt("inputs")]; + for (int i = 0; i < resources.getInt("inputs"); i++) { testInputs[i] = i * 2 - 3; } chromosome.setInputs((Object[]) testInputs); - for (int i = 0; i < (int) resources.get("inputs"); i++) { + for (int i = 0; i < resources.getInt("inputs"); i++) { assertTrue("Incorrect input returned.", ((Integer) chromosome.getInput(i).getValue()) == i * 2 - 3); } } @@ -250,8 +250,8 @@ public class ChromosomeTests { @Test public void getNodeTest() { // get all nodes one by one, check that they are all correct - for (int r = 0; r < (int) resources.get("rows"); r++) { - for (int c = 0; c < (int) resources.get("columns"); c++) { + for (int r = 0; r < resources.getInt("rows"); r++) { + for (int c = 0; c < resources.getInt("columns"); c++) { assertTrue("Incorrect node returned.", chromosome.getNode(r, c).getColumn() == c && chromosome.getNode(r, c).getRow() == r); } diff --git a/src/jcgp/tests/NodeTests.java b/src/jcgp/tests/NodeTests.java index 7ce5701..d8aa742 100644 --- a/src/jcgp/tests/NodeTests.java +++ b/src/jcgp/tests/NodeTests.java @@ -46,7 +46,7 @@ public class NodeTests { @Before public void setUp() throws Exception { - node = new Node(chromosome, 0, 0, (int) resources.get("arity")); + node = new Node(chromosome, 0, 0, resources.getInt("arity")); // make node with anonymous addition function and hard-coded value connections node.initialise(new Arithmetic.Addition(), new Connection[]{new Connection() { @@ -186,7 +186,7 @@ public class NodeTests { return null; } }; - node.setConnection(resources.getRandomInt((int) resources.get("arity")), conn2); + node.setConnection(resources.getRandomInt(resources.getInt("arity")), conn2); assertTrue("Connection was not found in node.", node.getConnection(0) == conn2 || node.getConnection(1) == conn2); diff --git a/src/jcgp/tests/PopulationTests.java b/src/jcgp/tests/PopulationTests.java index ca737d6..a11becf 100644 --- a/src/jcgp/tests/PopulationTests.java +++ b/src/jcgp/tests/PopulationTests.java @@ -70,7 +70,7 @@ public class PopulationTests { chromosomes++; } - assertTrue("Incorrect number of chromosomes generated.", chromosomes == (int) resources.get("popSize")); + assertTrue("Incorrect number of chromosomes generated.", chromosomes == resources.getInt("popSize")); } @Test |