Accord.Tests.Math.CobylaTest.ConstructorTest9 C# (CSharp) Method

ConstructorTest9() private method

private ConstructorTest9 ( ) : void
return void
        public void ConstructorTest9()
        {
            /// This problem is taken from page 111 of Hock and Schittkowski's
            /// book Test Examples for Nonlinear Programming Codes. It is their
            /// test problem Number 100.
            /// 
            var function = new NonlinearObjectiveFunction(7, x =>
                Math.Pow(x[0] - 10.0, 2.0) + 5.0 * Math.Pow(x[1] - 12.0, 2.0) + Math.Pow(x[2], 4.0) +
                3.0 * Math.Pow(x[3] - 11.0, 2.0) + 10.0 * Math.Pow(x[4], 6.0) + 7.0 * x[5] * x[5] + Math.Pow(x[6], 4.0) -
                4.0 * x[5] * x[6] - 10.0 * x[5] - 8.0 * x[6]);

            NonlinearConstraint[] constraints = 
            {
                new NonlinearConstraint(7, x => 127.0 - 2.0 * x[0] * x[0] - 3.0 * Math.Pow(x[1], 4.0)
                    - x[2] - 4.0 * x[3] * x[3] - 5.0 * x[4]),
                new NonlinearConstraint(7, x => 282.0 - 7.0 * x[0] - 3.0 * x[1] - 10.0 * x[2] * x[2] - x[3] + x[4]),
                new NonlinearConstraint(7, x => 196.0 - 23.0 * x[0] - x[1] * x[1] - 6.0 * x[5] * x[5] + 8.0 * x[6]),
                new NonlinearConstraint(7, x => -4.0 * x[0] * x[0] - x[1] * x[1] + 3.0 * x[0] * x[1] 
                    - 2.0 * x[2] * x[2] - 5.0 * x[5] + 11.0 * x[6])
            };

            Cobyla cobyla = new Cobyla(function, constraints);

            Assert.IsTrue(cobyla.Minimize());
            double minimum = cobyla.Value;
            double[] solution = cobyla.Solution;

            double[] expected = 
            {
                2.330499, 1.951372, -0.4775414, 4.365726, -0.624487, 1.038131, 1.594227
            };

            for (int i = 0; i < expected.Length; i++)
                Assert.AreEqual(expected[i], cobyla.Solution[i], 1e-4);
            Assert.AreEqual(680.63005737443393, minimum, 1e-6);

            double expectedMinimum = function.Function(cobyla.Solution);
            Assert.AreEqual(expectedMinimum, minimum);
        }