From f13ebf70037a6aa28dc53804c1f0cef6e2f23102 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Mon, 19 May 2014 01:36:03 +0100 Subject: Minor refactorings --- src/jcgp/backend/population/Chromosome.java | 4 +- src/jcgp/backend/population/Node.java | 57 ++++++++++++++--------------- 2 files changed, 28 insertions(+), 33 deletions(-) (limited to 'src/jcgp/backend/population') diff --git a/src/jcgp/backend/population/Chromosome.java b/src/jcgp/backend/population/Chromosome.java index e28032c..d84c5f0 100644 --- a/src/jcgp/backend/population/Chromosome.java +++ b/src/jcgp/backend/population/Chromosome.java @@ -112,13 +112,11 @@ public class Chromosome implements Comparable { inputs[i] = new Input(i); } - int arity = resources.arity(); - // rows first nodes = new Node[(resources.rows())][(resources.columns())]; for (int r = 0; r < nodes.length; r++) { for (int c = 0; c < nodes[r].length; c++) { - nodes[r][c] = new Node(this, r, c, arity); + nodes[r][c] = new Node(this, r, c); } } outputs = new Output[resources.outputs()]; diff --git a/src/jcgp/backend/population/Node.java b/src/jcgp/backend/population/Node.java index 7712c50..6696694 100644 --- a/src/jcgp/backend/population/Node.java +++ b/src/jcgp/backend/population/Node.java @@ -40,23 +40,13 @@ public class Node implements Mutable, Connection { * @param chromosome the chromosome this node belongs to. * @param row the node's row. * @param column the node's column. - * @param arity the maximum arity of the experiment. */ - public Node(Chromosome chromosome, int row, int column, int arity) { + public Node(Chromosome chromosome, int row, int column) { this.chromosome = chromosome; this.column = column; this.row = row; } - /** - * Sets the node function. - * - * @param newFunction the new function to set. - */ - public void setFunction(Function newFunction) { - function = newFunction; - } - /** * Initialises the node with the specified values. * The number of connections passed as argument must @@ -66,7 +56,7 @@ public class Node implements Mutable, Connection { * @param newFunction the node function to set. * @param newConnections the node connections to set. */ - public void initialise(Function newFunction, Connection ... newConnections) { + public void initialise(Function newFunction, Connection... newConnections) { function = newFunction; if (newConnections.length == chromosome.getResources().arity()) { connections = newConnections; @@ -96,6 +86,15 @@ public class Node implements Mutable, Connection { return function; } + /** + * Sets the node function. + * + * @param newFunction the new function to set. + */ + public void setFunction(Function newFunction) { + function = newFunction; + } + /** * @param index the connection to return. * @return the indexed connection. @@ -103,6 +102,22 @@ public class Node implements Mutable, Connection { public Connection getConnection(int index) { return connections[index]; } + + /** + * This method sets the indexed connection to the specified new connection. + * If the given connection is null or disrespects levels back, it is discarded + * and no connections are changed. + * + * @param index the connection index to set. + * @param newConnection the {@code Connection} to connect to. + */ + public void setConnection(int index, Connection newConnection) { + // connection must not be null + if (newConnection != null) { + connections[index] = newConnection; + chromosome.recomputeActiveNodes(); + } + } /** * For package use, this is a recursive method @@ -127,24 +142,6 @@ public class Node implements Mutable, Connection { } } } - - /** - * This method sets the indexed connection to the specified new connection. - * If the given connection is null or disrespects levels back, it is discarded - * and no connections are changed. - * - * @param index the connection index to set. - * @param newConnection the {@code Connection} to connect to. - */ - public void setConnection(int index, Connection newConnection) { - // connection must not be null - if (newConnection != null) { - //if () { - connections[index] = newConnection; - chromosome.recomputeActiveNodes(); - //} - } - } @Override public boolean copyOf(Mutable element) { -- cgit v1.2.3