package jcgp.population; import java.util.ArrayList; import javafx.beans.property.SimpleObjectProperty; public class Output extends Gene implements MutableElement { private SimpleObjectProperty source; private Chromosome chromosome; private int index; public Output(Chromosome chromosome, int index) { this.chromosome = chromosome; this.index = index; this.source = new SimpleObjectProperty(); } public Object calculate() { Object result = source.getValue(); return result; } @Override public void setConnection(int index, Connection newConnection) { source.set(newConnection); chromosome.recomputeActiveNodes(); } public int getIndex() { return index; } public Connection getSource() { return source.get(); } public SimpleObjectProperty sourceProperty() { return source; } public void getActiveNodes(ArrayList activeNodes) { if (source.get() instanceof Node) { ((Node) source.get()).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.get() != o.getSource()) { if (source.get() instanceof Input && o.getSource() instanceof Input) { if (((Input) source.get()).getIndex() == ((Input) o.getSource()).getIndex()) { return true; } } else if (source.get() instanceof Node && o.getSource() instanceof Node) { if (((Node) source.get()).getRow() == ((Node) o.getSource()).getRow() && ((Node) source.get()).getColumn() == ((Node) o.getSource()).getColumn()) { return true; } } } } } } return false; } }