diff options
Diffstat (limited to 'src/jcgp/backend/population/Node.java')
-rw-r--r-- | src/jcgp/backend/population/Node.java | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/jcgp/backend/population/Node.java b/src/jcgp/backend/population/Node.java index 1ac5b10..74f6b54 100644 --- a/src/jcgp/backend/population/Node.java +++ b/src/jcgp/backend/population/Node.java @@ -1,9 +1,7 @@ package jcgp.backend.population; import java.util.ArrayList; -import java.util.Arrays; -import jcgp.backend.exceptions.InsufficientConnectionsException; import jcgp.backend.function.Function; @@ -22,7 +20,11 @@ public class Node extends Gene implements MutableElement, Connection { @Override public Object getValue() { - return function.run(Arrays.copyOfRange(connections, 0, function.getArity())); + Object[] args = new Object[function.getArity()]; + for (int i = 0; i < function.getArity(); i++) { + args[i] = connections[i].getValue(); + } + return function.run(args); } public void setFunction(Function newFunction) { @@ -31,23 +33,18 @@ public class Node extends Gene implements MutableElement, Connection { @Override public void setConnection(int index, Connection newConnection) { - if (newConnection instanceof Node) { - if (((Node) newConnection).getColumn() < column) { - connections[index] = newConnection; - chromosome.recomputeActiveNodes(); - } - } else if (newConnection instanceof Input) { + if (newConnection != null) { connections[index] = newConnection; chromosome.recomputeActiveNodes(); } } - public void initialise(Function newFunction, Connection ... newConnections) throws InsufficientConnectionsException { + public void initialise(Function newFunction, Connection ... newConnections) { function = newFunction; if (newConnections.length == chromosome.getResources().arity()) { connections = newConnections; } else { - throw new InsufficientConnectionsException(); + throw new IllegalArgumentException("Received " + newConnections.length + " connections but needed exactly " + chromosome.getResources().arity()); } } |