} catch (Exception e) {
fail("wrong exception caught: " + e.getMessage());
}
count = 0;
PointCostPair optimum =
nm.minimize(rosenbrock, 100, new ValueChecker(1.0e-3),
new double[][] {
{ -1.2, 1.0 }, { 0.9, 1.2 }, { 3.5, -2.3 }
}, 10, 1642738l);
assertTrue(count > 700);
assertTrue(count < 800);
assertEquals(0.0, optimum.getCost(), 5.0e-5);
assertEquals(1.0, optimum.getPoint()[0], 0.01);
assertEquals(1.0, optimum.getPoint()[1], 0.01);
PointCostPair[] minima = nm.getMinima();
assertEquals(10, minima.length);
assertNotNull(minima[0]);
assertNull(minima[minima.length - 1]);
for (int i = 0; i < minima.length; ++i) {
if (minima[i] == null) {
if ((i + 1) < minima.length) {
assertTrue(minima[i+1] == null);
}
} else {
if (i > 0) {
assertTrue(minima[i-1].getCost() <= minima[i].getCost());
}
}
}
RandomGenerator rg = new JDKRandomGenerator();
rg.setSeed(64453353l);
RandomVectorGenerator rvg =
new UncorrelatedRandomVectorGenerator(new double[] { 0.9, 1.1 },
new double[] { 0.2, 0.2 },
new UniformRandomGenerator(rg));
optimum =
nm.minimize(rosenbrock, 100, new ValueChecker(1.0e-3), rvg);
assertEquals(0.0, optimum.getCost(), 2.0e-4);
optimum =
nm.minimize(rosenbrock, 100, new ValueChecker(1.0e-3), rvg, 3);
assertEquals(0.0, optimum.getCost(), 3.0e-5);
}