blob: 8958475861e03ddb458f913d2c6b45e2fbe5f1bb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package jcgp.population;
import jcgp.CGP.Utilities;
import jcgp.function.Function;
public class Node implements MutableElement, Connection {
private Function function;
private Connection[] connections;
@Override
public int evaluate() {
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();
}
}
}
|