aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/population
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/population')
-rw-r--r--src/jcgp/population/Chromosome.java11
-rw-r--r--src/jcgp/population/Connection.java7
-rw-r--r--src/jcgp/population/Input.java9
-rw-r--r--src/jcgp/population/Node.java14
-rw-r--r--src/jcgp/population/Output.java7
5 files changed, 38 insertions, 10 deletions
diff --git a/src/jcgp/population/Chromosome.java b/src/jcgp/population/Chromosome.java
index 1f264f2..08ff9b9 100644
--- a/src/jcgp/population/Chromosome.java
+++ b/src/jcgp/population/Chromosome.java
@@ -104,7 +104,7 @@ public class Chromosome {
// populate with connections equivalent to clone
Connection copyConnection;
for (int i = 0; i < connections.length; i++) {
- copyConnection = clone.getNode(r, c).getConnections(i);
+ copyConnection = clone.getNode(r, c).getConnection(i);
if (copyConnection instanceof Input) {
connections[i] = inputs[((Input) copyConnection).getIndex()];
} else if (copyConnection instanceof Node) {
@@ -251,12 +251,11 @@ public class Chromosome {
recomputeActiveNodes = false;
activeNodes = new ArrayList<Connection>();
- for (int r = 0; r < nodes.length; r++) {
- for (int c = 0; c < nodes[r].length; c++) {
-
- }
+ for (Output output : outputs) {
+ output.getActiveNodes(activeNodes);
}
- }
+
+ }
return activeNodes;
}
diff --git a/src/jcgp/population/Connection.java b/src/jcgp/population/Connection.java
index 4e69e99..12e92d6 100644
--- a/src/jcgp/population/Connection.java
+++ b/src/jcgp/population/Connection.java
@@ -1,6 +1,11 @@
package jcgp.population;
+import java.util.ArrayList;
+
public interface Connection {
- public abstract int getValue();
+ public int getValue();
+
+ public void getActive(ArrayList<Connection> activeNodes);
+
}
diff --git a/src/jcgp/population/Input.java b/src/jcgp/population/Input.java
index ee008ce..f3199b8 100644
--- a/src/jcgp/population/Input.java
+++ b/src/jcgp/population/Input.java
@@ -1,5 +1,7 @@
package jcgp.population;
+import java.util.ArrayList;
+
public class Input implements Connection {
private int value = 0, index;
@@ -21,4 +23,11 @@ public class Input implements Connection {
return index;
}
+ @Override
+ public void getActive(ArrayList<Connection> activeNodes) {
+ if (!activeNodes.contains(this)) {
+ activeNodes.add(this);
+ }
+ }
+
}
diff --git a/src/jcgp/population/Node.java b/src/jcgp/population/Node.java
index 40ffa52..c09532c 100644
--- a/src/jcgp/population/Node.java
+++ b/src/jcgp/population/Node.java
@@ -1,5 +1,7 @@
package jcgp.population;
+import java.util.ArrayList;
+
import jcgp.Parameters;
import jcgp.Utilities;
import jcgp.function.Function;
@@ -58,7 +60,17 @@ public class Node implements MutableElement, Connection {
return function;
}
- public Connection getConnections(int index) {
+ 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);
+ }
+ }
}
diff --git a/src/jcgp/population/Output.java b/src/jcgp/population/Output.java
index 68045b0..b3cb648 100644
--- a/src/jcgp/population/Output.java
+++ b/src/jcgp/population/Output.java
@@ -1,5 +1,7 @@
package jcgp.population;
+import java.util.ArrayList;
+
public class Output implements MutableElement {
@@ -29,7 +31,8 @@ public class Output implements MutableElement {
public Connection getSource() {
return source;
}
-
-
+ public void getActiveNodes(ArrayList<Connection> activeNodes) {
+ source.getActive(activeNodes);
+ }
}