package ec.app.semanticGP.func.numeric;

import ec.EvolutionState;
import ec.Problem;
import ec.app.semanticGP.RegressionData;
import ec.gp.ADFStack;
import ec.gp.GPData;
import ec.gp.GPIndividual;
import ec.gp.semantic.DoubleSemantics;
import ec.gp.semantic.ISemantics;
import ec.gp.semantic.func.BinaryNode;

public final class Sum extends BinaryNode<Double> {

	private static final String PLUS = "+";

	@Override
	public String toString() {
		return PLUS;
	}

	@Override
	public boolean isSymmetric() {
		return true;
	}

	@Override
	protected ISemantics execute(ISemantics... arguments) {
		double[] arg0 = (double[]) arguments[0].getValue();
		double[] arg1 = (double[]) arguments[1].getValue();
		double[] semantics = new double[arg0.length];

		for (int i = 0; i < semantics.length; ++i) {
			semantics[i] = arg0[i] + arg1[i];
		}

		return new DoubleSemantics(semantics);
	}

	@Override
	public Double[] invert(Double output, int missingArgIdx, Double... restOfArguments) {
		assert restOfArguments.length + 1 == this.children.length;
		return new Double[] { output - restOfArguments[0] };
	}

}
