package ec.app.semanticGP.func.numeric;

import ec.EvolutionState;
import ec.app.semanticGP.func.IConstant;
import ec.gp.GPNode;
import ec.gp.semantic.DoubleSemantics;
import ec.gp.semantic.ISemanticProblem;
import ec.gp.semantic.ISemantics;
import ec.gp.semantic.func.NullaryNode;
import ec.util.Parameter;
import library.semantics.TestCase;

import java.util.Arrays;
import java.util.List;

/**
 * @author Tomasz Pawlak
 */
public class Two extends NullaryNode<Double> implements IConstant<Double> {

	private static final String TWO = "2";

	private ISemantics semantics;

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

	@Override
	protected ISemantics execute(ISemantics... arguments) {
		ISemanticProblem<Double> problem = (ISemanticProblem<Double>) state.evaluator.p_problem;
		List<TestCase<Double>> cases = problem.getFitnessCases();

		double[] semantics = new double[cases.size()];
		Arrays.fill(semantics, 2.0);

		return new DoubleSemantics(semantics);
	}

	@Override
	public int nodeHashCode() {
		return this.getConstant().hashCode();
	}

	@Override
	public boolean nodeEquals(GPNode node) {
		if (!(node instanceof IConstant))
			return false;

		IConstant<Double> other = (IConstant<Double>) node;
		return this.getConstant() == other.getConstant();
	}

	@Override
	public Double getConstant() {
		return 2.0;
	}
}
