blob: c09532c42d8e901bdcb64395676bd97da1401ed7 (
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
package jcgp.population;
import java.util.ArrayList;
import jcgp.Parameters;
import jcgp.Utilities;
import jcgp.function.Function;
public class Node implements MutableElement, Connection {
private Function function;
private Connection[] connections;
private int column, row;
private Chromosome chromosome;
public Node(Chromosome chromosome, int row, int column) {
this.chromosome = chromosome;
this.column = column;
this.row = row;
}
@Override
public int getValue() {
return function.run(connections);
}
public void setFunction(Function newFunction) {
function = newFunction;
chromosome.recomputeActiveNodes();
}
@Override
public void setConnection(Connection newConnection) {
connections[Utilities.getRandomInt(connections.length)] = newConnection;
chromosome.recomputeActiveNodes();
}
public void initialise(Function newFunction, Connection ... newConnections) throws InsufficientConnectionsException {
function = newFunction;
if (newConnections.length >= Parameters.getMaxArity()) {
connections = newConnections;
} else {
throw new InsufficientConnectionsException();
}
}
public int getColumn() {
return column;
}
public int getRow() {
return row;
}
public Function getFunction() {
return function;
}
public Connection getConnection(int index) {
return connections[index];
}
@Override
public void getActive(ArrayList<Connection> activeNodes) {
if (!activeNodes.contains(this)) {
activeNodes.add(this);
}
for (int i = 0; i < function.getArity(); i++) {
connections[i].getActive(activeNodes);
}
}
}
|