package ec.gp.syntactic.simplification.logic;

import ec.EvolutionState;
import ec.app.semanticGP.func.logic.And;
import ec.app.semanticGP.func.logic.Inv;
import ec.app.semanticGP.func.logic.Or;
import ec.gp.GPNode;
import ec.gp.syntactic.simplification.IRule;
import ec.util.Parameter;

class OrNotNotRule implements IRule {

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

	}

	@Override
	public boolean match(GPNode subtree) {
		if (!(subtree instanceof Or))
			return false;
		
		return subtree.children[0] instanceof Inv && subtree.children[1] instanceof Inv;
	}

	@Override
	public GPNode replace(GPNode subtree) {
		assert match(subtree) : "The given tree is not a form of (not(p) or not(q))";
		
		And and = new And();
		and.children = new GPNode[] { subtree.children[0].children[0], subtree.children[1].children[0]};
		
		Inv inv = new Inv();
		inv.children = new GPNode[] { and };
		
		return inv;
	}

}
