package ec.app.complexregression.func;

import org.apache.commons.math3.complex.Complex;

import ec.EvolutionState;
import ec.Problem;
import ec.app.complexregression.ComplexData;
import ec.gp.ADFStack;
import ec.gp.GPData;
import ec.gp.GPIndividual;
import ec.gp.GPNode;

public class Pow extends GPNode {

	@Override
	public String toString() {
		return "^";
	}

	@Override
	public void eval(EvolutionState state, int thread, GPData input, ADFStack stack, GPIndividual individual,
			Problem problem) {
		ComplexData data = (ComplexData) input;

		children[0].eval(state, thread, input, stack, individual, problem);
		if(data.x.equals(Complex.ZERO)) {
			// keep current x value (0 + 0i)
		} else {
			Complex x = data.x;
			children[1].eval(state, thread, input, stack, individual, problem);
			//Complex y = data.x;
			data.x = x.pow(data.x);
			data.x = ComplexData.fixInfinity(data.x);
		}
	}

}
