package jcgp.population; import java.util.ArrayList; public class Output implements MutableElement { private Connection source; private Chromosome chromosome; private int index; public Output(Chromosome chromosome, int index) { this.chromosome = chromosome; this.index = index; } public int calculate() { return source.getValue(); } @Override public void setConnection(Connection newConnection) { source = newConnection; chromosome.recomputeActiveNodes(); } public int getIndex() { return index; } public Connection getSource() { return source; } public void getActiveNodes(ArrayList activeNodes) { if (source instanceof Node) { ((Node) source).getActive(activeNodes); } } @Override public boolean copyOf(MutableElement m) { if (this != m) { if (m instanceof Output) { Output o = (Output) m; if (index == o.getIndex()) { if (source != o.getSource()) { if (source instanceof Input && o.getSource() instanceof Input) { if (((Input) source).getIndex() == ((Input) o.getSource()).getIndex()) { return true; } } else if (source instanceof Node && o.getSource() instanceof Node) { if (((Node) source).getRow() == ((Node) o.getSource()).getRow() && ((Node) source).getColumn() == ((Node) o.getSource()).getColumn()) { return true; } } } } } } return false; } }