aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/population/Node.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/population/Node.java')
-rw-r--r--src/jcgp/population/Node.java114
1 files changed, 0 insertions, 114 deletions
diff --git a/src/jcgp/population/Node.java b/src/jcgp/population/Node.java
deleted file mode 100644
index 141a32a..0000000
--- a/src/jcgp/population/Node.java
+++ /dev/null
@@ -1,114 +0,0 @@
-package jcgp.population;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-
-import jcgp.exceptions.InsufficientConnectionsException;
-import jcgp.function.Function;
-
-
-public class Node extends Gene implements MutableElement, Connection {
-
- private Function function;
- private Connection[] connections;
- private int column, row;
- private Chromosome chromosome;
-
- public Node(Chromosome chromosome, int row, int column, int arity) {
- this.chromosome = chromosome;
- this.column = column;
- this.row = row;
- }
-
- @Override
- public Object getValue() {
- //System.out.print("Calculating node: (" + row + ", " + column + ") > ");
- return function.run(Arrays.copyOfRange(connections, 0, function.getArity()));
- }
-
- public void setFunction(Function newFunction) {
- function = newFunction;
- chromosome.recomputeActiveNodes();
- }
-
- @Override
- public void setConnection(int index, Connection newConnection) {
- connections[index] = newConnection;
- chromosome.recomputeActiveNodes();
- }
-
- public void initialise(Function newFunction, Connection ... newConnections) throws InsufficientConnectionsException {
- function = newFunction;
- if (newConnections.length == function.getArity()) {
- 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];
- }
-
- 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);
- }
-
- }
- }
-
- @Override
- public boolean copyOf(MutableElement m) {
- if (this != m) {
- if (m instanceof Node) {
- Node n = (Node) m;
- if (function == 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()) {
- 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()) {
- return false;
- }
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
- return true;
- }
- }
- }
- }
- return false;
- }
-
- @Override
- public String getDescription() {
- return "n: " + row + ", " + column;
- }
-}