package ec.gp.syntactic.simplification.numeric;

import ec.EvolutionState;
import ec.app.semanticGP.func.IConstant;
import ec.app.semanticGP.func.numeric.Div;
import ec.gp.GPNode;
import ec.gp.semantic.ISemantics;
import ec.gp.semantic.func.SimpleNodeBase;
import ec.gp.syntactic.simplification.IRule;
import ec.util.Parameter;

class DivZeroRule implements IRule {

	@Override
	public void setup(EvolutionState state, Parameter base) {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean match(GPNode subtree) {
		if (!(subtree instanceof Div))
			return false;

		if (!(subtree.children[0] instanceof IConstant && ((IConstant<Double>) subtree.children[0]).getConstant() == 0.0))
			return false;

		return true;
	}

	@Override
	public GPNode replace(GPNode subtree) {
		assert match(subtree) : "The given tree is not 0/p";

		return subtree.children[0]; // 0
	}

}
