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 Sub extends BinaryNode<Double> {

	private static final String MINUS = "-";

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

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

	@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) {
		switch (missingArgIdx) {
			case 0:
				return new Double[] { output + restOfArguments[0] };
			case 1:
			default:
				return new Double[] { restOfArguments[0] - output };
		}
	}

}
