package ec.gp.semantic.breed.nguyen;

import ec.EvolutionState;
import ec.gp.breed.GPBreedDefaults;
import ec.gp.semantic.ISemantics;
import ec.util.Parameter;

public class SSC extends SAC {

	private static final Parameter DEFAULT_BASE = GPBreedDefaults.base().push("SSC");
	protected static final String SENSITIVITY_LOW = "sensitivityLow";
	protected static final String SENSITIVITY_HIGH = "sensitivityHigh";

	protected double sensitivityLow = 0.002;
	protected double sensitivityHigh = 8;

	@Override
	public Parameter defaultBase() {
		return DEFAULT_BASE;
	}

	@Override
	public void setup(final EvolutionState state, final Parameter base) {
		super.setup(state, base);

		this.sensitivityLow = state.parameters.getDouble(base.push(SENSITIVITY_LOW),
				defaultBase().push(SENSITIVITY_LOW));
		this.sensitivityHigh = state.parameters.getDouble(base.push(SENSITIVITY_HIGH),
				defaultBase().push(SENSITIVITY_HIGH));
	}

	@Override
	protected boolean isEquivalent(final ISemantics semantics1, final ISemantics semantics2) {
		double diff = semantics1.distanceTo(semantics2);

		// let negate the condition, because crossover is canceled when this method returns true
		return !(this.sensitivityLow < diff && diff < this.sensitivityHigh);
	}
}
