NelderMead optimizer = new NelderMead();
optimizer.setConvergenceChecker(new SimpleScalarValueChecker(1.0e-10, 1.0e-30));
optimizer.setMaxIterations(100);
optimizer.setStartConfiguration(new double[] { 0.2, 0.2 });
RealPointValuePair optimum;
// minimization
optimum = optimizer.optimize(fourExtrema, GoalType.MINIMIZE, new double[] { -3.0, 0 });
assertEquals(xM, optimum.getPoint()[0], 2.0e-7);
assertEquals(yP, optimum.getPoint()[1], 2.0e-5);
assertEquals(valueXmYp, optimum.getValue(), 6.0e-12);
assertTrue(optimizer.getEvaluations() > 60);
assertTrue(optimizer.getEvaluations() < 90);
optimum = optimizer.optimize(fourExtrema, GoalType.MINIMIZE, new double[] { +1, 0 });
assertEquals(xP, optimum.getPoint()[0], 5.0e-6);
assertEquals(yM, optimum.getPoint()[1], 6.0e-6);
assertEquals(valueXpYm, optimum.getValue(), 1.0e-11);
assertTrue(optimizer.getEvaluations() > 60);
assertTrue(optimizer.getEvaluations() < 90);
// maximization
optimum = optimizer.optimize(fourExtrema, GoalType.MAXIMIZE, new double[] { -3.0, 0.0 });
assertEquals(xM, optimum.getPoint()[0], 1.0e-5);
assertEquals(yM, optimum.getPoint()[1], 3.0e-6);
assertEquals(valueXmYm, optimum.getValue(), 3.0e-12);
assertTrue(optimizer.getEvaluations() > 60);
assertTrue(optimizer.getEvaluations() < 90);
optimum = optimizer.optimize(fourExtrema, GoalType.MAXIMIZE, new double[] { +1, 0 });
assertEquals(xP, optimum.getPoint()[0], 4.0e-6);
assertEquals(yP, optimum.getPoint()[1], 5.0e-6);
assertEquals(valueXpYp, optimum.getValue(), 7.0e-12);
assertTrue(optimizer.getEvaluations() > 60);
assertTrue(optimizer.getEvaluations() < 90);
}