aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/population/Output.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/backend/population/Output.java')
-rw-r--r--src/jcgp/backend/population/Output.java51
1 files changed, 37 insertions, 14 deletions
diff --git a/src/jcgp/backend/population/Output.java b/src/jcgp/backend/population/Output.java
index 938741b..a346d4a 100644
--- a/src/jcgp/backend/population/Output.java
+++ b/src/jcgp/backend/population/Output.java
@@ -8,6 +8,10 @@ import java.util.ArrayList;
* returns the value of its single connection, but it
* may not be connected to - it terminates a chromosome
* active connection path.
+ * <br><br>
+ * When mutating an output, it is easiest to use {@code mutate()}.
+ * Alternatively, you may also perform a specific mutation using
+ * {@code setSource(...)}.
*
* @author Eduardo Pedroni
*
@@ -37,34 +41,47 @@ public class Output implements Mutable {
return source.getValue();
}
+ /**
+ * @return this output's index.
+ */
public int getIndex() {
return index;
}
+
+ /**
+ * This method sets the output source to the specified connection.
+ *
+ * @param newConnection the {@code Connection} to connect to.
+ */
+ public void setSource(Connection newConnection) {
+ source = newConnection;
+ // trigger active path recomputation
+ chromosome.recomputeActiveNodes();
+ }
+ /**
+ * @return the source of this output's value.
+ */
public Connection getSource() {
return source;
}
+ /**
+ * Calls {@code getActive(...)} on this output's
+ * source. This kicks off a recursive process whereby
+ * all nodes connected to this output are added to the
+ * specified list of nodes. This is used to create a
+ * list of all active nodes.
+ *
+ * @param activeNodes the list to add all active nodes to.
+ */
public void getActiveNodes(ArrayList<Node> activeNodes) {
+ // do not add if the source is an input
if (source instanceof Node) {
((Node) source).getActive(activeNodes);
}
}
- /**
- * When mutating an output, the index parameter
- * is simply ignored and the output source is
- * set.
- *
- * @see jcgp.backend.population.Mutable#setConnection(int, jcgp.backend.population.Connection)
- */
- @Override
- public void setConnection(int index, Connection newConnection) {
- source = newConnection;
- // trigger active path recomputation
- chromosome.recomputeActiveNodes();
- }
-
@Override
public boolean copyOf(Mutable m) {
// both cannot be the same instance
@@ -94,6 +111,12 @@ public class Output implements Mutable {
}
@Override
+ public void mutate() {
+ // simply change output to a new, random connection
+ setSource(chromosome.getRandomConnection());
+ }
+
+ @Override
public String toString() {
return "Output " + index;
}