aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/population
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/backend/population')
-rw-r--r--src/jcgp/backend/population/Chromosome.java4
-rw-r--r--src/jcgp/backend/population/Node.java57
2 files changed, 28 insertions, 33 deletions
diff --git a/src/jcgp/backend/population/Chromosome.java b/src/jcgp/backend/population/Chromosome.java
index e28032c..d84c5f0 100644
--- a/src/jcgp/backend/population/Chromosome.java
+++ b/src/jcgp/backend/population/Chromosome.java
@@ -112,13 +112,11 @@ public class Chromosome implements Comparable<Chromosome> {
inputs[i] = new Input(i);
}
- int arity = resources.arity();
-
// rows first
nodes = new Node[(resources.rows())][(resources.columns())];
for (int r = 0; r < nodes.length; r++) {
for (int c = 0; c < nodes[r].length; c++) {
- nodes[r][c] = new Node(this, r, c, arity);
+ nodes[r][c] = new Node(this, r, c);
}
}
outputs = new Output[resources.outputs()];
diff --git a/src/jcgp/backend/population/Node.java b/src/jcgp/backend/population/Node.java
index 7712c50..6696694 100644
--- a/src/jcgp/backend/population/Node.java
+++ b/src/jcgp/backend/population/Node.java
@@ -40,24 +40,14 @@ public class Node implements Mutable, Connection {
* @param chromosome the chromosome this node belongs to.
* @param row the node's row.
* @param column the node's column.
- * @param arity the maximum arity of the experiment.
*/
- public Node(Chromosome chromosome, int row, int column, int arity) {
+ public Node(Chromosome chromosome, int row, int column) {
this.chromosome = chromosome;
this.column = column;
this.row = row;
}
/**
- * Sets the node function.
- *
- * @param newFunction the new function to set.
- */
- public void setFunction(Function newFunction) {
- function = newFunction;
- }
-
- /**
* Initialises the node with the specified values.
* The number of connections passed as argument must
* be exactly the same as the experiment arity, or
@@ -66,7 +56,7 @@ public class Node implements Mutable, Connection {
* @param newFunction the node function to set.
* @param newConnections the node connections to set.
*/
- public void initialise(Function newFunction, Connection ... newConnections) {
+ public void initialise(Function newFunction, Connection... newConnections) {
function = newFunction;
if (newConnections.length == chromosome.getResources().arity()) {
connections = newConnections;
@@ -97,12 +87,37 @@ public class Node implements Mutable, Connection {
}
/**
+ * Sets the node function.
+ *
+ * @param newFunction the new function to set.
+ */
+ public void setFunction(Function newFunction) {
+ function = newFunction;
+ }
+
+ /**
* @param index the connection to return.
* @return the indexed connection.
*/
public Connection getConnection(int index) {
return connections[index];
}
+
+ /**
+ * This method sets the indexed connection to the specified new connection.
+ * If the given connection is null or disrespects levels back, it is discarded
+ * and no connections are changed.
+ *
+ * @param index the connection index to set.
+ * @param newConnection the {@code Connection} to connect to.
+ */
+ public void setConnection(int index, Connection newConnection) {
+ // connection must not be null
+ if (newConnection != null) {
+ connections[index] = newConnection;
+ chromosome.recomputeActiveNodes();
+ }
+ }
/**
* For package use, this is a recursive method
@@ -127,24 +142,6 @@ public class Node implements Mutable, Connection {
}
}
}
-
- /**
- * This method sets the indexed connection to the specified new connection.
- * If the given connection is null or disrespects levels back, it is discarded
- * and no connections are changed.
- *
- * @param index the connection index to set.
- * @param newConnection the {@code Connection} to connect to.
- */
- public void setConnection(int index, Connection newConnection) {
- // connection must not be null
- if (newConnection != null) {
- //if () {
- connections[index] = newConnection;
- chromosome.recomputeActiveNodes();
- //}
- }
- }
@Override
public boolean copyOf(Mutable element) {