aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/population/Node.java
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-03-23 18:05:13 +0000
committerEduardo Pedroni <ep625@york.ac.uk>2014-03-23 18:05:13 +0000
commit0c288cc1952809294c8d70d86b9f41b04878ac2e (patch)
treeef9671b711fe665a3156594663c083595861a4e6 /src/jcgp/population/Node.java
parentd3527a63e12c0e5288f1e7d2e2dc18e61d16b760 (diff)
Majorly refactored, node grid is fully implemented. About to attempt active path locking.
Diffstat (limited to 'src/jcgp/population/Node.java')
-rw-r--r--src/jcgp/population/Node.java75
1 files changed, 45 insertions, 30 deletions
diff --git a/src/jcgp/population/Node.java b/src/jcgp/population/Node.java
index 9fafe32..d7013d3 100644
--- a/src/jcgp/population/Node.java
+++ b/src/jcgp/population/Node.java
@@ -1,51 +1,58 @@
package jcgp.population;
import java.util.ArrayList;
-import java.util.Arrays;
-import jcgp.Utilities;
+import javafx.beans.property.SimpleObjectProperty;
import jcgp.exceptions.InsufficientConnectionsException;
-import jcgp.modules.function.Function;
-import jcgp.parameters.Parameters;
+import jcgp.function.Function;
-public class Node implements MutableElement, Connection {
+public class Node extends Gene implements MutableElement, Connection {
- private Function function;
- private Connection[] connections;
+ private SimpleObjectProperty<Function> function;
+ private ArrayList<SimpleObjectProperty<Connection>> connections;
private int column, row;
private Chromosome chromosome;
- public Node(Chromosome chromosome, int row, int column) {
+ public Node(Chromosome chromosome, int row, int column, int arity) {
+ this.function = new SimpleObjectProperty<Function>();
this.chromosome = chromosome;
this.column = column;
this.row = row;
- this.connections = new Connection[((int) Parameters.get("maxArity").getValue())];
+ this.connections = new ArrayList<SimpleObjectProperty<Connection>>(arity);
+ for (int c = 0; c < arity; c++) {
+ connections.add(new SimpleObjectProperty<Connection>());
+ }
}
@Override
public Object getValue() {
//System.out.print("Calculating node: (" + row + ", " + column + ") > ");
- return function.run(Arrays.copyOfRange(connections, 0, function.getArity()));
+ Connection[] list = new Connection[function.get().getArity()];
+ for (int i = 0; i < list.length; i++) {
+ list[i] = connections.get(i).get();
+ }
+
+ return function.get().run(list);
}
public void setFunction(Function newFunction) {
- function = newFunction;
+ function.set(newFunction);
chromosome.recomputeActiveNodes();
}
@Override
- public void setConnection(Connection newConnection) {
- connections[Utilities.getRandomInt(connections.length)] = newConnection;
+ public void setConnection(int index, Connection newConnection) {
+ connections.get(index).set(newConnection);
chromosome.recomputeActiveNodes();
}
public void initialise(Function newFunction, Connection ... newConnections) throws InsufficientConnectionsException {
-
- function = newFunction;
-
- if (newConnections.length >= ((int) Parameters.get("maxArity").getValue())) {
- connections = newConnections;
+ function.set(newFunction);
+ if (newConnections.length >= connections.size()) {
+ for (int i = 0; i < connections.size(); i++) {
+ connections.get(i).set(newConnections[i]);
+ }
} else {
throw new InsufficientConnectionsException();
}
@@ -60,20 +67,28 @@ public class Node implements MutableElement, Connection {
}
public Function getFunction() {
+ return function.get();
+ }
+
+ public SimpleObjectProperty<Function> functionProperty() {
return function;
}
+ public ArrayList<SimpleObjectProperty<Connection>> connections() {
+ return connections;
+ }
+
public Connection getConnection(int index) {
- return connections[index];
+ return connections.get(index).get();
}
public void getActive(ArrayList<Node> activeNodes) {
if (!activeNodes.contains(this)) {
activeNodes.add(this);
}
- for (int i = 0; i < function.getArity(); i++) {
- if (connections[i] instanceof Node) {
- ((Node) connections[i]).getActive(activeNodes);
+ for (int i = 0; i < function.get().getArity(); i++) {
+ if (connections.get(i).get() instanceof Node) {
+ ((Node) connections.get(i).get()).getActive(activeNodes);
}
}
@@ -84,17 +99,17 @@ public class Node implements MutableElement, Connection {
if (this != m) {
if (m instanceof Node) {
Node n = (Node) m;
- if (function == n.getFunction()) {
+ if (function.get() == n.getFunction()) {
if (column == n.getColumn() && row == n.getRow()) {
- for (int i = 0; i < connections.length; i++) {
- if (connections[i] != n.getConnection(i)) {
- if (connections[i] instanceof Input && n.getConnection(i) instanceof Input) {
- if (((Input) connections[i]).getIndex() != ((Input) n.getConnection(i)).getIndex()) {
+ for (int i = 0; i < connections.size(); i++) {
+ if (connections.get(i).get() != n.getConnection(i)) {
+ if (connections.get(i).get() instanceof Input && n.getConnection(i) instanceof Input) {
+ if (((Input) connections.get(i).get()).getIndex() != ((Input) n.getConnection(i)).getIndex()) {
return false;
}
- } else if (connections[i] instanceof Node && n.getConnection(i) instanceof Node) {
- if (((Node) connections[i]).getRow() != ((Node) n.getConnection(i)).getRow() &&
- ((Node) connections[i]).getColumn() != ((Node) n.getConnection(i)).getColumn()) {
+ } else if (connections.get(i).get() instanceof Node && n.getConnection(i) instanceof Node) {
+ if (((Node) connections.get(i).get()).getRow() != ((Node) n.getConnection(i)).getRow() &&
+ ((Node) connections.get(i).get()).getColumn() != ((Node) n.getConnection(i)).getColumn()) {
return false;
}
} else {