public void ConstructorTest8()
{
/// This problem is taken from page 66 of Hock and Schittkowski's book Test
/// Examples for Nonlinear Programming Codes. It is their test problem Number
/// 43, and has the name Rosen-Suzuki.
var function = new NonlinearObjectiveFunction(4, x => x[0] * x[0]
+ x[1] * x[1] + 2.0 * x[2] * x[2]
+ x[3] * x[3] - 5.0 * x[0] - 5.0 * x[1]
- 21.0 * x[2] + 7.0 * x[3]);
NonlinearConstraint[] constraints =
{
new NonlinearConstraint(4, x=> 8.0 - x[0] * x[0]
- x[1] * x[1] - x[2] * x[2] - x[3] * x[3] - x[0] + x[1] - x[2] + x[3]),
new NonlinearConstraint(4, x => 10.0 - x[0] * x[0]
- 2.0 * x[1] * x[1] - x[2] * x[2] - 2.0 * x[3] * x[3] + x[0] + x[3]),
new NonlinearConstraint(4, x => 5.0 - 2.0 * x[0] * x[0]
- x[1] * x[1] - x[2] * x[2] - 2.0 * x[0] + x[1] + x[3])
};
Cobyla cobyla = new Cobyla(function, constraints);
Assert.IsTrue(cobyla.Minimize());
double minimum = cobyla.Value;
double[] solution = cobyla.Solution;
double[] expected =
{
0.0, 1.0, 2.0, -1.0
};
for (int i = 0; i < expected.Length; i++)
Assert.AreEqual(expected[i], cobyla.Solution[i], 1e-4);
Assert.AreEqual(-44, minimum, 1e-10);
double expectedMinimum = function.Function(cobyla.Solution);
Assert.AreEqual(expectedMinimum, minimum);
}