From 2343cc0e456e0306711c0a7218d3027f17cffee7 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Fri, 31 Jan 2014 16:45:45 +0000 Subject: Added lots of utility methods for initialisation and mutation; the foundation is laid down and probably works, now it's time to test it and implement the standard CGP modules. --- src/jcgp/population/Node.java | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/jcgp/population/Node.java') diff --git a/src/jcgp/population/Node.java b/src/jcgp/population/Node.java index cce8dfd..8958475 100644 --- a/src/jcgp/population/Node.java +++ b/src/jcgp/population/Node.java @@ -1,5 +1,6 @@ package jcgp.population; +import jcgp.CGP.Utilities; import jcgp.function.Function; @@ -8,21 +9,28 @@ public class Node implements MutableElement, Connection { private Function function; private Connection[] connections; - public Node() { - - } - @Override public int evaluate() { - return function.run(connections[0], connections[1]); + return function.run(connections); } public void setFunction(Function newFunction) { function = newFunction; } + @Override public void setConnection(Connection newConnection) { + connections[Utilities.getRandomInt(connections.length)] = newConnection; + } + + public void initialise(Function newFunction, Connection ... newConnections) throws InsufficientConnectionsException { + + function = newFunction; + if (newConnections.length >= Utilities.getMaxArity()) { + connections = newConnections; + } else { + throw new InsufficientConnectionsException(); + } } - } -- cgit v1.2.3