diff options
Diffstat (limited to 'src/jcgp/population/Node.java')
-rw-r--r-- | src/jcgp/population/Node.java | 20 |
1 files changed, 14 insertions, 6 deletions
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(); + } } - } |