aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/population/Node.java
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-01-31 16:45:45 +0000
committerEduardo Pedroni <ep625@york.ac.uk>2014-01-31 16:45:45 +0000
commit2343cc0e456e0306711c0a7218d3027f17cffee7 (patch)
treeefb26576ff4a283a87bd4b56deb9aba175924cfe /src/jcgp/population/Node.java
parenta02f1fff03ab58416da812597e67a0c7e21fdbd5 (diff)
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.
Diffstat (limited to 'src/jcgp/population/Node.java')
-rw-r--r--src/jcgp/population/Node.java20
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();
+ }
}
-
}