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.java49
1 files changed, 40 insertions, 9 deletions
diff --git a/src/jcgp/backend/population/Output.java b/src/jcgp/backend/population/Output.java
index d876951..ab693e2 100644
--- a/src/jcgp/backend/population/Output.java
+++ b/src/jcgp/backend/population/Output.java
@@ -2,26 +2,39 @@ package jcgp.backend.population;
import java.util.ArrayList;
-public class Output extends Gene implements MutableElement {
+/**
+ * This is a chromosome output. Outputs are a special
+ * type of mutable element with a single connection. It
+ * returns the value of its single connection, but it
+ * may not be connected to - it terminates a chromosome
+ * active connection path.
+ *
+ * @author Eduardo Pedroni
+ *
+ */
+public class Output implements MutableElement {
private Connection source;
private Chromosome chromosome;
private int index;
+ /**
+ * Makes a new instance of {@code Output} with the
+ * specified arguments.
+ *
+ * @param chromosome the chromosome this output belongs to.
+ * @param index the output index.
+ */
public Output(Chromosome chromosome, int index) {
this.chromosome = chromosome;
this.index = index;
}
+ /**
+ * @return the value of the output's source.
+ */
public Object calculate() {
- Object result = source.getValue();
- return result;
- }
-
- @Override
- public void setConnection(int index, Connection newConnection) {
- source = newConnection;
- chromosome.recomputeActiveNodes();
+ return source.getValue();
}
public int getIndex() {
@@ -38,12 +51,30 @@ public class Output extends Gene implements MutableElement {
}
}
+ /**
+ * When mutating an output, the index parameter
+ * is simply ignored and the output source is
+ * set.
+ *
+ * @see jcgp.backend.population.MutableElement#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(MutableElement m) {
+ // both cannot be the same instance
if (this != m) {
+ // element must be instance of output
if (m instanceof Output) {
Output o = (Output) m;
+ // index must be the same
if (index == o.getIndex()) {
+ // source must be the same
if (source != o.getSource()) {
if (source instanceof Input && o.getSource() instanceof Input) {
if (((Input) source).getIndex() == ((Input) o.getSource()).getIndex()) {