public class UnivariateMultiStartOptimizerTest {
@Test
public void testSinMin() {
UnivariateFunction f = new SinFunction();
UnivariateOptimizer underlying = new BrentOptimizer(1e-10, 1e-14);
JDKRandomGenerator g = new JDKRandomGenerator();
g.setSeed(44428400075l);
UnivariateMultiStartOptimizer<UnivariateFunction> optimizer =
new UnivariateMultiStartOptimizer<UnivariateFunction>(underlying, 10, g);
optimizer.optimize(300, f, GoalType.MINIMIZE, -100.0, 100.0);
UnivariatePointValuePair[] optima = optimizer.getOptima();
for (int i = 1; i < optima.length; ++i) {
double d = (optima[i].getPoint() - optima[i-1].getPoint()) / (2 * FastMath.PI);
Assert.assertTrue(FastMath.abs(d - FastMath.rint(d)) < 1.0e-8);
Assert.assertEquals(-1.0, f.value(optima[i].getPoint()), 1.0e-10);
Assert.assertEquals(f.value(optima[i].getPoint()), optima[i].getValue(), 1.0e-10);
}
Assert.assertTrue(optimizer.getEvaluations() > 200);
Assert.assertTrue(optimizer.getEvaluations() < 300);
}