package pokus.sd;

import org.spaceroots.mantissa.optimization.ConvergenceChecker;
import org.spaceroots.mantissa.optimization.PointCostPair;

public class ValueChecker implements ConvergenceChecker {

	public ValueChecker(double threshold) {
		this.threshold = threshold;
	}

	public boolean converged(PointCostPair[] simplex) {
		PointCostPair smallest = simplex[0];
		PointCostPair largest = simplex[simplex.length - 1];
		return ((largest.cost - smallest.cost) / (simplex.length
				* simplex.length / 2)) < threshold;
	}

	private double threshold;

};